generamba 0.6.2 → 0.7.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
  SHA1:
3
- metadata.gz: 7cba8bb628b52530a159a36780d57b09ed21c345
4
- data.tar.gz: 1067a8772c6101c895318f7efebdeac4f67c767c
3
+ metadata.gz: 86031870069f4fd70b4aab732b9cd8b3b148bd73
4
+ data.tar.gz: 5cfaf9db6ee20956d3ca39a3540ed60ca1680437
5
5
  SHA512:
6
- metadata.gz: 261f30a1f64c7cec05a45772305d88835608e728914d2ec565378969ae58bad69a0f9fd362f70a43fe63474ca64619349045edcb5f2afaba33b144e81a4a527a
7
- data.tar.gz: f6c46c812e23bfc3118e671ba62340fdadfeddc083ab7b50e15f777bc3a526bf3dc1ca3269910a8453b7b4190360dd8c75094f7e42a2316bbee612f3cf67d0b3
6
+ metadata.gz: 5e11bd68fe9b713a03773084ff0aaf91584fb6fae2ec01eba3136b8ff8dda3d9b1d8c348f7d11ba4a4988570c9009c6be8a0247c6d8c299321aeb7d1926de349
7
+ data.tar.gz: 6488c2d30051969a72b09eca9da7c99f9382b13dee0c642d5cbb70be0791863f021719e51559e3ffb1a3edda8db4c26303aed04c8588e02bbff78d5143874100
@@ -14,4 +14,5 @@ module Generamba
14
14
  require 'generamba/template/processor/template_processor.rb'
15
15
  require 'generamba/configuration/user_preferences.rb'
16
16
  require 'generamba/template/creator/template_creator.rb'
17
+ require 'generamba/tools/string-colorize.rb'
17
18
  end
@@ -6,14 +6,22 @@ module Generamba::CLI
6
6
 
7
7
  include Generamba
8
8
 
9
- desc 'gen [MODULE_NAME] [TEMPLATE_NAME_KEY]', 'Creates a new VIPER module with a given name from a specific template'
9
+ desc 'gen [MODULE_NAME] [TEMPLATE_NAME]', 'Creates a new VIPER module with a given name from a specific template'
10
10
  method_option :description, :aliases => '-d', :desc => 'Provides a full description to the module'
11
+ method_option :module_targets, :desc => 'Specifies project targets for adding new module files'
12
+ method_option :module_file_path, :desc => 'Specifies a location in the filesystem for new files'
13
+ method_option :module_group_path, :desc => 'Specifies a location in Xcode groups for new files'
14
+ method_option :module_path, :desc => 'Specifies a location (both in the filesystem and Xcode) for new files'
15
+ method_option :test_targets, :desc => 'Specifies project targets for adding new test files'
16
+ method_option :test_file_path, :desc => 'Specifies a location in the filesystem for new test files'
17
+ method_option :test_group_path, :desc => 'Specifies a location in Xcode groups for new test files'
18
+ method_option :test_path, :desc => 'Specifies a location (both in the filesystem and Xcode) for new test files'
11
19
  def gen(module_name, template_name)
12
20
 
13
21
  does_rambafile_exist = Dir[RAMBAFILE_NAME].count > 0
14
22
 
15
23
  if (does_rambafile_exist == false)
16
- puts('Rambafile not found! Run `generamba setup` in the working directory instead!')
24
+ puts('Rambafile not found! Run `generamba setup` in the working directory instead!'.red)
17
25
  return
18
26
  end
19
27
 
@@ -26,9 +34,11 @@ module Generamba::CLI
26
34
  default_module_description = "#{module_name} module"
27
35
  module_description = options[:description] ? options[:description] : default_module_description
28
36
 
29
- generator = Generamba::ModuleGenerator.new()
30
- generator.generate_module(template_name, module_name, module_description)
37
+ template = ModuleTemplate.new(template_name)
38
+ code_module = CodeModule.new(module_name, module_description, options)
31
39
 
40
+ generator = Generamba::ModuleGenerator.new()
41
+ generator.generate_module(module_name, code_module, template)
32
42
  end
