Class: Generamba::CLI::Application

Inherits:
Thor
  • Object
show all
Includes:
Generamba
Defined in:
lib/generamba/cli/cli.rb,
lib/generamba/cli/gen_command.rb,
lib/generamba/cli/setup_command.rb,
lib/generamba/cli/version_command.rb,
lib/generamba/cli/template/template_group.rb

Constant Summary

Constants included from Generamba

AUTHOR_NAME_KEY, Generamba::C99IDENTIFIER, Generamba::CARTFILE_PATH_KEY, Generamba::CATALOGS_DIR, Generamba::CATALOGS_KEY, Generamba::COMPANY_KEY, Generamba::CREATE_LOGICAL_GROUPS_KEY, GENERAMBA_CATALOG_NAME, GENERAMBA_HOME_DIR, PATH_TYPE_PROJECT, PATH_TYPE_TEST, PODFILE_PATH_KEY, PRODUCT_MODULE_NAME_KEY, PROJECT_FILE_PATH_KEY, PROJECT_GROUP_PATH_KEY, PROJECT_NAME_KEY, PROJECT_PREFIX_KEY, PROJECT_TARGETS_KEY, PROJECT_TARGET_KEY, RAMBAFILE_NAME, RAMBASPEC_EXTENSION, RAMBLER_CATALOG_REPO, RELEASE_DATE, RELEASE_LINK, SLASH_REGEX, TEMPLATES_FOLDER, TEMPLATES_KEY, TEMPLATE_AUTHOR_KEY, TEMPLATE_CODE_FILES_KEY, TEMPLATE_DECLARATION_BRANCH_KEY, TEMPLATE_DECLARATION_GIT_KEY, TEMPLATE_DECLARATION_LOCAL_KEY, TEMPLATE_DECLARATION_NAME_KEY, TEMPLATE_DEPENDENCIES_KEY, TEMPLATE_FILE_CUSTOM_NAME_KEY, TEMPLATE_FILE_IS_RESOURCE_KEY, TEMPLATE_FILE_NAME_KEY, TEMPLATE_FILE_PATH_KEY, TEMPLATE_LICENSE_KEY, TEMPLATE_NAME_KEY, TEMPLATE_SUMMARY_KEY, TEMPLATE_TEST_FILES_KEY, TEMPLATE_TEST_SNAPSHOT_FILES_KEY, TEMPLATE_TEST_UNIT_FILES_KEY, TEMPLATE_VERSION_KEY, TEST_FILE_PATH_KEY, TEST_GROUP_PATH_KEY, TEST_SNAPSHOT_PATH_KEY, TEST_SNAPSHOT_TARGET_KEY, TEST_SNAPSHOT_TESTABLE_IMPORT, TEST_TARGETS_KEY, TEST_TARGET_KEY, TEST_UNIT_PATH_KEY, TEST_UNIT_TARGET_KEY, TEST_UNIT_TESTABLE_IMPORT, USERNAME_KEY, USER_PREFERENCES_FILE, VERSION, XCODEPROJ_PATH_KEY

Instance Method Summary collapse

Instance Method Details

#gen(module_name, template_name) ⇒ Object



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
72
73
# File 'lib/generamba/cli/gen_command.rb', line 27

def gen(module_name, template_name)
  does_rambafile_exist = Dir[RAMBAFILE_NAME].count > 0

  unless does_rambafile_exist
    puts('Rambafile not found! Run `generamba setup` in the working directory instead!'.red)
    return
  end

  rambafile_validator = Generamba::RambafileValidator.new
  rambafile_validator.validate(RAMBAFILE_NAME)

  setup_username_command = Generamba::CLI::SetupUsernameCommand.new
  setup_username_command.setup_username

  rambafile = YAML.load_file(RAMBAFILE_NAME)

  code_module = CodeModule.new(module_name, rambafile, options)

  module_validator = ModuleValidator.new
  module_validator.validate(code_module)

  module_info = ModuleInfoGenerator.new(code_module)
  template = ModuleTemplate.new(template_name, module_info.scope)

  parameters = GenCommandTableParametersFormatter.prepare_parameters_for_displaying(code_module, template_name)
  PrintTable.print_values(
      values: parameters,
      title: "Summary for gen #{module_name}"
  )

  DependencyChecker.check_all_required_dependencies_has_in_podfile(template.dependencies, code_module.podfile_path)
  DependencyChecker.check_all_required_dependencies_has_in_cartfile(template.dependencies, code_module.cartfile_path)

  project = XcodeprojHelper.obtain_project(code_module.xcodeproj_path)
  module_group_already_exists = XcodeprojHelper.module_with_group_path_already_exists(project, code_module.project_group_path, code_module.create_logical_groups)

  if module_group_already_exists
    replace_exists_module = yes?("#{module_name} module already exists. Replace? (yes/no)")
  
    unless replace_exists_module
      return
    end
  end

  generator = Generamba::ModuleGenerator.new
  generator.generate_module(module_name, code_module, template)
