viperaptor 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f58922aa6f479200b1c9099a373bed766afdb88d9beaea7be8ea508a85b71440
4
- data.tar.gz: 8d9e4a20456d7f2c675269b4574e72ce27dc5ca2f86d629a7895d65cbcaeb0e6
3
+ metadata.gz: 511d4e53992bbd033fa123803fc86f1c4b16aa0bc1fefbadf6524a9349f0151a
4
+ data.tar.gz: 459fd4cbc7ebf43e9ff8b27cc2a1d3bf7502d57ab16004007f06a6185e1230b1
5
5
  SHA512:
6
- metadata.gz: fb3a10779f5e0dfb0edc9d83a7114fe4a43c8baa5ca507b882c09f006fcda61986264e8aae8a480ddd91946f863b527d4bbe075c6579ae61a2371b4299924860
7
- data.tar.gz: 838bc157c71d2216fe479db47af6a20349b5b4dd15ac9e240491053de314b5c78e6e6ee7a72eb4e9f854de8c5b4bed52558b4967c88f100f39e58f1648361f88
6
+ metadata.gz: b643fec7143d92ff355466771c2d20c809933207b22fbea6f0666b30ddc3d69f83f96634ce0e87449378dc3dad7204e300138278d68c2100ef33b4d5192f2e68
7
+ data.tar.gz: 7ae375baddc38e7135bb4e42acde87c44499841ae487567bf21a434e595e38e11f92e87161c85b76a46eac39966966e5283ec9db976cc0ee1e630489c1d2e12d
@@ -1,40 +1,39 @@
1
- require 'thor'
1
+ require "thor"
2
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'
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
11
 
12
12
  module Viperaptor::CLI
13
13
  class Application < Thor
14
-
15
14
  include Viperaptor
16
15
 
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 :rambafile, :desc => 'Specifies Rambafile to use'
21
- method_option :project_targets, :desc => 'Specifies project targets for adding new module files'
22
- method_option :project_file_path, :desc => 'Specifies a location in the filesystem for new files'
23
- method_option :project_group_path, :desc => 'Specifies a location in Xcode groups for new files'
24
- method_option :module_path, :desc => 'Specifies a location (both in the filesystem and Xcode) for new files'
25
- method_option :test_targets, :desc => 'Specifies project targets for adding new test files'
26
- method_option :test_file_path, :desc => 'Specifies a location in the filesystem for new test files'
27
- method_option :test_group_path, :desc => 'Specifies a location in Xcode groups for new test files'
28
- method_option :test_path, :desc => 'Specifies a location (both in the filesystem and Xcode) for new test files'
29
- method_option :custom_parameters, :type => :hash, :default => {}, :desc => 'Specifies extra parameters in format `key1:value1 key2:value2` for usage during code generation'
30
- def gen(module_name = nil, template_name = nil)
16
+ desc "gen [MODULE_NAME] [TEMPLATE_NAME]", "Creates a new VIPER module with a given name from a specific template"
17
+ method_option :description, :aliases => "-d", :desc => "Provides a full description to the module"
18
+ method_option :author, :desc => "Specifies the author name for generated module"
19
+ method_option :rambafile, :desc => "Specifies Rambafile to use"
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"
31
29
 
30
+ def gen(module_name = nil, template_name = nil)
32
31
  Rambafile.use(options[:rambafile])
33
32
 
34
33
  does_rambafile_exist = Rambafile.exist
35
34
 
36
35
  unless does_rambafile_exist
37
- puts('Rambafile not found! Run `viperaptor setup` in the working directory instead!'.red)
36
+ puts("Rambafile not found! Run `viperaptor setup` in the working directory instead!".red)
38
37
  return
39
38
  end
40
39
 
@@ -55,15 +54,15 @@ module Viperaptor::CLI
55
54
  templates_as_set = Set.new(templates.map { |t| t["name"] })
56
55
  templates = templates.concat(TemplateHelper.global_templates.select { |t| !templates_as_set.include?(t) }.map { |name| { "name" => name } }).sort_by { |t| t["name"] }
57
56
 
58
- filter = rambafile[TEMPLATES_FILTER_KEY] || ''
57
+ filter = rambafile[TEMPLATES_FILTER_KEY] || ""
59
58
 
