viperaptor 2.0.2 → 2.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '05568a147ce6c94c0129756da124fbcdcccd0adadeda98470f8d74e7e6593e27'
4
- data.tar.gz: c4e0440b2aa1cddafc1ca301ecb5097bef675bace8d3819bdd76f3e8d90766c1
3
+ metadata.gz: fd05a070a0f35fb5c85b83430e309bbc0c849f4d03b1b38a6967cbd2dc31552f
4
+ data.tar.gz: 146089e69493d6e98fabe7cac5a21c900a48802d5b909c5ab5544a3bc84f217d
5
5
  SHA512:
6
- metadata.gz: 5208926beb1bab564491ddea68e61aa46a96091308491906e8df816a0da5b2f8709dbd1a86c10eaf26bc6c524d6df489198c5f1a9c1ea7f7928e2ee56116751d
7
- data.tar.gz: 2ae41d53a65ae9066ef1fd2b47113cc68c52d2485a88709c27da64548eea5bee8249142deb4f775e6ce52629f1702162b544a4b211ed33a5b135c5743d4a9155
6
+ metadata.gz: 3ae0cfa9f2d4f0c9c7f1895f8f59b0f71cbdaa73f67c2776d58f4c3d72c88e734214cabfc66a95213c89bba5911d803d86b3c1d771926ff0a9335cc2289f03a2
7
+ data.tar.gz: 8438da43ccb0b05b12c0598ca64818161752cc1bfe6eb139f1096ed188716830ca12c2112dbae18f1b31e8f93c79290cea4db26ffaace4357dd1b9f57d4b75f8
@@ -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
@@ -9,9 +9,14 @@ module Viperaptor
9
9
  # @param file [Hash<String,String>] A hashmap with template's filename and filepath
10
10
  # @param scope [Hash<String,String>] A hashmap with module info
11
11
  # @param template [ModuleTemplate] The model describing a Viperaptor template used for code generation
12
+ # @param variables [Hash<String,String>] Custom variables of template
12
13
  #
13
14
  # @return [String], [String] The generated file_name and body
14
15
  def self.create_file(file, scope, template)
16
+
17
+ custom_parameters = template.custom_parameters || {}
18
+ scope['custom_parameters'] = (scope['custom_parameters'] || {}).merge(custom_parameters)
19
+
15
20
  file_source = IO.read(template.template_path.join(file[TEMPLATE_FILE_PATH_KEY]))
16
21
  Liquid::Template.file_system = Liquid::LocalFileSystem.new(template.template_path.join('snippets'), '%s.liquid')
17
22
 
@@ -21,7 +26,7 @@ module Viperaptor
21
26
  file_basename = File.basename(file[TEMPLATE_FILE_NAME_KEY])
22
27
 
23
28
  module_info = scope['module_info']
24
-
29
+
25
30
  module_info['file_basename'] = file_basename
26
31
 
27
32
  file_name = filename_template.render(scope)
@@ -1,10 +1,81 @@
1
- require 'viperaptor/helpers/template_helper.rb'
1
+ require "viperaptor/helpers/template_helper.rb"
2
+ require "tty-prompt"
2
3
 
3
4
  module Viperaptor
4
5
 
5
6
  # Represents a single Viperaptor module template
6
7
  class ModuleTemplate
7
- attr_reader :template_name, :template_path, :code_files, :test_files, :dependencies
8
+ attr_reader :template_name, :template_path, :code_files, :test_files, :dependencies, :custom_parameters
9
+
10
+ def load_custom_parameters_from_spec(spec)
11
+ custom_parameters = spec[TEMPLATE_CUSTOM_PARAMETERS_KEY]
12
+ result = {}
13
+ unless custom_parameters.nil?
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
74
+ end
75
+ end
76
+ end
77
+ return result
78
+ end
8
79
 
9
80
  def initialize(name, options = nil)
10
81
  spec_path = TemplateHelper.obtain_spec(name)
@@ -18,6 +89,33 @@ module Viperaptor
18
89
  spec = YAML.load(spec_content)