end

#setupObject



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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/generamba/cli/setup_command.rb', line 13

def setup
  properties = {}

  setup_username_command = Generamba::CLI::SetupUsernameCommand.new
  setup_username_command.setup_username

  properties[COMPANY_KEY] = ask('The company name which will be used in the headers:')

  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):')

  xcodeproj_path = ask_file_with_path('*.xcodeproj',
                                      '.xcodeproj file of the project')

  properties[XCODEPROJ_PATH_KEY] = xcodeproj_path
  project = Xcodeproj::Project.open(xcodeproj_path)

  targets_prompt = ''
  project.targets.each_with_index { |element, i| targets_prompt += ("#{i}. #{element.name}" + "\n") }
  project_target = ask_index("Select the appropriate target for adding your MODULES (type the index):\n" + targets_prompt,project.targets)
  include_tests = yes?('Are you using unit-tests in this project? (yes/no)')

  test_target = nil

  if include_tests
    test_target = ask_index("Select the appropriate target for adding your TESTS (type the index):\n" + targets_prompt,project.targets)
  end

  should_add_all_modules_by_one_path = yes?('Do you want to add all your modules by one path? (yes/no)')

  project_file_path = nil
  project_group_path = nil

  test_file_path = nil
  test_group_path = nil
  
  create_logical_groups = nil

  if should_add_all_modules_by_one_path || include_tests
    should_use_same_paths = false

    if should_add_all_modules_by_one_path
      should_use_same_paths = yes?('Do you want to use the same paths for your files both in Xcode and the filesystem? (yes/no)')
    end

    if should_use_same_paths
      if should_add_all_modules_by_one_path
        project_group_path = ask('The default path for creating new modules:')
        project_file_path = project_group_path
      end

      if include_tests
        test_group_path = ask('The default path for creating tests:')
        test_file_path = test_group_path
      end
    else
      if should_add_all_modules_by_one_path
        project_group_path = ask('The default path for creating new modules (in Xcode groups):')
        project_file_path = ask('The default path for creating new modules (in the filesystem):')
      end

      if include_tests
        test_group_path = ask('The default path for creating tests (in Xcode groups):')
        test_file_path = ask('The default path for creating tests (in the filesystem):')
      end
    end
  end

  create_logical_groups = yes?('Do you want to create Groups in Xcode without folders in filesystem? (yes/no)')
  
  using_pods = yes?('Are you using Cocoapods? (yes/no)')
  if using_pods
    properties[PODFILE_PATH_KEY] = ask_file_with_path('Podfile', 'Podfile')
  end

  using_carthage = yes?('Are you using Carthage? (yes/no)')
  if using_carthage
    properties[CARTFILE_PATH_KEY] = ask_file_with_path('Cartfile', 'Cartfile')
  end

  should_add_templates = yes?('Do you want to add some well known templates to the Rambafile? (yes/no)')
  if should_add_templates
    properties[TEMPLATES_KEY] = [
        '{name: rviper_controller}',
        '{name: mvvm_controller}',
        '{name: swifty_viper}'
    ]
  end

  properties[PROJECT_TARGET_KEY] = project_target.name if project_target
  properties[PROJECT_FILE_PATH_KEY] = project_file_path if project_file_path
  properties[PROJECT_GROUP_PATH_KEY] = project_group_path if project_group_path
  properties[TEST_TARGET_KEY] = test_target.name if test_target
  properties[TEST_FILE_PATH_KEY] = test_file_path if test_file_path
  properties[TEST_GROUP_PATH_KEY] = test_group_path if test_group_path
  properties[CREATE_LOGICAL_GROUPS_KEY] = create_logical_groups if create_logical_groups
  
  PrintTable.print_values(
      values: properties,
      title: 'Summary for generamba setup'
  )

  Generamba::RambafileGenerator.create_rambafile(properties)
  if should_add_templates
    puts('Rambafile successfully created! Now run `generamba template install`.'.green)
  else
    puts('Rambafile successfully created!\n Go on and find some templates in our catalog using `generamba template list` command.\n Add any of them to the Rambafile and run `generamba template install`.'.green)
  end

end

#storage(module_name) ⇒ Object



115
116
117
# File 'lib/generamba/cli/gen_command.rb', line 115

def storage(module_name)
  gen(module_name, 'udf-storage')
end

#udf(module_name) ⇒ Object



93
94
95
# File 'lib/generamba/cli/gen_command.rb', line 93

def udf(module_name)
  gen(module_name, 'udf')
end

#versionObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/generamba/cli/version_command.rb', line 9

def version
  options = {}
  options['Version'] = Generamba::VERSION.green
  options['Release date'] = Generamba::RELEASE_DATE.green
  options['Change notes'] = Generamba::RELEASE_LINK.green

  values = []

  options.each do |title, value|
    values.push("#{title}: #{value}")
  end

  output = values.join("\n")
  puts(output)
end