rdm 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/example/Gemfile.lock +1 -1
- data/example/Rdm.packages +6 -1
- data/example/bin/console +37 -0
- data/example/env_files/development.env +1 -0
- data/example/env_files/production.env +3 -0
- data/example/env_files/test.env +1 -0
- data/example/server/bin/console +16 -0
- data/lib/rdm/cli/gen_package.rb +8 -6
- data/lib/rdm/cli/init.rb +1 -1
- data/lib/rdm/gen/init.rb +1 -0
- data/lib/rdm/gen/package.rb +2 -5
- data/lib/rdm/git/diff_command.rb +2 -4
- data/lib/rdm/git/diff_manager.rb +1 -1
- data/lib/rdm/handlers/template_handler.rb +39 -40
- data/lib/rdm/packages/compiler_service.rb +2 -4
- data/lib/rdm/settings.rb +3 -2
- data/lib/rdm/source_parser.rb +28 -3
- data/lib/rdm/spec_runner.rb +2 -2
- data/lib/rdm/spec_runner/runner.rb +1 -0
- data/lib/rdm/templates/init/Rdm.packages +2 -0
- data/lib/rdm/templates/init/bin/console +36 -0
- data/lib/rdm/templates/init/env_files/development.env +1 -0
- data/lib/rdm/templates/init/env_files/production.env +1 -0
- data/lib/rdm/templates/init/env_files/test.env +1 -0
- data/lib/rdm/templates/template_renderer.rb +17 -7
- data/lib/rdm/version.rb +1 -1
- data/spec/rdm/cli/compile_package_spec.rb +5 -5
- data/spec/rdm/cli/gen_package_spec.rb +10 -11
- data/spec/rdm/gen/init_spec.rb +4 -0
- data/spec/rdm/gen/package_spec.rb +3 -3
- data/spec/rdm/package/compiler_service_spec.rb +28 -19
- data/spec/rdm/source_parser_spec.rb +50 -2
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ccd255c90b9282d7099a6d56209702df3a6ae2ea
|
4
|
+
data.tar.gz: 45f8f4f7c203d6c9f24145df9f78ec150bad091f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43e2df557a1921a6ee3edc8d998113fd97efa8632ddcd3d7bb60596fdb63ca9f75f261666d305a149bcb75f6d91a3f01b60980db609f8e4422d681f552358a77
|
7
|
+
data.tar.gz: 037effcac344e15c413e24cc4b676ef5840eecadd0c70b2ce2752243541d9967c9e75f07fd6955a43177d6198b2b6bb83bfd102081b11f1b8d5a89b117d09969
|
data/Gemfile.lock
CHANGED
data/example/Gemfile.lock
CHANGED
data/example/Rdm.packages
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
setup do
|
2
2
|
role "production"
|
3
|
+
|
3
4
|
configs_dir "configs"
|
4
5
|
config_path ":configs_dir/:config_name/default.yml"
|
5
6
|
role_config_path ":configs_dir/:config_name/:role.yml"
|
7
|
+
|
8
|
+
env_files_dir "env_files"
|
9
|
+
|
6
10
|
package_subdir_name "package"
|
7
|
-
|
11
|
+
|
12
|
+
compile_path "/tmp/rdm/:package_name"
|
8
13
|
end
|
9
14
|
|
10
15
|
config :database
|
data/example/bin/console
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'rdm'
|
4
|
+
|
5
|
+
ENV['RUBY_ENV'] ||= 'development'
|
6
|
+
|
7
|
+
source_file = Rdm::SourceLocator.locate(__dir__)
|
8
|
+
source = Rdm::SourceParser.read_and_init_source(source_file)
|
9
|
+
package_consoles = source.packages.inject([]) do |res, (name,data)|
|
10
|
+
package_console_file = File.join(data.path, 'bin/console')
|
11
|
+
File.exists?(package_console_file) ?
|
12
|
+
res.push(name: name, path: package_console_file) :
|
13
|
+
res
|
14
|
+
end
|
15
|
+
|
16
|
+
if package_consoles.empty?
|
17
|
+
puts "Console files were not found"
|
18
|
+
exit(0)
|
19
|
+
end
|
20
|
+
|
21
|
+
puts "Select package:"
|
22
|
+
package_consoles.each_with_index do |package, idx|
|
23
|
+
puts "#{idx+1}. #{package[:name]}"
|
24
|
+
end
|
25
|
+
|
26
|
+
print "Type number for selected package: "
|
27
|
+
|
28
|
+
select_result = gets.chomp
|
29
|
+
if select_result == "exit" || select_result.to_i == 0
|
30
|
+
exit(0)
|
31
|
+
end
|
32
|
+
|
33
|
+
path_to_selected_console = package_consoles[select_result.to_i - 1][:path]
|
34
|
+
exit(0) if path_to_selected_console.nil?
|
35
|
+
system(path_to_selected_console)
|
36
|
+
|
37
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
RUBY_ENV=development
|
@@ -0,0 +1 @@
|
|
1
|
+
RUBY_ENV=test
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'rdm'
|
4
|
+
|
5
|
+
ENV['RUBY_ENV'] ||= 'development'
|
6
|
+
Rdm.init(File.expand_path('../../', __FILE__))
|
7
|
+
|
8
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
9
|
+
# with your gem easier. You can also use a different console, if you like.
|
10
|
+
|
11
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
12
|
+
# require "pry"
|
13
|
+
# Pry.start
|
14
|
+
|
15
|
+
require 'irb'
|
16
|
+
IRB.start
|
data/lib/rdm/cli/gen_package.rb
CHANGED
@@ -2,14 +2,14 @@ module Rdm
|
|
2
2
|
module CLI
|
3
3
|
class GenPackage
|
4
4
|
class << self
|
5
|
-
def run(package_name:, current_path:,
|
6
|
-
Rdm::CLI::GenPackage.new(package_name, current_path,
|
5
|
+
def run(package_name:, current_path:, path:, locals: {}, stdout: $stdout)
|
6
|
+
Rdm::CLI::GenPackage.new(package_name, current_path, path, locals, stdout).run
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
def initialize(package_name, current_path,
|
10
|
+
def initialize(package_name, current_path, path, locals, stdout)
|
11
11
|
@current_path = current_path
|
12
|
-
@
|
12
|
+
@path = path
|
13
13
|
@package_name = package_name
|
14
14
|
@locals = locals
|
15
15
|
@stdout = stdout
|
@@ -18,12 +18,12 @@ module Rdm
|
|
18
18
|
def run
|
19
19
|
generated_files_list = Rdm::Gen::Package.generate(
|
20
20
|
current_path: @current_path,
|
21
|
-
local_path: @
|
21
|
+
local_path: @path,
|
22
22
|
package_name: @package_name,
|
23
23
|
locals: @locals
|
24
24
|
)
|
25
25
|
|
26
|
-
generated_files_list.each { |file| @stdout.puts "Generated: #{file}" }
|
26
|
+
generated_files_list.compact.each { |file| @stdout.puts "Generated: #{file}" }
|
27
27
|
rescue Errno::ENOENT => e
|
28
28
|
@stdout.puts "Error occurred. Possible reasons:\n #{Rdm::SOURCE_FILENAME} not found. Please run on directory containing #{Rdm::SOURCE_FILENAME} \n#{e.inspect}"
|
29
29
|
rescue Rdm::Errors::PackageExists
|
@@ -34,6 +34,8 @@ module Rdm
|
|
34
34
|
@stdout.puts "Rdm.packages was not found. Run 'rdm init' to create it"
|
35
35
|
rescue Rdm::Errors::PackageDirExists => e
|
36
36
|
@stdout.puts "Error. Directory #{e.message} exists. Package was not generated"
|
37
|
+
rescue NoMethodError => e
|
38
|
+
@stdout.puts e.message
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
data/lib/rdm/cli/init.rb
CHANGED
@@ -21,7 +21,7 @@ module Rdm
|
|
21
21
|
console: @console
|
22
22
|
)
|
23
23
|
|
24
|
-
generated_files_list.each { |file| @stdout.puts "Generated: #{file}" }
|
24
|
+
generated_files_list.compact.each { |file| @stdout.puts "Generated: #{file}" }
|
25
25
|
rescue Errno::ENOENT => e
|
26
26
|
@stdout.puts "Error occurred. Possible reasons:\n #{@current_path} not found. Please run on empty directory \n#{e.inspect}"
|
27
27
|
rescue Rdm::Errors::ProjectAlreadyInitialized
|
data/lib/rdm/gen/init.rb
CHANGED
data/lib/rdm/gen/package.rb
CHANGED
@@ -24,16 +24,13 @@ module Rdm
|
|
24
24
|
raise Rdm::Errors::PackageNameNotSpecified if @package_name.nil? || @package_name.empty?
|
25
25
|
raise Rdm::Errors::PackageExists if source.packages.keys.include?(@package_name)
|
26
26
|
|
27
|
-
File.open(File.join(source.root_path, Rdm::SOURCE_FILENAME), 'a+') {|f| f.write("
|
27
|
+
File.open(File.join(source.root_path, Rdm::SOURCE_FILENAME), 'a+') {|f| f.write("\npackage '#{@local_path}'")}
|
28
28
|
|
29
29
|
Rdm::Handlers::TemplateHandler.generate(
|
30
30
|
template_name: TEMPLATE_NAME,
|
31
31
|
current_path: @current_path,
|
32
32
|
local_path: @local_path,
|
33
|
-
locals:
|
34
|
-
package_name: @package_name,
|
35
|
-
package_name_camelized: Rdm::Utils::StringUtils.camelize(@package_name)
|
36
|
-
}.merge(@locals)
|
33
|
+
locals: { package_name: @package_name }.merge(@locals)
|
37
34
|
)
|
38
35
|
end
|
39
36
|
|
data/lib/rdm/git/diff_command.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
|
-
require 'open3'
|
2
|
-
|
3
1
|
class Rdm::Git::DiffCommand
|
4
2
|
class << self
|
5
3
|
def get_only_diff_filenames(revision:, path:)
|
6
4
|
command = `cd #{path} && git diff --name-only #{revision}`
|
7
5
|
|
8
6
|
raise Rdm::Errors::GitCommandError, command unless $?.success?
|
9
|
-
|
7
|
+
|
10
8
|
command.split("\n")
|
11
9
|
end
|
12
10
|
end
|
13
|
-
end
|
11
|
+
end
|
data/lib/rdm/git/diff_manager.rb
CHANGED
@@ -13,7 +13,7 @@ module Rdm
|
|
13
13
|
check_repository_initialized!(abs_path)
|
14
14
|
|
15
15
|
return Rdm::Git::DiffCommand
|
16
|
-
.get_only_diff_filenames(revision: revision, path:
|
16
|
+
.get_only_diff_filenames(revision: revision, path: abs_path)
|
17
17
|
.map { |filename| File.expand_path(File.join(abs_path, filename)) }
|
18
18
|
end
|
19
19
|
|
@@ -4,6 +4,9 @@ require 'fileutils'
|
|
4
4
|
module Rdm
|
5
5
|
module Handlers
|
6
6
|
class TemplateHandler
|
7
|
+
REJECTED_TEMPLATE_FILES = %W(.DS_Store)
|
8
|
+
NOT_HANDLED_TEMPLATES_EXT = %W(.erb)
|
9
|
+
|
7
10
|
class << self
|
8
11
|
def generate(template_name:, local_path:, current_path:, locals: {},
|
9
12
|
ignore_source_file: false, stdout: STDOUT, stdin: STDIN)
|
@@ -30,7 +33,8 @@ module Rdm
|
|
30
33
|
@missing_variables = []
|
31
34
|
@stdout = stdout
|
32
35
|
@stdin = stdin
|
33
|
-
|
36
|
+
|
37
|
+
default_locals = { package_subdir_name: Rdm.settings.send(:package_subdir_name) }
|
34
38
|
@locals = default_locals.merge(locals)
|
35
39
|
end
|
36
40
|
|
@@ -38,38 +42,31 @@ module Rdm
|
|
38
42
|
project_path = @ignore_source_file ? @current_path : File.dirname(Rdm::SourceLocator.locate(@current_path))
|
39
43
|
template_detector = Rdm::Templates::TemplateDetector.new(project_path)
|
40
44
|
|
45
|
+
render_helper_path = "#{project_path}/.rdm/helpers/render_helper.rb"
|
46
|
+
require_relative render_helper_path if File.exist?(render_helper_path)
|
47
|
+
|
41
48
|
@template_directory = template_detector.detect_template_folder(@template_name)
|
42
49
|
@destination_directory = File.join(project_path, @local_path)
|
43
50
|
|
44
|
-
template_files_list = Dir
|
45
|
-
File.join(@template_directory, '**', '
|
46
|
-
File.
|
47
|
-
]
|
48
|
-
.select { |p| File.file?(p) }
|
49
|
-
.reject { |p| File.basename(p) == '.DS_Store' }
|
51
|
+
template_files_list = Dir
|
52
|
+
.glob(File.join(@template_directory, '**', '*'), File::FNM_DOTMATCH)
|
53
|
+
.reject { |path| REJECTED_TEMPLATE_FILES.include? File.basename(path) }
|
50
54
|
|
51
|
-
|
55
|
+
template_files_list.each do |path|
|
56
|
+
@missing_variables.concat(
|
57
|
+
Rdm::Templates::TemplateRenderer.get_undefined_variables(get_destination_path(path), @locals)
|
58
|
+
)
|
52
59
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
if File.extname(file) != '.erb'
|
57
|
-
missings.push(
|
58
|
-
*Rdm::Templates::TemplateRenderer.get_undefined_variables(File.read(file), @locals)
|
60
|
+
if handle_file_content?(path)
|
61
|
+
@missing_variables.concat(
|
62
|
+
Rdm::Templates::TemplateRenderer.get_undefined_variables(File.read(path), @locals)
|
59
63
|
)
|
60
64
|
end
|
61
|
-
|
62
|
-
@missing_variables.push(*missings)
|
63
|
-
end
|
64
|
-
|
65
|
-
template_dir_list.each do |dir|
|
66
|
-
@missing_variables.push(
|
67
|
-
*Rdm::Templates::TemplateRenderer.get_undefined_variables(get_destination_path(dir), @locals)
|
68
|
-
)
|
69
65
|
end
|
70
66
|
|
71
|
-
@missing_variables.uniq!
|
72
67
|
if @missing_variables.any?
|
68
|
+
@missing_variables.uniq!
|
69
|
+
|
73
70
|
@stdout.puts "Undefined variables were found:"
|
74
71
|
@missing_variables.size.times {|t| @stdout.puts " #{t+1}. #{@missing_variables[t]}"}
|
75
72
|
|
@@ -79,28 +76,32 @@ module Rdm
|
|
79
76
|
end
|
80
77
|
end
|
81
78
|
|
82
|
-
|
83
|
-
rendered_abs_path = Rdm::Templates::TemplateRenderer.handle(get_destination_path(
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
template_files_list.map do |file|
|
88
|
-
rendered_abs_path = Rdm::Templates::TemplateRenderer.handle(get_destination_path(file), @locals)
|
79
|
+
template_files_list.map! do |path|
|
80
|
+
rendered_abs_path = Rdm::Templates::TemplateRenderer.handle(get_destination_path(path), @locals)
|
81
|
+
rendered_rel_path = Pathname.new(rendered_abs_path).relative_path_from Pathname.new(project_path)
|
89
82
|
|
90
|
-
if File.exists?(rendered_abs_path)
|
91
|
-
@stdout.puts "Warning! #{
|
83
|
+
if File.file?(rendered_abs_path) && File.exists?(rendered_abs_path)
|
84
|
+
@stdout.puts "Warning! #{rendered_rel_path} already exists. Skipping file creation..."
|
85
|
+
next
|
86
|
+
end
|
87
|
+
|
88
|
+
if File.directory?(path)
|
89
|
+
FileUtils.mkdir_p rendered_abs_path
|
92
90
|
next
|
93
91
|
end
|
94
92
|
|
95
|
-
rendered_file_content =
|
96
|
-
File.read(
|
97
|
-
|
93
|
+
rendered_file_content = handle_file_content?(path) ?
|
94
|
+
Rdm::Templates::TemplateRenderer.handle(File.read(path), @locals) :
|
95
|
+
File.read(path)
|
96
|
+
|
98
97
|
|
99
98
|
FileUtils.mkdir_p(File.dirname(rendered_abs_path))
|
100
99
|
File.open(rendered_abs_path, 'w') { |f| f.write rendered_file_content }
|
101
100
|
|
102
|
-
|
101
|
+
rendered_rel_path
|
103
102
|
end
|
103
|
+
|
104
|
+
template_files_list.compact
|
104
105
|
end
|
105
106
|
|
106
107
|
private
|
@@ -112,10 +113,8 @@ module Rdm
|
|
112
113
|
File.join(@destination_directory, template_rel_path)
|
113
114
|
end
|
114
115
|
|
115
|
-
def
|
116
|
-
|
117
|
-
package_subdir_name: Rdm.settings.send(:package_subdir_name)
|
118
|
-
}
|
116
|
+
def handle_file_content?(path)
|
117
|
+
File.file?(path) && !NOT_HANDLED_TEMPLATES_EXT.include?(File.extname(path))
|
119
118
|
end
|
120
119
|
end
|
121
120
|
end
|
@@ -14,15 +14,12 @@ module Rdm
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def initialize(compile_path:, project_path:, package_name:)
|
17
|
-
@compile_path = compile_path
|
17
|
+
@compile_path = compile_path.gsub(/:package_name/, package_name)
|
18
18
|
@project_path = project_path
|
19
19
|
@package_name = package_name
|
20
20
|
end
|
21
21
|
|
22
22
|
def compile
|
23
|
-
render_helper_path = "#{@project_path}/.rdm/helpers/render_helper.rb"
|
24
|
-
require_relative render_helper_path if File.exist?(render_helper_path)
|
25
|
-
|
26
23
|
FileUtils.rm_rf(@compile_path) if Dir.exists?(@compile_path)
|
27
24
|
FileUtils.mkdir_p(@compile_path)
|
28
25
|
|
@@ -60,6 +57,7 @@ module Rdm
|
|
60
57
|
end
|
61
58
|
|
62
59
|
FileUtils.cp_r(File.join(@project_path, 'configs'), File.join(@compile_path, 'configs'))
|
60
|
+
FileUtils.cp_r(File.join(@project_path, Rdm.settings.env_files_dir), File.join(@compile_path, Rdm.settings.env_files_dir))
|
63
61
|
|
64
62
|
Rdm.settings.compile_ignore_files.each do |file|
|
65
63
|
Dir["#{@compile_path}/**/#{file}"].each do |file_to_remove|
|
data/lib/rdm/settings.rb
CHANGED
@@ -2,7 +2,7 @@ class Rdm::Settings
|
|
2
2
|
SETTING_KEYS = [
|
3
3
|
:role, :package_subdir_name, :configs_dir, :config_path, :role_config_path,
|
4
4
|
:silence_missing_package_file, :silence_missing_package, :compile_path,
|
5
|
-
:compile_ignore_files, :compile_add_files
|
5
|
+
:compile_ignore_files, :compile_add_files, :env_files_dir
|
6
6
|
].freeze
|
7
7
|
|
8
8
|
SETTING_VARIABLES = [:role, :configs_dir, :config_path, :role_config_path].freeze
|
@@ -13,6 +13,7 @@ class Rdm::Settings
|
|
13
13
|
silence_missing_package_file(false)
|
14
14
|
package_subdir_name('package')
|
15
15
|
configs_dir('configs')
|
16
|
+
env_files_dir('env_files')
|
16
17
|
compile_ignore_files([
|
17
18
|
'.gitignore',
|
18
19
|
'.byebug_history',
|
@@ -23,7 +24,7 @@ class Rdm::Settings
|
|
23
24
|
])
|
24
25
|
compile_add_files([
|
25
26
|
'Gemfile',
|
26
|
-
'Gemfile.lock'
|
27
|
+
'Gemfile.lock',
|
27
28
|
])
|
28
29
|
end
|
29
30
|
|
data/lib/rdm/source_parser.rb
CHANGED
@@ -3,15 +3,16 @@ class Rdm::SourceParser
|
|
3
3
|
end
|
4
4
|
|
5
5
|
class << self
|
6
|
-
def read_and_init_source(source_path)
|
7
|
-
Rdm::SourceParser.new(source_path).read_and_init_source
|
6
|
+
def read_and_init_source(source_path, stdout: nil)
|
7
|
+
Rdm::SourceParser.new(source_path, stdout).read_and_init_source
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
attr_accessor :source_path
|
12
12
|
|
13
|
-
def initialize(source_path)
|
13
|
+
def initialize(source_path, stdout)
|
14
14
|
@source_path = source_path
|
15
|
+
@stdout = stdout || STDOUT
|
15
16
|
end
|
16
17
|
|
17
18
|
# Read source file, parse and init it's packages and configs
|
@@ -28,6 +29,7 @@ class Rdm::SourceParser
|
|
28
29
|
|
29
30
|
init_and_set_packages(source)
|
30
31
|
init_and_set_configs(source)
|
32
|
+
init_and_set_env_variables(source)
|
31
33
|
source.init_with(packages: packages, configs: configs)
|
32
34
|
source
|
33
35
|
end
|
@@ -67,6 +69,25 @@ class Rdm::SourceParser
|
|
67
69
|
end
|
68
70
|
end
|
69
71
|
|
72
|
+
def init_and_set_env_variables(source)
|
73
|
+
role = settings.read_setting(:role)
|
74
|
+
|
75
|
+
unless File.exists?(env_file_path(role))
|
76
|
+
@stdout.puts "WARNING! Environment file for role '#{role}' was not found. Please, add #{env_file_path(role)} file..."
|
77
|
+
return
|
78
|
+
end
|
79
|
+
|
80
|
+
File.foreach(env_file_path(role)) do |line|
|
81
|
+
key, value = line.split('=').map(&:strip)
|
82
|
+
|
83
|
+
if ENV.has_key?(key) && ENV[key] != value
|
84
|
+
@stdout.puts "WARNING! Environment file '#{role}' overwrites ENV['#{key}'] variable from '#{ENV.fetch(key, nil)}' to '#{value}' ..."
|
85
|
+
end
|
86
|
+
|
87
|
+
ENV[key] = value
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
70
91
|
# Make sure that all required settings are in place
|
71
92
|
def validate_rdm_settings!
|
72
93
|
if settings.read_setting(:role).nil?
|
@@ -81,6 +102,10 @@ class Rdm::SourceParser
|
|
81
102
|
File.dirname(source_path)
|
82
103
|
end
|
83
104
|
|
105
|
+
def env_file_path(role)
|
106
|
+
File.join(root_path, settings.read_setting(:env_files_dir), "#{role}.env")
|
107
|
+
end
|
108
|
+
|
84
109
|
# [String] Source file content
|
85
110
|
def source_content
|
86
111
|
@source_content ||= File.read(source_path)
|
data/lib/rdm/spec_runner.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Rdm::SpecRunner
|
2
|
-
def self.run(path: nil, package: nil,
|
3
|
-
Rdm::SpecRunner::Runner.new(path: path, package: package,
|
2
|
+
def self.run(path: nil, package: nil, spec_matcher: nil)
|
3
|
+
Rdm::SpecRunner::Runner.new(path: path, package: package, spec_matcher: spec_matcher).run
|
4
4
|
end
|
5
5
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'rdm'
|
4
|
+
|
5
|
+
ENV['RUBY_ENV'] ||= 'development'
|
6
|
+
|
7
|
+
source_file = Rdm::SourceLocator.locate(__dir__)
|
8
|
+
source = Rdm::SourceParser.read_and_init_source(source_file)
|
9
|
+
package_consoles = source.packages.inject([]) do |res, (name,data)|
|
10
|
+
package_console_file = File.join(data.path, 'bin/console')
|
11
|
+
File.exists?(package_console_file) ?
|
12
|
+
res.push(name: name, path: package_console_file) :
|
13
|
+
res
|
14
|
+
end
|
15
|
+
|
16
|
+
if package_consoles.empty?
|
17
|
+
puts "Console files were not found"
|
18
|
+
exit(0)
|
19
|
+
end
|
20
|
+
|
21
|
+
puts "Select package:"
|
22
|
+
package_consoles.each_with_index do |package, idx|
|
23
|
+
puts "#{idx+1}. #{package[:name]}"
|
24
|
+
end
|
25
|
+
print "Type number for selected package: "
|
26
|
+
|
27
|
+
select_result = gets.chomp
|
28
|
+
if select_result == "exit" || select_result.to_i == 0
|
29
|
+
exit(0)
|
30
|
+
end
|
31
|
+
|
32
|
+
path_to_selected_console = package_consoles[select_result.to_i - 1][:path]
|
33
|
+
exit(0) if path_to_selected_console.nil?
|
34
|
+
system(path_to_selected_console)
|
35
|
+
|
36
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
RUBY_ENV=development
|
@@ -0,0 +1 @@
|
|
1
|
+
RUBY_ENV=production
|
@@ -0,0 +1 @@
|
|
1
|
+
RUBY_ENV=test
|
@@ -15,7 +15,8 @@ module Rdm
|
|
15
15
|
|
16
16
|
def initialize(template, locals)
|
17
17
|
@template = template
|
18
|
-
@locals
|
18
|
+
@locals = locals
|
19
|
+
@undefined_variables = []
|
19
20
|
end
|
20
21
|
|
21
22
|
def handle
|
@@ -25,17 +26,26 @@ module Rdm
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def get_undefined_variables
|
28
|
-
|
29
|
+
Rdm::Utils::RenderUtil.render(@template, @locals)
|
30
|
+
|
31
|
+
@undefined_variables
|
32
|
+
rescue NameError => e
|
33
|
+
raise NoMethodError, "Undefined method for template. Please, add :#{e.name} method to .rdm/helpers/render_helper.rb file!" if @undefined_variables.include?(e.name)
|
34
|
+
|
35
|
+
@locals[e.name] = e.name.to_s
|
36
|
+
@undefined_variables.push(e.name)
|
37
|
+
|
38
|
+
retry
|
29
39
|
end
|
30
40
|
|
31
41
|
private
|
32
42
|
|
33
43
|
def get_template_variables
|
34
|
-
@template
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
44
|
+
Rdm::Utils::RenderUtil.render(@template, {})
|
45
|
+
rescue NameError => e
|
46
|
+
@locals
|
47
|
+
|
48
|
+
get_template_variables(@template, fake_locals, undefined_variables)
|
39
49
|
end
|
40
50
|
|
41
51
|
def get_passed_variables
|
data/lib/rdm/version.rb
CHANGED
@@ -4,8 +4,8 @@ describe Rdm::CLI::CompilePackage do
|
|
4
4
|
include ExampleProjectHelper
|
5
5
|
|
6
6
|
subject { described_class }
|
7
|
-
let(:
|
8
|
-
let(:new_compile_path) { '/tmp/
|
7
|
+
let(:tmp_rdm) { '/tmp/rdm' }
|
8
|
+
let(:new_compile_path) { '/tmp/rdm/custom_name' }
|
9
9
|
|
10
10
|
describe "::compile" do
|
11
11
|
before :each do
|
@@ -14,8 +14,7 @@ describe Rdm::CLI::CompilePackage do
|
|
14
14
|
|
15
15
|
after :each do
|
16
16
|
reset_example_project
|
17
|
-
FileUtils.rm_rf(
|
18
|
-
FileUtils.rm_rf(new_compile_path)
|
17
|
+
FileUtils.rm_rf(tmp_rdm)
|
19
18
|
end
|
20
19
|
|
21
20
|
context "setup compile_path at Rdm.packages" do
|
@@ -24,7 +23,8 @@ describe Rdm::CLI::CompilePackage do
|
|
24
23
|
subject.compile(
|
25
24
|
project_path: example_project_path,
|
26
25
|
package_name: 'core',
|
27
|
-
overwrite_directory: ->() { true }
|
26
|
+
overwrite_directory: ->() { true },
|
27
|
+
compile_path: nil
|
28
28
|
)
|
29
29
|
}.to output(
|
30
30
|
<<~EOF
|
@@ -3,9 +3,8 @@ require "spec_helper"
|
|
3
3
|
describe Rdm::CLI::GenPackage do
|
4
4
|
include ExampleProjectHelper
|
5
5
|
|
6
|
-
subject
|
7
|
-
|
8
|
-
let(:stdout) { SpecLogger.new }
|
6
|
+
subject { described_class }
|
7
|
+
let(:stdout) { SpecLogger.new }
|
9
8
|
|
10
9
|
before { initialize_example_project }
|
11
10
|
after { reset_example_project }
|
@@ -15,7 +14,7 @@ describe Rdm::CLI::GenPackage do
|
|
15
14
|
subject.run(
|
16
15
|
package_name: "database",
|
17
16
|
current_path: example_project_path,
|
18
|
-
|
17
|
+
path: "infrastructure/database",
|
19
18
|
stdout: stdout
|
20
19
|
)
|
21
20
|
|
@@ -35,7 +34,7 @@ describe Rdm::CLI::GenPackage do
|
|
35
34
|
subject.run(
|
36
35
|
package_name: "database",
|
37
36
|
current_path: example_project_path,
|
38
|
-
|
37
|
+
path: "infrastructure/database",
|
39
38
|
stdout: stdout
|
40
39
|
)
|
41
40
|
|
@@ -48,7 +47,7 @@ describe Rdm::CLI::GenPackage do
|
|
48
47
|
subject.run(
|
49
48
|
package_name: "database",
|
50
49
|
current_path: File.dirname(example_project_path),
|
51
|
-
|
50
|
+
path: "infrastructure/database",
|
52
51
|
stdout: stdout
|
53
52
|
)
|
54
53
|
|
@@ -59,14 +58,14 @@ describe Rdm::CLI::GenPackage do
|
|
59
58
|
subject.run(
|
60
59
|
package_name: "database",
|
61
60
|
current_path: example_project_path,
|
62
|
-
|
61
|
+
path: "infrastructure/database",
|
63
62
|
stdout: stdout
|
64
63
|
)
|
65
64
|
|
66
65
|
subject.run(
|
67
66
|
package_name: "database",
|
68
67
|
current_path: example_project_path,
|
69
|
-
|
68
|
+
path: "infrastructure/database",
|
70
69
|
stdout: stdout
|
71
70
|
)
|
72
71
|
expect(stdout.output).to include("Error. Directory infrastructure/database exists. Package was not generated")
|
@@ -76,14 +75,14 @@ describe Rdm::CLI::GenPackage do
|
|
76
75
|
subject.run(
|
77
76
|
package_name: "database",
|
78
77
|
current_path: example_project_path,
|
79
|
-
|
78
|
+
path: "infrastructure/database",
|
80
79
|
stdout: stdout
|
81
80
|
)
|
82
81
|
|
83
82
|
subject.run(
|
84
83
|
package_name: "database",
|
85
84
|
current_path: example_project_path,
|
86
|
-
|
85
|
+
path: "database",
|
87
86
|
stdout: stdout
|
88
87
|
)
|
89
88
|
expect(stdout.output).to include("Error. Package already exist. Package was not generated")
|
@@ -93,7 +92,7 @@ describe Rdm::CLI::GenPackage do
|
|
93
92
|
subject.run(
|
94
93
|
package_name: "",
|
95
94
|
current_path: example_project_path,
|
96
|
-
|
95
|
+
path: "infrastructure/database",
|
97
96
|
stdout: stdout
|
98
97
|
)
|
99
98
|
expect(stdout.output).to include("Package name was not specified!")
|
data/spec/rdm/gen/init_spec.rb
CHANGED
@@ -17,6 +17,10 @@ describe Rdm::Gen::Init do
|
|
17
17
|
ensure_exists("Gemfile")
|
18
18
|
ensure_exists("Readme.md")
|
19
19
|
ensure_exists("tests/run")
|
20
|
+
ensure_exists("bin/console")
|
21
|
+
ensure_exists("env_files/test.env")
|
22
|
+
ensure_exists("env_files/development.env")
|
23
|
+
ensure_exists("env_files/production.env")
|
20
24
|
end
|
21
25
|
end
|
22
26
|
|
@@ -9,13 +9,13 @@ describe Rdm::Gen::Package do
|
|
9
9
|
after { reset_example_project }
|
10
10
|
|
11
11
|
context "sample package" do
|
12
|
-
it "
|
13
|
-
FileUtils.rm_rf(File.join(example_project_path, '.rdm'))
|
12
|
+
it "generates correct files" do
|
13
|
+
FileUtils.rm_rf(File.join(example_project_path, '.rdm', 'templates'))
|
14
14
|
|
15
15
|
subject.generate(
|
16
16
|
current_path: example_project_path,
|
17
17
|
package_name: "some",
|
18
|
-
local_path: "domain/some"
|
18
|
+
local_path: "domain/some"
|
19
19
|
)
|
20
20
|
|
21
21
|
FileUtils.cd(example_project_path) do
|
@@ -3,24 +3,33 @@ require 'spec_helper'
|
|
3
3
|
describe Rdm::Packages::CompilerService do
|
4
4
|
include ExampleProjectHelper
|
5
5
|
|
6
|
-
subject
|
7
|
-
let(:source_parser)
|
8
|
-
let(:source_path)
|
9
|
-
let(:
|
6
|
+
subject { described_class }
|
7
|
+
let(:source_parser) { Rdm::SourceParser }
|
8
|
+
let(:source_path) { File.join(compile_path, Rdm::SOURCE_FILENAME) }
|
9
|
+
let(:fixed_compile_path) { "/tmp/rdm/custom_name" }
|
10
|
+
let(:compile_path_template) { "/tmp/rdm/:package_name" }
|
11
|
+
|
12
|
+
def compile_path(package_name)
|
13
|
+
compile_path_template.gsub(/:package_name/, package_name)
|
14
|
+
end
|
15
|
+
|
16
|
+
def source_path(package_name)
|
17
|
+
File.join(compile_path(package_name), Rdm::SOURCE_FILENAME)
|
18
|
+
end
|
10
19
|
|
11
20
|
describe "::compile" do
|
12
21
|
before { initialize_example_project }
|
13
22
|
|
14
23
|
after do
|
15
24
|
reset_example_project
|
16
|
-
FileUtils.rm_rf
|
25
|
+
FileUtils.rm_rf File.dirname(fixed_compile_path)
|
17
26
|
end
|
18
27
|
|
19
28
|
context "to existing directory" do
|
20
29
|
before do
|
21
30
|
subject.compile(
|
22
31
|
package_name: 'web',
|
23
|
-
compile_path:
|
32
|
+
compile_path: fixed_compile_path,
|
24
33
|
project_path: example_project_path
|
25
34
|
)
|
26
35
|
end
|
@@ -29,20 +38,20 @@ describe Rdm::Packages::CompilerService do
|
|
29
38
|
before do
|
30
39
|
subject.compile(
|
31
40
|
package_name: 'core',
|
32
|
-
compile_path:
|
41
|
+
compile_path: fixed_compile_path,
|
33
42
|
project_path: example_project_path
|
34
43
|
)
|
35
44
|
end
|
36
|
-
|
45
|
+
|
37
46
|
it "deletes old unused package from file structure" do
|
38
47
|
expect(
|
39
|
-
File.exists?(File.join(
|
48
|
+
File.exists?(File.join(fixed_compile_path, 'application/web/package/web.rb'))
|
40
49
|
).to be false
|
41
50
|
end
|
42
51
|
|
43
52
|
it "deletes old unused package from Rdm.packages" do
|
44
53
|
package_names = source_parser
|
45
|
-
.read_and_init_source(source_path)
|
54
|
+
.read_and_init_source(source_path('custom_name'))
|
46
55
|
.packages
|
47
56
|
.values
|
48
57
|
.map(&:name)
|
@@ -57,28 +66,28 @@ describe Rdm::Packages::CompilerService do
|
|
57
66
|
before do
|
58
67
|
subject.compile(
|
59
68
|
package_name: 'repository',
|
60
|
-
compile_path:
|
69
|
+
compile_path: compile_path_template,
|
61
70
|
project_path: example_project_path
|
62
71
|
)
|
63
72
|
end
|
64
73
|
|
65
74
|
it "creates folder" do
|
66
|
-
expect(Dir.exists?(compile_path)).to be true
|
75
|
+
expect(Dir.exists?(compile_path('repository'))).to be true
|
67
76
|
end
|
68
77
|
|
69
78
|
it "creates Rdm.packges" do
|
70
|
-
expect(File.exists?(source_path)).to be true
|
79
|
+
expect(File.exists?(source_path('repository'))).to be true
|
71
80
|
end
|
72
81
|
|
73
82
|
it "copies files structure from original package" do
|
74
83
|
expect(
|
75
|
-
File.exists?(File.join(compile_path, 'infrastructure/repository/package/repository.rb'))
|
84
|
+
File.exists?(File.join(compile_path('repository'), 'infrastructure/repository/package/repository.rb'))
|
76
85
|
).to be true
|
77
86
|
end
|
78
87
|
|
79
88
|
it "add only required package name to Rdm.packages" do
|
80
89
|
package_names = source_parser
|
81
|
-
.read_and_init_source(source_path)
|
90
|
+
.read_and_init_source(source_path('repository'))
|
82
91
|
.packages
|
83
92
|
.values
|
84
93
|
.map(&:name)
|
@@ -92,24 +101,24 @@ describe Rdm::Packages::CompilerService do
|
|
92
101
|
before do
|
93
102
|
subject.compile(
|
94
103
|
package_name: 'web',
|
95
|
-
compile_path:
|
104
|
+
compile_path: compile_path_template,
|
96
105
|
project_path: example_project_path
|
97
106
|
)
|
98
107
|
end
|
99
108
|
|
100
109
|
it "copies files structure for each dependent package" do
|
101
110
|
expect(
|
102
|
-
File.exists?(File.join(compile_path, 'domain/core/package/core.rb'))
|
111
|
+
File.exists?(File.join(compile_path('web'), 'domain/core/package/core.rb'))
|
103
112
|
).to be true
|
104
113
|
|
105
114
|
expect(
|
106
|
-
File.exists?(File.join(compile_path, 'application/web/package/web.rb'))
|
115
|
+
File.exists?(File.join(compile_path('web'), 'application/web/package/web.rb'))
|
107
116
|
).to be true
|
108
117
|
end
|
109
118
|
|
110
119
|
it "add only required package name to Rdm.packages" do
|
111
120
|
package_names = source_parser
|
112
|
-
.read_and_init_source(source_path)
|
121
|
+
.read_and_init_source(source_path('web'))
|
113
122
|
.packages
|
114
123
|
.values
|
115
124
|
.map(&:name)
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Rdm::SourceParser do
|
4
|
+
include ExampleProjectHelper
|
5
|
+
|
4
6
|
describe "#parse" do
|
5
7
|
subject { Rdm::SourceParser }
|
6
8
|
|
@@ -17,7 +19,7 @@ describe Rdm::SourceParser do
|
|
17
19
|
}
|
18
20
|
|
19
21
|
before :each do
|
20
|
-
@source = subject.read_and_init_source(source_path)
|
22
|
+
@source = subject.read_and_init_source(source_path, stdout: SpecLogger.new)
|
21
23
|
end
|
22
24
|
|
23
25
|
it "returns Source object" do
|
@@ -55,7 +57,7 @@ describe Rdm::SourceParser do
|
|
55
57
|
}
|
56
58
|
|
57
59
|
before :each do
|
58
|
-
@source = subject.read_and_init_source(source_path)
|
60
|
+
@source = subject.read_and_init_source(source_path, stdout: SpecLogger.new)
|
59
61
|
end
|
60
62
|
|
61
63
|
it "returns Source object" do
|
@@ -75,4 +77,50 @@ describe Rdm::SourceParser do
|
|
75
77
|
expect(names).to include("database")
|
76
78
|
end
|
77
79
|
end
|
80
|
+
|
81
|
+
describe "::read_and_init_source" do
|
82
|
+
before { initialize_example_project }
|
83
|
+
after { reset_example_project }
|
84
|
+
|
85
|
+
subject { described_class }
|
86
|
+
let(:stdout) { SpecLogger.new }
|
87
|
+
|
88
|
+
describe "#init_and_set_env_variables" do
|
89
|
+
context "with defined role" do
|
90
|
+
it "load env_file variables into ENV hash" do
|
91
|
+
subject.read_and_init_source(@rdm_source_file)
|
92
|
+
|
93
|
+
expect(ENV['EXAMPLE_API_KEY']).to eq('example_key_value')
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "with undefined role" do
|
98
|
+
it "puts warning message" do
|
99
|
+
Rdm::Utils::FileUtils.change_file @rdm_source_file do |line|
|
100
|
+
line.include?('role "production"') ? 'role "stading"' : line
|
101
|
+
end
|
102
|
+
|
103
|
+
subject.read_and_init_source(@rdm_source_file, stdout: stdout)
|
104
|
+
|
105
|
+
expect(stdout.output).to include("WARNING! Environment file for role 'stading' was not found. Please, add /tmp/example/env_files/stading.env file...")
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "when try to overwrite ENV variable" do
|
110
|
+
before do
|
111
|
+
ENV['RUBY_ENV'] = 'test'
|
112
|
+
|
113
|
+
subject.read_and_init_source(@rdm_source_file, stdout: stdout)
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'puts warning message' do
|
117
|
+
expect(stdout.output).to include("WARNING! Environment file 'production' overwrites ENV['RUBY_ENV'] variable from 'test' to 'production' ...")
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'overwrites ENV variable' do
|
121
|
+
expect(ENV['RUBY_ENV']).to eq('production')
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
78
126
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Droid Labs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -149,16 +149,21 @@ files:
|
|
149
149
|
- example/application/web/Package.rb
|
150
150
|
- example/application/web/package/web.rb
|
151
151
|
- example/application/web/package/web/sample_controller.rb
|
152
|
+
- example/bin/console
|
152
153
|
- example/configs/app/default.yml
|
153
154
|
- example/configs/app/production.yml
|
154
155
|
- example/configs/database/default.yml
|
155
156
|
- example/domain/core/Package.rb
|
156
157
|
- example/domain/core/package/core.rb
|
157
158
|
- example/domain/core/package/core/sample_service.rb
|
159
|
+
- example/env_files/development.env
|
160
|
+
- example/env_files/production.env
|
161
|
+
- example/env_files/test.env
|
158
162
|
- example/infrastructure/repository/Package.rb
|
159
163
|
- example/infrastructure/repository/package/repository.rb
|
160
164
|
- example/infrastructure/repository/package/repository/sample_repository.rb
|
161
165
|
- example/server/Package.rb
|
166
|
+
- example/server/bin/console
|
162
167
|
- example/server/package/server.rb
|
163
168
|
- example/server/server.rb
|
164
169
|
- example/tests/diff_run
|
@@ -202,6 +207,10 @@ files:
|
|
202
207
|
- lib/rdm/templates/init/Gemfile
|
203
208
|
- lib/rdm/templates/init/Rdm.packages
|
204
209
|
- lib/rdm/templates/init/Readme.md
|
210
|
+
- lib/rdm/templates/init/bin/console
|
211
|
+
- lib/rdm/templates/init/env_files/development.env
|
212
|
+
- lib/rdm/templates/init/env_files/production.env
|
213
|
+
- lib/rdm/templates/init/env_files/test.env
|
205
214
|
- lib/rdm/templates/init/tests/diff_run
|
206
215
|
- lib/rdm/templates/init/tests/run
|
207
216
|
- lib/rdm/templates/package/.gitignore
|