app_archetype 1.2.4 → 1.2.6

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
  SHA256:
3
- metadata.gz: 712a81bd843f73805f693d41c2d2866b7c5953931385ec6011627ec924619c1a
4
- data.tar.gz: a5947470c4ff4e17c537b5cd3fbe2d28eea2c7d601e40ee970717362d73e97cf
3
+ metadata.gz: 5e74cf25e1e7b6d3d39473af26d5ba9306658755b6e22e24f985fc1f20fda3e6
4
+ data.tar.gz: '090fa7d8d796c5a0f734980b9b6fc77689edc5937aa66735798b5110bd07bb2b'
5
5
  SHA512:
6
- metadata.gz: 6700f0205d74ca6f5886cae5954c315032b93a70024c165be0586f7377ed7f49136106871b16584423db0e162427a6bf80ade4c39ac14d69e36c1b3ebfe79995
7
- data.tar.gz: d221d2a1e8e973793223d94694461e89d8e5b8b6ababb74643815f05e3e943170337e5071522fde14fae69ee33675fc4e519d05ea62b8eb371b0f7aee7e2065d
6
+ metadata.gz: 4de9bfcc1e636ec9437498de6134f696132221358a55f63c70664fe0fd8a2e0652b3918c3942ac965c46e4a053585cc3cd831294f082530966ac9b88473d09bf
7
+ data.tar.gz: a5dc66e068d8a54a9e72de76560816a2c1ef72fe0a0069a7cd05296ca9b2b8e810983b5161c37e434e253b7569b82ef59ccc6d56ef460d83019db319ea1daeac
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- app_archetype (1.2.4)
4
+ app_archetype (1.2.6)
5
5
  cli-format (~> 0.2)
6
6
  highline (~> 2.0)
7
7
  json (~> 2.3)
@@ -16,7 +16,7 @@ PATH
16
16
  GEM
17
17
  remote: https://rubygems.org/
18
18
  specs:
19
- activesupport (6.1.3.2)
19
+ activesupport (6.1.4)
20
20
  concurrent-ruby (~> 1.0, >= 1.0.2)
21
21
  i18n (>= 1.6, < 2)
22
22
  minitest (>= 5.1)
data/README.md CHANGED
@@ -6,18 +6,20 @@ Code project template renderer
6
6
 
7
7
  ## Installation
8
8
 
9
- Add the following to your Gemfile
10
-
11
- ```ruby
12
- gem 'app_archetype'
13
- ```
14
-
15
- Or install the gem into your system:
9
+ This is best run as a CLI tool installed into your system:
16
10
 
17
11
  ```bash
18
12
  gem install app_archetype
19
13
  ```
20
14
 
15
+ For inclusion in another script or application, add this line to your application's Gemfile:
16
+
17
+ Add the following to your Gemfile
18
+
19
+ ## Getting Started
20
+
21
+ ### Setting up your environment for CLI use
22
+
21
23
  If installed as a system gem, you'll need to create a template directory and set it in your environment:
22
24
 
23
25
  ```bash
@@ -57,7 +59,7 @@ Templates are a collection of files in the template folder with a manifest. The
57
59
  | - | - manifest.json
58
60
  ```
59
61
 
60
- Each template must include a manifest which has instructions necessary to render the template at run time.
62
+ Each template must include a manifest which has instructions necessary to render the template at run time.
61
63
 
62
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:
63
65
 
@@ -89,7 +91,10 @@ A manifest has a name, version and set of variables. A sample manifest looks lik
89
91
  }
90
92
  },
91
93
  "variables": {
92
- "foo": "bar",
94
+ "foo": {
95
+ "type": "string",
96
+ "default": "bar"
97
+ }
93
98
  }
94
99
  }