33
43
 
34
44
  end
@@ -67,7 +67,7 @@ module Generamba::CLI
67
67
  properties[TEST_GROUP_PATH_KEY] = test_group_path
68
68
 
69
69
  Generamba::RambafileGenerator.create_rambafile(properties)
70
- say('Rambafile successfully created! Now add some templates to the Rambafile and run `generamba template install`.')
70
+ puts('Rambafile successfully created! Now add some templates to the Rambafile and run `generamba template install`.'.green)
71
71
  end
72
72
  end
73
73
  end
@@ -5,7 +5,7 @@ module Generamba::CLI
5
5
  def setup_username
6
6
  username = Generamba::UserPreferences.obtain_username
7
7
  if username == nil
8
- puts('The author name is not configured!')
8
+ puts('The author name is not configured!'.red)
9
9
  git_username = Git.init.config['user.name']
10
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
11
  username = git_username
@@ -23,7 +23,7 @@ module Generamba::CLI
23
23
 
24
24
  template_creator = Generamba::TemplateCreator.new
25
25
  template_creator.create_template(properties)
26
- say("The template #{template_name} is successfully generated! Now add some file templates into it.")
26
+ puts("The template #{template_name} is successfully generated! Now add some file templates into it.".green)
27
27
  end
28
28
  end
29
29
  end
@@ -1,5 +1,7 @@
1
1
  require 'generamba/cli/template/template_install_command.rb'
2
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'
3
5
 
4
6
  module Generamba::CLI
5
7
  class Application < Thor
@@ -3,6 +3,13 @@ module Generamba::CLI
3
3
 
4
4
  desc 'install', 'Installs all the templates specified in the Rambafile from the current directory'
5
5
  def install
6
+ does_rambafile_exist = Dir[RAMBAFILE_NAME].count > 0
7
+
8
+ if (does_rambafile_exist == false)
9
+ puts('Rambafile not found! Run `generamba setup` in the working directory instead!'.red)
10
+ return
11
+ end
12
+
6
13
  template_processor = Generamba::TemplateProcessor.new
7
14
  template_processor.install_templates
8
15
  end
@@ -0,0 +1,21 @@
1
+ require 'generamba/template/helpers/catalog_downloader.rb'
2
+
3
+ module Generamba::CLI
4
+ class Template < Thor
5
+ include Generamba
6
+
7
+ desc 'list', 'Prints out the list of all templates available in the shared GitHub catalog'
8
+ def list
9
+ downloader = CatalogDownloader.new
10
+ generamba_catalog_path = downloader.download_catalog(GENERAMBA_CATALOG_NAME, RAMBLER_CATALOG_REPO)
11
+
12
+ generamba_catalog_path.children.select { |child|
13
+ child.directory? && child.split.last.to_s[0] != '.'
14
+ }.map { |template_path|
15
+ template_path.split.last.to_s
16
+ }.each { |template_name|
17
+ puts(template_name)
18
+ }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ require 'generamba/template/helpers/catalog_downloader.rb'
2
+
3
+ module Generamba::CLI
4
+ class Template < Thor
5
+ include Generamba
6
+
7
+ desc 'search [SEARCH_STRING]', 'Searches a template with a given name in the shared GitHub catalog'
8
+ def search(term)
9
+ downloader = CatalogDownloader.new
10
+ generamba_catalog_path = downloader.download_catalog(GENERAMBA_CATALOG_NAME, RAMBLER_CATALOG_REPO)
11
+
12
+ generamba_catalog_path.children.select { |child|
13
+ child.directory? && child.split.last.to_s[0] != '.'
14
+ }.map { |template_path|
15
+ template_path.split.last.to_s
16
+ }.select { |template_name|
17
+ template_name.include?(term)
18
+ }.map { |template_name|
19
+ keywords = term.squeeze.strip.split(' ').compact.uniq
20
+ matcher = Regexp.new('(' + keywords.join('|') + ')')
21
+ template_name.gsub(matcher) { |match| "#{match}".yellow }
22
+ }.each { |template_name|
23
+ puts(template_name)
24
+ }
25
+ end
26
+ end
27
+ end
@@ -26,7 +26,7 @@ module Generamba::CLI
26
26
  loop do
