generamba-mp 0.0.2
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 +7 -0
- data/.codeclimate.yml +10 -0
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/.travis.yml +17 -0
- data/CHANGELOG.md +180 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +62 -0
- data/Rakefile +6 -0
- data/VISION.md +41 -0
- data/bin/console +14 -0
- data/bin/generamba +5 -0
- data/bin/setup +7 -0
- data/docs/2.x/roadmap.md +365 -0
- data/generamba.gemspec +38 -0
- data/lib/generamba.rb +16 -0
- data/lib/generamba/cli/cli.rb +16 -0
- data/lib/generamba/cli/gen_command.rb +76 -0
- data/lib/generamba/cli/setup_command.rb +122 -0
- data/lib/generamba/cli/setup_username_command.rb +21 -0
- data/lib/generamba/cli/template/template_create_command.rb +40 -0
- data/lib/generamba/cli/template/template_group.rb +14 -0
- data/lib/generamba/cli/template/template_install_command.rb +21 -0
- data/lib/generamba/cli/template/template_list_command.rb +25 -0
- data/lib/generamba/cli/template/template_search_command.rb +30 -0
- data/lib/generamba/cli/thor_extension.rb +47 -0
- data/lib/generamba/cli/version_command.rb +25 -0
- data/lib/generamba/code_generation/Rambafile.liquid +41 -0
- data/lib/generamba/code_generation/code_module.rb +100 -0
- data/lib/generamba/code_generation/content_generator.rb +43 -0
- data/lib/generamba/code_generation/module_template.rb +28 -0
- data/lib/generamba/code_generation/rambafile_generator.rb +23 -0
- data/lib/generamba/configuration/user_preferences.rb +50 -0
- data/lib/generamba/constants/constants.rb +12 -0
- data/lib/generamba/constants/rambafile_constants.rb +31 -0
- data/lib/generamba/constants/rambaspec_constants.rb +18 -0
- data/lib/generamba/constants/user_preferences_constants.rb +5 -0
- data/lib/generamba/helpers/dependency_checker.rb +54 -0
- data/lib/generamba/helpers/gen_command_table_parameters_formatter.rb +33 -0
- data/lib/generamba/helpers/module_info_generator.rb +33 -0
- data/lib/generamba/helpers/module_validator.rb +85 -0
- data/lib/generamba/helpers/print_table.rb +17 -0
- data/lib/generamba/helpers/rambafile_validator.rb +18 -0
- data/lib/generamba/helpers/template_helper.rb +30 -0
- data/lib/generamba/helpers/xcodeproj_helper.rb +256 -0
- data/lib/generamba/module_generator.rb +104 -0
- data/lib/generamba/template/creator/new_template/Code/Service/service.h.liquid +11 -0
- data/lib/generamba/template/creator/new_template/Code/Service/service.m.liquid +13 -0
- data/lib/generamba/template/creator/new_template/Tests/Service/service_tests.m.liquid +35 -0
- data/lib/generamba/template/creator/new_template/template.rambaspec.liquid +20 -0
- data/lib/generamba/template/creator/template_creator.rb +39 -0
- data/lib/generamba/template/helpers/catalog_downloader.rb +58 -0
- data/lib/generamba/template/helpers/catalog_template_list_helper.rb +23 -0
- data/lib/generamba/template/helpers/catalog_template_search_helper.rb +27 -0
- data/lib/generamba/template/helpers/catalog_terminator.rb +21 -0
- data/lib/generamba/template/helpers/rambaspec_validator.rb +52 -0
- data/lib/generamba/template/installer/abstract_installer.rb +9 -0
- data/lib/generamba/template/installer/catalog_installer.rb +73 -0
- data/lib/generamba/template/installer/local_installer.rb +32 -0
- data/lib/generamba/template/installer/remote_installer.rb +50 -0
- data/lib/generamba/template/installer/template_installer_factory.rb +22 -0
- data/lib/generamba/template/processor/template_declaration.rb +36 -0
- data/lib/generamba/template/processor/template_processor.rb +75 -0
- data/lib/generamba/tools/string-colorize.rb +23 -0
- data/lib/generamba/version.rb +5 -0
- metadata +271 -0
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
require 'generamba/helpers/xcodeproj_helper.rb'
|
4
|
+
require 'generamba/helpers/module_info_generator.rb'
|
5
|
+
|
6
|
+
module Generamba
|
7
|
+
|
8
|
+
# Responsible for creating the whole code module using information from the CLI
|
9
|
+
class ModuleGenerator
|
10
|
+
|
11
|
+
def generate_module(name, code_module, template)
|
12
|
+
# Setting up Xcode objects
|
13
|
+
project = XcodeprojHelper.obtain_project(code_module.xcodeproj_path)
|
14
|
+
|
15
|
+
# Configuring file paths
|
16
|
+
# FileUtils.mkdir_p code_module.project_file_path if code_module.project_file_path
|
17
|
+
# FileUtils.mkdir_p code_module.test_file_path if code_module.test_file_path
|
18
|
+
|
19
|
+
# Creating code files
|
20
|
+
if code_module.project_targets && code_module.project_group_path && code_module.project_file_path
|
21
|
+
puts('Creating code files...')
|
22
|
+
process_files_if_needed(template.code_files,
|
23
|
+
code_module,
|
24
|
+
template,
|
25
|
+
project,
|
26
|
+
code_module.project_targets,
|
27
|
+
code_module.project_group_path,
|
28
|
+
code_module.project_file_path)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Creating test files
|
32
|
+
if code_module.test_targets && code_module.test_group_path && code_module.test_file_path
|
33
|
+
puts('Creating test files...')
|
34
|
+
process_files_if_needed(template.test_files,
|
35
|
+
code_module,
|
36
|
+
template,
|
37
|
+
project,
|
38
|
+
code_module.test_targets,
|
39
|
+
code_module.test_group_path,
|
40
|
+
code_module.test_file_path,
|
41
|
+
[code_module.project_group_path])
|
42
|
+
end
|
43
|
+
|
44
|
+
# Saving the current changes in the Xcode project
|
45
|
+
project.save
|
46
|
+
|
47
|
+
puts 'Module successfully created!'
|
48
|
+
puts "Name: #{name}".green
|
49
|
+
puts "Project file path: #{code_module.project_file_path}".green if code_module.project_file_path
|
50
|
+
puts "Project group path: #{code_module.project_group_path}".green if code_module.project_group_path
|
51
|
+
puts "Test file path: #{code_module.test_file_path}".green if code_module.test_file_path
|
52
|
+
puts "Test group path: #{code_module.test_group_path}".green if code_module.test_group_path
|
53
|
+
end
|
54
|
+
|
55
|
+
def process_files_if_needed(files, code_module, template, project, targets, group_path, dir_path, processed_groups = [])
|
56
|
+
# It's possible that current project doesn't test targets configured, so it doesn't need to generate tests.
|
57
|
+
# The same is for files property - a template can have only test or project files
|
58
|
+
if targets.count == 0 || files == nil || files.count == 0 || dir_path == nil || group_path == nil
|
59
|
+
return
|
60
|
+
end
|
61
|
+
|
62
|
+
XcodeprojHelper.clear_group(project, targets, group_path) unless processed_groups.include? group_path
|
63
|
+
files.each do |file|
|
64
|
+
unless file[TEMPLATE_FILE_PATH_KEY]
|
65
|
+
directory_name = file[TEMPLATE_NAME_KEY].gsub(/^\/|\/$/, '')
|
66
|
+
file_group = dir_path.join(directory_name)
|
67
|
+
|
68
|
+
FileUtils.mkdir_p file_group
|
69
|
+
XcodeprojHelper.add_group_to_project(project, group_path, dir_path, directory_name)
|
70
|
+
|
71
|
+
next
|
72
|
+
end
|
73
|
+
|
74
|
+
file_group = File.dirname(file[TEMPLATE_NAME_KEY])
|
75
|
+
file_group = nil if file_group == '.'
|
76
|
+
|
77
|
+
module_info = ModuleInfoGenerator.new(code_module)
|
78
|
+
|
79
|
+
# Generating the content of the code file and it's name
|
80
|
+
file_name, file_content = ContentGenerator.create_file(file, module_info.scope, template)
|
81
|
+
file_path = dir_path
|
82
|
+
file_path = file_path.join(file_group) if file_group
|
83
|
+
file_path = file_path.join(file_name) if file_name
|
84
|
+
|
85
|
+
# Creating the file in the filesystem
|
86
|
+
FileUtils.mkdir_p File.dirname(file_path)
|
87
|
+
File.open(file_path, 'w+') do |f|
|
88
|
+
f.write(file_content)
|
89
|
+
end
|
90
|
+
|
91
|
+
file_is_resource = file[TEMPLATE_FILE_IS_RESOURCE_KEY]
|
92
|
+
|
93
|
+
# Creating the file in the Xcode project
|
94
|
+
XcodeprojHelper.add_file_to_project_and_targets(project,
|
95
|
+
targets,
|
96
|
+
group_path,
|
97
|
+
dir_path,
|
98
|
+
file_group,
|
99
|
+
file_name,
|
100
|
+
file_is_resource)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
//
|
2
|
+
// {{ prefix }}{{ module_info.name }}{{ module_info.file_name }}
|
3
|
+
// {{ module_info.project_name }}
|
4
|
+
//
|
5
|
+
// Created by {{ developer.name }} on {{ date }}.
|
6
|
+
// Copyright {{ year }} {{ developer.company }}. All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
@interface {{ prefix }}{{ module_info.name }}Service : NSObject
|
10
|
+
|
11
|
+
@end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
//
|
2
|
+
// {{ prefix }}{{ module_info.name }}{{ module_info.file_name }}
|
3
|
+
// {{ module_info.project_name }}
|
4
|
+
//
|
5
|
+
// Created by {{ developer.name }} on {{ date }}.
|
6
|
+
// Copyright {{ year }} {{ developer.company }}. All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
#import "{{ prefix }}{{ module_info.name }}Service.h"
|
10
|
+
|
11
|
+
@implementation {{ prefix }}{{ module_info.name }}Service
|
12
|
+
|
13
|
+
@end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
//
|
2
|
+
// {{ prefix }}{{ module_info.name }}{{ module_info.file_name }}
|
3
|
+
// {{ module_info.project_name }}
|
4
|
+
//
|
5
|
+
// Created by {{ developer.name }} on {{ date }}.
|
6
|
+
// Copyright {{ year }} {{ developer.company }}. All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
#import <XCTest/XCTest.h>
|
10
|
+
|
11
|
+
#import "{{ prefix }}{{ module_info.name }}Service.h"
|
12
|
+
|
13
|
+
@interface {{ prefix }}{{ module_info.name }}ServiceTests : XCTestCase
|
14
|
+
|
15
|
+
@property (strong, nonatomic) {{ prefix }}{{ module_info.name }}Service *service;
|
16
|
+
|
17
|
+
@end
|
18
|
+
|
19
|
+
@implementation {{ prefix }}{{ module_info.name }}ServiceTests
|
20
|
+
|
21
|
+
#pragma mark - Test environment setup
|
22
|
+
|
23
|
+
- (void)setUp {
|
24
|
+
[super setUp];
|
25
|
+
|
26
|
+
self.service = [[{{ prefix }}{{ module_info.name }}Service alloc] init];
|
27
|
+
}
|
28
|
+
|
29
|
+
- (void)tearDown {
|
30
|
+
self.service = nil;
|
31
|
+
|
32
|
+
[super tearDown];
|
33
|
+
}
|
34
|
+
|
35
|
+
@end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Template information section
|
2
|
+
name: {{ name }}
|
3
|
+
summary: {{ summary }}
|
4
|
+
author: {{ author }}
|
5
|
+
version: 1.0.0
|
6
|
+
license: {{ license }}
|
7
|
+
|
8
|
+
# The declarations for code files
|
9
|
+
code_files:
|
10
|
+
- {name: Service/Service.h, path: Code/Service/service.h.liquid}
|
11
|
+
- {name: Service/Service.m, path: Code/Service/service.m.liquid}
|
12
|
+
|
13
|
+
# The declarations for test files
|
14
|
+
test_files:
|
15
|
+
- {name: Service/ServiceTests.m, path: Tests/Service/service_tests.m.liquid}
|
16
|
+
|
17
|
+
# Template dependencies
|
18
|
+
dependencies:
|
19
|
+
{% for dependency in dependencies %}- {{ dependency }}
|
20
|
+
{% endfor %}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Generamba
|
2
|
+
|
3
|
+
# Responsible for generating new .rambaspec files
|
4
|
+
class TemplateCreator
|
5
|
+
|
6
|
+
NEW_TEMPLATE_FOLDER = 'new_template'
|
7
|
+
RAMBASPEC_TEMPLATE_NAME = 'template.rambaspec.liquid'
|
8
|
+
CODE_FOLDER = 'Code'
|
9
|
+
TESTS_FOLDER = 'Tests'
|
10
|
+
|
11
|
+
# Generates and saves to filesystem a new template with a .rambaspec file and sample code and tests files
|
12
|
+
# @param properties [Hash] User-inputted template properties
|
13
|
+
#
|
14
|
+
# @return [Void]
|
15
|
+
def create_template(properties)
|
16
|
+
template_dir_path = Pathname.new(File.dirname(__FILE__)).join(NEW_TEMPLATE_FOLDER)
|
17
|
+
rambaspec_template_file_path = template_dir_path.join(RAMBASPEC_TEMPLATE_NAME)
|
18
|
+
code_file_path = template_dir_path.join(CODE_FOLDER)
|
19
|
+
tests_file_path = template_dir_path.join(TESTS_FOLDER)
|
20
|
+
|
21
|
+
file_source = IO.read(rambaspec_template_file_path)
|
22
|
+
|
23
|
+
template = Liquid::Template.parse(file_source)
|
24
|
+
output = template.render(properties)
|
25
|
+
|
26
|
+
result_name = properties[TEMPLATE_NAME_KEY] + RAMBASPEC_EXTENSION
|
27
|
+
result_dir_path = Pathname.new(properties[TEMPLATE_NAME_KEY])
|
28
|
+
|
29
|
+
FileUtils.mkdir_p result_dir_path
|
30
|
+
FileUtils.cp_r(code_file_path, result_dir_path)
|
31
|
+
FileUtils.cp_r(tests_file_path, result_dir_path)
|
32
|
+
|
33
|
+
File.open(result_dir_path.join(result_name), 'w+') {|f|
|
34
|
+
f.write(output)
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,58 @@
|
|
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
|
+
# Updates all of the template catalogs and returns their filepaths.
|
9
|
+
# If there is a Rambafile in the current directory, it also updates all of the catalogs specified there.
|
10
|
+
#
|
11
|
+
# @return [Array] An array of filepaths to downloaded catalogs
|
12
|
+
def update_all_catalogs_and_return_filepaths
|
13
|
+
does_rambafile_exist = Dir[RAMBAFILE_NAME].count > 0
|
14
|
+
|
15
|
+
if does_rambafile_exist
|
16
|
+
rambafile = YAML.load_file(RAMBAFILE_NAME)
|
17
|
+
catalogs = rambafile[CATALOGS_KEY]
|
18
|
+
end
|
19
|
+
|
20
|
+
terminator = CatalogTerminator.new
|
21
|
+
terminator.remove_all_catalogs
|
22
|
+
|
23
|
+
catalog_paths = [download_catalog(GENERAMBA_CATALOG_NAME, RAMBLER_CATALOG_REPO)]
|
24
|
+
|
25
|
+
if catalogs != nil && catalogs.count > 0
|
26
|
+
catalogs.each do |catalog_url|
|
27
|
+
catalog_name = catalog_url.split('://').last
|
28
|
+
catalog_name = catalog_name.gsub('/', '-');
|
29
|
+
catalog_paths.push(download_catalog(catalog_name, catalog_url))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
return catalog_paths
|
33
|
+
end
|
34
|
+
|
35
|
+
# Clones a template catalog from a remote repository
|
36
|
+
#
|
37
|
+
# @param name [String] The name of the template catalog
|
38
|
+
# @param url [String] The url of the repository
|
39
|
+
#
|
40
|
+
# @return [Pathname] A filepath to the downloaded catalog
|
41
|
+
def download_catalog(name, url)
|
42
|
+
catalogs_local_path = Pathname.new(ENV['HOME'])
|
43
|
+
.join(GENERAMBA_HOME_DIR)
|
44
|
+
.join(CATALOGS_DIR)
|
45
|
+
current_catalog_path = catalogs_local_path
|
46
|
+
.join(name)
|
47
|
+
|
48
|
+
if File.exists?(current_catalog_path)
|
49
|
+
g = Git.open(current_catalog_path)
|
50
|
+
g.pull
|
51
|
+
else
|
52
|
+
Git.clone(url, name, :path => catalogs_local_path)
|
53
|
+
end
|
54
|
+
|
55
|
+
return current_catalog_path
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Generamba
|
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
|
+
template_names = []
|
13
|
+
catalog_path.children.select { |child|
|
14
|
+
File.directory?(child) && child.split.last.to_s[0] != '.'
|
15
|
+
}.map { |template_path|
|
16
|
+
template_path.split.last.to_s
|
17
|
+
}.each { |template_name|
|
18
|
+
template_names.push(template_name)
|
19
|
+
}
|
20
|
+
return template_names
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Generamba
|
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 Generamba
|
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(GENERAMBA_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 Generamba
|
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,73 @@
|
|
1
|
+
require 'generamba/template/installer/abstract_installer.rb'
|
2
|
+
require 'generamba/template/helpers/rambaspec_validator.rb'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'tmpdir'
|
5
|
+
|
6
|
+
module Generamba
|
7
|
+
|
8
|
+
# Incapsulates the logic of installing Generamba 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(GENERAMBA_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 = Generamba::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 = Generamba::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(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 = catalog_path.join(template_name)
|
65
|
+
|
66
|
+
if Dir.exist?(template_path)
|
67
|
+
return template_path
|
68
|
+
end
|
69
|
+
|
70
|
+
return nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|