app_archetype 1.2.3 → 1.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -5
- data/README.md +42 -10
- data/app_archetype.gemspec +1 -1
- data/lib/app_archetype.rb +33 -0
- data/lib/app_archetype/cli.rb +1 -1
- data/lib/app_archetype/cli/presenters.rb +1 -1
- data/lib/app_archetype/cli/prompts.rb +1 -1
- data/lib/app_archetype/template/variable.rb +16 -3
- data/lib/app_archetype/template/variable_manager.rb +9 -0
- data/lib/app_archetype/version.rb +1 -1
- data/spec/app_archetype/template/variable_manager_spec.rb +13 -0
- data/spec/app_archetype/template/variable_spec.rb +14 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69596e80065838a6a6ee3e106cf923c0a5cde9c3ab021ad453cec86693b7a54e
|
4
|
+
data.tar.gz: 0c2efba5fa04672d651f85ee96c1758d5a1b2af04dc8229684f6a510208bcc46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bdf46483034b8a0655597c181a2710a8d426f10b27aef0f9ae3d49598f3457e5f9231aab1c853dfbd17fefa2ceb2cb2a80e251a146a25abac3bb72e5ae789e0
|
7
|
+
data.tar.gz: 5925cafc17983ad94872e22a430a858b5f53feb1ebef9a4b1b00f1c6a337816b7331d0cc51f06c5d9bba74f57b1884378cc869cb283ceac46272970039ad10ca
|
data/Gemfile.lock
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
app_archetype (1.2.
|
4
|
+
app_archetype (1.2.8)
|
5
5
|
cli-format (~> 0.2)
|
6
6
|
highline (~> 2.0)
|
7
7
|
json (~> 2.3)
|
8
8
|
json-schema (~> 2.8)
|
9
|
-
jsonnet (~> 0.
|
9
|
+
jsonnet (~> 0.4.0)
|
10
10
|
logger (~> 1.4.2)
|
11
11
|
os (~> 1.1)
|
12
12
|
ostruct (~> 0.3)
|
@@ -16,7 +16,7 @@ PATH
|
|
16
16
|
GEM
|
17
17
|
remote: https://rubygems.org/
|
18
18
|
specs:
|
19
|
-
activesupport (6.1.
|
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)
|
@@ -60,7 +60,7 @@ GEM
|
|
60
60
|
json (2.5.1)
|
61
61
|
json-schema (2.8.1)
|
62
62
|
addressable (>= 2.4)
|
63
|
-
jsonnet (0.
|
63
|
+
jsonnet (0.4.0)
|
64
64
|
mini_portile2 (>= 2.2.0)
|
65
65
|
kwalify (0.7.2)
|
66
66
|
launchy (2.5.0)
|
@@ -70,7 +70,7 @@ GEM
|
|
70
70
|
mini_portile2 (2.6.1)
|
71
71
|
minitest (5.14.4)
|
72
72
|
os (1.1.1)
|
73
|
-
ostruct (0.
|
73
|
+
ostruct (0.4.0)
|
74
74
|
parallel (1.19.2)
|
75
75
|
parser (2.7.1.5)
|
76
76
|
ast (~> 2.4.1)
|
data/README.md
CHANGED
@@ -6,18 +6,20 @@ Code project template renderer
|
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
|
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":
|
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
|
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
|
|
@@ -133,6 +161,10 @@ You can list the templates in your template directory at any time by running the
|
|
133
161
|
archetype list
|
134
162
|
```
|
135
163
|
|
164
|
+
## Contributing
|
165
|
+
|
166
|
+
See CONTRIBUTING.md for more information
|
167
|
+
|
136
168
|
## Licence
|
137
169
|
|
138
170
|
This gem is covered by the terms of the MIT licence. See LICENCE for more information
|
data/app_archetype.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.add_dependency 'cli-format', '~> 0.2'
|
20
20
|
spec.add_dependency 'highline', '~> 2.0'
|
21
21
|
spec.add_dependency 'json', '~> 2.3'
|
22
|
-
spec.add_dependency 'jsonnet', '~> 0.
|
22
|
+
spec.add_dependency 'jsonnet', '~> 0.4.0'
|
23
23
|
spec.add_dependency 'json-schema', '~> 2.8'
|
24
24
|
spec.add_dependency 'logger', '~> 1.4.2'
|
25
25
|
spec.add_dependency 'os', '~> 1.1'
|
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
|
data/lib/app_archetype/cli.rb
CHANGED
@@ -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 [
|
201
|
+
# @param [Object] input
|
189
202
|
#
|
190
203
|
# @return [Boolean]
|
191
204
|
#
|
@@ -34,6 +34,15 @@ module AppArchetype
|
|
34
34
|
@data.detect { |var| var.name == name }
|
35
35
|
end
|
36
36
|
|
37
|
+
##
|
38
|
+
# Adds a variable to the set
|
39
|
+
#
|
40
|
+
# @param [AppArchetype::Template::Variable] var
|
41
|
+
#
|
42
|
+
def add(var)
|
43
|
+
@data << var
|
44
|
+
end
|
45
|
+
|
37
46
|
##
|
38
47
|
# Creates a hash representation of variables.
|
39
48
|
#
|
@@ -58,6 +58,19 @@ RSpec.describe AppArchetype::Template::VariableManager do
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
describe '#add' do
|
62
|
+
let(:new_var) { double(AppArchetype::Template::Variable) }
|
63
|
+
|
64
|
+
before do
|
65
|
+
subject.add(new_var)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'adds variable to set' do
|
69
|
+
expect(subject.instance_variable_get(:@data).include?(new_var))
|
70
|
+
.to be true
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
61
74
|
describe '#to_h' do
|
62
75
|
let(:instance_helpers) { double }
|
63
76
|
let(:random_result) { 'random-string-25-chars-long' }
|
@@ -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
|
+
version: 1.2.8
|
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-
|
11
|
+
date: 2021-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cli-format
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
61
|
+
version: 0.4.0
|
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.
|
68
|
+
version: 0.4.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: json-schema
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|