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
|
# File 'lib/tumugi/command/new.rb', line 7
def execute(name, options={})
full_project_name = "tumugi-plugin-#{name}"
templates = [
[ "Gemfile.erb", "Gemfile" ],
[ "gemspec.erb", "#{full_project_name}.gemspec" ],
[ "gitignore.erb", ".gitignore" ],
[ "Rakefile.erb", "Rakefile" ],
[ "README.md.erb", "README.md" ],
[ "examples/example.rb.erb", "examples/example.rb" ],
[ "lib/tumugi/plugin/target/target.rb.erb", "lib/tumugi/plugin/target/#{name}.rb" ],
[ "lib/tumugi/plugin/task/task.rb.erb", "lib/tumugi/plugin/task/#{name}.rb" ],
[ "test/test_helper.rb.erb", "test/test_helper.rb" ],
[ "test/test.rb.erb", "test/#{name}_test.rb" ],
[ "test/plugin/target/target_test.rb.erb", "test/plugin/target/#{name}_test.rb" ],
[ "test/plugin/task/task_test.rb.erb", "test/plugin/task/#{name}_test.rb" ],
]
@data_dir = "#{File.expand_path(File.dirname(__FILE__))}/../data/new"
@dest_dir = "#{(options[:path] || '.')}/#{full_project_name}"
if File.exist?(@dest_dir)
logger.error("#{@dest_dir} is already exists. Please delete it first")
return false
end
FileUtils.mkdir_p(@dest_dir)
templates.each do |value|
src_file, dest_file = value
eruby = Erubis::Eruby.new(File.read(src_path(src_file)))
eruby.filename = src_path(src_file)
context = {
full_project_name: full_project_name,
name: name,
tumugi_version: Tumugi::VERSION,
}
logger.info("Create #{dest_path(dest_file)}")
FileUtils.mkdir_p(File.dirname(dest_path(dest_file)))
File.write(dest_path(dest_file), eruby.result(context))
end
return true
end
|