app_archetype 1.2.8 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +36 -9
  3. data/README.md +150 -28
  4. data/app_archetype.gemspec +3 -0
  5. data/bin/app_archetype +20 -0
  6. data/bin/archetype +1 -1
  7. data/lib/app_archetype/cli.rb +171 -139
  8. data/lib/app_archetype/commands/delete_template.rb +58 -0
  9. data/lib/app_archetype/commands/find_templates.rb +66 -0
  10. data/lib/app_archetype/commands/list_templates.rb +49 -0
  11. data/lib/app_archetype/commands/new_template.rb +42 -0
  12. data/lib/app_archetype/commands/open_manifest.rb +48 -0
  13. data/lib/app_archetype/commands/print_path.rb +20 -0
  14. data/lib/app_archetype/commands/print_template_variables.rb +67 -0
  15. data/lib/app_archetype/commands/print_version.rb +19 -0
  16. data/lib/app_archetype/commands/render_template.rb +178 -0
  17. data/lib/app_archetype/commands.rb +13 -0
  18. data/lib/app_archetype/generators.rb +1 -1
  19. data/lib/app_archetype/template_manager.rb +9 -0
  20. data/lib/app_archetype/version.rb +1 -1
  21. data/lib/app_archetype.rb +40 -23
  22. data/scripts/create_new_command +32 -0
  23. data/scripts/generators/command/manifest.json +15 -0
  24. data/scripts/generators/command/template/lib/app_archetype/commands/{{command_name.snake_case}}.rb.hbs +17 -0
  25. data/spec/app_archetype/cli/presenters_spec.rb +99 -99
  26. data/spec/app_archetype/cli/prompts_spec.rb +291 -291
  27. data/spec/app_archetype/cli_spec.rb +427 -65
  28. data/spec/app_archetype/commands/delete_template_spec.rb +132 -0
  29. data/spec/app_archetype/commands/find_templates_spec.rb +130 -0
  30. data/spec/app_archetype/commands/list_templates_spec.rb +55 -0
  31. data/spec/app_archetype/commands/new_template_spec.rb +84 -0
  32. data/spec/app_archetype/commands/open_manifest_spec.rb +113 -0
  33. data/spec/app_archetype/commands/print_path_spec.rb +22 -0
  34. data/spec/app_archetype/commands/print_template_variables_spec.rb +158 -0
  35. data/spec/app_archetype/commands/print_version_spec.rb +21 -0
  36. data/spec/app_archetype/commands/render_template_spec.rb +479 -0
  37. data/spec/app_archetype/generators_spec.rb +1 -1
  38. data/spec/app_archetype/template_manager_spec.rb +32 -0
  39. data/spec/app_archetype_spec.rb +65 -0
  40. metadata +79 -4
  41. data/lib/app_archetype/cli/presenters.rb +0 -106
  42. data/lib/app_archetype/cli/prompts.rb +0 -152
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69596e80065838a6a6ee3e106cf923c0a5cde9c3ab021ad453cec86693b7a54e
4
- data.tar.gz: 0c2efba5fa04672d651f85ee96c1758d5a1b2af04dc8229684f6a510208bcc46
3
+ metadata.gz: 2bb47f2a7af33ef1049d56b7e69a036d61d7de23460550b543a4ac4d61642981
4
+ data.tar.gz: a50728d4d05815813e7dbfa4106fabfe6905abde52991a287f7de4cc5fbcccc4
5
5
  SHA512:
6
- metadata.gz: 6bdf46483034b8a0655597c181a2710a8d426f10b27aef0f9ae3d49598f3457e5f9231aab1c853dfbd17fefa2ceb2cb2a80e251a146a25abac3bb72e5ae789e0
7
- data.tar.gz: 5925cafc17983ad94872e22a430a858b5f53feb1ebef9a4b1b00f1c6a337816b7331d0cc51f06c5d9bba74f57b1884378cc869cb283ceac46272970039ad10ca
6
+ metadata.gz: bb195a0f24fcada15e1bebb8f08b45b97c2be98d84ceab8e145a4becccf33c4358039207e32f71a661dfee3c98a202a595ea81a5be8eca5a796dc0ecfd82c8de
7
+ data.tar.gz: bae355af34912e60be9260355222fb295226df3b01c0ad4346e8678831688cb0e13238cccd56e177cdcdda32c417e269630dd1ea6fed1663b1a48600d6b98f94
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- app_archetype (1.2.8)
4
+ app_archetype (1.3.0)
5
5
  cli-format (~> 0.2)