95
100
  ```
@@ -97,7 +102,30 @@ A manifest has a name, version and set of variables. A sample manifest looks lik
97
102
  - `name` should be a unique name that identifies a manifest for you
98
103
  - `version` should be the version of the template
99
104
  - `metadata.app_archetype` is information about the manifest for the app archetype gem. `metadata.app_archetype.version` is required, and must be less than the version of the currently installed gem.
100
- - `variables` is a schemaless object that you may use to provide variables at render time
105
+ - `variables` is an object of variable descriptions
106
+
107
+ #### Variable Descriptions
108
+
109
+ Variable descriptions looks like this:
110
+
111
+ ```json
112
+ {
113
+ "variables": {
114
+ "foo": {
115
+ "type": "string",
116
+ "description": "An example string",
117
+ "default": "bar"
118
+ },
119
+ }
120
+ }
121
+ ```
122
+
123
+ Below is a description of the supported attributes in a variable definition:
124
+
125
+ - `type` (required) specifies the type of the variable. This can be one of `string`, `boolean`, `integer` or `map`
126
+ - `description` (recommended) a short string that describes to the user what the variable is going to be usef for
127
+ - `default` (optional) allows you to specify a default that is selected as the value when the user enters nothing into the prompt
128
+ - `value` (optional) when set the user will not be prompted for a value when the template is being generated
101
129
 
102
130
  ##### Jsonnet support
103
131
 
data/lib/app_archetype.rb CHANGED
@@ -7,8 +7,41 @@ require 'app_archetype/template_manager'
7
7
  require 'app_archetype/renderer'
8
8
  require 'app_archetype/generators'
9
9
 
10
+ require 'app_archetype/cli/prompts'
11
+
10
12
  require 'app_archetype/version'
11
13
 
12
14
  # AppArchetype is the namespace for app_archetype
13
15
  module AppArchetype
16
+ def self.render(
17
+ name,
18
+ templates_dir,
19
+ destination_path: Dir.pwd,
20
+ overwrite: true,
21
+ variables: []
22
+ )
23
+ manifest_file = File.join(templates_dir, name, 'manifest.json')
24
+
25
+ manifest = AppArchetype::Template::Manifest.new_from_file(manifest_file)
26
+
27
+ template = manifest.template
28
+ template.load
29
+
30
+ variables.each { |var| manifest.variables.add(var) }
31
+
32
+ manifest.variables.all.each do |var|
33
+ value = AppArchetype::CLI::Prompts.variable_prompt_for(var)
34
+ var.set!(value)
35
+ end
36
+
37
+ plan = AppArchetype::Template::Plan.new(
38
+ template,
39
+ manifest.variables,
40
+ destination_path: destination_path,
41
+ overwrite: overwrite
42
+ )
43
+
44
+ plan.devise
45
+ plan.execute
46
+ end
14
47
  end
@@ -16,7 +16,8 @@ module AppArchetype
16
16
  DEFAULT_VALUES = {
17
17
  'string' => '',
18
18
  'boolean' => false,
19
- 'integer' => 0
19
+ 'integer' => 0,
20
+ 'map' => {}
20
21
  }.freeze
21
22
 
22
23
  ##
@@ -55,13 +56,25 @@ module AppArchetype
55
56
  input != '0' && input.to_i != 0
56
57
  end
57
58
 
59
+ ##
60
+ # Map validation function. Ensures given input is a map
61
+ #
62
+ # @param [Object] input
63
+ #
64
+ # @return [Boolean]
65
+ #
66
+ MAP_VALIDATOR = lambda do |input|
67
+ input.is_a?(Hash)
68
+ end
69
+
58
70
  ##
59
71
  # Maps type to validation function
60
72
  #
61
73
  VALIDATORS = {
62
74
  'string' => STRING_VALIDATOR,
63
75
  'boolean' => BOOLEAN_VALIDATOR,
64
- 'integer' => INTEGER_VALIDATOR
76
+ 'integer' => INTEGER_VALIDATOR,
77
+ 'map' => MAP_VALIDATOR
65
78
  }.freeze
66
79
 
67
80
  ##
@@ -185,7 +198,7 @@ module AppArchetype
185
198
  ##
186
199
  # Returns true if the value input is valid.
187
200
  #
188
- # @param [String] input
201
+ # @param [Object] input
189
202
  #
190
203
  # @return [Boolean]
191
204
  #
@@ -2,5 +2,5 @@ module AppArchetype
2
2
  ##
3
3
  # AppArchetype version
4
4
  #
5
- VERSION = '1.2.4'.freeze
5
+ VERSION = '1.2.6'.freeze
6
6
  end
@@ -72,6 +72,20 @@ RSpec.describe AppArchetype::Template::Variable do
72
72
  end
73
73
  end
74
74
 
75
+ describe '::MAP_VALIDATOR' do
76
+ it 'returns true when given hash' do
77
+ expect(
78
+ described_class::MAP_VALIDATOR.call({})
79
+ ).to be true
80
+ end
81
+
82
+ it 'returns false when given a non hash input' do
83
+ expect(
84
+ described_class::MAP_VALIDATOR.call('zyzz')
85
+ ).to be false
86
+ end
87
+ end
88
+
75
89
  describe '#set!' do
76
90
  context 'setting with a valid value' do
77
91
  before { subject.set!('a value') }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: app_archetype
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Bigger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-24 00:00:00.000000000 Z
11
+ date: 2021-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cli-format