Skip to content

Commit c2b9526

Browse files
committed
feat(template): add crystal-lua, start template impl
1 parent 7ce9002 commit c2b9526

3 files changed

Lines changed: 66 additions & 5 deletions

File tree

src/geode.cr

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
require "cling"
22
require "cling/ext"
33
require "colorize"
4+
require "crystal-lua"
45
require "file_utils"
56
require "license"
6-
require "lua"
77
require "shards/commands/install"
88
require "trigram"
99
require "wait_group"
@@ -14,6 +14,7 @@ require "./config"
1414
require "./shard"
1515
require "./shards/base"
1616
require "./shards/install"
17+
require "./template/*"
1718

1819
Colorize.on_tty_only!
1920

@@ -52,9 +53,7 @@ module Geode
5253
add_command Commands::Licenses.new
5354
add_command Commands::Run.new
5455
add_command Commands::Config.new
55-
{% if flag?(:templates) %}
56-
add_command Commands::Template.new
57-
{% end %}
56+
add_command Commands::Template.new
5857
add_command Commands::Help.new
5958
end
6059

src/main.cr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env crystal
21
require "./geode"
32

43
Geode::CLI.new.execute ARGV

src/template/template.cr

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
module Geode
2+
class Template
3+
include YAML::Serializable
4+
5+
getter name : String
6+
getter summary : String
7+
getter author : String
8+
getter version : String
9+
getter source : String?
10+
getter files : Array(String) = [] of String
11+
@[YAML::Field(ignore: true)]
12+
property? shell_execute : Bool = false
13+
14+
Dir.mkdir_p Config::TEMPLATES
15+
16+
def self.list : Array({String, String})
17+
info = [] of {String, String}
18+
19+
Dir.each_child(Config::TEMPLATES) do |name|
20+
next unless File.exists?(Config::TEMPLATES / name / "control.yml")
21+
next unless File.exists?(Config::TEMPLATES / name / "control.lua")
22+
23+
template = load name
24+
info << {name, template.version}
25+
end
26+
27+
info
28+
end
29+
30+
def self.exists?(name : String) : Bool
31+
File.exists?(Config::TEMPLATES / name / "control.yml") &&
32+
File.exists?(Config::TEMPLATES / name / "control.lua")
33+
end
34+
35+
def self.load(name : String) : self
36+
File.open(Config::TEMPLATES / name / "control.yml") do |file|
37+
Template.from_yaml file
38+
end
39+
end
40+
41+
def initialize(@name, @summary, @author, @source, @version, @files)
42+
end
43+
44+
def install(source : Path) : Nil
45+
Dir.mkdir_p(dest = Config::TEMPLATES / @name)
46+
File.copy(source / "control.yml", dest / "control.yml")
47+
File.copy(source / "control.lua", dest / "control.lua")
48+
49+
unless @files.empty?
50+
FileUtils.cp(@files.map { |f| source / f }, dest)
51+
end
52+
end
53+
54+
def run_script(output : IO) : Nil
55+
script = File.read Config::TEMPLATES / name / "control.lua"
56+
runner = Runner.new script, output
57+
runner.load_standard_functions
58+
end
59+
60+
def test_script(output : IO) : Nil
61+
end
62+
end
63+
end

0 commit comments

Comments
 (0)