60
59
  if !filter.kind_of?(Array)
61
60
  filter = [filter]
62
61
  end
63
62
 
64
63
  filter = filter.map { |f| f.strip }.select { |f| !f.empty? }
65
- negative_filters = filter.select { |f| f.start_with?('!') }.map { |f| f[1...] }.map { |f| Regexp.new(f, Regexp::IGNORECASE) }
66
- positive_filters = filter.select { |f| !f.start_with?('!') }.map { |f| Regexp.new(f, Regexp::IGNORECASE) }
64
+ negative_filters = filter.select { |f| f.start_with?("!") }.map { |f| f[1...] }.map { |f| Regexp.new(f, Regexp::IGNORECASE) }
65
+ positive_filters = filter.select { |f| !f.start_with?("!") }.map { |f| Regexp.new(f, Regexp::IGNORECASE) }
67
66
  original_templates = templates
68
67
 
69
68
  if original_templates.count == 0
@@ -72,7 +71,6 @@ module Viperaptor::CLI
72
71
  end
73
72
 
74
73
  templates = templates.select do |t|
75
-
76
74
  if filter.count == 0
77
75
  next true
78
76
  end
@@ -110,8 +108,8 @@ module Viperaptor::CLI
110
108
 
111
109
  parameters = GenCommandTableParametersFormatter.prepare_parameters_for_displaying(code_module, template_name)
112
110
  PrintTable.print_values(
113
- values: parameters,
114
- title: "Summary for gen #{module_name}"
111
+ values: parameters,
112
+ title: "Summary for gen #{module_name}",
115
113
  )
116
114
 
117
115
  DependencyChecker.check_all_required_dependencies_has_in_podfile(template.dependencies, code_module.podfile_path)
@@ -122,7 +120,7 @@ module Viperaptor::CLI
122
120
 
123
121
  if module_group_already_exists
124
122
  replace_exists_module = yes?("#{module_name} module already exists. Replace? (yes/no)")
125
-
123
+
126
124
  unless replace_exists_module
127
125
  return
128
126
  end
@@ -131,6 +129,5 @@ module Viperaptor::CLI
131
129
  generator = Viperaptor::ModuleGenerator.new
132
130
  generator.generate_module(module_name, code_module, template)
133
131
  end
134
-
135
132
  end
136
- end
133
+ end
@@ -14,7 +14,7 @@ module Viperaptor
14
14
  # @return [String], [String] The generated file_name and body
15
15
  def self.create_file(file, scope, template)
16
16
 
17
- custom_parameters = template.custom_parameters
17
+ custom_parameters = template.custom_parameters || {}
18
18
  scope['custom_parameters'] = (scope['custom_parameters'] || {}).merge(custom_parameters)
19
19
 
20
20
  file_source = IO.read(template.template_path.join(file[TEMPLATE_FILE_PATH_KEY]))
@@ -1,4 +1,4 @@
1
- require 'viperaptor/helpers/template_helper.rb'
1
+ require "viperaptor/helpers/template_helper.rb"
2
2
  require "tty-prompt"
3
3
 
4
4
  module Viperaptor
@@ -7,30 +7,74 @@ module Viperaptor
7
7
  class ModuleTemplate
8
8
  attr_reader :template_name, :template_path, :code_files, :test_files, :dependencies, :custom_parameters
9
9
 
10
- def load_variables_from_spec(spec)
10
+ def load_custom_parameters_from_spec(spec)
11
11
  custom_parameters = spec[TEMPLATE_CUSTOM_PARAMETERS_KEY]
12
- @custom_parameters = {}
12
+ result = {}
13
13
  unless custom_parameters.nil?