19
90
  end
20
91
 
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?
101
+ spec_source = IO.read(spec_path)
102
+ spec_template = Liquid::Template.parse(spec_source)
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)
115
+ spec = YAML.load(spec_content)
116
+ end
117
+
118
+ @custom_parameters = options["custom_parameters"]
21
119
  @code_files = spec[TEMPLATE_CODE_FILES_KEY]
22
120
  @test_files = spec[TEMPLATE_TEST_FILES_KEY]
23
121
  @template_name = spec[TEMPLATE_NAME_KEY]
@@ -25,4 +123,4 @@ module Viperaptor
25
123
  @dependencies = spec[TEMPLATE_DEPENDENCIES_KEY]
26
124
  end
27
125
  end
28
- end
126
+ end
@@ -1,18 +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'
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"
16
17
 
17
- TEMPLATE_DEPENDENCIES_KEY = 'dependencies'
18
- end
18
+ TEMPLATE_DEPENDENCIES_KEY = "dependencies"
19
+ TEMPLATE_VIPERAPTOR_KEY = "viperaptor"
20
+ end
@@ -9,6 +9,7 @@ module Viperaptor
9
9
  class ModuleGenerator
10
10
 
11
11
  def generate_module(name, code_module, template)
12
+
12
13
  # Setting up Xcode objects
13
14
  project = XcodeprojHelper.obtain_project(code_module.xcodeproj_path)
14
15
 
@@ -1,5 +1,5 @@
1
1
  module Viperaptor
2
- VERSION = '2.0.2'
3
- RELEASE_DATE = '29.01.2021'
2
+ VERSION = "2.2.1"
3
+ RELEASE_DATE = "23.02.2022"
4
4
  RELEASE_LINK = "https://github.com/ladeiko/Viperaptor/releases/tag/#{VERSION}"
5
5
  end
data/viperaptor.gemspec CHANGED
@@ -20,13 +20,13 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.required_ruby_version = '>= 2.3'
22
22
 
23
- spec.add_runtime_dependency 'thor', '1.0.1'
24
- spec.add_runtime_dependency 'xcodeproj', '1.19.0'
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'
28
- spec.add_runtime_dependency 'terminal-table', '2.0.0'
29
- spec.add_runtime_dependency 'tty-prompt', '~> 0.23.0'
23
+ spec.add_runtime_dependency 'thor', '1.2.1'
24
+ spec.add_runtime_dependency 'xcodeproj', '1.21.0'
25
+ spec.add_runtime_dependency 'liquid', '5.1.0'
26
+ spec.add_runtime_dependency 'git', '1.10.2'
27
+ spec.add_runtime_dependency 'cocoapods-core', '1.11.2'
28
+ spec.add_runtime_dependency 'terminal-table', '3.0.2'
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.0.2
4
+ version: 2.2.1
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-01-29 00:00:00.000000000 Z
11
+ date: 2022-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -16,98 +16,98 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.1
19
+ version: 1.2.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.1
26
+ version: 1.2.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: xcodeproj
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 1.19.0
33
+ version: 1.21.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 1.19.0
40
+ version: 1.21.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: liquid
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 4.0.3
47
+ version: 5.1.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 4.0.3
54
+ version: 5.1.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: git
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 1.7.0
61
+ version: 1.10.2
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.10.2
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.11.2
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.11.2
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: terminal-table
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - '='
88
88
  - !ruby/object:Gem::Version
89
- version: 2.0.0
89
+ version: 3.0.2
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - '='
95
95
  - !ruby/object:Gem::Version
96
- version: 2.0.0
96
+ version: 3.0.2
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: tty-prompt
99
99
  requirement: !ruby/object:Gem::Requirement
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
@@ -266,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
266
  - !ruby/object:Gem::Version
267
267
  version: '0'
268
268
  requirements: []
269
- rubygems_version: 3.1.4
269
+ rubygems_version: 3.2.22
270
270
  signing_key:
271
271
  specification_version: 4
272
272
  summary: Advanced code generator for Xcode projects with a nice and flexible template