power_stencil 0.4.22 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/plugins.md +269 -18
- data/etc/meta_templates/plugin_seed/etc/command_line.yaml +1 -1
- data/etc/meta_templates/plugin_seed/etc/plugin_capabilities.yaml +33 -0
- data/etc/meta_templates/plugin_seed/etc/templates/{entity}_entity/.copy_ignore +2 -0
- data/etc/meta_templates/plugin_seed/etc/templates/{entity}_entity/.subst_ignore +1 -0
- data/etc/meta_templates/plugin_seed/etc/templates/{entity}_entity/message.txt +7 -0
- data/etc/meta_templates/plugin_seed/lib/{entity}.rb.erb +9 -24
- data/etc/meta_templates/plugin_seed/lib/{entity}/dsl/{entity}_dsl.rb.erb +9 -0
- data/etc/meta_templates/plugin_seed/lib/{entity}/entity_definitions/{entity}_entity.rb.erb +2 -0
- data/etc/meta_templates/plugin_seed/lib/{entity}/{entity}_processor.rb.erb +4 -1
- data/etc/templates/plugin_definition/.travis.yml +1 -1
- data/etc/templates/plugin_definition/CODE_OF_CONDUCT.md +1 -1
- data/etc/templates/plugin_definition/etc/command_line.yaml +1 -1
- data/etc/templates/plugin_definition/etc/plugin_capabilities.yaml +33 -0
- data/etc/templates/plugin_definition/etc/plugin_config.yaml +1 -1
- data/etc/templates/plugin_definition/etc/templates/{entity}_entity/.copy_ignore +2 -0
- data/etc/templates/plugin_definition/etc/templates/{entity}_entity/.subst_ignore +1 -0
- data/etc/templates/plugin_definition/etc/templates/{entity}_entity/message.txt +7 -0
- data/etc/templates/plugin_definition/lib/{entity}.rb.erb +9 -24
- data/etc/templates/plugin_definition/lib/{entity}/dsl/{entity}_dsl.rb.erb +9 -0
- data/etc/templates/plugin_definition/lib/{entity}/entity_definitions/{entity}_entity.rb.erb +2 -0
- data/etc/templates/plugin_definition/lib/{entity}/{entity}_processor.rb.erb +4 -1
- data/lib/power_stencil/command_processors/info.rb +0 -3
- data/lib/power_stencil/dsl/plugin_generation.rb +9 -0
- data/lib/power_stencil/engine/build_handling.rb +12 -7
- data/lib/power_stencil/engine/project_engine.rb +13 -9
- data/lib/power_stencil/plugins/base.rb +20 -5
- data/lib/power_stencil/plugins/build.rb +17 -0
- data/lib/power_stencil/plugins/capabilities.rb +24 -15
- data/lib/power_stencil/plugins/command_line.rb +13 -1
- data/lib/power_stencil/plugins/config.rb +11 -15
- data/lib/power_stencil/plugins/dsl.rb +17 -0
- data/lib/power_stencil/plugins/entity_definitions.rb +17 -0
- data/lib/power_stencil/plugins/require.rb +1 -31
- data/lib/power_stencil/plugins/templates.rb +10 -8
- data/lib/power_stencil/plugins/type.rb +13 -0
- data/lib/power_stencil/project/config.rb +2 -2
- data/lib/power_stencil/project/paths.rb +3 -0
- data/lib/power_stencil/project/plugins.rb +3 -14
- data/lib/power_stencil/utils/secure_require.rb +1 -1
- data/lib/power_stencil/version.rb +1 -1
- metadata +21 -9
- data/lib/power_stencil/plugins/dependencies.rb +0 -32
@@ -8,7 +8,10 @@ module <%= plugin_module_name %>
|
|
8
8
|
|
9
9
|
|
10
10
|
def execute
|
11
|
-
|
11
|
+
hello_message = '<%= main_entry_point.upcase %> PLUGIN WAZ HERE !!'
|
12
|
+
# You have full access to the configuration and command line options within the plugin !
|
13
|
+
hello_message = 'HI, ' + hello_message if config[:hello]
|
14
|
+
puts hello_message
|
12
15
|
end
|
13
16
|
|
14
17
|
|
@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
|
|
55
55
|
## Enforcement
|
56
56
|
|
57
57
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at lbnetid+
|
58
|
+
reported by contacting the project team at lbnetid+rb@gmail.com. All
|
59
59
|
complaints will be reviewed and investigated and will result in a response that
|
60
60
|
is deemed necessary and appropriate to the circumstances. The project team is
|
61
61
|
obligated to maintain confidentiality with regard to the reporter of an incident.
|
@@ -0,0 +1,33 @@
|
|
1
|
+
---
|
2
|
+
# This file defines the capabilities exposed by the plugin. This file is mandatory
|
3
|
+
# for a plugin to be considered as valid.
|
4
|
+
|
5
|
+
# Define the main module of the plugin. In this module you can define the build method
|
6
|
+
# if the plugin exposes a build (actually a post build hook occurring after the files
|
7
|
+
# are "detemplatized")
|
8
|
+
:plugin_module: <%= plugin_module_name %>
|
9
|
+
|
10
|
+
# In the processors defined in the hereunder hash you map a subcommand with the processor
|
11
|
+
# that will handle it. A plugin can define as many subcommands as needed, or none...
|
12
|
+
# Hash keys should match sub-commands declared in the `command_line.yaml` file and processor
|
13
|
+
# classes should expose an `execute` method.
|
14
|
+
:processors:
|
15
|
+
<%= plugin_name %>: <%= plugin_module_name %>::Processor
|
16
|
+
|
17
|
+
# This is the name of the method called after the files are detemplatized. This method has
|
18
|
+
# to be a module method in the `plugin_module` module.
|
19
|
+
:build: post_build_hook
|
20
|
+
|
21
|
+
# If a dsl module is declared it will be injected in the DSL available in the shell or templates
|
22
|
+
:dsl: null
|
23
|
+
|
24
|
+
# These are the files (array) defining entity types. These files should not be already
|
25
|
+
# required by the plugin as they will be required by the framework when needed.
|
26
|
+
:entity_definitions:
|
27
|
+
- <%= plugin_name %>/entity_definitions/<%= plugin_name %>_entity
|
28
|
+
|
29
|
+
# A list of root directories where you can find templates in directories named from the
|
30
|
+
# entity types they are attached to.
|
31
|
+
:templates:
|
32
|
+
- etc/templates
|
33
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
**
|
@@ -0,0 +1,7 @@
|
|
1
|
+
|
2
|
+
This message has been generated on the <%= erb_insert 'Time.now' %>
|
3
|
+
This is an example of what you can do, and how much PowerStencil is customizable ! Check the plugin generated code and
|
4
|
+
taylor it to your needs...
|
5
|
+
|
6
|
+
This text is the result of a full build process of the entity '<%= erb_insert 'build_target.as_path' %>' by the plugin '<%= erb_insert 'build_target.buildable_by' %>'.
|
7
|
+
|
@@ -1,34 +1,19 @@
|
|
1
1
|
require '<%= plugin_name %>/version'
|
2
2
|
require '<%= plugin_name %>/plugin_helper'
|
3
3
|
require '<%= plugin_name %>/<%= plugin_name %>_processor'
|
4
|
+
require '<%= plugin_name %>/dsl/<%= plugin_name %>_dsl'
|
4
5
|
|
5
6
|
module <%= plugin_module_name %>
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.setup_entity_definitions
|
18
|
-
PowerStencil.logger.info 'Setting up <%= main_entry_point %> plugin entities'
|
19
|
-
securely_require '<%= plugin_name %>/entity_definitions/<%= plugin_name %>_entity', fail_on_error: true
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.setup_plugin_templates
|
23
|
-
Dir.entries(plugin_templates_path).reject { |e| %w(. ..).include? e }.each do |entry|
|
24
|
-
template_path = File.join(plugin_templates_path, entry)
|
25
|
-
if Dir.exist? template_path
|
26
|
-
PowerStencil.project.register_template_path_for_type entry.to_sym, template_path
|
27
|
-
end
|
8
|
+
def self.post_build_hook(built_entity, generated_files_path)
|
9
|
+
# This is an example of what you could do after files are generated, ie pretty much anything...
|
10
|
+
case built_entity.type
|
11
|
+
when :<%= plugin_name %>_entity
|
12
|
+
generated_file = File.join generated_files_path, 'message.txt'
|
13
|
+
puts File.readlines(generated_file)
|
14
|
+
else
|
15
|
+
raise PowerStencil::Error, 'Plugin <%= plugin_name %> doesnt know how handle the build of a <%= plugin_name %>_entity entity type !'
|
28
16
|
end
|
29
17
|
end
|
30
18
|
|
31
19
|
end
|
32
|
-
|
33
|
-
# All plugins have to be in the PowerStencil::Plugin namespace !
|
34
|
-
PowerStencil::Plugin::<%= plugin_module_name %> = <%= plugin_module_name %>
|
@@ -8,7 +8,10 @@ module <%= plugin_module_name %>
|
|
8
8
|
|
9
9
|
|
10
10
|
def execute
|
11
|
-
|
11
|
+
hello_message = '<%= main_entry_point.upcase %> PLUGIN WAZ HERE !!'
|
12
|
+
# You have full access to the configuration and command line options within the plugin !
|
13
|
+
hello_message = 'HI, ' + hello_message if config[:hello]
|
14
|
+
puts hello_message
|
12
15
|
end
|
13
16
|
|
14
17
|
|
@@ -20,9 +20,6 @@ module PowerStencil
|
|
20
20
|
puts '-' * 80
|
21
21
|
puts ' Plugins:'
|
22
22
|
project.plugins.each do |plugin_name, plugin|
|
23
|
-
if plugin.has_dependencies?
|
24
|
-
puts " --> Plugin '#{plugin_name}' depends on plugin#{plugin.declared_dependencies.size > 1 ? 's' : ''}: '#{plugin.declared_dependencies.join ', '}'"
|
25
|
-
end
|
26
23
|
puts " --> Plugin '#{plugin_name}' has following capabilities:"
|
27
24
|
puts(project.plugin_report(plugin_name, plugin).map { |p| ' - %s' % [p] })
|
28
25
|
end
|
@@ -11,6 +11,15 @@ module PowerStencil
|
|
11
11
|
plugin_name.camelize
|
12
12
|
end
|
13
13
|
|
14
|
+
def erb_code(ruby_code_str, skip_line = true)
|
15
|
+
end_char = skip_line ? '-' : ''
|
16
|
+
'%s %s %s%s' % ['<%', ruby_code_str, end_char, '%>']
|
17
|
+
end
|
18
|
+
|
19
|
+
def erb_insert(ruby_code_str)
|
20
|
+
'%s %s %s' % ['<%=', ruby_code_str, '%>']
|
21
|
+
end
|
22
|
+
|
14
23
|
end
|
15
24
|
|
16
25
|
end
|
@@ -36,8 +36,8 @@ module PowerStencil
|
|
36
36
|
File.join build_target_path, entity_to_build.as_path.tr('/', '_')
|
37
37
|
end
|
38
38
|
|
39
|
-
puts_and_logs "De-templating files for '#{entity_to_build.as_path}' into '#{build_entity_target_path}'"
|
40
39
|
build_entity entity_to_build, build_entity_target_path
|
40
|
+
|
41
41
|
entity_build_report << 'Ok'
|
42
42
|
rescue => e
|
43
43
|
logger.error "Failed building '#{entity_to_build.as_path}' because '#{e.message}' !"
|
@@ -96,21 +96,26 @@ module PowerStencil
|
|
96
96
|
|
97
97
|
|
98
98
|
def build_entity(entity_to_build, target_path)
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
manage_build_links target_path
|
103
|
-
target_plugin_name = entity_to_build.buildable_by
|
99
|
+
target_plugin_name = entity_to_build.buildable_by.to_s
|
100
|
+
default_build entity_to_build, target_path
|
101
|
+
|
104
102
|
if target_plugin_name.empty?
|
105
103
|
post_build_hook entity_to_build, target_path
|
106
104
|
else
|
107
105
|
target_plugin = project.plugins[target_plugin_name]
|
108
106
|
raise PowerStencil::Error, "Could not find plugin '#{target_plugin_name}' !" if target_plugin.nil?
|
109
107
|
raise PowerStencil::Error, "Plugin '#{target_plugin_name}' has no build capability !" unless target_plugin.capabilities[:build]
|
110
|
-
target_plugin.
|
108
|
+
target_plugin.post_build_hook entity_to_build, target_path
|
111
109
|
end
|
112
110
|
end
|
113
111
|
|
112
|
+
def default_build(entity_to_build, target_path)
|
113
|
+
logger.info "Building #{entity_to_build.as_path} in '#{target_path}'"
|
114
|
+
render_source entity_to_build.templates_path, target_path, main_entry_point: entity_to_build.as_path
|
115
|
+
logger.info "Detemplatized filed generated in '#{target_path}'"
|
116
|
+
manage_build_links target_path
|
117
|
+
end
|
118
|
+
|
114
119
|
def post_build_hook(entity_to_build, files_path)
|
115
120
|
case entity_to_build.type
|
116
121
|
when :simple_exec
|
@@ -17,6 +17,7 @@ module PowerStencil
|
|
17
17
|
@project = project
|
18
18
|
load_system_entities_definition
|
19
19
|
load_plugins_entities_definition
|
20
|
+
load_plugins_dsl_definition
|
20
21
|
load_project_entities_definition
|
21
22
|
load_entities
|
22
23
|
end
|
@@ -32,15 +33,6 @@ module PowerStencil
|
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
|
-
def load_plugins_entities_definition
|
36
|
-
project.plugins.each do |plugin_name, plugin|
|
37
|
-
if plugin.capabilities[:entity_definitions]
|
38
|
-
logger.info "Loading entity definitions for plugin '#{plugin_name}'."
|
39
|
-
plugin.plugin_module.send PowerStencil::Plugins::Require::SETUP_ENTITY_DEFINITIONS_CALLBACK
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
36
|
def load_entities
|
45
37
|
root_universe.clear
|
46
38
|
load_system_entities
|
@@ -50,6 +42,18 @@ module PowerStencil
|
|
50
42
|
|
51
43
|
private
|
52
44
|
|
45
|
+
def load_plugins_entities_definition
|
46
|
+
project.plugins.each do |_, plugin|
|
47
|
+
plugin.require_plugin_entity_definitions if plugin.capabilities[:entity_definitions]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def load_plugins_dsl_definition
|
52
|
+
project.plugins.each do |_, plugin|
|
53
|
+
plugin.require_plugin_dsl if plugin.capabilities[:dsl]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
53
57
|
def load_project_entities
|
54
58
|
logger.debug 'Loading project entities - NOT IMPLEMENTED'
|
55
59
|
root_universe.import project.project_entities_path, stop_on_error: false do |new_entity|
|
@@ -1,10 +1,13 @@
|
|
1
|
-
require 'power_stencil/plugins/
|
1
|
+
require 'power_stencil/plugins/type'
|
2
2
|
require 'power_stencil/plugins/config'
|
3
3
|
require 'power_stencil/plugins/command_line'
|
4
|
+
require 'power_stencil/plugins/entity_definitions'
|
4
5
|
require 'power_stencil/plugins/templates'
|
5
6
|
require 'power_stencil/plugins/require'
|
6
7
|
require 'power_stencil/plugins/capabilities'
|
7
8
|
require 'power_stencil/plugins/gem'
|
9
|
+
require 'power_stencil/plugins/build'
|
10
|
+
require 'power_stencil/plugins/dsl'
|
8
11
|
|
9
12
|
module PowerStencil
|
10
13
|
|
@@ -15,19 +18,23 @@ module PowerStencil
|
|
15
18
|
extend PowerStencil::Plugins::Gem
|
16
19
|
|
17
20
|
include Climatic::Proxy
|
18
|
-
include PowerStencil::Plugins::
|
21
|
+
include PowerStencil::Plugins::Type
|
19
22
|
include PowerStencil::Plugins::Config
|
20
23
|
include PowerStencil::Plugins::CommandLine
|
21
24
|
include PowerStencil::Plugins::Require
|
22
25
|
include PowerStencil::Plugins::Capabilities
|
26
|
+
include PowerStencil::Plugins::EntityDefinitions
|
23
27
|
include PowerStencil::Plugins::Templates
|
28
|
+
include PowerStencil::Plugins::Build
|
24
29
|
|
25
30
|
attr_reader :name, :version, :entry_point_path
|
26
31
|
|
27
|
-
def initialize(name, project)
|
32
|
+
def initialize(name, project, type = :local)
|
28
33
|
@name = name
|
29
34
|
@project = project
|
30
35
|
@version = PowerStencil::Utils::SemanticVersion.new '0.0.0-not-specified'
|
36
|
+
raise PowerStencil::Error, "Invalid plugin type (#{type}) for plugin '#{name}'" unless PLUGIN_TYPES.include? type
|
37
|
+
@type = type
|
31
38
|
logger.debug "Loading plugin '#{name}'..."
|
32
39
|
setup_plugin
|
33
40
|
logger.info "Plugin '#{name}' successfully available"
|
@@ -35,7 +42,14 @@ module PowerStencil
|
|
35
42
|
end
|
36
43
|
|
37
44
|
def path
|
38
|
-
|
45
|
+
case type
|
46
|
+
when :local
|
47
|
+
project.project_plugin_path(name)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def plugin_module
|
52
|
+
Object.const_get plugin_definition[:plugin_module]
|
39
53
|
end
|
40
54
|
|
41
55
|
private
|
@@ -43,9 +57,10 @@ module PowerStencil
|
|
43
57
|
attr_reader :project
|
44
58
|
|
45
59
|
def setup_plugin
|
46
|
-
|
60
|
+
load_capabilities
|
47
61
|
load_plugin_specific_config
|
48
62
|
load_yaml_command_definition
|
63
|
+
require_entry_point
|
49
64
|
end
|
50
65
|
|
51
66
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module PowerStencil
|
2
|
+
module Plugins
|
3
|
+
|
4
|
+
module Build
|
5
|
+
|
6
|
+
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 !"
|
9
|
+
raise PowerStencil::Error, msg unless plugin_module.respond_to? build_method_name
|
10
|
+
plugin_module.send build_method_name, *args
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
@@ -3,25 +3,34 @@ module PowerStencil
|
|
3
3
|
|
4
4
|
module Capabilities
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
templates: false
|
16
|
-
}.freeze
|
6
|
+
include PowerStencil::Utils::FileHelper
|
7
|
+
|
8
|
+
CAPABILITIES = %i(config command_line processors build dsl entity_definitions templates).freeze
|
9
|
+
|
10
|
+
attr_reader :plugin_definition
|
11
|
+
|
12
|
+
def plugin_capabilities_definition_file
|
13
|
+
project.plugin_capabilities_definition_file self.name
|
14
|
+
end
|
17
15
|
|
18
16
|
def capabilities
|
19
|
-
@capabilities ||=
|
17
|
+
@capabilities ||= CAPABILITIES.dup.zip([false] * CAPABILITIES.size).to_h
|
20
18
|
end
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
private
|
21
|
+
|
22
|
+
def load_capabilities
|
23
|
+
yaml_file = plugin_capabilities_definition_file
|
24
|
+
unless File.exists? yaml_file and File.file? yaml_file and File.readable? yaml_file
|
25
|
+
raise PowerStencil::Error, "Plugin '#{self.name}' has no definition file !"
|
26
|
+
end
|
27
|
+
@plugin_definition = yaml_file_to_hash yaml_file
|
28
|
+
%i(processors entity_definitions templates build dsl).each do |capability|
|
29
|
+
unless plugin_definition[capability].nil? or plugin_definition[capability].empty?
|
30
|
+
capabilities[capability] = true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
25
34
|
end
|
26
35
|
|
27
36
|
end
|
@@ -5,10 +5,22 @@ module PowerStencil
|
|
5
5
|
|
6
6
|
attr_reader :plugin_command_line_modifier
|
7
7
|
|
8
|
+
def plugin_commands_line_definition_file
|
9
|
+
project.plugin_commands_line_definition_file self.name
|
10
|
+
end
|
11
|
+
|
12
|
+
def register_processors
|
13
|
+
plugin_definition[:processors].each do |processors_name, processor|
|
14
|
+
clm = PowerStencil.command_line_manager
|
15
|
+
processor_class = Object.const_get processor
|
16
|
+
clm.register_processor clm.command_by_alias(processors_name), processor_class.new
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
8
20
|
private
|
9
21
|
|
10
22
|
def load_yaml_command_definition
|
11
|
-
yaml_file =
|
23
|
+
yaml_file = plugin_commands_line_definition_file
|
12
24
|
if File.exists? yaml_file and File.file? yaml_file and File.readable? yaml_file
|
13
25
|
logger.info "Adding extra command line definition for '#{name}' plugin..."
|
14
26
|
@plugin_command_line_modifier = project.yaml_file_to_hash yaml_file
|