14
- custom_parameters.sort_by { |a| (a['order'] || 0) }.map do |desc|
15
- if desc["type"].is_a?(Array)
16
- prompt = TTY::Prompt.new
17
- choices = desc["type"]
18
- value = prompt.select("Select #{desc["description"]}?", choices, per_page: choices.count)
19
- @custom_parameters[desc["name"]] = value
20
- elsif desc["type"] == 'boolean'
21
- prompt = TTY::Prompt.new
22
- value = prompt.yes?("#{desc["description"]}?")
23
- @custom_parameters[desc["name"]] = value
24
- elsif desc["type"] == 'text'
25
- prompt = TTY::Prompt.new
26
- value = prompt.ask("#{desc["description"]}?")
27
- @custom_parameters[desc["name"]] = value
28
- else
29
- puts("ERROR: Invalid variable type of template custom parameter '#{desc['name']}'".red)
30
- exit(1)
14
+ custom_parameters.sort_by { |a| (a["order"] || 0) }.each do |desc|
15
+ skip = false
16
+
17
+ if !desc["only_if"].nil? && desc["only_if"].is_a?(Hash)
18
+ desc["only_if"].each do |key, value|
19
+ if value.is_a?(Array)
20
+ if result[key].nil?
21
+ puts("ERROR: Required custom_parameter '#{key}' not defined".red)
22
+ exit(1)
23
+ end
24
+
25
+ if !value.include?(result[key])
26
+ skip = true
27
+ break
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ if !skip
34
+ if !desc["only_if"].nil? && desc["only_if_not"].is_a?(Hash)
35
+ desc["only_if"].each do |key, value|
36
+ if value.is_a?(Array)
37
+ if result[key].nil?
38
+ break
39
+ end
40
+
41
+ if value.include?(result[key])
42
+ skip = true
43
+ break
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ if !skip
51
+ if desc["options"].instance_of?(Array)
52
+ prompt = TTY::Prompt.new
53
+ choices = desc["options"]
54
+ value = prompt.select("#{desc["description"]}?", choices, per_page: choices.count)
55
+
56
+ case value
57
+ when "yes"
58
+ value = "true"
59
+ when "no"
60
+ value = "false"
61
+ else
62
+ #
63
+ end
64
+
65
+ result[desc["name"]] = value
66
+ elsif desc["options"].nil?
67
+ prompt = TTY::Prompt.new
68
+ value = prompt.ask("#{desc["description"]}?")
69
+ result[desc["name"]] = value
70
+ else
71
+ puts("ERROR: Invalid variable 'options' of template custom parameter '#{desc["name"]}'".red)
72
+ exit(1)
73
+ end
31
74
  end
32
75
  end
33
76
  end
77
+ return result
34
78
  end
35
79
 
36
80
  def initialize(name, options = nil)
@@ -45,14 +89,33 @@ module Viperaptor
45
89
  spec = YAML.load(spec_content)
46
90
  end
47
91
 
48
- load_variables_from_spec(spec)
49
- if !@custom_parameters.empty? && !options.nil?
92
+ viperaptor = spec[TEMPLATE_VIPERAPTOR_KEY]
93
+ if !viperaptor.nil? && Gem::Version.new(Viperaptor::VERSION) < Gem::Version.new(viperaptor)
94
+ puts("ERROR: Your viperaptor version is '#{Viperaptor::VERSION}' template requires '#{viperaptor}'. Please update it.".red)
95
+ exit(1)
96
+ end
97
+
98
+ custom_parameters = load_custom_parameters_from_spec(spec)
99
+
100
+ if !custom_parameters.empty? && !options.nil?
50
101
  spec_source = IO.read(spec_path)
51
102
  spec_template = Liquid::Template.parse(spec_source)
52
- spec_content = spec_template.render(options.merge(@custom_parameters))
103
+
104
+ if options["custom_parameters"].nil?
105
+ options["custom_parameters"] = {}
106
+ end
107
+
108
+ new_options = options["custom_parameters"].merge(custom_parameters)
109
+
110
+ new_options.each_key do |k|
111
+ options["custom_parameters"][k] = new_options[k]
112
+ end
113
+
114
+ spec_content = spec_template.render(options)
53
115
  spec = YAML.load(spec_content)
54
116
  end
55
117
 
118
+ @custom_parameters = options["custom_parameters"]
56
119
  @code_files = spec[TEMPLATE_CODE_FILES_KEY]
57
120
  @test_files = spec[TEMPLATE_TEST_FILES_KEY]
58
121
  @template_name = spec[TEMPLATE_NAME_KEY]
@@ -60,4 +123,4 @@ module Viperaptor
60
123
  @dependencies = spec[TEMPLATE_DEPENDENCIES_KEY]
61
124
  end
62
125
  end
63
- end
126
+ end
@@ -1,19 +1,20 @@
1
1
  module Viperaptor
2
2
 