27
27
  value = ask(message)
28
28
  return value if is_valid_value.call(value)
29
- puts(description)
29
+ puts(description.red)
30
30
  end
31
31
  end
32
32
  end
@@ -3,8 +3,8 @@ company: {{ company }}
3
3
 
4
4
  ### Xcode project settings
5
5
  project_name: {{ project_name }}
6
- prefix: {{ prefix }}
7
6
  xcodeproj_path: {{ xcodeproj_path }}
7
+ {% if prefix != "" %}prefix: {{ prefix }}{% endif %}
8
8
 
9
9
  ### Code generation settings section
10
10
  # The main project target name
@@ -16,19 +16,19 @@ project_file_path: {{ project_file_path }}
16
16
  # The Xcode group path to new modules
17
17
  project_group_path: {{ project_group_path }}
18
18
 
19
- ### Tests generation settings section
20
- # The tests target name
21
- test_target: {{ test_target }}
19
+ {% if test_target != "" or test_file_path != "" or test_group_path != "" %}### Tests generation settings section{% endif %}
20
+ {% if test_target != "" %}# The tests target name
21
+ test_target: {{ test_target }}{% endif %}
22
22
 
23
- # The file path for new tests
24
- test_file_path: {{ test_file_path }}
23
+ {% if test_file_path != "" %}# The file path for new tests
24
+ test_file_path: {{ test_file_path }}{% endif %}
25
25
 
26
- # The Xcode group path to new tests
27
- test_group_path: {{ test_group_path }}
26
+ {% if test_group_path != "" %}# The Xcode group path to new tests
27
+ test_group_path: {{ test_group_path }}{% endif %}
28
28
 
29
- ### Dependencies settings section
30
- podfile_path: {{ podfile_path }}
31
- cartfile_path: {{ cartfile_path }}
29
+ {% if podfile_path != "" or cartfile_path != "" %}### Dependencies settings section{% endif %}
30
+ {% if podfile_path != "" %}podfile_path: {{ podfile_path }}{% endif %}
31
+ {% if cartfile_path != "" %}cartfile_path: {{ cartfile_path }}{% endif %}
32
32
 
33
33
  ### Templates
34
34
  templates:
@@ -2,11 +2,32 @@ module Generamba
2
2
 
3
3
  # Represents currently generating code module
4
4
  class CodeModule
5
- attr_reader :name, :description, :author, :company, :year, :prefix, :project_name
5
+ attr_reader :name,
6
+ :description,
7
+ :module_file_path,
8
+ :module_group_path,
9
+ :test_file_path,
10
+ :test_group_path,
11
+ :project_targets,
12
+ :test_targets
6
13
 
7
- def initialize(name, description)
14
+ def initialize(name, description, options)
8
15
  @name = name
9
16
  @description = description
17
+
18
+ @project_targets = options[:module_targets].split(',') if options[:module_targets]
19
+ @test_targets = options[:test_targets].split(',') if options[:test_targets]
20
+
21
+ @module_file_path = Pathname.new(options[:module_file_path]) if options[:module_file_path]
22
+ @module_group_path = Pathname.new(options[:module_group_path]) if options[:module_group_path]
23
+ @test_file_path = Pathname.new(options[:test_file_path]) if options[:test_file_path]
24
+ @test_group_path = Pathname.new(options[:test_group_path]) if options[:test_group_path]
25
+
26
+ # The priority is given to `module_path` and 'test_path' options
27
+ @module_file_path = Pathname.new(options[:module_path]) if options[:module_path]
28
+ @module_group_path = Pathname.new(options[:module_path]) if options[:module_path]
29
+ @test_file_path = Pathname.new(options[:test_path]) if options[:test_path]
30
+ @test_group_path = Pathname.new(options[:test_path]) if options[:test_path]
10
31
  end
11
32
 
12
33
  def author
