class Generambo::CLI::Application
Public Instance Methods
gen(module_name, template_folder)
click to toggle source
# File lib/generambo/cli/gen_command.rb, line 9 def gen(module_name, template_folder) does_generambofile_exist = Dir[GENERAMBO_FILE].count > 0 unless does_generambofile_exist puts('generambofile not found! Run `generambo setup` in the working directory instead!'.colorize(:red)) exit end setup_username_command = Generambo::CLI::SetupUsernameCommand.new setup_username_command.setup_username properties = YAML.load_file(GENERAMBO_FILE) properties[USERNAME_KEY] = Generambo::UserPreferences.obtain_username properties[CURRENT_DATE_KEY] = Time.now.strftime('%d.%m.%Y') properties[MODULE_NAME_KEY] = module_name template_folder_path = File.join(Dir.pwd, 'Templates', template_folder) unless File.directory?(template_folder_path) puts('Template does not exist!'.colorize(:red)) exit end module_path = File.join(Dir.pwd, module_name) if File.directory?(module_path) answer = ask('The module already exists. Overwrite it? (y/n)'.colorize(:blue)) exit unless answer == 'y' # remove old directory FileUtils.rm_rf(module_path) end # copying template files Generambo::Helpers::Copier.transfer(template_folder_path, module_path) # processing template files Generambo::Helpers::TemplateHandler.handle!(module_path, properties) end
setup()
click to toggle source
# File lib/generambo/cli/setup_command.rb, line 8 def setup does_generambofile_exist = Dir[GENERAMBO_FILE].count > 0 if does_generambofile_exist answer = ask('Do you want to overwrite an existing generambofile? (y/n)'.colorize(:red)) exit unless answer == 'y' end properties = {} setup_username_command = Generambo::CLI::SetupUsernameCommand.new setup_username_command.setup_username project_name = Pathname.new(Dir.getwd).basename.to_s is_right_project_name = yes?("The name of your project is #{project_name}. Do you want to use it? (yes/no)") properties[PROJECT_NAME_KEY] = is_right_project_name ? project_name : ask_non_empty_string('The project name:', 'Project name should not be empty') properties[PROJECT_PREFIX_KEY] = ask('The project prefix (if any):') Generambo::GenerambofileGenerator.create_generambofile(properties) puts('Generambofile successful created!'.colorize(:green)) end