6
+ hashie
6
7
  highline (~> 2.0)
7
8
  json (~> 2.3)
8
9
  json-schema (~> 2.8)
@@ -12,11 +13,13 @@ PATH
12
13
  ostruct (~> 0.3)
13
14
  ruby-handlebars (~> 0.4)
14
15
  thor (~> 1.0)
16
+ tty-prompt (~> 0.23.1)
17
+ tty-table (~> 0.12.0)
15
18
 
16
19
  GEM
17
20
  remote: https://rubygems.org/
18
21
  specs:
19
- activesupport (6.1.4)
22
+ activesupport (6.1.4.1)
20
23
  concurrent-ruby (~> 1.0, >= 1.0.2)
21
24
  i18n (>= 1.6, < 2)
22
25
  minitest (>= 5.1)
@@ -53,11 +56,12 @@ GEM
53
56
  path_expander (~> 1.0)
54
57
  ruby_parser (~> 3.1, > 3.1.0)
55
58
  sexp_processor (~> 4.8)
59
+ hashie (4.1.0)
56
60
  highline (2.0.3)
57
- i18n (1.8.10)
61
+ i18n (1.8.11)
58
62
  concurrent-ruby (~> 1.0)
59
63
  ice_nine (0.11.2)
60
- json (2.5.1)
64
+ json (2.6.1)
61
65
  json-schema (2.8.1)
62
66
  addressable (>= 2.4)
63
67
  jsonnet (0.4.0)
@@ -65,16 +69,18 @@ GEM
65
69
  kwalify (0.7.2)
66
70
  launchy (2.5.0)
67
71
  addressable (~> 2.7)
68
- logger (1.4.3)
72
+ logger (1.4.4)
69
73
  method_source (1.0.0)
70
- mini_portile2 (2.6.1)
74
+ mini_portile2 (2.7.1)
71
75
  minitest (5.14.4)
72
- os (1.1.1)
73
- ostruct (0.4.0)
76
+ os (1.1.4)
77
+ ostruct (0.5.0)
74
78
  parallel (1.19.2)
75
79
  parser (2.7.1.5)
76
80
  ast (~> 2.4.1)
77
81
  parslet (1.8.2)
82
+ pastel (0.8.0)
83
+ tty-color (~> 0.5)
78
84
  path_expander (1.1.0)
79
85
  private_gem (1.1.4)
80
86
  bundler (> 1.7, < 3.0)
@@ -138,20 +144,41 @@ GEM
138
144
  docile (~> 1.1)
139
145
  simplecov-html (~> 0.11)
140
146
  simplecov-html (0.12.3)
147
+ strings (0.2.1)
148
+ strings-ansi (~> 0.2)
149
+ unicode-display_width (>= 1.5, < 3.0)
150
+ unicode_utils (~> 1.4)
151
+ strings-ansi (0.2.0)
141
152
  text-table (1.2.4)
142
153
  thor (1.0.1)
143
154
  thread_safe (0.3.6)
155
+ tty-color (0.6.0)
156
+ tty-cursor (0.7.1)
157
+ tty-prompt (0.23.1)
158
+ pastel (~> 0.8)
159
+ tty-reader (~> 0.8)
160
+ tty-reader (0.9.0)
161
+ tty-cursor (~> 0.7)
162
+ tty-screen (~> 0.8)
163
+ wisper (~> 2.0)
164
+ tty-screen (0.8.1)
165
+ tty-table (0.12.0)
166
+ pastel (~> 0.8)
167
+ strings (~> 0.2.0)
168
+ tty-screen (~> 0.8)
144
169
  tty-which (0.4.2)
145
170
  tzinfo (2.0.4)
146
171
  concurrent-ruby (~> 1.0)
147
172
  unicode-display_width (1.7.0)
173
+ unicode_utils (1.4.0)
148
174
  virtus (1.0.5)
149
175
  axiom-types (~> 0.1)
150
176
  coercible (~> 1.0)
151
177
  descendants_tracker (~> 0.0, >= 0.0.3)
152
178
  equalizer (~> 0.0, >= 0.0.9)
179
+ wisper (2.0.1)
153
180
  yard (0.9.25)
154
- zeitwerk (2.4.2)
181
+ zeitwerk (2.5.1)
155
182
 
156
183
  PLATFORMS
157
184
  ruby
