viperaptor 2.0.0

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.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +10 -0
  3. data/.gitignore +8 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +16 -0
  6. data/Gemfile +6 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +64 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/bin/viperaptor +8 -0
  13. data/lib/viperaptor/cli/cli.rb +16 -0
  14. data/lib/viperaptor/cli/gen_command.rb +132 -0
  15. data/lib/viperaptor/cli/setup_command.rb +122 -0
  16. data/lib/viperaptor/cli/setup_username_command.rb +21 -0
  17. data/lib/viperaptor/cli/template/template_create_command.rb +40 -0
  18. data/lib/viperaptor/cli/template/template_group.rb +14 -0
  19. data/lib/viperaptor/cli/template/template_install_command.rb +21 -0
  20. data/lib/viperaptor/cli/template/template_list_command.rb +16 -0
  21. data/lib/viperaptor/cli/template/template_search_command.rb +30 -0
  22. data/lib/viperaptor/cli/thor_extension.rb +47 -0
  23. data/lib/viperaptor/cli/version_command.rb +25 -0
  24. data/lib/viperaptor/code_generation/Rambafile.liquid +54 -0
  25. data/lib/viperaptor/code_generation/code_module.rb +104 -0
  26. data/lib/viperaptor/code_generation/content_generator.rb +43 -0
  27. data/lib/viperaptor/code_generation/module_template.rb +28 -0
  28. data/lib/viperaptor/code_generation/rambafile_generator.rb +23 -0
  29. data/lib/viperaptor/configuration/user_preferences.rb +87 -0
  30. data/lib/viperaptor/constants/constants.rb +13 -0
  31. data/lib/viperaptor/constants/rambafile_constants.rb +34 -0
  32. data/lib/viperaptor/constants/rambaspec_constants.rb +18 -0
  33. data/lib/viperaptor/constants/user_preferences_constants.rb +7 -0
  34. data/lib/viperaptor/helpers/dependency_checker.rb +54 -0
  35. data/lib/viperaptor/helpers/gen_command_table_parameters_formatter.rb +33 -0
  36. data/lib/viperaptor/helpers/module_info_generator.rb +33 -0
  37. data/lib/viperaptor/helpers/module_validator.rb +85 -0
  38. data/lib/viperaptor/helpers/print_table.rb +17 -0
  39. data/lib/viperaptor/helpers/rambafile.rb +75 -0
  40. data/lib/viperaptor/helpers/template_helper.rb +76 -0
  41. data/lib/viperaptor/helpers/xcodeproj_helper.rb +256 -0
  42. data/lib/viperaptor/module_generator.rb +104 -0
  43. data/lib/viperaptor/template/creator/new_template/Code/Service/service.h.liquid +11 -0
  44. data/lib/viperaptor/template/creator/new_template/Code/Service/service.m.liquid +13 -0
  45. data/lib/viperaptor/template/creator/new_template/Tests/Service/service_tests.m.liquid +35 -0
  46. data/lib/viperaptor/template/creator/new_template/template.rambaspec.liquid +20 -0
  47. data/lib/viperaptor/template/creator/template_creator.rb +39 -0
  48. data/lib/viperaptor/template/helpers/catalog_downloader.rb +107 -0
  49. data/lib/viperaptor/template/helpers/catalog_template_list_helper.rb +55 -0
  50. data/lib/viperaptor/template/helpers/catalog_template_search_helper.rb +27 -0
  51. data/lib/viperaptor/template/helpers/catalog_terminator.rb +21 -0
  52. data/lib/viperaptor/template/helpers/rambaspec_validator.rb +52 -0
  53. data/lib/viperaptor/template/installer/abstract_installer.rb +9 -0
  54. data/lib/viperaptor/template/installer/catalog_installer.rb +78 -0
  55. data/lib/viperaptor/template/installer/local_installer.rb +32 -0
  56. data/lib/viperaptor/template/installer/remote_installer.rb +51 -0
  57. data/lib/viperaptor/template/installer/template_installer_factory.rb +22 -0
  58. data/lib/viperaptor/template/processor/template_declaration.rb +36 -0
  59. data/lib/viperaptor/template/processor/template_processor.rb +73 -0
  60. data/lib/viperaptor/tools/string-colorize.rb +23 -0
  61. data/lib/viperaptor/version.rb +5 -0
  62. data/lib/viperaptor.rb +16 -0
  63. data/viperaptor.gemspec +36 -0
  64. metadata +274 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 04c78b517567b2c0c13908a460b62ab9864a77ef76249e2307d52fe0dd6135f3
