power_stencil 0.9.3 → 0.9.4

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: c36f08f7b3ad9a916e27a18e755af6794084b97f
4
- data.tar.gz: 82104cf2bda5b15f57020b57ccf66b1e95ee241c
3
+ metadata.gz: 7c8c69b2dc3cdadebcdf0899978842ccf2fe9759
4
+ data.tar.gz: 7381be842bd05452ba6c71f8e6cffb417eb4d9eb
5
5
  SHA512:
6
- metadata.gz: 6d1db8dd8989c9299eea8fe869e527f7c86b93db49353962ecf2620a34614fb143a39b02e12480dd02929c57c5adce19ec53b35754e327e79c9620bff0d1708f
7
- data.tar.gz: 8e1377704873ca6d8a8eb69c4ba7e41f3e2a9cb0af77b3c7d06ea5bb5fc3174b72dc3df81140dcbd4cb0c286b21bac3ebc7e15fff4ff44d82e4e08acc5925e31
6
+ metadata.gz: efe862901f45e4c0df84304f5aa41ddf5985f898e85b73d3d8ebe1822478007c59eadb72fcce2adb73dddc0b8394bb4c15899478485e34fcdf50d849dfccad66
7
+ data.tar.gz: ed7abb218f9551d5bc5732016874db6e34375a2581fdc2b4b69cdff3663af5d1baeb80114b48b35c35cccf1e104dbc0a369a33aef5c21b18bcddbbdfde00b452
@@ -14,9 +14,15 @@
14
14
  :processors:
15
15
  <%= plugin_name %>: <%= plugin_module_name %>::Processor
16
16
 
17
+
18
+ # This is the name of the method called __instead__ of standard file detemplatization. This method has
19
+ # to be a module method in the `plugin_module` module.
20
+ :generate_build_files: generate_build_files
21
+
22
+
17
23
  # This is the name of the method called after the files are detemplatized. This method has
18
24
  # to be a module method in the `plugin_module` module.
19
- :build: post_build_hook
25
+ :post_build: post_build_hook
20
26
 
21
27
  # If a dsl module is declared it will be injected in the DSL available in the shell or templates
22
28
  :dsl:
@@ -5,12 +5,23 @@ require '<%= plugin_name %>/dsl/<%= plugin_name %>_dsl'
5
5
 
6
6
  module <%= plugin_module_name %>
7
7
 
8
+ extend Climatic::Utils::SafeExec
9
+
10
+ def self.generate_build_files(entity_to_build, target_directory)
11
+ # This is an example of what you could do to generate files, here using default detemplatization...
12
+ PowerStencil.logger.debug "By default plugin '<%= plugin_name %>' uses standard build..."
13
+ PowerStencil.project.engine.generate_build_files entity_to_build, target_directory
14
+ end
15
+
8
16
  def self.post_build_hook(built_entity, generated_files_path)
9
17
  # This is an example of what you could do after files are generated, ie pretty much anything...
10
18
  case built_entity.type
11
19
  when :<%= plugin_name %>_entity
12
20
  generated_file = File.join generated_files_path, 'message.txt'
13
- puts File.readlines(generated_file)
21
+ # Enclose in `safely_exec_code` code that is protected by the `--simulate` command-line flag.
22
+ safely_exec_code(message: "Displaying content of '#{generated_file}'.") do
23
+ puts File.readlines(generated_file)
24
+ end
14
25
  else
15
26
  raise PowerStencil::Error, 'Plugin <%= plugin_name %> doesnt know how handle the build of a <%= plugin_name %>_entity entity type !'
16
27
  end
@@ -14,9 +14,15 @@
14
14
  :processors:
15
15
  <%= plugin_name %>: <%= plugin_module_name %>::Processor
16
16
 
17
+
18
+ # This is the name of the method called __instead__ of standard file detemplatization. This method has
19
+ # to be a module method in the `plugin_module` module.
20
+ :generate_build_files: generate_build_files
21
+
22
+
17
23
  # This is the name of the method called after the files are detemplatized. This method has
18
24
  # to be a module method in the `plugin_module` module.
19
- :build: post_build_hook
25
+ :post_build: post_build_hook
20
26
 
21
27
  # If a dsl module is declared it will be injected in the DSL available in the shell or templates
22
28
  :dsl:
@@ -5,12 +5,23 @@ require '<%= plugin_name %>/dsl/<%= plugin_name %>_dsl'
5
5
 
6
6
  module <%= plugin_module_name %>
7
7
 
