viperaptor 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,107 @@
1
+ require 'git'
2
+ require 'fileutils'
3
+
4
+ module Viperaptor
5
+
6
+ # Provides the functionality to download template catalogs from the remote repository
7
+ class CatalogDownloader
8
+
9
+ def external_catalogs_filepaths
10
+
11
+ catalogs_path = Pathname.new(ENV['HOME'])
12
+ .join(APP_HOME_DIR)
13
+ .join(CATALOGS_DIR)
14
+
15
+ return [] unless catalogs_path.exist?
16
+
17
+ catalogs_path.children.select { |child|
18
+ child.directory? && child.split.last.to_s[0] != '.'
19
+ }
20
+ end
21
+
22
+ # Updates all of the template catalogs and returns their filepaths.
23
+ # If there is a Rambafile in the current directory, it also updates all of the catalogs specified there.
24
+ #
25
+ # @return [Array] An array of filepaths to downloaded catalogs
26
+ def update_all_catalogs_and_return_filepaths(throttled = false)
27
+ does_rambafile_exist = Rambafile.exist
28
+
29
+ if does_rambafile_exist
30
+ rambafile = Rambafile.rambafile
31
+ catalogs = rambafile[CATALOGS_KEY]
32
+ end
33
+
34
+ # terminator = CatalogTerminator.new
35
+ # terminator.remove_all_catalogs
36
+
37
+ repos = (Viperaptor::UserPreferences.obtain_custom_catalogs_repos || []) + PREDEFINED_CATALOG_REPOS
38
+
39
+ catalog_paths = repos.map do |repo|
40
+ name = repo.split('/').last
41
+
42
+ catalogs_local_path = Pathname.new(ENV['HOME'])
43
+ .join(APP_HOME_DIR)
44
+ .join(CATALOGS_DIR)
45
+ current_catalog_path = catalogs_local_path
46
+ .join(name)
47
+
48
+ if !current_catalog_path.exist? || !throttled || (Time.now - current_catalog_path.mtime) > 3600.0 * 12.0
49
+ download_catalog(name, repo)
50
+ end
51
+
52
+ current_catalog_path
53
+ end
54
+
55
+ if catalogs != nil && catalogs.count > 0
56
+ catalogs.each do |catalog_url|
57
+
58
+ name = catalog_url.split('://').last
59
+ name = name.gsub('/', '-');
60
+
61
+ catalogs_local_path = Pathname.new(ENV['HOME'])
62
+ .join(APP_HOME_DIR)
63
+ .join(CATALOGS_DIR)
64
+ current_catalog_path = catalogs_local_path
65
+ .join(name)
66
+
67
+ if !current_catalog_path.exist? || !throttled || (Time.now - current_catalog_path.mtime) > 3600.0 * 12.0
68
+ download_catalog(name, catalog_url)
69
+ end
70
+
71
+ catalog_paths.push(current_catalog_path)
72
+ end
73
+ end
74
+ return catalog_paths
75
+ end
76
+
77
+ # Clones a template catalog from a remote repository
78
+ #
79
+ # @param name [String] The name of the template catalog
80
+ # @param url [String] The url of the repository
81
+ #
82
+ # @return [Pathname] A filepath to the downloaded catalog
83
+ def download_catalog(name, url)
84
+
85
+ catalogs_local_path = Pathname.new(ENV['HOME'])
86
+ .join(APP_HOME_DIR)
87
+ .join(CATALOGS_DIR)
88
+ current_catalog_path = catalogs_local_path
89
+ .join(name)
90
+
91
+ puts("Updating #{name} specs (#{url})...")
92
+
93
+ git_dir = current_catalog_path.join('.git')
94
+
95
+ if File.directory?(git_dir)
96
+ g = Git.open(current_catalog_path)
97
+ g.pull
98
+ FileUtils.touch current_catalog_path
99
+ else
100
+ FileUtils.rm_rf current_catalog_path
101
+ Git.clone(url, name, :path => catalogs_local_path)
102
+ end
103
+
104
+ return current_catalog_path
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,55 @@
1
+ module Viperaptor
2
+
3
+ # Provides the functionality to list all of the templates, available in the catalog
4
+ class CatalogTemplateListHelper
5
+
6
+ # Finds out all of the templates located in a catalog
7
+ #
8
+ # @param catalog_path [Pathname] The path to a template catalog
9
+ #
10
+ # @return [Array] An array with template names
11
+ def obtain_all_templates_from_a_catalog(catalog_path)
12
+
13
+ return [] unless catalog_path.exist?
14
+
15
+ contains_specs = catalog_path.children.count { |c|
16
+ c.extname == RAMBASPEC_EXTENSION
17
+ } > 0
18
+
19
+ skip_testable = ENV['RACK_ENV'] != 'test'
20
+
21
+ if contains_specs
22
+
23
+ if !skip_testable || catalog_path.split.last.to_s.start_with?("test-")
24
+ return []
25
+ end
26
+
27
+ return catalog_path.children
28
+ .map { |child| child.split.last.to_s }
29
+ .select { |i| /^[a-z0-9_]+\.rambaspec$/.match(i) }
30
+ .map { |i| i.gsub RAMBASPEC_EXTENSION, '' }
31
+ else
32
+ return catalog_path.children
33
+ .select {|child| child.directory? && child.split.last.to_s[0] != '.' }
34
+ .select {|child| !skip_testable || !child.split.last.to_s.start_with?("test-") }
35
+ .select {|child|
36
+ child.join(child.split.last.to_s.gsub('/','') + RAMBASPEC_EXTENSION).exist? }
37
+ .map { |child| child.split.last.to_s }
38
+ end
39
+ end
40
+
41
+ def template_path(catalog_path, template_name)
42
+ contains_specs = catalog_path.children.count { |c|
43
+ c.extname == RAMBASPEC_EXTENSION
44
+ } > 0
45
+
46
+ if contains_specs
47
+ return catalog_path
48
+ else
49
+ return catalog_path.join(template_name)
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,27 @@
1
+ module Viperaptor
2
+
3
+ # Provides the functionality to search templates, in catalogs
4
+ class CatalogTemplateSearchHelper
5
+
6
+ # Finds out all of the templates located in a catalog
7
+ #
8
+ # @param catalog_path [Pathname] The path to a template catalog
9
+ #
10
+ # @return [Array] An array with template names
11
+ def search_templates_in_a_catalog(catalog_path, search_term)
12
+ template_names = []
13
+
14
+ catalog_path.children.select { |child|
15
+ File.directory?(child) && child.split.last.to_s[0] != '.'
16
+ }.map { |template_path|
17
+ template_path.split.last.to_s
18
+ }.select { |template_name|
19
+ template_name.include?(search_term)
20
+ }.each { |template_name|
21
+ template_names.push(template_name)
22
+ }
23
+
24
+ return template_names
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,21 @@
1
+ module Viperaptor
2
+
3
+ # Provides a functionality to terminate all previously installed catalogs
4
+ #
5
+ # @return [Void]
6
+ class CatalogTerminator
7
+ def remove_all_catalogs
8
+ catalogs_path = Pathname.new(ENV['HOME'])
9
+ .join(APP_HOME_DIR)
10
+ .join(CATALOGS_DIR)
11
+ if Dir.exist?(catalogs_path) == false
12
+ FileUtils.mkdir_p catalogs_path
13
+ end
14
+ catalogs_path.children.select { |child|
15
+ child.directory? && child.split.last.to_s[0] != '.'
16
+ }.each { |catalog_path|
17
+ FileUtils.rm_rf(catalog_path)
18
+ }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,52 @@
1
+ module Viperaptor
2
+
3
+ # Provides methods that validate .rambaspec file existance and structure
4
+ class RambaspecValidator
5
+
6
+ # Validates the existance of a .rambaspec file for a given template
7
+ #
8
+ # @param template_name [String] The name of the template
9
+ # @param template_path [String] The local filepath to the template
10
+ #
11
+ # @return [Bool]
12
+ def self.validate_spec_existance(template_name, template_path)
13
+ local_spec_path = self.obtain_spec_path(template_name, template_path)
14
+ File.file?(local_spec_path)
15
+ end
16
+
17
+ # Validates the structure of a .rambaspec file for a given template
18
+ #
19
+ # @param template_name [String] The name of the template
20
+ # @param template_path [String] The local filepath to the template
21
+ #
22
+ # @return [Bool]
23
+ def self.validate_spec(template_name, template_path)
24
+ spec_path = self.obtain_spec_path(template_name, template_path)
25
+
26
+ spec_source = IO.read(spec_path)
27
+ spec_template = Liquid::Template.parse(spec_source)
28
+ spec_content = spec_template.render
29
+ spec = YAML.load(spec_content)
30
+
31
+ is_spec_valid =
32
+ spec[TEMPLATE_NAME_KEY] != nil &&
33
+ spec[TEMPLATE_AUTHOR_KEY] != nil &&
34
+ spec[TEMPLATE_VERSION_KEY] != nil &&
35
+ (spec[TEMPLATE_CODE_FILES_KEY] != nil || spec[TEMPLATE_TEST_FILES_KEY] != nil)
36
+ return is_spec_valid
37
+ end
38
+
39
+ private
40
+
41
+ # Returns a filepath for a given .rambaspec filename
42
+ #
43
+ # @param template_name [String] The name of the template
44
+ # @param template_path [String] The local filepath to the template
45
+ #
46
+ # @return [Bool]
47
+ def self.obtain_spec_path(template_name, template_path)
48
+ spec_filename = template_name + RAMBASPEC_EXTENSION
49
+ Pathname.new(template_path).join(spec_filename)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,9 @@
1
+ module Viperaptor
2
+
3
+ # Abstract template installer class
4
+ class AbstractInstaller
5
+ def install_template(template_declaration)
6
+ raise 'Abstract Method - you should implement it in the concrete subclass'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,78 @@
1
+ require 'viperaptor/template/installer/abstract_installer.rb'
2
+ require 'viperaptor/template/helpers/rambaspec_validator.rb'
3
+ require 'fileutils'
4
+ require 'tmpdir'
5
+
6
+ module Viperaptor
7
+
8
+ # Incapsulates the logic of installing Viperaptor templates from the template catalog
9
+ class CatalogInstaller < AbstractInstaller
10
+ def install_template(template_declaration)
11
+ template_name = template_declaration.name
12
+ puts("Installing #{template_name}...")
13
+
14
+ template_name = template_declaration.name
15
+ catalogs_path = Pathname.new(ENV['HOME'])
16
+ .join(APP_HOME_DIR)
17
+ .join(CATALOGS_DIR)
18
+
19
+ catalog_path = catalogs_path.children.select { |child|
20
+ child.directory? && child.split.last.to_s[0] != '.'
21
+ }.select { |catalog_path|
22
+ template_path = browse_catalog_for_a_template(catalog_path, template_name)
23
+ template_path != nil
24
+ }.first
25
+
26
+ if catalog_path == nil
27
+ error_description = "Cannot find #{template_name} in any catalog. Try another name.".red
28
+ puts(error_description)
29
+ return
30
+ end
31
+
32
+ template_path = catalog_path.join(template_name)
33
+ rambaspec_exist = Viperaptor::RambaspecValidator.validate_spec_existance(template_name, template_path)
34
+ unless rambaspec_exist
35
+ error_description = "Cannot find #{template_name + RAMBASPEC_EXTENSION} in the template catalog #{catalog_path}. Try another name.".red
36
+ puts(error_description)
37
+ return
38
+ end
39
+
40
+ rambaspec_valid = Viperaptor::RambaspecValidator.validate_spec(template_name, template_path)
41
+ unless rambaspec_valid
42
+ error_description = "#{template_name + RAMBASPEC_EXTENSION} is not valid.".red
43
+ puts(error_description)
44
+ return
45
+ end
46
+
47
+ install_path = Pathname.new(Rambafile.suffix(TEMPLATES_FOLDER))
48
+ .join(template_name)
49
+ FileUtils.mkdir_p install_path
50
+
51
+ src = template_path.to_s + '/.'
52
+ FileUtils.cp_r(src, install_path)
53
+ end
54
+
55
+ private
56
+
57
+ # Browses a given catalog and returns a template path
58
+ #
59
+ # @param catalog_path [Pathname] A path to a catalog
60
+ # @param template_name [String] A name of the template
61
+ #
62
+ # @return [Pathname] A path to a template, if found
63
+ def browse_catalog_for_a_template(catalog_path, template_name)
64
+ template_path_as_folder = catalog_path.join(template_name)
65
+ template_path_as_spec = catalog_path.join(template_name + RAMBASPEC_EXTENSION)
66
+
67
+ if File.exist?(template_path_as_spec)
68
+ return catalog_path
69
+ end
70
+
71
+ if Dir.exist?(template_path_as_folder)
72
+ return template_path_as_folder
73
+ end
74
+
75
+ return nil
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,32 @@
1
+ require 'viperaptor/template/installer/abstract_installer.rb'
2
+ require 'viperaptor/template/helpers/rambaspec_validator.rb'
3
+
4
+ module Viperaptor
5
+
6
+ # Incapsulates the logic of verifying and installing local templates
7
+ class LocalInstaller < AbstractInstaller
8
+ def install_template(template_declaration)
9
+ template_name = template_declaration.name
10
+ puts("Installing #{template_name}...")
11
+
12
+ local_path = template_declaration.local
13
+ rambaspec_exist = Viperaptor::RambaspecValidator.validate_spec_existance(template_name, local_path)
14
+
15
+ unless rambaspec_exist
16
+ error_description = "Cannot find #{template_name + RAMBASPEC_EXTENSION} in the specified directory. Try another path or name.".red
17
+ raise StandardError.new(error_description)
18
+ end
19
+
20
+ rambaspec_valid = Viperaptor::RambaspecValidator.validate_spec(template_name, local_path)
21
+ unless rambaspec_valid
22
+ error_description = "#{template_name + RAMBASPEC_EXTENSION} is not valid.".red
23
+ raise StandardError.new(error_description)
24
+ end
25
+
26
+ install_path = Pathname.new(Rambafile.suffix(TEMPLATES_FOLDER))
27
+ .join(template_name)
28
+ FileUtils.mkdir_p install_path
29
+ FileUtils.copy_entry(local_path, install_path)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,51 @@
1
+ require 'viperaptor/template/installer/abstract_installer.rb'
2
+ require 'viperaptor/template/helpers/rambaspec_validator.rb'
3
+ require 'git'
4
+ require 'fileutils'
5
+ require 'tmpdir'
6
+
7
+ module Viperaptor
8
+
9
+ # Incapsulates the logic of fetching remote templates, verifying and installing them
10
+ class RemoteInstaller < AbstractInstaller
11
+ def install_template(template_declaration)
12
+ template_name = template_declaration.name
13
+ puts("Installing #{template_name}...")
14
+
15
+ repo_url = template_declaration.git
16
+ repo_branch = template_declaration.branch
17
+
18
+ Dir.mktmpdir do |temp_path|
19
+ template_dir = Pathname.new(temp_path).join(template_name)
20
+
21
+ if repo_branch != nil
22
+ Git.export(repo_url, template_name, :branch => repo_branch, :path => temp_path)
23
+ else
24
+ Git.clone(repo_url, template_name, :path => temp_path)
25
+ end
26
+
27
+ template_path = "#{template_dir}"
28
+
29
+ rambaspec_exist = Viperaptor::RambaspecValidator.validate_spec_existance(template_name, template_path)
30
+ unless rambaspec_exist
31
+ FileUtils.rm_rf(temp_path)
32
+ error_description = "Cannot find #{template_name + RAMBASPEC_EXTENSION} in the root directory of specified repository.".red
33
+ raise StandardError.new(error_description)
34
+ end
35
+
36
+ rambaspec_valid = Viperaptor::RambaspecValidator.validate_spec(template_name, template_path)
37
+ unless rambaspec_valid
38
+ error_description = "#{template_name + RAMBASPEC_EXTENSION} is not valid.".red
39
+ raise StandardError.new(error_description)
40
+ end
41
+
42
+ install_path = Pathname.new(Rambafile.suffix(TEMPLATES_FOLDER))
43
+ .join(template_name)
44
+ FileUtils.mkdir_p install_path
45
+ FileUtils.copy_entry(template_path, install_path)
46
+
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,22 @@
1
+ require 'viperaptor/template/processor/template_declaration'
2
+
3
+ module Viperaptor
4
+
5
+ # Factory that creates a proper installer for a given template type
6
+ class TemplateInstallerFactory
7
+
8
+ # Provides the appropriate strategy for a given template type
9
+ def installer_for_type(type)
10
+ case type
11
+ when TemplateDeclarationType::LOCAL_TEMPLATE
12
+ return Viperaptor::LocalInstaller.new
13
+ when TemplateDeclarationType::REMOTE_TEMPLATE
14
+ return Viperaptor::RemoteInstaller.new
15
+ when TemplateDeclarationType::CATALOG_TEMPLATE
16
+ return Viperaptor::CatalogInstaller.new
17
+ else
18
+ return nil
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,36 @@
1
+ module Viperaptor
2
+
3
+ # This class acts as an Enumeration for TemplateDeclaration types
4
+ class TemplateDeclarationType
5
+ # A local template - usually it's stored somewhere outside the current project directory
6
+ LOCAL_TEMPLATE = 0
7
+
8
+ # A remote template - it's stored in a remote Git repository
9
+ REMOTE_TEMPLATE = 1
10
+
11
+ # A template from our shared catalog
12
+ CATALOG_TEMPLATE = 2
13
+ end
14
+
15
+ # Describes a Viperaptor template declaration model
16
+ class TemplateDeclaration
17
+
18
+ attr_reader :name, :local, :git, :branch, :type
19
+
20
+ def initialize(template_hash)
21
+ @name = template_hash[TEMPLATE_DECLARATION_NAME_KEY]
22
+ @local = template_hash[TEMPLATE_DECLARATION_LOCAL_KEY]
23
+ @git = template_hash[TEMPLATE_DECLARATION_GIT_KEY]
24
+ @branch = template_hash[TEMPLATE_DECLARATION_BRANCH_KEY]
25
+
26
+ @type = TemplateDeclarationType::LOCAL_TEMPLATE if @local
27
+ @type = TemplateDeclarationType::REMOTE_TEMPLATE if @git
28
+ @type = TemplateDeclarationType::CATALOG_TEMPLATE if @git == nil && @local == nil
29
+ end
30
+
31
+ def install(strategy)
32
+ strategy.install_template(self)
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,73 @@
1
+ require 'viperaptor/template/processor/template_declaration.rb'
2
+ require 'viperaptor/template/installer/local_installer.rb'
3
+ require 'viperaptor/template/installer/remote_installer.rb'
4
+ require 'viperaptor/template/installer/catalog_installer.rb'
5
+ require 'viperaptor/template/helpers/catalog_downloader.rb'
6
+ require 'viperaptor/template/helpers/catalog_terminator'
7
+ require 'git'
8
+
9
+ module Viperaptor
10
+
11
+ # Incapsulates logic of processing templates declaration section from Rambafile
12
+ class TemplateProcessor
13
+
14
+ def initialize(catalog_downloader, installer_factory)
15
+ @catalog_downloader = catalog_downloader
16
+ @installer_factory = installer_factory
17
+ end
18
+
19
+ # This method parses Rambafile, serializes templates hashes into model objects and install them
20
+ def install_templates(rambafile)
21
+ # We always clear previously installed templates to avoid conflicts in different versions
22
+ clear_installed_templates
23
+
24
+ templates = rambafile[TEMPLATES_KEY] || []
25
+
26
+ # Mapping hashes to model objects
27
+ templates = templates.map { |template_hash|
28
+ Viperaptor::TemplateDeclaration.new(template_hash)
29
+ }
30
+
31
+ catalogs = rambafile[CATALOGS_KEY] || []
32
+
33
+ # If there is at least one template from catalogs, we should update our local copy of the catalog
34
+ update_catalogs_if_needed(catalogs, templates)
35
+
36
+ templates.each do |template_declaration|
37
+ strategy = @installer_factory.installer_for_type(template_declaration.type)
38
+ template_declaration.install(strategy)
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ # Clears all of the currently installed templates
45
+ def clear_installed_templates
46
+ install_path = Pathname.new(Rambafile.suffix(TEMPLATES_FOLDER))
47
+ FileUtils.rm_rf(Dir.glob(install_path))
48
+ end
49
+
50
+ # Clones remote template catalogs to the local directory
51
+ def update_catalogs_if_needed(catalogs, templates)
52
+ needs_update = templates.any? {|template| template.type == TemplateDeclarationType::CATALOG_TEMPLATE}
53
+
54
+ return unless needs_update
55
+
56
+ terminator = CatalogTerminator.new
57
+ terminator.remove_all_catalogs
58
+ puts('Updating shared catalogs specs...')
59
+
60
+ catalogs.each do |catalog_url|
61
+ @catalog_downloader.download_catalog(catalog_url.split('/').last, catalog_url)
62
+ end
63
+
64
+ return unless catalogs != nil && catalogs.count > 0
65
+
66
+ catalogs.each do |catalog_url|
67
+ catalog_name = catalog_url.split('://').last
68
+ catalog_name = catalog_name.gsub('/', '-');
69
+ @catalog_downloader.download_catalog(catalog_name, catalog_url)
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,23 @@
1
+ # Adds a number of methods for colorizing output strings
2
+ class String
3
+
4
+ def colorize(color_code)
5
+ "\e[#{color_code}m#{self}\e[0m"
6
+ end
7
+
8
+ def red
9
+ colorize(31)
10
+ end
11
+
12
+ def green
13
+ colorize(32)
14
+ end
15
+
16
+ def yellow
17
+ colorize(33)
18
+ end
19
+
20
+ def blue
21
+ colorize(34)
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ module Viperaptor
2
+ VERSION = '2.0.0'
3
+ RELEASE_DATE = '11.01.2021'
4
+ RELEASE_LINK = "https://github.com/ladeiko/Viperaptor/releases/tag/#{VERSION}"
5
+ end
data/lib/viperaptor.rb ADDED
@@ -0,0 +1,16 @@
1
+ module Viperaptor
2
+ require 'viperaptor/constants/constants.rb'
3
+ require 'viperaptor/constants/rambafile_constants.rb'
4
+ require 'viperaptor/constants/rambaspec_constants.rb'
5
+ require 'viperaptor/cli/cli.rb'
6
+ require 'viperaptor/code_generation/code_module.rb'
7
+ require 'viperaptor/code_generation/module_template.rb'
8
+ require 'viperaptor/code_generation/content_generator.rb'
9
+ require 'viperaptor/code_generation/rambafile_generator.rb'
10
+ require 'viperaptor/module_generator.rb'
11
+ require 'viperaptor/template/processor/template_processor.rb'
12
+ require 'viperaptor/template/installer/template_installer_factory'
13
+ require 'viperaptor/configuration/user_preferences.rb'
14
+ require 'viperaptor/template/creator/template_creator.rb'
15
+ require 'viperaptor/tools/string-colorize.rb'
16
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'viperaptor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'viperaptor'
8
+ spec.version = Viperaptor::VERSION
9
+ spec.authors = ['Siarhei Ladzeika']
10
+ spec.email = 'sergey.ladeiko@gmail.com'
11
+
12
+ spec.summary = 'Advanced code generator for Xcode projects with a nice and flexible template system.'
13
+ spec.description = 'New reincarnation of Rambler Generamba tool (original code got from Generamba)'
14
+ spec.homepage = 'https://github.com/ladeiko/Viperaptor'
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 = ['viperaptor']
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.required_ruby_version = '>= 2.3'
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'
30
+
31
+ spec.add_development_dependency 'bundler', '>= 1.16'
32
+ spec.add_development_dependency 'rake', '~> 13.0'
33
+ spec.add_development_dependency 'rspec', '~> 3.7'
34
+ spec.add_development_dependency 'fakefs', '~> 1.3'
35
+ spec.add_development_dependency 'activesupport', '~> 5.2'
36
+ end