@@ -28,5 +49,77 @@ module Generamba
28
49
  def project_name
29
50
  ProjectConfiguration.project_name
30
51
  end
52
+
53
+ def module_file_path
54
+ return @module_file_path != nil ?
55
+ @module_file_path :
56
+ Pathname.new(ProjectConfiguration.project_file_path)
57
+ .join(@name)
58
+ end
59
+
60
+ def module_group_path
61
+ return @module_group_path != nil ?
62
+ @module_group_path :
63
+ Pathname.new(ProjectConfiguration.project_group_path)
64
+ .join(@name)
65
+ end
66
+
67
+ def test_file_path
68
+ if @test_file_path == nil
69
+ if ProjectConfiguration.test_file_path == nil
70
+ return nil
71
+ end
72
+
73
+ return Pathname.new(ProjectConfiguration.test_file_path)
74
+ .join(@name)
75
+ end
76
+ return @test_file_path
77
+ end
78
+
79
+ def test_group_path
80
+ if @test_group_path == nil
81
+ if ProjectConfiguration.test_group_path == nil
82
+ return nil
83
+ end
84
+
85
+ return Pathname.new(ProjectConfiguration.test_group_path)
86
+ .join(@name)
87
+ end
88
+ return @test_group_path
89
+ end
90
+
91
+ def project_targets
92
+ targets = Array.new
93
+ if ProjectConfiguration.project_target != nil
94
+ targets = [ProjectConfiguration.project_target]
95
+ end
96
+
97
+ if ProjectConfiguration.project_targets != nil
98
+ targets = ProjectConfiguration.project_targets
99
+ end
100
+
101
+ if @project_targets != nil
102
+ targets = @project_targets
103
+ end
104
+
105
+ return targets
106
+ end
107
+
108
+ def test_targets
109
+ targets = Array.new
110
+ if ProjectConfiguration.test_target != nil
111
+ targets = [ProjectConfiguration.test_target]
112
+ end
113
+
114
+ if ProjectConfiguration.test_targets != nil
115
+ targets = ProjectConfiguration.test_targets
116
+ end
117
+
118
+ if @test_targets != nil
119
+ targets = @test_targets
120
+ end
121
+
122
+ return targets
123
+ end
31
124
  end
32
125
  end
@@ -5,5 +5,6 @@ module Generamba
5
5
  # A singletone class representing a Rambafile of the current project
6
6
  class ProjectConfiguration < Settingslogic
7
7
  source Dir.getwd + '/' + RAMBAFILE_NAME
8
+ suppress_errors(true)
8
9
  end
9
10
  end
@@ -7,10 +7,12 @@ module Generamba
7
7
  XCODEPROJ_PATH_KEY = 'xcodeproj_path'
8
8
 
9
9
  PROJECT_TARGET_KEY = 'project_target'
10
+ PROJECT_TARGETS_KEY = 'project_targets'
10
11
  PROJECT_FILE_PATH_KEY = 'project_file_path'
11
12
  PROJECT_GROUP_PATH_KEY = 'project_group_path'
12
13
 
13
14
  TEST_TARGET_KEY = 'test_target'
15
+ TEST_TARGETS_KEY = 'test_targets'
14
16
  TEST_FILE_PATH_KEY = 'test_file_path'
15
17
  TEST_GROUP_PATH_KEY = 'test_group_path'
16
18
 
@@ -12,23 +12,33 @@ module Generamba
12
12
  mandatory_fields = [COMPANY_KEY,
13
13
  PROJECT_NAME_KEY,
14
14
  XCODEPROJ_PATH_KEY,
15
- PROJECT_TARGET_KEY,
16
15
  PROJECT_FILE_PATH_KEY,
17
16
  PROJECT_GROUP_PATH_KEY,
18
- TEST_TARGET_KEY,
19
- TEST_FILE_PATH_KEY,
20
- TEST_GROUP_PATH_KEY,
21
17
  TEMPLATES_KEY]
22
18
 