data/README.md CHANGED
@@ -14,7 +14,9 @@ gem install app_archetype
14
14
 
15
15
  For inclusion in another script or application, add this line to your application's Gemfile:
16
16
 
17
- Add the following to your Gemfile
17
+ ```ruby
18
+ gem 'app_archetype'
19
+ ```
18
20
 
19
21
  ## Getting Started
20
22
 
@@ -44,42 +46,71 @@ echo 'export ARCHETYPE_EDITOR="vi"' >> $HOME/.zshrc # sets vim as default editor
44
46
  echo 'export ARCHETYPE_EDITOR="vi"' >> $HOME/.bashrc # sets vim as default editor
45
47
  ```
46
48
 
47
- ## Usage
49
+ ### Use in another project/script (standalone)
48
50
 
49
- ### Creating a template
51
+ An alternative method of usage is to create standalone ruby scripts for standalone exection (outside of the `ARCHETYPE_TEMPLATE_DIR`). As an example, the following describes a code component renderer, where a command class for a simple CLI application can be rendered automatically.
50
52
 
51
- Templates are a collection of files in the template folder with a manifest. The structure is thus:
53
+ For this example you may wish to introduce a `scripts` folder to a project:
54
+
55
+ ```bash
56
+ mkdir path/to/my_project/scripts
57
+ ```
58
+
59
+ And under that make an archetypes template directory:
52
60
 
53
61
  ```text
54
- - $ARCHETYPE_TEMPLATE_DIR
55
- | - my_template
56
- | - | - template/
57
- | - | - | - file.erb
58
- | - | - | - file2.txt
59
- | - | - manifest.json
62
+ - 📁 path/to/my_project/scripts
63
+ | - 📁 generators/
64
+ | - | - 📁 command/
65
+ | - | - | - 📁 template/
66
+ | - | - | - | - 📁 lib/
67
+ | - | - | - | - | 📁 app_archetype/
68
+ | - | - | - | - | - | 📁 commands/
69
+ | - | - | - | - | - | - | 📄 {{command_name.snake_case}}.rb.hbs
70
+ | - | - | - 📄 manifest.json
71
+ | - | 📄 create_new_command
60
72
  ```
61
73
 
62
- Each template must include a manifest which has instructions necessary to render the template at run time.
74
+ A standalone generator can be written using the standalone render method exposed in the `AppArchetype` namespace. The following would be the content of the `create_new_command` script.
63
75
 
64
- To create a blank template run the new command with the relative (from your template directory) path to your new template. For example to create a ruby gem you might:
76
+ ```ruby
77
+ #!/usr/bin/env ruby
65
78
 
66
- ```bash
67
- archetype new ruby/gem # creates a template at $ARCHETYPE_TEMPLATE_DIR/ruby/gem
79
+ require_relative '../lib/app_archetype'
68
80
 
69
- # or
81
+ puts 'CREATE NEW COMMAND'
70
82
 
71
- archetype new ruby_gem # creates a template at $ARCHETYPE_TEMPLATE_DIR/ruby_gem
83
+ manifest = AppArchetype.render_template(
84
+ collection_dir: File.join(__dir__, 'generators'),
85
+ template_name: 'command',
86
+ destination_path: File.expand_path(File.join(__dir__, '..'))
87
+ )
88
+ ```
89
+
90
+ ## Usage
72
91
 
73
- # or
92
+ ### Creating a template
74
93
 
75
- archetype new ruby/gem/on_rails # creates a template at $ARCHETYPE_TEMPLATE_DIR/ruby/gem/on_rails
94
+ Templates are a collection of files in the template folder with a manifest. The structure is thus:
76
95
 
77
- # etc.
96
+ ```text
97
+ - 📁 $ARCHETYPE_TEMPLATE_DIR
98
+ | - 📁 my_template
99
+ | - | - 📁 template/
100
+ | - | - | - 📄 file.erb
101
+ | - | - | - 📄 file2.txt
102
+ | - | - 📄 manifest.json
103
+ ```
104
+
105
+ To create a blank template like the one above in the `ARCHETYPE_TEMPLATE_DIR` run:
106
+
107
+ ```bash
108
+ archetype new
78
109
  ```
79
110
 
80
111
  #### Template Manifests
81
112
 