8
+ extend Climatic::Utils::SafeExec
9
+
10
+ def self.generate_build_files(entity_to_build, target_directory)
11
+ # This is an example of what you could do to generate files, here using default detemplatization...
12
+ PowerStencil.logger.debug "By default plugin '<%= plugin_name %>' uses standard build..."
13
+ PowerStencil.project.engine.generate_build_files entity_to_build, target_directory
14
+ end
15
+
8
16
  def self.post_build_hook(built_entity, generated_files_path)
9
17
  # This is an example of what you could do after files are generated, ie pretty much anything...
10
18
  case built_entity.type
11
19
  when :<%= plugin_name %>_entity
12
20
  generated_file = File.join generated_files_path, 'message.txt'
13
- puts File.readlines(generated_file)
21
+ # Enclose in `safely_exec_code` code that is protected by the `--simulate` command-line flag.
22
+ safely_exec_code(message: "Displaying content of '#{generated_file}'.") do
23
+ puts File.readlines(generated_file)
24
+ end
14
25
  else
15
26
  raise PowerStencil::Error, 'Plugin <%= plugin_name %> doesnt know how handle the build of a <%= plugin_name %>_entity entity type !'
16
27
  end
@@ -52,6 +52,28 @@ module PowerStencil
52
52
  end
53
53
  end
54
54
 
55
+ def generate_build_files(entity_to_build, target_path)
56
+ logger.info "Rendering '#{entity_to_build.as_path}' templates in '#{target_path}'"
57
+ render_source entity_to_build.templates_path, target_path, main_entry_point: entity_to_build.as_path
58
+ logger.info "Detemplatized files generated in '#{target_path}'"
59
+ manage_build_links target_path
60
+ end
61
+
62
+ def post_build_hook(entity_to_build, files_path)
63
+ case entity_to_build.type
64
+ when :simple_exec
65
+ script_to_execute = File.expand_path File.join(files_path, entity_to_build.post_process.process)
66
+ exec_options = {message: "Running '#{script_to_execute}'"}
67
+ exec_options[:show_output] = true if config[:verbose]
68
+ process_report = safely_exec_command "'#{script_to_execute}'", exec_options
69
+ unless process_report.exit_status.exitstatus == 0
70
+ raise PowerStencil::Error, "Process `#{process_report.command}` failed and returned exit code '#{process_report.exit_status.exitstatus}'"
71
+ end
72
+ process_report
73
+ end
74
+ end
75
+
76
+
55
77
  private
56
78
 
57
79
  def manage_build_links(last_build_path)
@@ -97,43 +119,34 @@ module PowerStencil
97
119
  def build_entity(entity_to_build, target_path)
98
120
  initial_directory = Dir.pwd
99
121
  target_plugin_name = entity_to_build.buildable_by.to_s
100
- default_build entity_to_build, target_path
122
+
123
+ # Files generation
124
+ if target_plugin_name.empty?
125
+ generate_build_files entity_to_build, target_path
126
+ else
127
+ target_plugin = project.plugins[target_plugin_name]
128
+ raise PowerStencil::Error, "Could not find plugin '#{target_plugin_name}' !" if target_plugin.nil?
129
+ raise PowerStencil::Error, "Plugin '#{target_plugin_name}' has no file generation capability !" unless target_plugin.capabilities[:generate_build_files]
130
+ target_plugin.generate_build_files entity_to_build, target_path
131
+ end
132
+
101
133
  # Post processing executed from generated directory (#11)
102
134
  Dir.chdir target_path
103
135
 
136
+ # Post generation action
104
137
  if target_plugin_name.empty?
105
138
  post_build_hook entity_to_build, target_path
106
139
  else
107
140
  target_plugin = project.plugins[target_plugin_name]
108
141
  raise PowerStencil::Error, "Could not find plugin '#{target_plugin_name}' !" if target_plugin.nil?
109
- raise PowerStencil::Error, "Plugin '#{target_plugin_name}' has no build capability !" unless target_plugin.capabilities[:build]
142
+ raise PowerStencil::Error, "Plugin '#{target_plugin_name}' has no post build capability !" unless target_plugin.capabilities[:post_build]
110
143
  target_plugin.post_build_hook entity_to_build, target_path
111
144
  end
145
+
112
146
  ensure
113
147
  Dir.chdir initial_directory
114
148
  end
115
149
 
