-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile.rb
More file actions
37 lines (31 loc) · 821 Bytes
/
compile.rb
File metadata and controls
37 lines (31 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'yaml'
TARGET = 'bin/trails.rb'
CONFIGS = Dir['config/**/*.yml'].sort.map do |f|
const = File.basename(f, '.*').upcase.to_sym
"#{const} = #{YAML.load_file(f)}"
end.join "\n"
SNIPPETS = {}
Dir['snippets/**/*'].sort.each do |f|
sym = File.basename(f, '.*').to_sym
SNIPPETS[sym] = File.readlines(f).join
end
MODULES = Dir['modules/**/*.rb'].sort.map do |f|
File.read(f)
end.join "\n"
OUTPUT = <<-EOT
#{CONFIGS}
SNIPPETS = #{SNIPPETS}
#{MODULES}
@env = ask("What is type of the project? web/api : ").downcase
@env = "web" unless (["web", "api"]).include? @env
# add env propety to context instance
def self.env
@env
end
MODULES[self.env].each do |module_name|
klass = eval "\#{module_name}Module"
klass.call self
end
EOT
File.write(TARGET, OUTPUT)
puts "TRails compiled successfully. #{TARGET}"