4
+ data.tar.gz: f7fcd96e19a87f3c45240b2113a8c05ce112b57e1e624e1706f4d5644b4b9779
5
+ SHA512:
6
+ metadata.gz: 3a231c6f53c9b10a5c742322b471ded32153182120aec1412259cce52278140f1277c9890c1a7e32a91b85e244fd552c37324ba4eaa8ff0accb7272224b4f678
7
+ data.tar.gz: 88f25b617ca1ccd48b00056edf5cb41fc311001e8eb9fcd0bcff463cc2442a201845353da5eaf5da2b0c41f138cd028e2be43a64a4f7c8cd5aa259fcf9aa8941
data/.codeclimate.yml ADDED
@@ -0,0 +1,10 @@
1
+ engines:
2
+ rubocop:
3
+ enabled: true
4
+
5
+ ratings:
6
+ paths:
7
+ - "**.rb"
8
+
9
+ exclude_paths:
10
+ - spec/**/*
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ .idea/*
2
+ .rakeTasks
3
+ encodings.xml
4
+ Gemfile.lock
5
+ /.vscode/
6
+ /pkg/
7
+ *.DS_Store
8
+ /vendor/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ language: objective-c
2
+ osx_image: xcode9.3
3
+
4
+ cache:
5
+ bundler: true
6
+
7
+ bundler_args: --jobs 3 --retry 3
8
+
9
+ rvm:
10
+ - 2.3.1
11
+
12
+ before_install:
13
+ - gem update --system --no-doc --no-ri
14
+ - gem install bundler --no-doc --no-ri
15
+
16
+ script: bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in viperaptor.gemspec
4
+ gemspec
5
+
6
+ gem 'rspec', '~> 3.0'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020-present Siarhei Ladzeika
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ <p align="center">
2
+ <img src="http://i.imgur.com/1AwoVaN.png"/>
3
+ </p>
4
+
5
+ **Original code taken** from [https://github.com/AYastrebov/Generamba](https://github.com/AYastrebov/Generamba). Thanks to authors!!!
6
+
7
+ NOTE: Most command works as it was in Generamba.
8
+
9
+ [![Build Status](https://travis-ci.org/ladeiko/Viperaptor.svg?branch=develop)](https://travis-ci.org/ladeiko/Viperaptor)
10
+ [![Gem Version](https://badge.fury.io/rb/viperaptor.svg)](https://badge.fury.io/rb/viperaptor)
11
+
12
+ **Viperaptor** is a code generator made for working with Xcode.
13
+ Primarily it is designed to generate code modules but it is quite easy to customize it for generation of any other classes (both in Objective-C and Swift).
14
+
15
+ ![Viperaptor Screenshot](https://habrastorage.org/files/b98/770/b37/b98770b37dc54de98daf0e22fea38478.gif)
16
+
17
+ ### Key features
18
+
19
+ - Supports work with *.xcodeproj* files out of the box. All generated class files are automatically placed to specific folders and groups of Xcode project.
20
+ - Can generate both code itself and tests adding them to right targets.
21
+ - Based on work with [liquid-templates](https://github.com/Shopify/liquid) that have plain and readable syntax in comparison with templates for Xcode.
22
+ - It is very easy to create a new module: `viperaptor gen [MODULE_NAME] [TEMPLATE_NAME]` or `viperaptor gen`. You do not need to input a bunch of data each time because each project corresponds to only one configuration file that holds standard file system and Xcode-project pathes, names of targets, information about the author.
23
+ - You can use multiple Rambafiles: Just should contain 'Rambafile' prefix.
24
+ ### Installation
25
+
26
+ > Ruby 2.3 or later version is required. To check your current Ruby version run this command in terminal:
27
+ ```bash
28
+ $ ruby --version
29
+ ```
30
+ When necessary you can install the required Ruby version with the help of [`rvm`](http://octopress.org/docs/setup/rvm/) or [`rbenv`](http://octopress.org/docs/setup/rbenv/).
31
+
32
+ In your terminal run:
33
+
34
+ ```bash
35
+ gem install viperaptor
36
+ ```
37
+
38
+ ### Usage
39
+ 1. Run [`bundle exec viperaptor setup`](https://github.com/AYastrebov/Generamba/wiki/Available-Commands#basic-generamba-configuration) in the project root folder. This command helps to create [Rambafile](https://github.com/AYastrebov/Generamba/wiki/Rambafile-Structure) that define all configuration needed to generate code. You can modify this file directly in future.
40
+ 2. Add all templates planned to use in the project to the generated [Rambafile](https://github.com/AYastrebov/Generamba/wiki/Rambafile-Structure). You can begin with one of the templates from our catalog: `{name: 'rviper_controller'}`.
41
+ 3. Run [`bundle exec viperaptor template install`](https://github.com/AYastrebov/Generamba/wiki/Available-Commands#template-installation). All the templates will be placed in the '/Templates' folder of your current project.
42
+ 4. Run [`bundle exec viperaptor gen [MODULE_NAME] [TEMPLATE_NAME]`](https://github.com/AYastrebov/Generamba/wiki/Available-Commands#module-generation) - It creates module with specific name from specific template.
43
+
44
+ ### Additional info
45
+
46
+ Run `viperaptor help` to learn more about each of the Viperaptor features.
47
+
48
+ **Wiki:**
49
+ - [Command list](https://github.com/AYastrebov/Generamba/wiki/Available-Commands)
50
+ - [Understanding the Rambafile](https://github.com/AYastrebov/Generamba/wiki/Rambafile-Structure)
51
+ - [Understanding templates](https://github.com/AYastrebov/Generamba/wiki/Template-Structure)
52
+
53
+ **Other materials:**
54
+ - [Russian] Rambler.iOS V: Generamba and Code Generation ([Slides](http://www.slideshare.net/Rambler-iOS/viper-56423582) | [Video](http://www.youtube.com/watch?v=NXNiN9FaUnY))
55
+ - [Introduction to original Generamba](http://etolstoy.com/2016/02/10/generamba/)
56
+
57
+ ### Authors
58
+
59
+ - Siarhei Ladzeika <sergey.ladeiko@gmail.com>
60
+ - Authors of original Generamba code: Egor Tolstoy, Beniamin Sarkisyan, Andrey Zarembo and the rest of [Rambler.iOS team](https://github.com/orgs/AYastrebov/teams/ios-team).
61
+
62
+ ### License
63
+
64
+ MIT
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "viperaptor"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -euo pipefail
4
+ IFS=$'\n\t'
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/viperaptor ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.dirname(File.expand_path(__FILE__)) + '/../lib'
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'viperaptor'
7
+
8
+ Viperaptor::CLI::Application.start(ARGV)
@@ -0,0 +1,16 @@
1
+ require 'thor'
2
+ require 'xcodeproj'
3
+ require 'liquid'
4
+ require 'git'
5
+ require 'viperaptor/cli/gen_command.rb'
6
+ require 'viperaptor/cli/setup_command.rb'
7
+ require 'viperaptor/cli/version_command.rb'
8
+ require 'viperaptor/cli/setup_username_command.rb'
9
+ require 'viperaptor/cli/thor_extension.rb'
10
+ require 'viperaptor/cli/template/template_group.rb'
11
+
12
+ module Viperaptor::CLI
13
+ class Application < Thor
14
+
15
+ end
16
+ end
@@ -0,0 +1,132 @@
1
+ require 'thor'
2
+ require "tty-prompt"
3
+ require 'set'
4
+ require 'viperaptor/helpers/print_table.rb'
5
+ require 'viperaptor/helpers/rambafile.rb'
6
+ require 'viperaptor/helpers/xcodeproj_helper.rb'
7
+ require 'viperaptor/helpers/dependency_checker.rb'
8
+ require 'viperaptor/helpers/gen_command_table_parameters_formatter.rb'
9
+ require 'viperaptor/helpers/module_validator.rb'
10
+ require 'viperaptor/helpers/module_info_generator.rb'
11
+
12
+ module Viperaptor::CLI
13
+ class Application < Thor
14
+
15
+ include Viperaptor
16
+
17
+ desc 'gen [MODULE_NAME] [TEMPLATE_NAME]', 'Creates a new VIPER module with a given name from a specific template'
18
+ method_option :description, :aliases => '-d', :desc => 'Provides a full description to the module'
19
+ method_option :author, :desc => 'Specifies the author name for generated module'
20
+ method_option :project_targets, :desc => 'Specifies project targets for adding new module files'
21
+ method_option :project_file_path, :desc => 'Specifies a location in the filesystem for new files'
22
+ method_option :project_group_path, :desc => 'Specifies a location in Xcode groups for new files'
23
+ method_option :module_path, :desc => 'Specifies a location (both in the filesystem and Xcode) for new files'
24
+ method_option :test_targets, :desc => 'Specifies project targets for adding new test files'
25
+ method_option :test_file_path, :desc => 'Specifies a location in the filesystem for new test files'
26
+ method_option :test_group_path, :desc => 'Specifies a location in Xcode groups for new test files'
27
+ method_option :test_path, :desc => 'Specifies a location (both in the filesystem and Xcode) for new test files'
28
+ method_option :custom_parameters, :type => :hash, :default => {}, :desc => 'Specifies extra parameters in format `key1:value1 key2:value2` for usage during code generation'
29
+ def gen(module_name = nil, template_name = nil)
30
+ does_rambafile_exist = Rambafile.exist
31
+
32
+ unless does_rambafile_exist
33
+ puts('Rambafile not found! Run `viperaptor setup` in the working directory instead!'.red)
34
+ return
35
+ end
36
+
37
+ setup_username_command = Viperaptor::CLI::SetupUsernameCommand.new
38
+ setup_username_command.setup_username
39
+
40
+ rambafile = Rambafile.rambafile
41
+
42
+ if module_name == nil
43
+ prompt = TTY::Prompt.new
44
+ module_name = prompt.ask("Enter the name of module?") do |q|
45
+ q.required true
46
+ q.validate /^[A-Z]\w*$/
47
+ end
48
+ end
49
+
50
+ templates = rambafile[TEMPLATES_KEY] || []
51
+ templates_as_set = Set.new(templates.map { |t| t["name"] })
52
+ templates = templates.concat(TemplateHelper.global_templates.select { |t| !templates_as_set.include?(t) }.map { |name| { "name" => name } }).sort_by { |t| t["name"] }
53
+
54
+ filter = rambafile[TEMPLATES_FILTER_KEY] || ''
55
+
56
+ if !filter.kind_of?(Array)
57
+ filter = [filter]
58
+ end
59
+
60
+ filter = filter.map { |f| f.strip }.select { |f| !f.empty? }
61
+ negative_filters = filter.select { |f| f.start_with?('!') }.map { |f| f[1...] }.map { |f| Regexp.new(f, Regexp::IGNORECASE) }
62
+ positive_filters = filter.select { |f| !f.start_with?('!') }.map { |f| Regexp.new(f, Regexp::IGNORECASE) }
63
+ original_templates = templates
64
+
65
+ if original_templates.count == 0
66
+ puts("No any templates found. Add templates catalog or templates to Rambafile.".red)
67
+ exit
68
+ end
69
+
70
+ templates = templates.select do |t|
71
+
72
+ if filter.count == 0
73
+ next true
74
+ end
75
+
76
+ negative_filters.none? { |f| f.match(t["name"]) } && (positive_filters.count == 0 || positive_filters.any? { |f| f.match(t["name"]) })
77
+ end
78
+
79
+ if templates.count == 0
80
+ puts("No templates found. Try to modify *templates_filter*.".red)
81
+ exit
82
+ end
83
+
84
+ if template_name == nil
85
+ prompt = TTY::Prompt.new
86
+ choices = templates.map { |t| t["name"] }
87
+ index = 1
88
+ history = Viperaptor::UserPreferences.obtain_templates_history
89
+ if history.count > 0
90
+ matching = choices.find_index(history[0])
91
+ if matching != nil
92
+ index = matching + 1
93
+ end
94
+ end
95
+ template_name = prompt.select("Select template?", choices, per_page: choices.count, default: index)
96
+ Viperaptor::UserPreferences.add_template_to_history(template_name)
97
+ end
98
+
99
+ code_module = CodeModule.new(module_name, rambafile, options)
100
+
101
+ module_validator = ModuleValidator.new
102
+ module_validator.validate(code_module)
103
+
104
+ module_info = ModuleInfoGenerator.new(code_module)
105
+ template = ModuleTemplate.new(template_name, module_info.scope)
106
+
107
+ parameters = GenCommandTableParametersFormatter.prepare_parameters_for_displaying(code_module, template_name)
108
+ PrintTable.print_values(
109
+ values: parameters,
110
+ title: "Summary for gen #{module_name}"
111
+ )
112
+
113
+ DependencyChecker.check_all_required_dependencies_has_in_podfile(template.dependencies, code_module.podfile_path)
114
+ DependencyChecker.check_all_required_dependencies_has_in_cartfile(template.dependencies, code_module.cartfile_path)
115
+
116
+ project = XcodeprojHelper.obtain_project(code_module.xcodeproj_path)
117
+ module_group_already_exists = XcodeprojHelper.module_with_group_path_already_exists(project, code_module.project_group_path)
118
+
119
+ if module_group_already_exists
120
+ replace_exists_module = yes?("#{module_name} module already exists. Replace? (yes/no)")
121
+
122
+ unless replace_exists_module
123
+ return
124
+ end
125
+ end
126
+
127
+ generator = Viperaptor::ModuleGenerator.new
128
+ generator.generate_module(module_name, code_module, template)
129
+ end
130
+
131
+ end
132
+ end
@@ -0,0 +1,122 @@
1
+ require 'thor'
2
+ require 'xcodeproj'
3
+ require 'liquid'
4
+ require 'git'
5
+ require 'viperaptor/constants/rambafile_constants.rb'
6
+ require 'viperaptor/helpers/print_table.rb'
7
+
8
+ module Viperaptor::CLI
9
+ class Application < Thor
10
+ include Viperaptor
11
+
12
+ desc 'setup', 'Creates a Rambafile with a config for a given project'
13
+ def setup
14
+ properties = {}
15
+
16
+ setup_username_command = Viperaptor::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 viperaptor setup'
111
+ )
112
+
113
+ Viperaptor::RambafileGenerator.create_rambafile(properties)
114
+ if should_add_templates
115
+ puts('Rambafile successfully created! Now run `viperaptor template install`.'.green)
116
+ else
117
+ puts('Rambafile successfully created!\n Go on and find some templates in our catalog using `viperaptor 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 Viperaptor::CLI
2
+ class SetupUsernameCommand < Thor
3
+
4
+ no_commands {
5
+ def setup_username
6
+ username = Viperaptor::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
+ Viperaptor::UserPreferences.save_username(username)
16
+ end
17
+
18
+ end
19
+ }
20
+ end
21
+ end
@@ -0,0 +1,40 @@
1
+ require 'viperaptor/helpers/print_table.rb'
2
+
3
+ module Viperaptor::CLI
4
+ class Template < Thor
5
+ include Viperaptor
6
+
7
+ desc 'create [TEMPLATE_NAME]', 'Creates a new Viperaptor 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 = Viperaptor::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 'viperaptor/cli/template/template_install_command.rb'
2
+ require 'viperaptor/cli/template/template_create_command.rb'
3
+ require 'viperaptor/cli/template/template_list_command.rb'
4
+ require 'viperaptor/cli/template/template_search_command.rb'
5
+
6
+ module Viperaptor::CLI
7
+ class Application < Thor
8
+ register(Viperaptor::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 Viperaptor::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 = Rambafile.exist
7
+
8
+ unless does_rambafile_exist
9
+ puts('Rambafile not found! Run `viperaptor setup` in the working directory instead!'.red)
10
+ return
11
+ end
12
+
13
+ catalog_downloader = Viperaptor::CatalogDownloader.new
14
+ installer_factory = Viperaptor::TemplateInstallerFactory.new
15
+ template_processor = Viperaptor::TemplateProcessor.new(catalog_downloader, installer_factory)
16
+
17
+ rambafile = Rambafile.rambafile
18
+ template_processor.install_templates(rambafile)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ require 'viperaptor/template/helpers/catalog_downloader'
2
+ require 'viperaptor/template/helpers/catalog_template_list_helper'
3
+
4
+ module Viperaptor::CLI
5
+ class Template < Thor
6
+ include Viperaptor
7
+
8
+ desc 'list', 'Prints out the list of all templates available in the shared GitHub catalog'
9
+ def list
10
+ templates = TemplateHelper.global_templates
11
+ templates.each do |template_name|
12
+ puts(template_name)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,30 @@
1
+ require 'viperaptor/template/helpers/catalog_downloader.rb'
2
+ require 'viperaptor/template/helpers/catalog_template_search_helper'
3
+
4
+ module Viperaptor::CLI
5
+ class Template < Thor
6
+ include Viperaptor
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 Viperaptor::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 != nil && 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