-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.rb
71 lines (58 loc) · 1.69 KB
/
app.rb
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# frozen_string_literal: true
module Flame
class CLI < Clamp::Command
class New < Clamp::Command
## Class for Flame Application
class App < Clamp::Command
using GorillaPatch::Inflections
parameter 'APP_NAME', 'application name'
def execute
@app_name = app_name
@module_name = @app_name.camelize
@short_module_name =
@module_name.split(/([[:upper:]][[:lower:]]*)/).map! { |s| s[0] }.join
@domain_name = @module_name.downcase
make_dir do
copy_template
grant_permissions
end
puts 'Done!'
system "cd #{@app_name}"
end
private
def make_dir(&block)
puts "Creating '#{@app_name}' directory..."
FileUtils.mkdir @app_name
FileUtils.cd @app_name, &block
end
def copy_template
puts 'Copy template directories and files...'
FileUtils.cp_r File.join(__dir__, '../../../../template/.'), '.'
clean_dirs
render_templates
end
def clean_dirs
puts 'Clean directories...'
FileUtils.rm Dir.glob('**/.keep', File::FNM_DOTMATCH)
end
def render_templates
puts 'Replace module names in template...'
Dir.glob('**/*.erb', File::FNM_DOTMATCH).sort.each do |file|
file_pathname = Pathname.new(file)
basename_pathname = file_pathname.sub_ext('')
puts "- #{basename_pathname}"
content = ERB.new(File.read(file)).result(binding)
File.write(basename_pathname, content)
FileUtils.rm file
end
end
PERMISSIONS = {}.freeze
def grant_permissions
return unless PERMISSIONS.any?
puts 'Grant permissions to files...'
PERMISSIONS.each { |file, permissions| File.chmod permissions, file }
end
end
end
end
end