generamba-mp 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.codeclimate.yml +10 -0
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/.travis.yml +17 -0
- data/CHANGELOG.md +180 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +62 -0
- data/Rakefile +6 -0
- data/VISION.md +41 -0
- data/bin/console +14 -0
- data/bin/generamba +5 -0
- data/bin/setup +7 -0
- data/docs/2.x/roadmap.md +365 -0
- data/generamba.gemspec +38 -0
- data/lib/generamba.rb +16 -0
- data/lib/generamba/cli/cli.rb +16 -0
- data/lib/generamba/cli/gen_command.rb +76 -0
- data/lib/generamba/cli/setup_command.rb +122 -0
- data/lib/generamba/cli/setup_username_command.rb +21 -0
- data/lib/generamba/cli/template/template_create_command.rb +40 -0
- data/lib/generamba/cli/template/template_group.rb +14 -0
- data/lib/generamba/cli/template/template_install_command.rb +21 -0
- data/lib/generamba/cli/template/template_list_command.rb +25 -0
- data/lib/generamba/cli/template/template_search_command.rb +30 -0
- data/lib/generamba/cli/thor_extension.rb +47 -0
- data/lib/generamba/cli/version_command.rb +25 -0
- data/lib/generamba/code_generation/Rambafile.liquid +41 -0
- data/lib/generamba/code_generation/code_module.rb +100 -0
- data/lib/generamba/code_generation/content_generator.rb +43 -0
- data/lib/generamba/code_generation/module_template.rb +28 -0
- data/lib/generamba/code_generation/rambafile_generator.rb +23 -0
- data/lib/generamba/configuration/user_preferences.rb +50 -0
- data/lib/generamba/constants/constants.rb +12 -0
- data/lib/generamba/constants/rambafile_constants.rb +31 -0
- data/lib/generamba/constants/rambaspec_constants.rb +18 -0
- data/lib/generamba/constants/user_preferences_constants.rb +5 -0
- data/lib/generamba/helpers/dependency_checker.rb +54 -0
- data/lib/generamba/helpers/gen_command_table_parameters_formatter.rb +33 -0
- data/lib/generamba/helpers/module_info_generator.rb +33 -0
- data/lib/generamba/helpers/module_validator.rb +85 -0
- data/lib/generamba/helpers/print_table.rb +17 -0
- data/lib/generamba/helpers/rambafile_validator.rb +18 -0
- data/lib/generamba/helpers/template_helper.rb +30 -0
- data/lib/generamba/helpers/xcodeproj_helper.rb +256 -0
- data/lib/generamba/module_generator.rb +104 -0
- data/lib/generamba/template/creator/new_template/Code/Service/service.h.liquid +11 -0
- data/lib/generamba/template/creator/new_template/Code/Service/service.m.liquid +13 -0
- data/lib/generamba/template/creator/new_template/Tests/Service/service_tests.m.liquid +35 -0
- data/lib/generamba/template/creator/new_template/template.rambaspec.liquid +20 -0
- data/lib/generamba/template/creator/template_creator.rb +39 -0
- data/lib/generamba/template/helpers/catalog_downloader.rb +58 -0
- data/lib/generamba/template/helpers/catalog_template_list_helper.rb +23 -0
- data/lib/generamba/template/helpers/catalog_template_search_helper.rb +27 -0
- data/lib/generamba/template/helpers/catalog_terminator.rb +21 -0
- data/lib/generamba/template/helpers/rambaspec_validator.rb +52 -0
- data/lib/generamba/template/installer/abstract_installer.rb +9 -0
- data/lib/generamba/template/installer/catalog_installer.rb +73 -0
- data/lib/generamba/template/installer/local_installer.rb +32 -0
- data/lib/generamba/template/installer/remote_installer.rb +50 -0
- data/lib/generamba/template/installer/template_installer_factory.rb +22 -0
- data/lib/generamba/template/processor/template_declaration.rb +36 -0
- data/lib/generamba/template/processor/template_processor.rb +75 -0
- data/lib/generamba/tools/string-colorize.rb +23 -0
- data/lib/generamba/version.rb +5 -0
- metadata +271 -0
data/generamba.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'generamba/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'generamba-mp'
|
8
|
+
spec.version = '0.0.2'
|
9
|
+
spec.authors = ['Marton Pito']
|
10
|
+
spec.email = 'martonpito@gmail.com'
|
11
|
+
|
12
|
+
spec.summary = 'Generamba forked for own modifications.'
|
13
|
+
spec.description = 'Generamba is a powerful and easy-to-use Xcode code generator. It provides a project-based configuration, flexible templates system, the ability to generate code and tests simultaneously.'
|
14
|
+
spec.homepage = 'https://github.com/Hunartimon/Generamba'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.executables = ['generamba']
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.required_ruby_version = '>= 2.2'
|
22
|
+
|
23
|
+
spec.add_runtime_dependency 'thor', '0.19.1'
|
24
|
+
spec.add_runtime_dependency 'xcodeproj', '1.4.2'
|
25
|
+
spec.add_runtime_dependency 'liquid', '4.0.0'
|
26
|
+
spec.add_runtime_dependency 'git', '1.2.9.1'
|
27
|
+
spec.add_runtime_dependency 'cocoapods-core', '1.0.1'
|
28
|
+
spec.add_runtime_dependency 'terminal-table', '1.4.5'
|
29
|
+
|
30
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
31
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
32
|
+
spec.add_development_dependency 'rspec', '~> 3.4'
|
33
|
+
spec.add_development_dependency 'fakefs', '~> 0.6.1'
|
34
|
+
# ActiveSupport dependency is not used by dashramba; instead some other dependency
|
35
|
+
# requires it. We lock it to 4.2.7 so as to avoid using 5.0, which is
|
36
|
+
# not compatible with older versions of Ruby.
|
37
|
+
spec.add_development_dependency 'activesupport', '~> 4.2', '>= 4.2.7'
|
38
|
+
end
|
data/lib/generamba.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Generamba
|
2
|
+
require 'generamba/constants/constants.rb'
|
3
|
+
require 'generamba/constants/rambafile_constants.rb'
|
4
|
+
require 'generamba/constants/rambaspec_constants.rb'
|
5
|
+
require 'generamba/cli/cli.rb'
|
6
|
+
require 'generamba/code_generation/code_module.rb'
|
7
|
+
require 'generamba/code_generation/module_template.rb'
|
8
|
+
require 'generamba/code_generation/content_generator.rb'
|
9
|
+
require 'generamba/code_generation/rambafile_generator.rb'
|
10
|
+
require 'generamba/module_generator.rb'
|
11
|
+
require 'generamba/template/processor/template_processor.rb'
|
12
|
+
require 'generamba/template/installer/template_installer_factory'
|
13
|
+
require 'generamba/configuration/user_preferences.rb'
|
14
|
+
require 'generamba/template/creator/template_creator.rb'
|
15
|
+
require 'generamba/tools/string-colorize.rb'
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'xcodeproj'
|
3
|
+
require 'liquid'
|
4
|
+
require 'git'
|
5
|
+
require 'generamba/cli/gen_command.rb'
|
6
|
+
require 'generamba/cli/setup_command.rb'
|
7
|
+
require 'generamba/cli/version_command.rb'
|
8
|
+
require 'generamba/cli/setup_username_command.rb'
|
9
|
+
require 'generamba/cli/thor_extension.rb'
|
10
|
+
require 'generamba/cli/template/template_group.rb'
|
11
|
+
|
12
|
+
module Generamba::CLI
|
13
|
+
class Application < Thor
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'generamba/helpers/print_table.rb'
|
3
|
+
require 'generamba/helpers/rambafile_validator.rb'
|
4
|
+
require 'generamba/helpers/xcodeproj_helper.rb'
|
5
|
+
require 'generamba/helpers/dependency_checker.rb'
|
6
|
+
require 'generamba/helpers/gen_command_table_parameters_formatter.rb'
|
7
|
+
require 'generamba/helpers/module_validator.rb'
|
8
|
+
require 'generamba/helpers/module_info_generator.rb'
|
9
|
+
|
10
|
+
module Generamba::CLI
|
11
|
+
class Application < Thor
|
12
|
+
|
13
|
+
include Generamba
|
14
|
+
|
15
|
+
desc 'gen [MODULE_NAME] [TEMPLATE_NAME]', 'Creates a new VIPER module with a given name from a specific template'
|
16
|
+
method_option :description, :aliases => '-d', :desc => 'Provides a full description to the module'
|
17
|
+
method_option :author, :desc => 'Specifies the author name for generated module'
|
18
|
+
method_option :project_targets, :desc => 'Specifies project targets for adding new module files'
|
19
|
+
method_option :project_file_path, :desc => 'Specifies a location in the filesystem for new files'
|
20
|
+
method_option :project_group_path, :desc => 'Specifies a location in Xcode groups for new files'
|
21
|
+
method_option :module_path, :desc => 'Specifies a location (both in the filesystem and Xcode) for new files'
|
22
|
+
method_option :test_targets, :desc => 'Specifies project targets for adding new test files'
|
23
|
+
method_option :test_file_path, :desc => 'Specifies a location in the filesystem for new test files'
|
24
|
+
method_option :test_group_path, :desc => 'Specifies a location in Xcode groups for new test files'
|
25
|
+
method_option :test_path, :desc => 'Specifies a location (both in the filesystem and Xcode) for new test files'
|
26
|
+
method_option :custom_parameters, :type => :hash, :default => {}, :desc => 'Specifies extra parameters in format `key1:value1 key2:value2` for usage during code generation'
|
27
|
+
def gen(module_name, template_name)
|
28
|
+
does_rambafile_exist = Dir[RAMBAFILE_NAME].count > 0
|
29
|
+
|
30
|
+
unless does_rambafile_exist
|
31
|
+
puts('Rambafile not found! Run `generamba setup` in the working directory instead!'.red)
|
32
|
+
return
|
33
|
+
end
|
34
|
+
|
35
|
+
rambafile_validator = Generamba::RambafileValidator.new
|
36
|
+
rambafile_validator.validate(RAMBAFILE_NAME)
|
37
|
+
|
38
|
+
setup_username_command = Generamba::CLI::SetupUsernameCommand.new
|
39
|
+
setup_username_command.setup_username
|
40
|
+
|
41
|
+
rambafile = YAML.load_file(RAMBAFILE_NAME)
|
42
|
+
|
43
|
+
code_module = CodeModule.new(module_name, rambafile, options)
|
44
|
+
|
45
|
+
module_validator = ModuleValidator.new
|
46
|
+
module_validator.validate(code_module)
|
47
|
+
|
48
|
+
module_info = ModuleInfoGenerator.new(code_module)
|
49
|
+
template = ModuleTemplate.new(template_name, module_info.scope)
|
50
|
+
|
51
|
+
parameters = GenCommandTableParametersFormatter.prepare_parameters_for_displaying(code_module, template_name)
|
52
|
+
PrintTable.print_values(
|
53
|
+
values: parameters,
|
54
|
+
title: "Summary for gen #{module_name}"
|
55
|
+
)
|
56
|
+
|
57
|
+
DependencyChecker.check_all_required_dependencies_has_in_podfile(template.dependencies, code_module.podfile_path)
|
58
|
+
DependencyChecker.check_all_required_dependencies_has_in_cartfile(template.dependencies, code_module.cartfile_path)
|
59
|
+
|
60
|
+
project = XcodeprojHelper.obtain_project(code_module.xcodeproj_path)
|
61
|
+
module_group_already_exists = XcodeprojHelper.module_with_group_path_already_exists(project, code_module.project_group_path)
|
62
|
+
|
63
|
+
if module_group_already_exists
|
64
|
+
replace_exists_module = yes?("#{module_name} module already exists. Replace? (yes/no)")
|
65
|
+
|
66
|
+
unless replace_exists_module
|
67
|
+
return
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
generator = Generamba::ModuleGenerator.new
|
72
|
+
generator.generate_module(module_name, code_module, template)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'xcodeproj'
|
3
|
+
require 'liquid'
|
4
|
+
require 'git'
|
5
|
+
require 'generamba/constants/rambafile_constants.rb'
|
6
|
+
require 'generamba/helpers/print_table.rb'
|
7
|
+
|
8
|
+
module Generamba::CLI
|
9
|
+
class Application < Thor
|
10
|
+
include Generamba
|
11
|
+
|
12
|
+
desc 'setup', 'Creates a Rambafile with a config for a given project'
|
13
|
+
def setup
|
14
|
+
properties = {}
|
15
|
+
|
16
|
+
setup_username_command = Generamba::CLI::SetupUsernameCommand.new
|
17
|
+
setup_username_command.setup_username
|
18
|
+
|
19
|
+
properties[COMPANY_KEY] = ask('The company name which will be used in the headers:')
|
20
|
+
|
21
|
+
project_name = Pathname.new(Dir.getwd).basename.to_s
|
22
|
+
is_right_project_name = yes?("The name of your project is #{project_name}. Do you want to use it? (yes/no)")
|
23
|
+
|
24
|
+
properties[PROJECT_NAME_KEY] = is_right_project_name ? project_name : ask_non_empty_string('The project name:', 'Project name should not be empty')
|
25
|
+
properties[PROJECT_PREFIX_KEY] = ask('The project prefix (if any):')
|
26
|
+
|
27
|
+
xcodeproj_path = ask_file_with_path('*.xcodeproj',
|
28
|
+
'.xcodeproj file of the project')
|
29
|
+
|
30
|
+
properties[XCODEPROJ_PATH_KEY] = xcodeproj_path
|
31
|
+
project = Xcodeproj::Project.open(xcodeproj_path)
|
32
|
+
|
33
|
+
targets_prompt = ''
|
34
|
+
project.targets.each_with_index { |element, i| targets_prompt += ("#{i}. #{element.name}" + "\n") }
|
35
|
+
project_target = ask_index("Select the appropriate target for adding your MODULES (type the index):\n" + targets_prompt,project.targets)
|
36
|
+
include_tests = yes?('Are you using unit-tests in this project? (yes/no)')
|
37
|
+
|
38
|
+
test_target = nil
|
39
|
+
|
40
|
+
if include_tests
|
41
|
+
test_target = ask_index("Select the appropriate target for adding your TESTS (type the index):\n" + targets_prompt,project.targets)
|
42
|
+
end
|
43
|
+
|
44
|
+
should_add_all_modules_by_one_path = yes?('Do you want to add all your modules by one path? (yes/no)')
|
45
|
+
|
46
|
+
project_file_path = nil
|
47
|
+
project_group_path = nil
|
48
|
+
|
49
|
+
test_file_path = nil
|
50
|
+
test_group_path = nil
|
51
|
+
|
52
|
+
if should_add_all_modules_by_one_path || include_tests
|
53
|
+
should_use_same_paths = false
|
54
|
+
|
55
|
+
if should_add_all_modules_by_one_path
|
56
|
+
should_use_same_paths = yes?('Do you want to use the same paths for your files both in Xcode and the filesystem? (yes/no)')
|
57
|
+
end
|
58
|
+
|
59
|
+
if should_use_same_paths
|
60
|
+
if should_add_all_modules_by_one_path
|
61
|
+
project_group_path = ask('The default path for creating new modules:')
|
62
|
+
project_file_path = project_group_path
|
63
|
+
end
|
64
|
+
|
65
|
+
if include_tests
|
66
|
+
test_group_path = ask('The default path for creating tests:')
|
67
|
+
test_file_path = test_group_path
|
68
|
+
end
|
69
|
+
else
|
70
|
+
if should_add_all_modules_by_one_path
|
71
|
+
project_group_path = ask('The default path for creating new modules (in Xcode groups):')
|
72
|
+
project_file_path = ask('The default path for creating new modules (in the filesystem):')
|
73
|
+
end
|
74
|
+
|
75
|
+
if include_tests
|
76
|
+
test_group_path = ask('The default path for creating tests (in Xcode groups):')
|
77
|
+
test_file_path = ask('The default path for creating tests (in the filesystem):')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
using_pods = yes?('Are you using Cocoapods? (yes/no)')
|
83
|
+
if using_pods
|
84
|
+
properties[PODFILE_PATH_KEY] = ask_file_with_path('Podfile', 'Podfile')
|
85
|
+
end
|
86
|
+
|
87
|
+
using_carthage = yes?('Are you using Carthage? (yes/no)')
|
88
|
+
if using_carthage
|
89
|
+
properties[CARTFILE_PATH_KEY] = ask_file_with_path('Cartfile', 'Cartfile')
|
90
|
+
end
|
91
|
+
|
92
|
+
should_add_templates = yes?('Do you want to add some well known templates to the Rambafile? (yes/no)')
|
93
|
+
if should_add_templates
|
94
|
+
properties[TEMPLATES_KEY] = [
|
95
|
+
'{name: rviper_controller}',
|
96
|
+
'{name: mvvm_controller}',
|
97
|
+
'{name: swifty_viper}'
|
98
|
+
]
|
99
|
+
end
|
100
|
+
|
101
|
+
properties[PROJECT_TARGET_KEY] = project_target.name if project_target
|
102
|
+
properties[PROJECT_FILE_PATH_KEY] = project_file_path if project_file_path
|
103
|
+
properties[PROJECT_GROUP_PATH_KEY] = project_group_path if project_group_path
|
104
|
+
properties[TEST_TARGET_KEY] = test_target.name if test_target
|
105
|
+
properties[TEST_FILE_PATH_KEY] = test_file_path if test_file_path
|
106
|
+
properties[TEST_GROUP_PATH_KEY] = test_group_path if test_group_path
|
107
|
+
|
108
|
+
PrintTable.print_values(
|
109
|
+
values: properties,
|
110
|
+
title: 'Summary for generamba setup'
|
111
|
+
)
|
112
|
+
|
113
|
+
Generamba::RambafileGenerator.create_rambafile(properties)
|
114
|
+
if should_add_templates
|
115
|
+
puts('Rambafile successfully created! Now run `generamba template install`.'.green)
|
116
|
+
else
|
117
|
+
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)
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Generamba::CLI
|
2
|
+
class SetupUsernameCommand < Thor
|
3
|
+
|
4
|
+
no_commands {
|
5
|
+
def setup_username
|
6
|
+
username = Generamba::UserPreferences.obtain_username
|
7
|
+
unless username
|
8
|
+
puts('The author name is not configured!'.red)
|
9
|
+
git_username = Git.init.config['user.name']
|
10
|
+
if git_username != nil && yes?("Your name in git is configured as #{git_username}. Do you want to use it in code headers? (yes/no)")
|
11
|
+
username = git_username
|
12
|
+
else
|
13
|
+
username = ask_non_empty_string('The author name which will be used in the headers:', 'User name should not be empty')
|
14
|
+
end
|
15
|
+
Generamba::UserPreferences.save_username(username)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'generamba/helpers/print_table.rb'
|
2
|
+
|
3
|
+
module Generamba::CLI
|
4
|
+
class Template < Thor
|
5
|
+
include Generamba
|
6
|
+
|
7
|
+
desc 'create [TEMPLATE_NAME]', 'Creates a new Generamba template with a given name'
|
8
|
+
def create(template_name)
|
9
|
+
summary = ask('The brief description of your new template:')
|
10
|
+
author = ask('Who is the author of this template:')
|
11
|
+
license = ask('What license will be used (e.g. MIT):')
|
12
|
+
|
13
|
+
has_dependencies = yes?('Will your template contain any third-party dependencies (available via Cocoapods or Carthage)? (yes/no)')
|
14
|
+
if has_dependencies
|
15
|
+
dependencies = ask_loop('Enter the name of your dependency (empty string to stop):')
|
16
|
+
end
|
17
|
+
|
18
|
+
properties = {
|
19
|
+
TEMPLATE_NAME_KEY => template_name,
|
20
|
+
TEMPLATE_SUMMARY_KEY => summary,
|
21
|
+
TEMPLATE_AUTHOR_KEY => author,
|
22
|
+
TEMPLATE_LICENSE_KEY => license
|
23
|
+
}
|
24
|
+
|
25
|
+
if dependencies and !dependencies.empty?
|
26
|
+
properties[TEMPLATE_DEPENDENCIES_KEY] = dependencies
|
27
|
+
end
|
28
|
+
|
29
|
+
PrintTable.print_values(
|
30
|
+
values: properties,
|
31
|
+
title: "Summary for template create"
|
32
|
+
)
|
33
|
+
|
34
|
+
template_creator = Generamba::TemplateCreator.new
|
35
|
+
template_creator.create_template(properties)
|
36
|
+
puts("The template #{template_name} is successfully generated! Now add some file templates into it.".green)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'generamba/cli/template/template_install_command.rb'
|
2
|
+
require 'generamba/cli/template/template_create_command.rb'
|
3
|
+
require 'generamba/cli/template/template_list_command.rb'
|
4
|
+
require 'generamba/cli/template/template_search_command.rb'
|
5
|
+
|
6
|
+
module Generamba::CLI
|
7
|
+
class Application < Thor
|
8
|
+
register(Generamba::CLI::Template, 'template', 'template <command>', 'Provides a set of commands for working with templates')
|
9
|
+
end
|
10
|
+
|
11
|
+
class Template < Thor
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Generamba::CLI
|
2
|
+
class Template < Thor
|
3
|
+
|
4
|
+
desc 'install', 'Installs all the templates specified in the Rambafile from the current directory'
|
5
|
+
def install
|
6
|
+
does_rambafile_exist = Dir[RAMBAFILE_NAME].count > 0
|
7
|
+
|
8
|
+
unless does_rambafile_exist
|
9
|
+
puts('Rambafile not found! Run `generamba setup` in the working directory instead!'.red)
|
10
|
+
return
|
11
|
+
end
|
12
|
+
|
13
|
+
catalog_downloader = Generamba::CatalogDownloader.new
|
14
|
+
installer_factory = Generamba::TemplateInstallerFactory.new
|
15
|
+
template_processor = Generamba::TemplateProcessor.new(catalog_downloader, installer_factory)
|
16
|
+
|
17
|
+
rambafile = YAML.load_file(RAMBAFILE_NAME)
|
18
|
+
template_processor.install_templates(rambafile)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'generamba/template/helpers/catalog_downloader'
|
2
|
+
require 'generamba/template/helpers/catalog_template_list_helper'
|
3
|
+
|
4
|
+
module Generamba::CLI
|
5
|
+
class Template < Thor
|
6
|
+
include Generamba
|
7
|
+
|
8
|
+
desc 'list', 'Prints out the list of all templates available in the shared GitHub catalog'
|
9
|
+
def list
|
10
|
+
downloader = CatalogDownloader.new
|
11
|
+
catalog_template_list_helper = CatalogTemplateListHelper.new
|
12
|
+
|
13
|
+
templates = []
|
14
|
+
catalog_paths = downloader.update_all_catalogs_and_return_filepaths
|
15
|
+
catalog_paths.each do |path|
|
16
|
+
templates += catalog_template_list_helper.obtain_all_templates_from_a_catalog(path)
|
17
|
+
templates = templates.uniq
|
18
|
+
end
|
19
|
+
|
20
|
+
templates.each do |template_name|
|
21
|
+
puts(template_name)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'generamba/template/helpers/catalog_downloader.rb'
|
2
|
+
require 'generamba/template/helpers/catalog_template_search_helper'
|
3
|
+
|
4
|
+
module Generamba::CLI
|
5
|
+
class Template < Thor
|
6
|
+
include Generamba
|
7
|
+
|
8
|
+
desc 'search [SEARCH_STRING]', 'Searches a template with a given name in the shared GitHub catalog'
|
9
|
+
def search(term)
|
10
|
+
downloader = CatalogDownloader.new
|
11
|
+
catalog_template_search_helper = CatalogTemplateSearchHelper.new
|
12
|
+
|
13
|
+
catalog_paths = downloader.update_all_catalogs_and_return_filepaths
|
14
|
+
|
15
|
+
templates = []
|
16
|
+
catalog_paths.each do |path|
|
17
|
+
templates += catalog_template_search_helper.search_templates_in_a_catalog(path, term)
|
18
|
+
templates = templates.uniq
|
19
|
+
end
|
20
|
+
|
21
|
+
templates.map { |template_name|
|
22
|
+
keywords = term.squeeze.strip.split(' ').compact.uniq
|
23
|
+
matcher = Regexp.new('(' + keywords.join('|') + ')')
|
24
|
+
template_name.gsub(matcher) { |match| "#{match}".yellow }
|
25
|
+
}.each { |template_name|
|
26
|
+
puts(template_name)
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module Generamba::CLI
|
4
|
+
class ::Thor
|
5
|
+
no_commands do
|
6
|
+
def ask_index(message, array)
|
7
|
+
value_index = ask_with_validation(message,->(value){ (value.to_i >= 0 and value.to_i < array.count) },"Invalid selection. Please enter number from 0 to #{array.count-1}")
|
8
|
+
return array[value_index.to_i]
|
9
|
+
end
|
10
|
+
|
11
|
+
def ask_non_empty_string(message, description = 'Value should be nonempty string')
|
12
|
+
return ask_with_validation(message,->(value){value.length > 0 },description)
|
13
|
+
end
|
14
|
+
|
15
|
+
def ask_loop(message)
|
16
|
+
array = Array.new
|
17
|
+
loop do
|
18
|
+
value = ask(message)
|
19
|
+
break if value.empty?
|
20
|
+
array.push(value)
|
21
|
+
end
|
22
|
+
return array
|
23
|
+
end
|
24
|
+
|
25
|
+
def ask_with_validation(message, is_valid_value, description = 'Invalid value')
|
26
|
+
loop do
|
27
|
+
value = ask(message)
|
28
|
+
return value if is_valid_value.call(value)
|
29
|
+
puts(description.red)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def ask_file_with_path(pattern, message_file_name)
|
34
|
+
project_files = Dir[pattern]
|
35
|
+
count = project_files.count
|
36
|
+
default_message = "The path to a #{message_file_name}:"
|
37
|
+
if count == 1
|
38
|
+
is_right_path = yes?"The path to a #{message_file_name} is '#{project_files[0]}'. Do you want to use it? (yes/no)"
|
39
|
+
xcode_path = is_right_path ? project_files[0] : ask(default_message)
|
40
|
+
else
|
41
|
+
xcode_path = ask(default_message)
|
42
|
+
end
|
43
|
+
return xcode_path
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|