power_stencil 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +198 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/bin/update_plugin_template +79 -0
  13. data/doc/builds.md +267 -0
  14. data/doc/entities.md +964 -0
  15. data/doc/example_use_cases.md +59 -0
  16. data/doc/images/power-stencil-entity-build.svg +481 -0
  17. data/doc/images/power-stencil-entity-creation.svg +375 -0
  18. data/doc/images/power-stencil-simple-flow.svg +265 -0
  19. data/doc/plugins.md +169 -0
  20. data/doc/templates.md +333 -0
  21. data/etc/base_commands_definition.yml +259 -0
  22. data/etc/meta_templates/plugin_seed/etc/command_line.yaml +12 -0
  23. data/etc/meta_templates/plugin_seed/etc/plugin_config.yaml +4 -0
  24. data/etc/meta_templates/plugin_seed/etc/templates/.git_keep +0 -0
  25. data/etc/meta_templates/plugin_seed/lib/{entity}.rb.erb +34 -0
  26. data/etc/meta_templates/plugin_seed/lib/{entity}/entity_definitions/{entity}_entity.rb.erb +11 -0
  27. data/etc/meta_templates/plugin_seed/lib/{entity}/plugin_helper.rb.erb +17 -0
  28. data/etc/meta_templates/plugin_seed/lib/{entity}/version.rb.erb +3 -0
  29. data/etc/meta_templates/plugin_seed/lib/{entity}/{entity}_processor.rb.erb +19 -0
  30. data/etc/meta_templates/plugin_seed/psplugin_{entity}.gemspec +36 -0
  31. data/etc/power_stencil.yaml +92 -0
  32. data/etc/templates/plugin_definition/.gitignore +11 -0
  33. data/etc/templates/plugin_definition/.rspec +3 -0
  34. data/etc/templates/plugin_definition/.travis.yml +5 -0
  35. data/etc/templates/plugin_definition/CODE_OF_CONDUCT.md +74 -0
  36. data/etc/templates/plugin_definition/Gemfile +6 -0
  37. data/etc/templates/plugin_definition/LICENSE.txt +21 -0
  38. data/etc/templates/plugin_definition/README.md +43 -0
  39. data/etc/templates/plugin_definition/Rakefile +6 -0
  40. data/etc/templates/plugin_definition/bin/console +14 -0
  41. data/etc/templates/plugin_definition/bin/setup +8 -0
  42. data/etc/templates/plugin_definition/etc/command_line.yaml +12 -0
  43. data/etc/templates/plugin_definition/etc/plugin_config.yaml +4 -0
  44. data/etc/templates/plugin_definition/etc/templates/.git_keep +1 -0
  45. data/etc/templates/plugin_definition/lib/{entity}.rb.erb +34 -0
  46. data/etc/templates/plugin_definition/lib/{entity}/entity_definitions/{entity}_entity.rb.erb +11 -0
  47. data/etc/templates/plugin_definition/lib/{entity}/plugin_helper.rb.erb +17 -0
  48. data/etc/templates/plugin_definition/lib/{entity}/version.rb.erb +3 -0
  49. data/etc/templates/plugin_definition/lib/{entity}/{entity}_processor.rb.erb +19 -0
  50. data/etc/templates/plugin_definition/psplugin_{entity}.gemspec +36 -0
  51. data/etc/templates/plugin_definition/spec/spec_helper.rb +14 -0
  52. data/etc/templates/plugin_definition/spec/{entity}_spec.rb +9 -0
  53. data/etc/templates/project/.copy_ignore +2 -0
  54. data/etc/templates/project/.gitignore.erb +6 -0
  55. data/etc/templates/project/.ps_project/entities/.gitkeep +0 -0
  56. data/etc/templates/project/.ps_project/entities/README.md +11 -0
  57. data/etc/templates/project/.ps_project/entity_definitions/.gitkeep +0 -0
  58. data/etc/templates/project/.ps_project/entity_definitions/README.md +15 -0
  59. data/etc/templates/project/.ps_project/personal-config.yaml +8 -0
  60. data/etc/templates/project/.ps_project/plugins/.gitkeep +0 -0
  61. data/etc/templates/project/.ps_project/templates-templates/.gitkeep +0 -0
  62. data/etc/templates/project/.ps_project/templates-templates/README.md +13 -0
  63. data/etc/templates/project/.ps_project/user_entities/.gitkeep +0 -0
  64. data/etc/templates/project/.ps_project/user_entities/README.md +12 -0
  65. data/etc/templates/project/.ps_project/versioned-config.yaml +6 -0
  66. data/etc/templates/simple_exec/main.sh +4 -0
  67. data/exe/power_stencil +28 -0
  68. data/lib/power_stencil.rb +53 -0
  69. data/lib/power_stencil/command_processors/build.rb +43 -0
  70. data/lib/power_stencil/command_processors/check.rb +35 -0
  71. data/lib/power_stencil/command_processors/create.rb +70 -0
  72. data/lib/power_stencil/command_processors/delete.rb +38 -0
  73. data/lib/power_stencil/command_processors/edit.rb +35 -0
  74. data/lib/power_stencil/command_processors/entity_helper.rb +105 -0
  75. data/lib/power_stencil/command_processors/get.rb +22 -0
  76. data/lib/power_stencil/command_processors/info.rb +41 -0
  77. data/lib/power_stencil/command_processors/init.rb +47 -0
  78. data/lib/power_stencil/command_processors/new_plugin.rb +31 -0
  79. data/lib/power_stencil/command_processors/root.rb +27 -0
  80. data/lib/power_stencil/command_processors/shell.rb +37 -0
  81. data/lib/power_stencil/command_processors/trace_helper.rb +20 -0
  82. data/lib/power_stencil/dsl/base.rb +24 -0
  83. data/lib/power_stencil/dsl/entities.rb +46 -0
  84. data/lib/power_stencil/dsl/plugin_generation.rb +17 -0
  85. data/lib/power_stencil/engine/base.rb +50 -0
  86. data/lib/power_stencil/engine/build_handling.rb +77 -0
  87. data/lib/power_stencil/engine/directory_processor.rb +111 -0
  88. data/lib/power_stencil/engine/entities_definitions.rb +42 -0
  89. data/lib/power_stencil/engine/entities_handling.rb +76 -0
  90. data/lib/power_stencil/engine/entity_engine.rb +20 -0
  91. data/lib/power_stencil/engine/init_engine.rb +18 -0
  92. data/lib/power_stencil/engine/project_engine.rb +75 -0
  93. data/lib/power_stencil/engine/renderers/erb.rb +21 -0
  94. data/lib/power_stencil/error.rb +20 -0
  95. data/lib/power_stencil/initializer.rb +87 -0
  96. data/lib/power_stencil/plugins/base.rb +54 -0
  97. data/lib/power_stencil/plugins/capabilities.rb +30 -0
  98. data/lib/power_stencil/plugins/command_line.rb +27 -0
  99. data/lib/power_stencil/plugins/config.rb +32 -0
  100. data/lib/power_stencil/plugins/dependencies.rb +32 -0
  101. data/lib/power_stencil/plugins/gem.rb +57 -0
  102. data/lib/power_stencil/plugins/require.rb +77 -0
  103. data/lib/power_stencil/plugins/templates.rb +21 -0
  104. data/lib/power_stencil/project/base.rb +79 -0
  105. data/lib/power_stencil/project/config.rb +54 -0
  106. data/lib/power_stencil/project/create.rb +30 -0
  107. data/lib/power_stencil/project/info.rb +72 -0
  108. data/lib/power_stencil/project/paths.rb +119 -0
  109. data/lib/power_stencil/project/plugins.rb +89 -0
  110. data/lib/power_stencil/project/proxy.rb +13 -0
  111. data/lib/power_stencil/project/templates.rb +56 -0
  112. data/lib/power_stencil/project/versioning.rb +29 -0
  113. data/lib/power_stencil/system_entity_definitions/all.rb +14 -0
  114. data/lib/power_stencil/system_entity_definitions/buildable.rb +23 -0
  115. data/lib/power_stencil/system_entity_definitions/entity_override.rb +8 -0
  116. data/lib/power_stencil/system_entity_definitions/entity_project_common.rb +33 -0
  117. data/lib/power_stencil/system_entity_definitions/has_associated_files.rb +13 -0
  118. data/lib/power_stencil/system_entity_definitions/non_persistent.rb +14 -0
  119. data/lib/power_stencil/system_entity_definitions/plugin.rb +17 -0
  120. data/lib/power_stencil/system_entity_definitions/process_descriptor.rb +15 -0
  121. data/lib/power_stencil/system_entity_definitions/project_config.rb +24 -0
  122. data/lib/power_stencil/system_entity_definitions/project_entity.rb +16 -0
  123. data/lib/power_stencil/system_entity_definitions/simple_exec.rb +47 -0
  124. data/lib/power_stencil/utils/directory_processor.rb +54 -0
  125. data/lib/power_stencil/utils/file_edit.rb +87 -0
  126. data/lib/power_stencil/utils/file_helper.rb +56 -0
  127. data/lib/power_stencil/utils/gem_utils.rb +13 -0
  128. data/lib/power_stencil/utils/secure_require.rb +26 -0
  129. data/lib/power_stencil/utils/semantic_version.rb +128 -0
  130. data/lib/power_stencil/version.rb +3 -0
  131. data/power_stencil.gemspec +32 -0
  132. metadata +287 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2919b7c8587ab13f5df85a63bcf280c0c77402e0