116
- def default_build(entity_to_build, target_path)
117
- logger.info "Building #{entity_to_build.as_path} in '#{target_path}'"
118
- render_source entity_to_build.templates_path, target_path, main_entry_point: entity_to_build.as_path
119
- logger.info "Detemplatized filed generated in '#{target_path}'"
120
- manage_build_links target_path
121
- end
122
-
123
- def post_build_hook(entity_to_build, files_path)
124
- case entity_to_build.type
125
- when :simple_exec
126
- script_to_execute = File.expand_path File.join(files_path, entity_to_build.post_process.process)
127
- exec_options = {message: "Running '#{script_to_execute}'"}
128
- exec_options[:show_output] = true if config[:verbose]
129
- process_report = safely_exec_command "'#{script_to_execute}'", exec_options
130
- unless process_report.exit_status.exitstatus == 0
131
- raise PowerStencil::Error, "Process `#{process_report.command}` failed and returned exit code '#{process_report.exit_status.exitstatus}'"
132
- end
133
- process_report
134
- end
135
- end
136
-
137
150
  end
138
151
 
139
152
  end
@@ -3,9 +3,16 @@ module PowerStencil
3
3
 
4
4
  module Build
5
5
 
6
+ def generate_build_files(*args)
7
+ build_method_name = plugin_definition[:generate_build_files]
8
+ msg = "Plugin '#{self.name}' doesn't contain the '#{build_method_name}' method in the '#{plugin_definition[:plugin_module]}' module. Cannot delegate !"
9
+ raise PowerStencil::Error, msg unless plugin_module.respond_to? build_method_name
10
+ plugin_module.send build_method_name, *args
11
+ end
12
+
6
13
  def post_build_hook(*args)
7
- build_method_name = plugin_definition[:build]
8
- msg = "Plugin '#{self.name}' doesn't contain the '#{build_method_name}' method in the '#{plugin_definition[:plugin_module]}' module. Cannot build !"
14
+ build_method_name = plugin_definition[:post_build]
15
+ msg = "Plugin '#{self.name}' doesn't contain the '#{build_method_name}' method in the '#{plugin_definition[:plugin_module]}' module. Cannot delegate !"
9
16
  raise PowerStencil::Error, msg unless plugin_module.respond_to? build_method_name
10
17
  plugin_module.send build_method_name, *args
11
18
  end
@@ -5,7 +5,7 @@ module PowerStencil
5
5
 
6
6
  include PowerStencil::Utils::FileHelper
7
7
 
8
- CAPABILITIES = %i(config command_line processors build dsl entity_definitions templates).freeze
8
+ CAPABILITIES = %i(config command_line processors generate_build_files post_build dsl entity_definitions templates).freeze
9
9
 
10
10
  attr_reader :plugin_definition
11
11
 
@@ -27,7 +27,7 @@ module PowerStencil
27
27
  logger.debug "Loading plugin '#{self.name}' capabilities..."
28
28
  begin
29
29
  @plugin_definition = yaml_file_to_hash yaml_file
30
- %i(processors entity_definitions templates build dsl).each do |capability|
30
+ %i(processors entity_definitions templates generate_build_files post_build dsl).each do |capability|
31
31
  unless plugin_definition[capability].nil? or plugin_definition[capability].empty?
32
32
  capabilities[capability] = true
33
33
  end
@@ -1,3 +1,3 @@
1
1
  module PowerStencil
2
- VERSION = '0.9.3'.freeze
2
+ VERSION = '0.9.4'.freeze
3
3
  end
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'rake', '~> 10.0'
26
26
  spec.add_development_dependency 'rspec', '~> 3.0'
27
27
 
28
- spec.add_dependency 'climatic', '~> 0.2.34'
28
+ spec.add_dependency 'climatic', '~> 0.2.35'
29
29
  spec.add_dependency 'dir_glob_ignore', '~> 0.3'
30
30
  spec.add_dependency 'universe_compiler', '~> 0.5.5'
31
31
  spec.add_dependency 'pry'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: power_stencil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laurent Briais
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-13 00:00:00.000000000 Z
11
+ date: 2019-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.2.34
61
+ version: 0.2.35
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.2.34
68
+ version: 0.2.35
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: dir_glob_ignore
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -327,7 +327,7 @@ metadata:
327
327
  documentation_uri: https://gitlab.com/tools4devops/power_stencil/blob/master/README.md
328
328
  source_code_uri: https://gitlab.com/tools4devops/power_stencil
329
329
  homepage_uri: https://powerstencil.brizone.org/
330
- post_install_message: "\nThank you for installing PowerStencil 0.9.3 !\nFrom the command
330
+ post_install_message: "\nThank you for installing PowerStencil 0.9.4 !\nFrom the command
331
331
  line you can run `power_stencil --help`\nIf your shell is not completing the command:\n
332
332
  \ If you use rbenv: `rbenv rehash`\n If you use zsh : `rehash`\n\nOfficial Website
333
333
  \ : https://powerstencil.brizone.org/\nFull documentation here : https://gitlab.com/tools4devops/power_stencil/blob/master/README.md\nFeel