23
- mandatory_fields.each { |field|
19
+ interchangable_fields = [[PROJECT_TARGETS_KEY, PROJECT_TARGET_KEY]]
20
+
21
+ mandatory_fields.each do |field|
24
22
  if preferences.has_key?(field) == false
25
- error_description = "Rambafile is broken! Cannot find #{field} field, which is mandatory. Either add it manually, or run *generamba setup*."
23
+ error_description = "Rambafile is broken! Cannot find #{field} field, which is mandatory. Either add it manually, or run *generamba setup*.".red
24
+ raise StandardError.new(error_description)
25
+ end
26
+ end
27
+
28
+ interchangable_fields.each do |fields_array|
29
+ has_value = false
30
+ fields_array.each do |field|
31
+ has_value = preferences.has_key?(field) || has_value
32
+ end
33
+
34
+ if has_value == false
35
+ error_description = "Rambafile is broken! Cannot find any of #{fields_array} fields, one of them is mandatory. Either add it manually, or run *generamba setup*.".red
26
36
  raise StandardError.new(error_description)
27
37
  end
28
- }
38
+ end
29
39
 
30
40
  if preferences[TEMPLATES_KEY] == nil
31
- error_description = "You can't run *generamba gen* without any templates installed. Add their declarations to a Rambafile and run *generamba template install*."
41
+ error_description = "You can't run *generamba gen* without any templates installed. Add their declarations to a Rambafile and run *generamba template install*.".red
32
42
  raise StandardError.new(error_description)
33
43
  end
34
44
 
@@ -23,7 +23,7 @@ module Generamba
23
23
  .join(TEMPLATES_FOLDER)
24
24
  .join(template_name)
25
25
 
26
- error_description = "Cannot find #{template_name}! Add it to the Rambafile and run *generamba template install*"
26
+ error_description = "Cannot find template named #{template_name}! Add it to the Rambafile and run *generamba template install*".red
27
27
  raise StandardError.new(error_description) if path.exist? == false
28
28
 
29
29
  return path
@@ -11,33 +11,23 @@ module Generamba
11
11
  Xcodeproj::Project.open(project_name)
12
12
  end
13
13
 
14
- # Returns an AbstractTarget class for a given name
15
- # @param target_name [String] The name of the target
16
- # @param project [Xcodeproj::Project] The target xcodeproj file
17
- #
18
- # @return [Xcodeproj::AbstractTarget]
19
- def self.obtain_target(target_name, project)
20
- project.targets.each { |target|
21
- if target.name == target_name
22
- return target
23
- end
24
- }
25
- end
26
-
27
14
  # Adds a provided file to a specific Project and Target
28
15
  # @param project [Xcodeproj::Project] The target xcodeproj file
29
- # @param target [AbstractTarget] The target for a file
16
+ # @param targets [AbstractTarget] Array of tatgets
30
17
  # @param group_path [Pathname] The Xcode group path for current file
31
18
  # @param file_path [Pathname] The file path for current file
32
19
  #
33
20
  # @return [void]
34
- def self.add_file_to_project_and_target(project, target, group_path, file_path)
21
+ def self.add_file_to_project_and_targets(project, targets, group_path, file_path)
35
22
  module_group = self.retreive_or_create_group(group_path, project)
36
23
  xcode_file = module_group.new_file(File.absolute_path(file_path))
37
24
 
38
25
  file_name = File.basename(file_path)
39
26
  if File.extname(file_name) == '.m'
40
- target.add_file_references([xcode_file])
27
+ targets.each do |target|
28
+ xcode_target = self.obtain_target(target, project)
29
+ xcode_target.add_file_references([xcode_file])
30
+ end
41
31
  end
42
32
  end
43
33
 
@@ -75,6 +65,22 @@ module Generamba
75
65
  return final_group
76
66
  end
77
67
 
68
+ # Returns an AbstractTarget class for a given name
69
+ # @param target_name [String] The name of the target
70
+ # @param project [Xcodeproj::Project] The target xcodeproj file
71
+ #
72
+ # @return [Xcodeproj::AbstractTarget]
73
+ def self.obtain_target(target_name, project)
74
+ project.targets.each do |target|
75
+ if target.name == target_name
76
+ return target
77
+ end
78
+ end
79
+
80
+ error_description = "Cannot find a target with name #{target_name} in Xcode project".red
81
+ raise StandardError.new(error_description)
82
+ end
83
+
78
84
  # Splits the provided Xcode group path to an array of separate groups
