contentful_bootstrap 3.4.0 → 3.5.0
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/CHANGELOG.md +14 -0
- data/Gemfile +1 -1
- data/README.md +19 -8
- data/bin/contentful_bootstrap +13 -1
- data/contentful_bootstrap.gemspec +2 -2
- data/lib/contentful/bootstrap/command_runner.rb +3 -15
- data/lib/contentful/bootstrap/commands/base.rb +27 -13
- data/lib/contentful/bootstrap/commands/create_space.rb +41 -39
- data/lib/contentful/bootstrap/commands/generate_json.rb +3 -2
- data/lib/contentful/bootstrap/commands/generate_token.rb +20 -19
- data/lib/contentful/bootstrap/commands/update_space.rb +15 -14
- data/lib/contentful/bootstrap/support.rb +18 -1
- data/lib/contentful/bootstrap/templates/base.rb +16 -11
- data/lib/contentful/bootstrap/templates/json_template.rb +14 -6
- data/lib/contentful/bootstrap/version.rb +1 -1
- data/spec/contentful/bootstrap/command_runner_spec.rb +6 -6
- data/spec/contentful/bootstrap/commands/base_spec.rb +35 -21
- data/spec/contentful/bootstrap/commands/create_space_spec.rb +16 -16
- data/spec/contentful/bootstrap/commands/generate_token_spec.rb +19 -22
- data/spec/contentful/bootstrap/commands/update_space_spec.rb +6 -6
- data/spec/contentful/bootstrap/support_spec.rb +1 -3
- data/spec/contentful/bootstrap/templates/base_spec.rb +2 -2
- data/spec/contentful/bootstrap/templates/json_template_spec.rb +19 -4
- data/spec/fixtures/json_fixtures/object.json +38 -0
- data/spec/spec_helper.rb +20 -0
- metadata +17 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3069a4e110431c036457ac8839dc3e01d48146e3
|
4
|
+
data.tar.gz: 9fdeed19e3bdd8c97d77424e029b3f76b65a78e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a29cc6c70e7e062bc0224b0831a1b3841059ba99e1954690cdf8dfe702bde14cd8090d7c8cad8d52766cef84d81df1e7a9e7bbd3352efced2b7c48a857924ac
|
7
|
+
data.tar.gz: b8638c2bbc11a3f8cb2f5c4a99e763c2220d8b318eccaea6c8e1a01c7123c7807b90aa2b852ea50b8d40229ba81ae3bf197fae3b1c1119b75eb31aa2da2a11d8
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,20 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## v3.5.0
|
6
|
+
|
7
|
+
### Added
|
8
|
+
* Add `-q` and `--quiet` flags to the CLI Tool and their respective command classes [#48](https://github.com/contentful/contentful-bootstrap.rb/issues/48)
|
9
|
+
* Add `:no_input` option to library commands [#48](https://github.com/contentful/contentful-bootstrap.rb/issues/48)
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
* Refactored internals to allow more option flexibility and simplified the `CommandRunner`.
|
13
|
+
* Updated dependencies to the newest available SDKs
|
14
|
+
|
15
|
+
### Fixed
|
16
|
+
* Fixed Object Field parsing for JSON Templates [#51](https://github.com/contentful/contentful-bootstrap.rb/issues/51)
|
17
|
+
|
18
|
+
|
5
19
|
## v3.4.0
|
6
20
|
### Added
|
7
21
|
* Add `-v` and `--version` flags to output current version
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -26,25 +26,25 @@ $ gem install contentful_bootstrap
|
|
26
26
|
You can create spaces by doing:
|
27
27
|
|
28
28
|
```bash
|
29
|
-
$ contentful_bootstrap create_space <space_name> [--template template_name] [--json-template template_path] [--mark-processed] [--config CONFIG_PATH]
|
29
|
+
$ contentful_bootstrap create_space <space_name> [--template template_name] [--json-template template_path] [--mark-processed] [--config CONFIG_PATH] [--quiet]
|
30
30
|
```
|
31
31
|
|
32
32
|
You can also generate new Delivery API Tokens by doing:
|
33
33
|
|
34
34
|
```bash
|
35
|
-
$ contentful_bootstrap generate_token <space_id> [--name token_name] [--config CONFIG_PATH]
|
35
|
+
$ contentful_bootstrap generate_token <space_id> [--name token_name] [--config CONFIG_PATH] [--quiet]
|
36
36
|
```
|
37
37
|
|
38
38
|
You can also generate JSON Templates from existing spaces by doing:
|
39
39
|
|
40
40
|
```bash
|
41
|
-
$ contentful_bootstrap generate_json <space_id> <delivery_api_access_token> [--output-file OUTPUT PATH] [--content-types-only]
|
41
|
+
$ contentful_bootstrap generate_json <space_id> <delivery_api_access_token> [--output-file OUTPUT PATH] [--content-types-only] [--quiet]
|
42
42
|
```
|
43
43
|
|
44
44
|
You can update existing spaces from JSON Templates by doing:
|
45
45
|
|
46
46
|
```bash
|
47
|
-
$ contentful_bootstrap update_space <space_id> -j template_path [--mark-processed] [--skip-content-types]
|
47
|
+
$ contentful_bootstrap update_space <space_id> -j template_path [--mark-processed] [--skip-content-types] [--quiet]
|
48
48
|
```
|
49
49
|
|
50
50
|
### Built-in templates
|
@@ -88,7 +88,9 @@ options = {
|
|
88
88
|
template: "blog", # Will use one of the predefined templates and create Content Types, Assets and Entries
|
89
89
|
json_template: "/path/to/template.json", # Will use the JSON file specified as a Template
|
90
90
|
mark_processed: false, # if true will mark all resources as 'bootstrapProcessed' and will be avoided for update_space calls (doesnt affect create_space)
|
91
|
-
trigger_oauth: true # if true will trigger OAuth process
|
91
|
+
trigger_oauth: true, # if true will trigger OAuth process
|
92
|
+
quiet: false, # if true will not output to STDOUT
|
93
|
+
no_input: false # if true all input operations won't be done, exceptions thrown with alternatives through configuration file in cases in which it cannot proceed
|
92
94
|
}
|
93
95
|
Contentful::Bootstrap::CommandRunner.new.create_space("space_name", options)
|
94
96
|
```
|
@@ -101,6 +103,8 @@ options = {
|
|
101
103
|
mark_processed: false, # if true will mark all resources as 'bootstrapProcessed and will be avoided on future update_space calls
|
102
104
|
trigger_oauth: true, # if true will trigger OAuth process
|
103
105
|
skip_content_types: false, # if true will avoid creating the content types
|
106
|
+
quiet: false, # if true will not output to STDOUT
|
107
|
+
no_input: false # if true all input operations won't be done, exceptions thrown with alternatives through configuration file in cases in which it cannot proceed
|
104
108
|
}
|
105
109
|
Contentful::Bootstrap::CommandRunner.new.update_space("space_id", options)
|
106
110
|
```
|
@@ -116,7 +120,9 @@ Additionally, you can send an options hash with the following keys:
|
|
116
120
|
```ruby
|
117
121
|
options = {
|
118
122
|
name: "Some Nice Token Name", # Will Create the Delivery API Token with the specified name
|
119
|
-
trigger_oauth: true # if true will trigger OAuth process
|
123
|
+
trigger_oauth: true, # if true will trigger OAuth process
|
124
|
+
quiet: false, # if true will not output to STDOUT
|
125
|
+
no_input: false # if true all input operations won't be done, exceptions thrown with alternatives through configuration file in cases in which it cannot proceed
|
120
126
|
}
|
121
127
|
Contentful::Bootstrap::CommandRunner.new.generate_token("space_id", options)
|
122
128
|
```
|
@@ -127,7 +133,9 @@ To Generate a JSON Template from an exising Space
|
|
127
133
|
Contentful::Bootstrap::CommandRunner.new.generate_json(
|
128
134
|
"space_id",
|
129
135
|
access_token: "delivery_api_access_token",
|
130
|
-
|
136
|
+
filename: nil, # path to file in which to store JSON
|
137
|
+
content_types_only: false, # if true will not fetch Entries and Assets
|
138
|
+
quiet: false # if true will not output to STDOUT - only when filename is provided
|
131
139
|
)
|
132
140
|
```
|
133
141
|
|
@@ -137,7 +145,9 @@ Additionally, you can send an options hash with the following keys:
|
|
137
145
|
```ruby
|
138
146
|
options = {
|
139
147
|
access_token: "access_token" # REQUIRED
|
140
|
-
filename: "template.json" # Will save the JSON to the specified file
|
148
|
+
filename: "template.json", # Will save the JSON to the specified file
|
149
|
+
quiet: false, # if true will not output to STDOUT
|
150
|
+
no_input: false # if true all input operations won't be done, exceptions thrown with alternatives through configuration file in cases in which it cannot proceed
|
141
151
|
}
|
142
152
|
Contentful::Bootstrap::CommandRunner.new.generate_json("space_id", options)
|
143
153
|
```
|
@@ -157,6 +167,7 @@ The configuration file will be in `ini` format and looks like the following
|
|
157
167
|
|
158
168
|
```ini
|
159
169
|
[global]
|
170
|
+
CONTENTFUL_ORGANIZATION_ID = an_organization_id
|
160
171
|
CONTENTFUL_MANAGEMENT_ACCESS_TOKEN = a_management_access_token
|
161
172
|
|
162
173
|
[space_name]
|
data/bin/contentful_bootstrap
CHANGED
@@ -20,6 +20,9 @@ subcommands = {
|
|
20
20
|
opts.on("-c CONFIG_PATH", "--config CONFIG_PATH", "Specify Configuration Path") do |c|
|
21
21
|
options[:config_path] = c
|
22
22
|
end
|
23
|
+
opts.on("-q", "--quiet", "Don't output to STDOUT") do |q|
|
24
|
+
options[:quiet] = q
|
25
|
+
end
|
23
26
|
opts.on_tail("-h", "--help", "Print this message") do
|
24
27
|
puts opts
|
25
28
|
end
|
@@ -38,6 +41,9 @@ subcommands = {
|
|
38
41
|
opts.on("-c CONFIG_PATH", "--config CONFIG_PATH", "Specify Configuration Path") do |c|
|
39
42
|
options[:config_path] = c
|
40
43
|
end
|
44
|
+
opts.on("-q", "--quiet", "Don't output to STDOUT") do |q|
|
45
|
+
options[:quiet] = q
|
46
|
+
end
|
41
47
|
opts.on_tail("-h", "--help", "Print this message") do
|
42
48
|
puts opts
|
43
49
|
end
|
@@ -50,6 +56,9 @@ subcommands = {
|
|
50
56
|
opts.on("-c CONFIG_PATH", "--config CONFIG_PATH", "Specify Configuration Path") do |c|
|
51
57
|
options[:config_path] = c
|
52
58
|
end
|
59
|
+
opts.on("-q", "--quiet", "Don't output to STDOUT") do |q|
|
60
|
+
options[:quiet] = q
|
61
|
+
end
|
53
62
|
opts.on_tail("-h", "--help", "Print this message") do
|
54
63
|
puts opts
|
55
64
|
end
|
@@ -62,6 +71,9 @@ subcommands = {
|
|
62
71
|
opts.on("-o OUTPUT_PATH", "--output-file OUTPUT_PATH", "Specify Output File") do |f|
|
63
72
|
options[:filename] = f
|
64
73
|
end
|
74
|
+
opts.on("-q", "--quiet", "Don't output to STDOUT") do |q|
|
75
|
+
options[:quiet] = q
|
76
|
+
end
|
65
77
|
opts.on_tail("-h", "--help", "Print this message") do
|
66
78
|
puts opts
|
67
79
|
end
|
@@ -95,7 +107,7 @@ if subcommands.key? command
|
|
95
107
|
unless STDIN.tty? && STDOUT.tty?
|
96
108
|
$stderr.write "This tool requires user interaction\n"
|
97
109
|
$stderr.write "Exiting!\n"
|
98
|
-
exit
|
110
|
+
exit(1)
|
99
111
|
end
|
100
112
|
|
101
113
|
if is_help
|
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency "guard-rspec"
|
29
29
|
spec.add_development_dependency 'listen', '~> 3.0.0'
|
30
30
|
spec.add_runtime_dependency "launchy"
|
31
|
-
spec.add_runtime_dependency "contentful-management", '~> 0
|
32
|
-
spec.add_runtime_dependency "contentful", "
|
31
|
+
spec.add_runtime_dependency "contentful-management", '~> 1.0'
|
32
|
+
spec.add_runtime_dependency "contentful", "> 0", "< 3"
|
33
33
|
spec.add_runtime_dependency "inifile"
|
34
34
|
end
|
@@ -12,32 +12,20 @@ module Contentful
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def create_space(space_name, options = {})
|
15
|
-
template_name = options.fetch(:template, nil)
|
16
|
-
json_template = options.fetch(:json_template, nil)
|
17
|
-
mark_processed = options.fetch(:mark_processed, false)
|
18
|
-
trigger_oauth = options.fetch(:trigger_oauth, true)
|
19
|
-
|
20
15
|
Contentful::Bootstrap::Commands::CreateSpace.new(
|
21
|
-
@token, space_name,
|
16
|
+
@token, space_name, options
|
22
17
|
).run
|
23
18
|
end
|
24
19
|
|
25
20
|
def update_space(space_id, options = {})
|
26
|
-
json_template = options.fetch(:json_template, nil)
|
27
|
-
mark_processed = options.fetch(:mark_processed, false)
|
28
|
-
trigger_oauth = options.fetch(:trigger_oauth, true)
|
29
|
-
|
30
21
|
Contentful::Bootstrap::Commands::UpdateSpace.new(
|
31
|
-
@token, space_id,
|
22
|
+
@token, space_id, options
|
32
23
|
).run
|
33
24
|
end
|
34
25
|
|
35
26
|
def generate_token(space, options = {})
|
36
|
-
token_name = options.fetch(:name, 'Bootstrap Token')
|
37
|
-
trigger_oauth = options.fetch(:trigger_oauth, true)
|
38
|
-
|
39
27
|
Contentful::Bootstrap::Commands::GenerateToken.new(
|
40
|
-
@token, space,
|
28
|
+
@token, space, options
|
41
29
|
).run
|
42
30
|
end
|
43
31
|
|
@@ -7,11 +7,16 @@ module Contentful
|
|
7
7
|
module Bootstrap
|
8
8
|
module Commands
|
9
9
|
class Base
|
10
|
-
|
11
|
-
|
10
|
+
attr_reader :space, :token, :options, :quiet, :no_input, :client
|
11
|
+
|
12
|
+
def initialize(token, space, options = {})
|
13
|
+
trigger_oauth = options.fetch(:trigger_oauth, true)
|
12
14
|
|
13
|
-
def initialize(token, space, trigger_oauth = true)
|
14
15
|
@token = token
|
16
|
+
@options = options
|
17
|
+
@quiet = options.fetch(:quiet, false)
|
18
|
+
@no_input = options.fetch(:no_input, false)
|
19
|
+
|
15
20
|
configuration if trigger_oauth
|
16
21
|
management_client_init if trigger_oauth
|
17
22
|
@space = space
|
@@ -21,32 +26,41 @@ module Contentful
|
|
21
26
|
fail 'must implement'
|
22
27
|
end
|
23
28
|
|
29
|
+
protected
|
30
|
+
|
31
|
+
def output(text = nil)
|
32
|
+
Support.output(text, @quiet)
|
33
|
+
end
|
34
|
+
|
24
35
|
private
|
25
36
|
|
26
37
|
def management_client_init
|
27
|
-
::Contentful::Bootstrap::Management.new(@token.read, raise_errors: true)
|
38
|
+
@client ||= ::Contentful::Bootstrap::Management.new(@token.read, raise_errors: true)
|
28
39
|
end
|
29
40
|
|
30
41
|
def configuration
|
31
42
|
if @token.present?
|
32
|
-
|
43
|
+
output 'OAuth token found, moving on!'
|
33
44
|
return
|
34
45
|
end
|
35
46
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
47
|
+
Support.input('OAuth Token not found, do you want to create a new configuration file? (Y/n): ', no_input) do |answer|
|
48
|
+
if answer.downcase == 'n'
|
49
|
+
output 'Exiting!'
|
50
|
+
exit
|
51
|
+
end
|
40
52
|
end
|
41
53
|
|
42
|
-
|
43
|
-
|
54
|
+
fail 'OAuth token required to proceed' if no_input
|
55
|
+
|
56
|
+
output "Configuration will be saved on #{@token.filename}"
|
57
|
+
output 'A new tab on your browser will open for requesting OAuth permissions'
|
44
58
|
token_server
|
45
|
-
|
59
|
+
output
|
46
60
|
end
|
47
61
|
|
48
62
|
def token_server
|
49
|
-
silence_stderr do # Don't show any WEBrick related stuff
|
63
|
+
Support.silence_stderr do # Don't show any WEBrick related stuff
|
50
64
|
server = Contentful::Bootstrap::Server.new(@token)
|
51
65
|
|
52
66
|
server.start
|
@@ -9,33 +9,32 @@ module Contentful
|
|
9
9
|
module Commands
|
10
10
|
class CreateSpace < Base
|
11
11
|
attr_reader :template_name, :json_template
|
12
|
-
def initialize(
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@mark_processed = mark_processed
|
12
|
+
def initialize(token, space, options = {})
|
13
|
+
@template_name = options.fetch(:template, nil)
|
14
|
+
@json_template = options.fetch(:json_template, nil)
|
15
|
+
@mark_processed = options.fetch(:mark_processed, false)
|
16
|
+
|
17
|
+
super(token, space, options)
|
19
18
|
end
|
20
19
|
|
21
20
|
def run
|
22
|
-
|
21
|
+
output "Creating Space '#{@space}'"
|
23
22
|
|
24
23
|
new_space = fetch_space
|
25
24
|
|
26
|
-
|
27
|
-
|
25
|
+
output "Space '#{@space}' created!"
|
26
|
+
output
|
28
27
|
|
29
28
|
create_template(new_space) unless @template_name.nil?
|
30
29
|
create_json_template(new_space) unless @json_template.nil?
|
31
30
|
|
32
31
|
access_token = generate_token(new_space)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
output
|
33
|
+
output "Space ID: '#{new_space.id}'"
|
34
|
+
output "Access Token: '#{access_token}'"
|
35
|
+
output
|
36
|
+
output 'You can now insert those values into your configuration blocks'
|
37
|
+
output "Manage your content at https://app.contentful.com/spaces/#{new_space.id}"
|
39
38
|
|
40
39
|
new_space
|
41
40
|
end
|
@@ -49,18 +48,21 @@ module Contentful
|
|
49
48
|
name: @space
|
50
49
|
}
|
51
50
|
options[:organization_id] = @token.read_organization_id unless @token.read_organization_id.nil?
|
52
|
-
new_space =
|
51
|
+
new_space = client.spaces.create(options)
|
53
52
|
rescue Contentful::Management::NotFound
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
53
|
+
fail "Organization ID is required, provide it in Configuration File" if no_input
|
54
|
+
|
55
|
+
output 'Your account has multiple organizations:'
|
56
|
+
output organizations.join("\n")
|
57
|
+
Support.input('Please insert the Organization ID you\'d want to create the spaces for: ', no_input) do |answer|
|
58
|
+
organization_id = answer
|
59
|
+
@token.write_organization_id(organization_id)
|
60
|
+
output 'Your Organization ID has been stored as the default organization.'
|
61
|
+
new_space = client.spaces.create(
|
62
|
+
name: @space,
|
63
|
+
organization_id: organization_id
|
64
|
+
)
|
65
|
+
end
|
64
66
|
end
|
65
67
|
|
66
68
|
new_space
|
@@ -71,7 +73,7 @@ module Contentful
|
|
71
73
|
def organizations
|
72
74
|
client = management_client_init
|
73
75
|
url = client.base_url.sub('spaces', 'token')
|
74
|
-
response =
|
76
|
+
response = client.get_http(url, nil, client.request_headers)
|
75
77
|
organization_ids = JSON.load(response.body.to_s)['includes']['Organization'].map do |org|
|
76
78
|
sprintf('%-20s %s', org['name'], org['sys']['id'])
|
77
79
|
end
|
@@ -88,30 +90,30 @@ module Contentful
|
|
88
90
|
|
89
91
|
def create_template(space)
|
90
92
|
if templates.key? @template_name.to_sym
|
91
|
-
|
93
|
+
output "Creating Template '#{@template_name}'"
|
92
94
|
|
93
|
-
templates[@template_name.to_sym].new(space).run
|
94
|
-
|
95
|
+
templates[@template_name.to_sym].new(space, quiet).run
|
96
|
+
output "Template '#{@template_name}' created!"
|
95
97
|
else
|
96
|
-
|
98
|
+
output "Template '#{@template_name}' not found. Valid templates are '#{templates.keys.map(&:to_s).join('\', \'')}'"
|
97
99
|
end
|
98
|
-
|
100
|
+
output
|
99
101
|
end
|
100
102
|
|
101
103
|
def create_json_template(space)
|
102
104
|
if ::File.exist?(@json_template)
|
103
|
-
|
104
|
-
Templates::JsonTemplate.new(space, @json_template, @mark_processed).run
|
105
|
-
|
105
|
+
output "Creating JSON Template '#{@json_template}'"
|
106
|
+
Templates::JsonTemplate.new(space, @json_template, @mark_processed, true, quiet).run
|
107
|
+
output "JSON Template '#{@json_template}' created!"
|
106
108
|
else
|
107
|
-
|
109
|
+
output "JSON Template '#{@json_template}' does not exist. Please check that you specified the correct file name."
|
108
110
|
end
|
109
|
-
|
111
|
+
output
|
110
112
|
end
|
111
113
|
|
112
114
|
def generate_token(space)
|
113
115
|
Contentful::Bootstrap::Commands::GenerateToken.new(
|
114
|
-
@token, space,
|
116
|
+
@token, space, options
|
115
117
|
).run
|
116
118
|
end
|
117
119
|
end
|
@@ -6,11 +6,12 @@ module Contentful
|
|
6
6
|
module Commands
|
7
7
|
class GenerateJson
|
8
8
|
attr_reader :space_id, :filename, :access_token, :content_types_only
|
9
|
-
def initialize(space_id, access_token, filename = nil, content_types_only = false)
|
9
|
+
def initialize(space_id, access_token, filename = nil, content_types_only = false, quiet = false)
|
10
10
|
@space_id = space_id
|
11
11
|
@access_token = access_token
|
12
12
|
@filename = filename
|
13
13
|
@content_types_only = content_types_only
|
14
|
+
@quiet = quiet
|
14
15
|
end
|
15
16
|
|
16
17
|
def run
|
@@ -32,7 +33,7 @@ module Contentful
|
|
32
33
|
if filename.nil?
|
33
34
|
puts "#{json}\n"
|
34
35
|
else
|
35
|
-
puts "Saving JSON template to '#{filename}'"
|
36
|
+
puts "Saving JSON template to '#{filename}'" unless @quiet
|
36
37
|
::File.write(filename, json)
|
37
38
|
end
|
38
39
|
end
|