3
3
  # Keys of .rambaspec files
4
- TEMPLATE_NAME_KEY = 'name'
5
- TEMPLATE_SUMMARY_KEY = 'summary'
6
- TEMPLATE_AUTHOR_KEY = 'author'
7
- TEMPLATE_VERSION_KEY = 'version'
8
- TEMPLATE_LICENSE_KEY = 'license'
4
+ TEMPLATE_NAME_KEY = "name"
5
+ TEMPLATE_SUMMARY_KEY = "summary"
6
+ TEMPLATE_AUTHOR_KEY = "author"
7
+ TEMPLATE_VERSION_KEY = "version"
8
+ TEMPLATE_LICENSE_KEY = "license"
9
9
 
10
- TEMPLATE_CODE_FILES_KEY = 'code_files'
11
- TEMPLATE_TEST_FILES_KEY = 'test_files'
12
- TEMPLATE_FILE_NAME_KEY = 'name'
13
- TEMPLATE_FILE_CUSTOM_NAME_KEY = 'custom_name'
14
- TEMPLATE_FILE_PATH_KEY = 'path'
15
- TEMPLATE_FILE_IS_RESOURCE_KEY = 'is_resource'
16
- TEMPLATE_CUSTOM_PARAMETERS_KEY = 'custom_parameters'
10
+ TEMPLATE_CODE_FILES_KEY = "code_files"
11
+ TEMPLATE_TEST_FILES_KEY = "test_files"
12
+ TEMPLATE_FILE_NAME_KEY = "name"
13
+ TEMPLATE_FILE_CUSTOM_NAME_KEY = "custom_name"
14
+ TEMPLATE_FILE_PATH_KEY = "path"
15
+ TEMPLATE_FILE_IS_RESOURCE_KEY = "is_resource"
16
+ TEMPLATE_CUSTOM_PARAMETERS_KEY = "custom_parameters"
17
17
 
18
- TEMPLATE_DEPENDENCIES_KEY = 'dependencies'
19
- end
18
+ TEMPLATE_DEPENDENCIES_KEY = "dependencies"
19
+ TEMPLATE_VIPERAPTOR_KEY = "viperaptor"
20
+ end
@@ -1,5 +1,5 @@
1
1
  module Viperaptor
2
- VERSION = '2.1.0'
3
- RELEASE_DATE = '01.02.2021'
2
+ VERSION = "2.2.0"
3
+ RELEASE_DATE = "24.06.2021"
4
4
  RELEASE_LINK = "https://github.com/ladeiko/Viperaptor/releases/tag/#{VERSION}"
5
5
  end
data/viperaptor.gemspec CHANGED
@@ -23,10 +23,10 @@ Gem::Specification.new do |spec|
23
23
  spec.add_runtime_dependency 'thor', '1.0.1'
24
24
  spec.add_runtime_dependency 'xcodeproj', '1.19.0'
25
25
  spec.add_runtime_dependency 'liquid', '4.0.3'
26
- spec.add_runtime_dependency 'git', '1.7.0'
27
- spec.add_runtime_dependency 'cocoapods-core', '1.10.0'
26
+ spec.add_runtime_dependency 'git', '1.8.1'
27
+ spec.add_runtime_dependency 'cocoapods-core', '1.10.1'
28
28
  spec.add_runtime_dependency 'terminal-table', '2.0.0'
29
- spec.add_runtime_dependency 'tty-prompt', '~> 0.23.0'
29
+ spec.add_runtime_dependency 'tty-prompt', '~> 0.23.1'
30
30
 
31
31
  spec.add_development_dependency 'bundler', '>= 1.16'
32
32
  spec.add_development_dependency 'rake', '~> 13.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: viperaptor
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Siarhei Ladzeika
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-01 00:00:00.000000000 Z
11
+ date: 2021-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -58,28 +58,28 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 1.7.0
61
+ version: 1.8.1
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 1.7.0
68
+ version: 1.8.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: cocoapods-core
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 1.10.0
75
+ version: 1.10.1
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: 1.10.0
82
+ version: 1.10.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: terminal-table
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.23.0
103
+ version: 0.23.1
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 0.23.0
110
+ version: 0.23.1
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: bundler
113
113
  requirement: !ruby/object:Gem::Requirement