79
85
  # @param group_path The full group path
80
86
  #
@@ -7,61 +7,56 @@ module Generamba
7
7
  # Responsible for creating the whole code module using information from the CLI
8
8
  class ModuleGenerator
9
9
 
10
- def generate_module(template_name, name, description)
11
- # Setting up CodeModule and ModuleTemplate objects.
12
- # TODO: Move it to the CLI infrastructure
13
- code_module = CodeModule.new(name, description)
14
- template = ModuleTemplate.new(template_name)
15
-
10
+ def generate_module(name, code_module, template)
16
11
  # Setting up Xcode objects
17
12
  project = XcodeprojHelper.obtain_project(ProjectConfiguration.xcodeproj_path)
18
- project_target = XcodeprojHelper.obtain_target(ProjectConfiguration.project_target,
19
- project)
20
- test_target = XcodeprojHelper.obtain_target(ProjectConfiguration.test_target,
21
- project)
22
13
 
23
14
  # Configuring file paths
24
- module_dir_path = Pathname.new(ProjectConfiguration.project_file_path)
25
- .join(name)
26
- test_dir_path = Pathname.new(ProjectConfiguration.test_file_path)
27
- .join(name)
28
- FileUtils.mkdir_p module_dir_path
29
- FileUtils.mkdir_p test_dir_path
15
+ FileUtils.mkdir_p code_module.module_file_path
30
16
 
31
- # Configuring group paths
32
- module_group_path = Pathname.new(ProjectConfiguration.project_group_path)
33
- .join(name)
34
- test_group_path = Pathname.new(ProjectConfiguration.test_group_path)
35
- .join(name)
17
+ if code_module.test_file_path != nil
18
+ FileUtils.mkdir_p code_module.test_file_path
19
+ end
36
20
 
37
21
  # Creating code files
38
22
  puts('Creating code files...')
39
- process_files(template.code_files,
40
- name,
41
- code_module,
42
- template,
43
- project,
44
- project_target,
45
- module_group_path,
46
- module_dir_path)
23
+ process_files_if_needed(template.code_files,
24
+ name,
25
+ code_module,
26
+ template,
27
+ project,
28
+ code_module.project_targets,
29
+ code_module.module_group_path,
30
+ code_module.module_file_path)
47
31
 
48
32
  # Creating test files
49
33
  puts('Creating test files...')
50
- process_files(template.test_files,
51
- name,
52
- code_module,
53
- template,
54
- project,
55
- test_target,
56
- test_group_path,
57
- test_dir_path)
34
+ process_files_if_needed(template.test_files,
35
+ name,
36
+ code_module,
37
+ template,
38
+ project,
39
+ code_module.test_targets,
40
+ code_module.test_group_path,
41
+ code_module.test_file_path)
58
42
 
59
43
  # Saving the current changes in the Xcode project
60
44
  project.save
61
- puts("Module #{name} successfully created!")
45
+ puts("Module successfully created!\n" +
46
+ "Name: #{name}".green + "\n" +
47
+ "Module file path: #{code_module.module_file_path}".green + "\n" +
48
+ "Module group path: #{code_module.module_group_path}".green + "\n" +
49
+ "Test file path: #{code_module.test_file_path}".green + "\n" +
50
+ "Test group path: #{code_module.test_group_path}".green)
62
51
  end
63
52
 
64
- def process_files(files, name, code_module, template, project, target, group_path, dir_path)
53
+ def process_files_if_needed(files, name, code_module, template, project, targets, group_path, dir_path)
54
+ # It's possible that current project doesn't test targets configured, so it doesn't need to generate tests.
55
+ # The same is for files property - a template can have only test or project files
56
+ if targets.count == 0 || files == nil || files.count == 0 || dir_path == nil || group_path == nil
57
+ return
58
+ end
59
+
65
60
  XcodeprojHelper.clear_group(project, group_path)
