Class: Enoki::CLI
- Inherits:
-
Thor
- Object
- Thor
- Enoki::CLI
- Includes:
- Thor::Actions
- Defined in:
- lib/enoki/cli.rb,
lib/enoki/cli/init.rb,
lib/enoki/cli/list.rb,
lib/enoki/cli/show.rb,
lib/enoki/cli/shell.rb,
lib/enoki/cli/common.rb,
lib/enoki/cli/generate.rb
Constant Summary collapse
- NAME_PLACEHOLDER =
"__name__"
- EXT_TEMPLATE =
".tt"
- SOURCE_CODE_EXT_LIST =
%w(c m mm swift).map { |ext| ".#{ext}" }
Class Method Summary collapse
Instance Method Summary collapse
- #generate(template_name, name) ⇒ Object
- #init ⇒ Object
- #list ⇒ Object
- #show ⇒ Object
- #version ⇒ Object
Class Method Details
.source_root ⇒ Object
5 6 7 |
# File 'lib/enoki/cli/init.rb', line 5 def self.source_root File.("../", File.dirname(__FILE__)) end |
Instance Method Details
#generate(template_name, name) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/enoki/cli/generate.rb', line 13 def generate(template_name, name) unless templates.include? template_name say_error "Template not found" exit 1 end selected_template_root = Pathname.new(File.(template_name, template_dir)) project_root = Pathname.new(project_root_dir) file_list = Dir.glob(selected_template_root.join("**/*#{EXT_TEMPLATE}")).map do |file| Pathname.new(file).relative_path_from(selected_template_root) end file_list.each do |path| resolved_path = Pathname.new(path.to_path.gsub(NAME_PLACEHOLDER, name.capitalize).chomp(EXT_TEMPLATE)) source_path = path.(selected_template_root).to_path dest_path = resolved_path.(project_root).to_path template(source_path, dest_path, context: context_for_template(name)) add_file_reference(resolved_path, [:target]) end project.save end |
#init ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/enoki/cli/init.rb', line 10 def init if File.exist?(settings_file) exit 0 unless yes?("Settings file already exist. Re-create settings file? (y/N)", :yellow) end default_template_dir = "./templates" default_project_root_dir = "./" default_project_file_path = "./YourProject.xcodeproj" template_dir = ask("Your template directory?", default: default_template_dir, path: true) project_root_dir = ask("Your project root directory?", default: default_project_root_dir, path: true) project_file_path = ask("Your project file path?", default: default_project_file_path, path: true) template("templates/.enoki.yml.tt", settings_file, context: binding) end |
#list ⇒ Object
4 5 6 |
# File 'lib/enoki/cli/list.rb', line 4 def list puts templates end |
#show ⇒ Object
4 5 6 7 8 |
# File 'lib/enoki/cli/show.rb', line 4 def show [:template_dir, :project_root_dir, :project_file_path].each do |e| puts("#{e}: #{send(e)}") end end |