4
+ data.tar.gz: 2bb5e955ddebbabd4abd47276d16afb4ecede82d
5
+ SHA512:
6
+ metadata.gz: 0d8992f40f5a6638a7e453528806d40e18d122ed347f251c7ab82712036b95977712c3c8c8352f48d4221dc96a437d5eb1ce197a387646008e7677db16f62a9e
7
+ data.tar.gz: 658a06ca8cdbedcda1ebfea8dda9881baaa74ccfac5ba706f579bf8e6c2debd58a7be91b3bf320687eae3f032a6c9ad51eec95bdb9aebcdcc8972db7f6c4c3ad
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /etc/templates/plugin_definition-*.old/
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ /.idea/
13
+ /test/test_project/build/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.15.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at lbnetid+gh@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in power_stencil.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Laurent B.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,198 @@
1
+ PowerStencil
2
+ ============
3
+
4
+ `Power Stencil` is the Swiss-army knife templating workflow for developers and ops.
5
+
6
+ <!-- TOC -->
7
+
8
+ - [Core concepts](#core-concepts)
9
+ - [Pfff, yet another templating engine...](#pfff-yet-another-templating-engine)
10
+ - [Installation](#installation)
11
+ - [Usage](#usage)
12
+ - [Help](#help)
13
+ - [Creating a `PowerStencil` project](#creating-a-powerstencil-project)
14
+ - [`PowerStencil` project structure](#powerstencil-project-structure)
15
+ - [Getting started](#getting-started)
16
+ - [Contributing](#contributing)
17
+ - [License](#license)
18
+ - [Code of Conduct](#code-of-conduct)
19
+
20
+ <!-- /TOC -->
21
+
22
+ # Core concepts
23
+
24
+ `PowerStencil` proposes a radical approach on how to manage your shared configuration.
25
+
26
+ Internally `PowerStencil` is composed of a data repository and a pretty standard templating flow to generate whatever is needed by your project or organization:
27
+
28
+ ![simple-flow-image]
29
+
30
+ Configuration is one of the most complex things to maintain, and anyone who participated in a large scale piece of software or documentation knows how complex it is to maintain, keep consistent and avoid duplication on the long run across the various projects that may share this configuration.
31
+
32
+ `PowerStencil` provides **development and operations friendly workflows to fully manage the maintenance of a complex shared config** in order to generate anything you may want like _documentation_, _static sites_, _code_, _configuration_ for multiple tools..., while **avoiding duplication, and manage it like code** !
33
+
34
+ It is a common pattern to introduce a database to manage this configuration, and it is a very bad idea because it implies extra tooling, and specific developments that de-facto become single point of failure at the heart of your development process. Why would you do that when something as versatile and ubiquitous as Git exists that will __integrate smoothly within your existing development and operations workflows__, builds, CI/CD, while benefiting from all the goodness provided by Git, like branches, decentralization, versioning, tags, code reviews, traceability, simplified fallbacks etc... ?
35
+
36
+ **With `PowerStencil` everything is maintained in a git repository**: data, templates, specific code. No more config loss, no more change applied without a full lineage.
37
+
38
+ See some real world [example use cases].
39
+
40
+ The `PowerStencil` gem provides the `power_stencil` executable which is a pluggable CLI to:
41
+
42
+ - CRUD [entities] using either an editor or a dedicated REPL
43
+ - Manage [templates]
44
+ - Manage [builds]
45
+ - Create and manipulate [plugins]
46
+
47
+ # Pfff, yet another templating engine...
48
+
49
+ **Actually `PowerStencil` is _not_ a templating engine** per se. Instead it uses already existing and proven templating engines.
50
+ Currently it uses [ERB], which is pretty standard in [Ruby] world, but this is not hardcoded and any templating engine could be used (in parallel, meaning different templating engines can be used automatically depending on what you actually want to generate), even if only [ERB] is implemented for the time-being, `PowerStencil` is modular from ground-up and at least a second implementation for [Haml] templating engine is planned to ease generation of XML-like files, still currently you can do it with [ERB]. See the [templates] section for more information about templates in `PowerStencil`.
51
+
52
+ No, the real value of `PowerStencil` is not really in its templating capabilities even if very powerful, but in the development flow it proposes around this templating mechanism for both development and/or operations teams, in the way you organize and trace the data which is the real asset, and in the way you can easily extend it to fit the particular needs of a project or organization.
53
+
54
+ # Installation
55
+
56
+ You need a working install of the [Ruby] language (>= 2.2).
57
+
58
+ You can install the `PowerStencil` gem by issuing the usual:
59
+
60
+ $ gem install power_stencil
61
+
62
+ # Usage
63
+
64
+ ## Help
65
+
66
+ The `power_stencil` CLI provides a contextual help. You can start by:
67
+
68
+ $ power_stencil --help
69
+
70
+ That will display a basic help:
71
+
72
+ ```shell
73
+ This is power_stencil. A powerful templating engine.
74
+ -- Options ---------------------------------------------------------------------
75
+ -v, --verbose Displays extra runtime information.
76
+ -h, --help Displays this help.
77
+ --program-version, -V, --version Displays program version.
78
+ --simulate Will not perform actual actions
79
+ --debug Debug mode
80
+ --debug-on-err, --debug-on-stderr Sends debugging to SDTERR
81
+ --log-level Defines the level of logging (0 to 5)
82
+ --log-file Specifies a file to log into
83
+ --truncate-log-file Truncates the log file (appends by default)
84
+ --project-path Specifies a startup path to use instead of '.'
85
+ --auto Bypasses command-line confirmations to the user
86
+
87
+ --------------------------------------------------------------------------------
88
+ Following subcommands exist too:
89
+ For more information you can always issue sub_command_name --help...
90
+ --------------------------------------------------------------------------------
91
+ * init: Initializes a PowerStencil repository ...
92
+ * info: Generic information about the repository ...
93
+ * new-plugin: Generates the skeleton for a plugin ...
94
+ * get: Query entities from repository ...
95
+ * shell: Opens a shell to interact with entities ...
96
+ * check: Check repository entities consistency ...
97
+ * create: Creates entities in the repository ...
98
+ * edit: Edit entities from repository ...
99
+ * delete: Delete entities from repository ...
100
+ * build: Builds entities ...
101
+ ```
102
+
103
+ The program uses the standard paradigm of sub-commands (à-la-git), and each can have its own options that you can check using:
104
+
105
+ $ power_stencil <subcommand> --help
106
+
107
+ [Plugins] may bring extra subcommands and/or options, so depending on the project you are working in, the output of `--help` may differ...
108
+
109
+ ## Creating a `PowerStencil` project
110
+
111
+ To create a new project, use the `init` sub-command. It works as you would expect. If you run it in an existing directory it will create the project here but you can specify the directory where you want the project to be created (the path will be created provided you have the rights on the filesystem):
112
+
113
+ $ power_stencil init --project-path /where/you/want
114
+
115
+ The `--project-path` option can be applied to any sub-command, but à-la-git, once the project created if you are anywhere within the project tree, you don't need to specify the project path.
116
+
117
+ :information_source: The rest of this documentation will assume you are at the root of this created project.
118
+
119
+ ## `PowerStencil` project structure
120
+
121
+ The structure of a brand new `PowerStencil` project is the following:
122
+
123
+ ```
124
+ ├── .gitignore
125
+ └── .ps_project
126
+ ├── entities
127
+ │   └── README.md
128
+ ├── entity_definitions
129
+ │   └── README.md
130
+ ├── personal-config.yaml
131
+ ├── plugins
132
+ ├── templates-templates
133
+ │   └── README.md
134
+ ├── user_entities
135
+ │   └── README.md
136
+ └── versioned-config.yaml
137
+ ```
138
+ New directories will appear once you start some [builds] or when you will define [templates].
139
+
140
+ Not all the files in this directory should be versioned, and this the reason why there is a preconfigured `.gitignore` at the root of the project.
141
+
142
+ The project has two distinct config files. Keep the official project config in the `.ps_project/versioned-config.yaml` which, as its name suggest will be versioned. But any developer who wants to temporarily override some configuration should do it in the `.ps_project/personal-config.yaml` which is not be versioned. The content defined in the latter overrides the content of the official one. This is a clean way for anyone who wants to test something to safely do it locally without the risk to pollute the central repo.
143
+
144
+ There is the same mechanism between `.ps_project/entities` and `.ps_project/user_entities`, but as opposed to the two aforementioned config files you should not edit anything directly there, but instead interact using the CLI. More information on how to manage entities [here][entities].
145
+
146
+ The `plugins` directory can optionally contain project specific plugins. Plugins are a great way to extend `PowerStencil` for the needs of a project or organization. See the [plugins] documentation.
147
+
148
+ ## Getting started
149
+
150
+ The core of the system is the `entity`, so you should start by having a look at what entities are, how they are easily managed using the `PowerStencil` CLI and shell.
151
+
152
+ :arrow_forward: [Entities]
153
+
154
+ Then it is important to understand how to use entities within `templates`. Templates are the way to generate something (doc, code, descriptors, sites, whatever...) from the data that the entities represent.
155
+
156
+ :arrow_forward: [Templates]
157
+
158
+ The mechanism that combines entities and templates is called a `build`. A build is always attached to an entity (you build something). The result of a build is a set of files. Optionally an action can be triggered after the files are generated (could be as simple as calling a script that has been generated).
159
+
160
+ :arrow_forward: [Builds]
161
+
162
+ `PowerStencil` could stop there, and you would be able to do whatever you want, but there is a whole world beyond. `Plugins` provide a way to completely extend `PowerStencil`, further control relations between entities, implement complex post-build actions, add CLI sub-commands and options. Plugins can be local to the project or coming in the form of standard Ruby Gems ! The icing on the cake...
163
+
164
+ :arrow_forward: [Plugins]
165
+
166
+ # Contributing
167
+
168
+ Bug reports and pull requests are welcome on Gitlab at https://gitlab.com/tools4devops/power_stencil. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
169
+
170
+ ## License
171
+
172
+ The gem is available as open source under the terms of the [MIT License].
173
+
174
+ ## Code of Conduct
175
+
176
+ Everyone interacting in the PowerStencil project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct].
177
+
178
+ <!-- End of Document -->
179
+
180
+ <!-- Pages -->
181
+ [templates]: doc/templates.md "Templates in PowerStencil"
182
+ [entities]: doc/entities.md "Entities in PowerStencil"
183
+ [builds]: doc/builds.md "Builds in PowerStencil"
184
+ [plugins]: doc/plugins.md "Plugins in PowerStencil"
185
+ [example use cases]: doc/example_use_cases.md "Example uses cases using PowerStencil"
186
+ [code of conduct]: CODE_OF_CONDUCT.md
187
+
188
+ <!-- Code links -->
189
+ [ERB implementation]: lib/power_stencil/engine/renderers/erb.rb "Mostly the only module you need to clone to implement another templating engine"
190
+
191
+ <!-- Illustrations -->
192
+ [simple-flow-image]: doc/images/power-stencil-simple-flow.svg
193
+
194
+ <!-- External links -->
195
+ [MIT License]: http://opensource.org/licenses/MIT "The MIT license"
196
+ [ERB]: https://ruby-doc.org/stdlib-2.6.3/libdoc/erb/rdoc/ERB.html "Quick ERB description"
197
+ [Haml]: http://haml.info/ "The templating engine for XML-like documents"
198
+ [Ruby]: https://www.ruby-lang.org "The powerful Ruby language"
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'power_stencil'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ require 'bundler/setup'
5
+ require 'tmpdir'
6
+ require 'power_stencil'
7
+
8
+ LOGGER = Logger.new STDERR
9
+
10
+ def logger
11
+ LOGGER
12
+ end
13
+
14
+ include Climatic::Proxy
15
+ include PowerStencil::Utils::FileHelper
16
+ include PowerStencil::Utils::DirectoryProcessor
17
+
18
+ POWER_STENCIL_ETC = File.expand_path File.join( '..', '..', 'etc'), __FILE__
19
+ POWER_STENCIL_TEMPLATES_PATH = File.join POWER_STENCIL_ETC, 'templates'
20
+ PLUGIN_DEFINITION_PATH = File.join POWER_STENCIL_TEMPLATES_PATH,'plugin_definition'
21
+ PLUGIN_SEED_PATH = File.join POWER_STENCIL_ETC, 'meta_templates', 'plugin_seed'
22
+ BACKUP_PATH = "%s-#{timestamp Time.now}.old" % [PLUGIN_DEFINITION_PATH]
23
+ # puts "Plugin definition path: '#{PLUGIN_DEFINITION_PATH}'", "Backup path: '#{BACKUP_PATH}'"
24
+
25
+ def generate_gem(gem_name, dir)
26
+ Dir.chdir dir do
27
+ # Let's create a new gem using bundle
28
+ res = `bundle gem #{gem_name} --no-exe`
29
+ # Remove useless files from generated gem source
30
+ logger.debug "#{res}"
31
+ gem_path = File.join dir, gem_name
32
+ substituted_path = File.join dir, 'plugin_definition'
33
+ gitdir = File.join gem_path,'.git'
34
+ libdir = File.join gem_path,'lib'
35
+ gemspecfile = File.join gem_path, "#{gem_name}.gemspec"
36
+ FileUtils.remove_entry_secure gitdir
37
+ FileUtils.remove_entry_secure libdir
38
+ FileUtils.remove_entry_secure gemspecfile
39
+ # Copy files from power_stencil seed files
40
+ FileUtils.copy_entry PLUGIN_SEED_PATH, gem_path
41
+ # Perform file names and content substitutions
42
+ process_directory source: gem_path,
43
+ destination: substituted_path do |source_file, potential_target_file|
44
+ next if File.directory? source_file
45
+ target_file = potential_target_file.gsub gem_name, '{entity}'
46
+ logger.info "Processing #{source_file} -> #{target_file}"
47
+ file_content = File.read source_file
48
+ file_content.gsub! gem_name, '<%= plugin_module_name %>'
49
+ modes = File.stat(source_file).mode
50
+ FileUtils.mkdir_p(File.dirname target_file)
51
+ File.open(target_file, 'w') do |file|
52
+ file.puts file_content
53
+ end
54
+ logger.debug "Processed #{target_file}"
55
+ end
56
+
57
+ end
58
+ end
59
+
60
+ def update_definition_template(source_dir, dest_dir)
61
+ # Backup old plugin template definition in power stencil gem
62
+ FileUtils.mv PLUGIN_DEFINITION_PATH, BACKUP_PATH
63
+ # Copy new definition into gem
64
+ FileUtils.copy_entry source_dir, dest_dir
65
+ end
66
+
67
+ fake_gem_name = 'XXXXXXXXXXXX'
68
+
69
+ Dir.mktmpdir do |tmpdir|
70
+ Dir.chdir tmpdir do
71
+ generate_gem fake_gem_name, tmpdir
72
+ generated_gem_path = File.join(tmpdir, 'plugin_definition')
73
+ update_definition_template generated_gem_path, PLUGIN_DEFINITION_PATH
74
+ puts 'bye'
75
+ end
76
+ end
77
+
78
+
79
+