66
61
  files.each do |file|
67
62
  # The target file's name consists of three parameters: project prefix, module name and template file name.
@@ -87,8 +82,8 @@ module Generamba
87
82
  end
88
83
 
89
84
  # Creating the file in the Xcode project
90
- XcodeprojHelper.add_file_to_project_and_target(project,
91
- target,
85
+ XcodeprojHelper.add_file_to_project_and_targets(project,
86
+ targets,
92
87
  group_path.join(file_group),
93
88
  file_path)
94
89
  end
@@ -0,0 +1,27 @@
1
+ require 'git'
2
+
3
+ module Generamba
4
+
5
+ # Provides the functionality to download template catalogs from the remote repository
6
+ class CatalogDownloader
7
+
8
+ # Clones a template catalog from a remote repository
9
+ #
10
+ # @param name [String] The name of the template catalog
11
+ # @param url [String] The url of the repository
12
+ #
13
+ # @return [Pathname] A filepath to the downloaded catalog
14
+ def download_catalog(name, url)
15
+ catalog_local_path = Pathname.new(ENV['HOME'])
16
+ .join(GENERAMBA_HOME_DIR)
17
+ .join(CATALOGS_DIR)
18
+ FileUtils.rm_rf catalog_local_path
19
+ FileUtils.mkdir_p catalog_local_path
20
+
21
+ Git.clone(url, name, :path => catalog_local_path)
22
+
23
+ return catalog_local_path
24
+ .join(name)
25
+ end
26
+ end
27
+ end
@@ -21,13 +21,13 @@ module Generamba
21
21
  rambaspec_exist = Generamba::RambaspecValidator.validate_spec_existance(template_name, template_path)
22
22
 
23
23
  if rambaspec_exist == false
24
- error_description = "Cannot find #{template_name + RAMBASPEC_EXTENSION} in the template catalog. Try another name."
24
+ error_description = "Cannot find #{template_name + RAMBASPEC_EXTENSION} in the template catalog. Try another name.".red
25
25
  raise StandardError.new(error_description)
26
26
  end
27
27
 
28
28
  rambaspec_valid = Generamba::RambaspecValidator.validate_spec(template_name, template_path)
29
29
  if rambaspec_valid == false
30
- error_description = "#{template_name + RAMBASPEC_EXTENSION} is not valid."
30
+ error_description = "#{template_name + RAMBASPEC_EXTENSION} is not valid.".red
31
31
  raise StandardError.new(error_description)
32
32
  end
33
33
 
@@ -13,13 +13,13 @@ module Generamba
13
13
  rambaspec_exist = Generamba::RambaspecValidator.validate_spec_existance(template_name, local_path)
14
14
 
15
15
  if rambaspec_exist == false
16
- error_description = "Cannot find #{template_name + RAMBASPEC_EXTENSION} in the specified directory. Try another path or name."
16
+ error_description = "Cannot find #{template_name + RAMBASPEC_EXTENSION} in the specified directory. Try another path or name.".red
17
17
  raise StandardError.new(error_description)
18
18
  end
19
19
 
20
20
  rambaspec_valid = Generamba::RambaspecValidator.validate_spec(template_name, local_path)
21
21
  if rambaspec_valid == false
22
- error_description = "#{template_name + RAMBASPEC_EXTENSION} is not valid."
22
+ error_description = "#{template_name + RAMBASPEC_EXTENSION} is not valid.".red
23
23
  raise StandardError.new(error_description)
24
24
  end
25
25
 
@@ -22,13 +22,13 @@ module Generamba
22
22
  rambaspec_exist = Generamba::RambaspecValidator.validate_spec_existance(template_name, template_dir)
23
23
  if rambaspec_exist == false
24
24
  FileUtils.rm_rf(temp_path)
25
- error_description = "Cannot find #{template_name + RAMBASPEC_EXTENSION} in the root directory of specified repository."
25
+ error_description = "Cannot find #{template_name + RAMBASPEC_EXTENSION} in the root directory of specified repository.".red
26
26
  raise StandardError.new(error_description)
27
27
  end
28
28
 
29
29
  rambaspec_valid = Generamba::RambaspecValidator.validate_spec(template_name, template_dir)
30
30
  if rambaspec_valid == false
31
- error_description = "#{template_name + RAMBASPEC_EXTENSION} is not valid."
31
+ error_description = "#{template_name + RAMBASPEC_EXTENSION} is not valid.".red
32
32
  raise StandardError.new(error_description)
33
33
  end
34
34
 
@@ -2,6 +2,7 @@ require 'generamba/template/processor/template_declaration.rb'
2
2
  require 'generamba/template/installer/local_installer.rb'
3
3
  require 'generamba/template/installer/remote_installer.rb'
4
4
  require 'generamba/template/installer/catalog_installer.rb'
5
+ require 'generamba/template/helpers/catalog_downloader.rb'
5
6
  require 'git'
6
7
 
7
8
  module Generamba
@@ -22,7 +23,7 @@ module Generamba
22
23
  }