82
- A manifest has a name, version and set of variables. A sample manifest looks like this:
113
+ Template manifests describe what should be done with a template at render time. For more detailed documentation on the AppArchetype manifest schema see [https://docs.biggerconcept.com/app_archetype/templates/manifest/](https://docs.biggerconcept.com/app_archetype/templates/manifest/) for more detail, however as a brief overview, a manifest has a name, version and set of variables. A sample manifest looks like this:
83
114
 
84
115
  ```json
85
116
  {
@@ -133,34 +164,125 @@ If plain ol' JSON isn't quite enough for you - manifests can also be expressed i
133
164
 
134
165
  See [https://jsonnet.org/](https://jsonnet.org/) for more jsonnet documentation
135
166
 
136
- #### Template Files
167
+ #### Template Folder
137
168
 
138
169
  Templates are a collection of files within a folder. You may put any files you want in side the `/template` directory and when it comes time to use the template.
139
170
 
140
- ERB templates or handlebar templates will be rendered using the variables specified in the manifest.json. Anything that's not ERB or HBS will be copied across to the destination as is.
171
+ ERB templates or handlebar templates (HBS) will be rendered using the variables specified in the manifest.json. Anything that's not ERB or HBS will be copied across to the destination as is.
172
+
173
+ You can include handlebars in file names, and like template files, the variables will be used to render the filenames. See [https://docs.biggerconcept.com/app_archetype/templates/folder/](https://docs.biggerconcept.com/app_archetype/templates/folder/) for more detailed information about template folders.
174
+
175
+ #### Variable Supporting Functions
176
+
177
+ AppArchetype exposes functions to either further parse the value of a variable or generate data as a value of a variable. The use cases are subtly different, but can be described in the following groups:
178
+
179
+ - [Generator Functions](https://docs.biggerconcept.com/app_archetype/templates/functions/generators/) useful for generating data for use within filenames and template files
180
+ - [Helper Functions](https://docs.biggerconcept.com/app_archetype/templates/functions/helpers/) useful for parsing values provided for variables.
181
+
182
+ See the supporting documentation for more specifid information about supporting functions.
183
+
184
+ ### Using the CLI
141
185
 
142
- You can include handlebars in file names, and like template files, the variables will be used to render the filenames.
186
+ When setup with a template directory and when installed into the system, app archetype has the following commands:
187
+
188
+ - `render` - Renders a template to the current location
189
+ - `list` - Prints a list of known templates to STDOUT
190
+ - `find` - Searches for a template by name
191
+ - `open` - Opens manifest of template in `ARCHETYPE_EDITOR` process
192
+ - `new` - Creates a new blank template in `ARCHETYPE_TEMPLATE_DIR`
193
+ - `delete` - Deletes template and manifest from `ARCHETYPE_TEMPLATE_DIR`
194
+ - `variables` - Prints list of known variables from a manifest
195
+ - `path` - Prints path to `ARCHETYPE_TEMPLATE_DIR` to STDOUT
196
+ - `version` - Prints gem version to STDOUT
197
+ - `help` - Provides help on any of the above commands
198
+
199
+ You will find detailed usage instructions of all commands here: [https://docs.biggerconcept.com/app_archetype/commands/](https://docs.biggerconcept.com/app_archetype/commands/)
143
200
 
144
201
  ### Rendering a Template
145
202
 
146
- Adjust the template manifest to include the variables you want, and then run:
203
+ The [`archetype render`](https://docs.biggerconcept.com/app_archetype/commands/render/) command will render a template from the `ARCHETYPE_TEMPLATE_DIR` to the current CLI location.
204
+
205
+ It supports an optional `--name` parameter that refers to the name of the template to render, when this is not provided, the tool will present a list of known templates.
206
+
207
+ To use:
147
208
 
148
209
  ```bash
149
210
  mkdir where_id_like_to_render
150
211
  cd where_id_like_to_render
151
- archetype render my_template
212
+ archetype render --name my_template
152
213
  ```
153
214
 
154
- And the template will be rendered with the instructions in the manifest to the destinaton location as simple as that.
155
-
156
215
  ### Listing Templates
157
216
 
158
- You can list the templates in your template directory at any time by running the list command:
217
+ You can list the templates in your template directory at any time by running the [`archetype list`](https://docs.biggerconcept.com/app_archetype/commands/list/) command:
159
218
 
160
219
  ```bash
161
220
  archetype list
162
221
  ```
163
222
 
223
+ You will see a summary of known templates similar to this:
224
+
225
+ ```text
226
+ NAME VERSION
227
+ go_module 2.0.1
228
+ bash_script 1.0.0
229
+ ruby_cli_gem 1.0.0
230
+ ```
231
+
232
+ ### Finding Templates
233
+
234
+ You can search known templates in your template directory using the [`archetype find`](https://docs.biggerconcept.com/app_archetype/commands/find/) command:
235
+
236
+ ```bash
237
+ archetype find --name bash
238
+ ```
239
+
240
+ You will be presented with a list of templates that include the given name:
241
+
242
+ ```text
243
+ NAME VERSION
244
+ bash_script 1.0.0
245
+ ```
246
+
247
+ ### Opening Template Manifest
248
+
249
+ If you have your `ARCHETYPE_EDITOR` variable set in your environment. You can use the [`archetype open`](https://docs.biggerconcept.com/app_archetype/commands/open/) command to open the manifest in a new editor process (for example `vi`).
250
+
251
+ Similar to the `archetype find` command, you may provide a name option to choose the manifest:
252
+
253
+ ```bash
254
+ archetype open --name bash_script
255
+ ```
256
+
257
+ ### Creating a new Template
258
+
259
+ The [`archetype new`](https://docs.biggerconcept.com/app_archetype/commands/new/) renders a new blank template into the `ARCHETYPE_TEMPLATE_DIR` location.
260
+
261
+ Simply run:
262
+
263
+ ```bash
264
+ archetype new
265
+ ```
266
+
267
+ And follow the prompts.
268
+
269
+ ### Deleting an existing template
270
+
271
+ You can delete a template manifest and its files by running the [`archetype delete`](https://docs.biggerconcept.com/app_archetype/commands/delete/) command.
272
+
273
+ ```bash
274
+ archetype delete --name bash_script
275
+ ```
276
+
277
+ ### Help and configuration
278
+
279
+ The Gem provides 2 commands to inspect its config. They are:
280
+
281
+ - [`archetype path`](https://docs.biggerconcept.com/app_archetype/commands/path/) which displays the currently configured `ARCHETYPE_TEMPLATE_DIR`
282
+ - [`archetype version`](https://docs.biggerconcept.com/app_archetype/commands/version/) which displays the current installed gem version
283
+
284
+ Additionally the [`archetype help`](https://docs.biggerconcept.com/app_archetype/commands/help/) provides more detailed usage information about all of the above mentioned commands.
285
+
164
286
  ## Contributing
165
287
 
166
288
  See CONTRIBUTING.md for more information
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.require_paths = ['lib']
18
18
 
19
19
  spec.add_dependency 'cli-format', '~> 0.2'
20
+ spec.add_dependency 'hashie'
20
21
  spec.add_dependency 'highline', '~> 2.0'
21
22
  spec.add_dependency 'json', '~> 2.3'
22
23
  spec.add_dependency 'jsonnet', '~> 0.4.0'
@@ -26,6 +27,8 @@ Gem::Specification.new do |spec|
26
27
  spec.add_dependency 'ostruct', '~> 0.3'
27
28
  spec.add_dependency 'ruby-handlebars', '~> 0.4'
28
29
  spec.add_dependency 'thor', '~> 1.0'
30
+ spec.add_dependency 'tty-prompt', '~> 0.23.1'
31
+ spec.add_dependency 'tty-table', '~> 0.12.0'
29
32
 
30
33
  spec.add_development_dependency 'bump', '~> 0.9'
31
34
  spec.add_development_dependency 'private_gem', '~> 1.1'
data/bin/app_archetype ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib_path = File.expand_path('../lib', __dir__)
4
+ $LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
5
+
6
+ require 'pry'
7
+ require 'app_archetype/cli'
8
+
9
+ Signal.trap('INT') do
10
+ warn("\n#{caller.join("\n")}: interrupted")
11
+ exit(1)
12
+ end
13
+
14
+ begin
15
+ AppArchetype::CLI.start
16
+ rescue StandardError => e
17
+ puts "✖ ERROR: #{e.message}"
18
+ puts e.backtrace.join("\n")
19
+ exit 1
20
+ end
data/bin/archetype CHANGED
@@ -14,7 +14,7 @@ end
14
14
  begin
15
15
  AppArchetype::CLI.start
16
16
  rescue StandardError => e
17
- puts "ERROR: #{e.message}"
17
+ puts "ERROR: #{e.message}"
18
18
  puts e.backtrace.join("\n")
19
19
  exit 1
20
20
  end