23
24
 
24
25
  if !templates || templates.count == 0
25
- error_description = 'You must specify at least one template in Rambafile under the key *project_templates*'
26
+ error_description = 'You must specify at least one template in Rambafile under the key *project_templates*'.red
26
27
  raise StandardError.new(error_description)
27
28
  end
28
29
 
@@ -51,13 +52,8 @@ module Generamba
51
52
 
52
53
  puts('Updating shared generamba-catalog specs...')
53
54
 
54
- catalog_local_path = Pathname.new(ENV['HOME'])
55
- .join(GENERAMBA_HOME_DIR)
56
- .join(CATALOGS_DIR)
57
- FileUtils.rm_rf catalog_local_path
58
- FileUtils.mkdir_p catalog_local_path
59
-
60
- Git.clone(RAMBLER_CATALOG_REPO, GENERAMBA_CATALOG_NAME, :path => catalog_local_path)
55
+ downloader = CatalogDownloader.new
56
+ downloader.download_catalog(GENERAMBA_CATALOG_NAME, RAMBLER_CATALOG_REPO)
61
57
  end
62
58
 
63
59
  # Provides the appropriate strategy for a given template type
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Generamba
2
- VERSION = '0.6.2'
2
+ VERSION = '0.7.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: generamba
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Egor Tolstoy
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-25 00:00:00.000000000 Z
12
+ date: 2015-12-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -165,6 +165,8 @@ files:
165
165
  - lib/generamba/cli/template/template_create_command.rb
166
166
  - lib/generamba/cli/template/template_group.rb
167
167
  - lib/generamba/cli/template/template_install_command.rb
168
+ - lib/generamba/cli/template/template_list_command.rb
169
+ - lib/generamba/cli/template/template_search_command.rb
168
170
  - lib/generamba/cli/thor_extension.rb
169
171
  - lib/generamba/code_generation/Rambafile.liquid
170
172
  - lib/generamba/code_generation/code_module.rb
@@ -186,6 +188,7 @@ files:
186
188
  - lib/generamba/template/creator/new_template/Tests/Service/service_tests.m.liquid
187
189
  - lib/generamba/template/creator/new_template/template.rambaspec.liquid
188
190
  - lib/generamba/template/creator/template_creator.rb
191
+ - lib/generamba/template/helpers/catalog_downloader.rb
189
192
  - lib/generamba/template/helpers/rambaspec_validator.rb
190
193
  - lib/generamba/template/installer/abstract_installer.rb
191
194
  - lib/generamba/template/installer/catalog_installer.rb
@@ -193,6 +196,7 @@ files:
193
196
  - lib/generamba/template/installer/remote_installer.rb
194
197
  - lib/generamba/template/processor/template_declaration.rb
195
198
  - lib/generamba/template/processor/template_processor.rb
199
+ - lib/generamba/tools/string-colorize.rb
196
200
  - lib/generamba/version.rb
197
201
  homepage: https://github.com/rambler-ios/Generamba
198
202
  licenses: