commercelayer-cli 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +14 -2
- data/commercelayer-cli.gemspec +2 -1
- data/lib/commercelayer/cli.rb +1 -0
- data/lib/commercelayer/cli/bootstrappers.rb +9 -1
- data/lib/commercelayer/cli/bootstrappers/contentful.rb +215 -0
- data/lib/commercelayer/cli/bootstrappers/datocms.rb +1 -1
- data/lib/commercelayer/cli/helpers.rb +5 -1
- data/lib/commercelayer/cli/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efa84785e926096aa4e87619e52b234514b1ecf5af176bb56373cce07d4a3d5f
|
4
|
+
data.tar.gz: 9d3de336ec13403024491e48c719210da3020a27dd6d441792b08d7cc2f0b716
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f107320dc608b00e61a08b242129fed2b8cbcc43edc3281ddf0b878c4a45f319b4e8c0457dd2be87e17eb4f44626be08d37d040033a7f239aeacf50014dbfa5
|
7
|
+
data.tar.gz: 034d1100741a03876913eac059358a25a3526fe8a00df06721396ae1c52422d6b89df92f01709589ccb84187b9a4938c809bc3f77d37fabb4e79cda75731eff5
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
commercelayer-cli (0.2.
|
4
|
+
commercelayer-cli (0.2.2)
|
5
5
|
commercelayer
|
6
|
+
contentful-management
|
6
7
|
dato
|
7
8
|
thor
|
8
9
|
|
@@ -23,6 +24,10 @@ GEM
|
|
23
24
|
jsonapi-consumer (~> 1.0)
|
24
25
|
oauth2 (~> 1.4.0)
|
25
26
|
concurrent-ruby (1.0.5)
|
27
|
+
contentful-management (2.3.0)
|
28
|
+
http (> 1.0, < 3.0)
|
29
|
+
json (~> 1.8)
|
30
|
+
multi_json (~> 1)
|
26
31
|
dato (0.6.8)
|
27
32
|
activesupport (>= 4.2.7)
|
28
33
|
addressable
|
@@ -51,13 +56,20 @@ GEM
|
|
51
56
|
faraday (>= 0.7.4, < 1.0)
|
52
57
|
fastimage (2.1.4)
|
53
58
|
ffi (1.9.25)
|
59
|
+
http (2.2.2)
|
60
|
+
addressable (~> 2.3)
|
61
|
+
http-cookie (~> 1.0)
|
62
|
+
http-form_data (~> 1.0.1)
|
63
|
+
http_parser.rb (~> 0.6.0)
|
54
64
|
http-cookie (1.0.3)
|
55
65
|
domain_name (~> 0.5)
|
66
|
+
http-form_data (1.0.3)
|
67
|
+
http_parser.rb (0.6.0)
|
56
68
|
i18n (1.1.0)
|
57
69
|
concurrent-ruby (~> 1.0)
|
58
70
|
imgix (1.1.0)
|
59
71
|
addressable
|
60
|
-
json (
|
72
|
+
json (1.8.6)
|
61
73
|
json_schema (0.19.1)
|
62
74
|
jsonapi-consumer (1.0.1)
|
63
75
|
activemodel (>= 3.2)
|
data/commercelayer-cli.gemspec
CHANGED
data/lib/commercelayer/cli.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative "bootstrappers/datocms"
|
2
|
+
require_relative "bootstrappers/contentful"
|
2
3
|
|
3
4
|
module Commercelayer
|
4
5
|
module CLI
|
@@ -8,12 +9,19 @@ module Commercelayer
|
|
8
9
|
commercelayer_client.authorize!
|
9
10
|
case destination
|
10
11
|
when "datocms"
|
11
|
-
if yes? "Warning: this will erase your DatoCMS
|
12
|
+
if yes? "Warning: this will erase your DatoCMS data. Continue?", :yellow
|
12
13
|
say "Exporting data to DatoCMS...", :blue
|
13
14
|
DatoCMS.new.bootstrap!
|
14
15
|
else
|
15
16
|
say "Nothing to do here. Bye!", :blue
|
16
17
|
end
|
18
|
+
when "contentful"
|
19
|
+
if yes? "Warning: this will erase your Contentful data. Continue?", :yellow
|
20
|
+
say "Exporting data to Contentful...", :blue
|
21
|
+
Contentful.new.bootstrap!
|
22
|
+
else
|
23
|
+
say "Nothing to do here. Bye!", :blue
|
24
|
+
end
|
17
25
|
else
|
18
26
|
say "coming soon...", :yellow
|
19
27
|
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
module Commercelayer
|
2
|
+
module CLI
|
3
|
+
module Bootstrappers
|
4
|
+
class Contentful
|
5
|
+
|
6
|
+
include Helpers
|
7
|
+
|
8
|
+
def initialize(options={})
|
9
|
+
puts "Clearing entries..."
|
10
|
+
master.entries.all.each do |entry|
|
11
|
+
entry.unpublish if entry.published?
|
12
|
+
entry.destroy
|
13
|
+
end
|
14
|
+
puts "Clearing content types..."
|
15
|
+
master.content_types.all.each do |content_type|
|
16
|
+
content_type.unpublish if content_type.published?
|
17
|
+
content_type.destroy
|
18
|
+
end
|
19
|
+
puts "Clearing assets..."
|
20
|
+
master.assets.all.each do |asset|
|
21
|
+
asset.unpublish if asset.published?
|
22
|
+
asset.destroy
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def bootstrap!
|
27
|
+
create_variant_model!
|
28
|
+
create_product_model!
|
29
|
+
create_variant_model_fields!
|
30
|
+
create_product_model_fields!
|
31
|
+
create_records!
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def create_product_model!
|
36
|
+
puts "Creating product model..."
|
37
|
+
@product_model = master.content_types.create({
|
38
|
+
id: "product",
|
39
|
+
name: "Product"
|
40
|
+
})
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_variant_model!
|
44
|
+
puts "Creating variant model..."
|
45
|
+
@variant_model = master.content_types.create({
|
46
|
+
id: "variant",
|
47
|
+
name: "Variant"
|
48
|
+
})
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_product_model_fields!
|
52
|
+
puts "Creating product model fields..."
|
53
|
+
product_model_fields.each do |id, options|
|
54
|
+
@product_model.fields.create({ id: id }.merge(options))
|
55
|
+
end
|
56
|
+
@product_model.activate
|
57
|
+
@product_model.update(displayField: "reference")
|
58
|
+
@product_model.activate
|
59
|
+
end
|
60
|
+
|
61
|
+
def create_variant_model_fields!
|
62
|
+
puts "Creating variant model fields..."
|
63
|
+
variant_model_fields.each do |id, options|
|
64
|
+
@variant_model.fields.create({ id: id }.merge(options))
|
65
|
+
end
|
66
|
+
@variant_model.activate
|
67
|
+
@variant_model.update(displayField: "name")
|
68
|
+
@variant_model.activate
|
69
|
+
end
|
70
|
+
|
71
|
+
def product_model_fields
|
72
|
+
{
|
73
|
+
reference: {
|
74
|
+
name: "Reference",
|
75
|
+
type: "Symbol",
|
76
|
+
required: true,
|
77
|
+
validations: [ validation(unique: true) ]
|
78
|
+
},
|
79
|
+
image: {
|
80
|
+
name: "Image",
|
81
|
+
type: "Link",
|
82
|
+
link_type: "Asset",
|
83
|
+
validations: [ validation(link_mimetype_group: 'image') ]
|
84
|
+
},
|
85
|
+
variants: {
|
86
|
+
name: "Variants",
|
87
|
+
type: "Array",
|
88
|
+
items: link(type: "variant")
|
89
|
+
}
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
def variant_model_fields
|
94
|
+
{
|
95
|
+
name: {
|
96
|
+
name: "Name",
|
97
|
+
type: "Symbol",
|
98
|
+
required: true,
|
99
|
+
validations: [ validation(unique: true) ]
|
100
|
+
},
|
101
|
+
code: {
|
102
|
+
name: "Code",
|
103
|
+
type: "Symbol",
|
104
|
+
required: true,
|
105
|
+
validations: [ validation(unique: true) ]
|
106
|
+
},
|
107
|
+
description: {
|
108
|
+
name: "Description",
|
109
|
+
type: "Text"
|
110
|
+
},
|
111
|
+
image: {
|
112
|
+
name: "Image",
|
113
|
+
type: "Link",
|
114
|
+
link_type: "Asset",
|
115
|
+
validations: [ validation(link_mimetype_group: 'image') ]
|
116
|
+
}
|
117
|
+
}
|
118
|
+
end
|
119
|
+
|
120
|
+
def create_records!
|
121
|
+
puts "Creating entries..."
|
122
|
+
last_product_reference = nil
|
123
|
+
last_product_id = nil
|
124
|
+
last_product_variants = []
|
125
|
+
Commercelayer::Sku.order(:reference).all.each_total do |sku|
|
126
|
+
puts "> #{sku.code}"
|
127
|
+
if sku.reference != last_product_reference
|
128
|
+
if last_product_id
|
129
|
+
product = master.entries.find(last_product_id)
|
130
|
+
product.update({
|
131
|
+
reference: last_product_reference,
|
132
|
+
image: last_product_variants.first.image,
|
133
|
+
variants: last_product_variants
|
134
|
+
})
|
135
|
+
product.publish
|
136
|
+
last_product_variants = []
|
137
|
+
end
|
138
|
+
|
139
|
+
begin
|
140
|
+
product = @product_model.entries.create({
|
141
|
+
reference: sku.reference,
|
142
|
+
variants: []
|
143
|
+
})
|
144
|
+
last_product_reference = sku.reference
|
145
|
+
last_product_id = product.id
|
146
|
+
rescue => e
|
147
|
+
puts e.inspect
|
148
|
+
break
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
begin
|
153
|
+
variant = @variant_model.entries.create({
|
154
|
+
code: sku.code,
|
155
|
+
name: sku.name,
|
156
|
+
description: sku.description,
|
157
|
+
image: image(sku)
|
158
|
+
})
|
159
|
+
variant.publish
|
160
|
+
last_product_variants << variant
|
161
|
+
rescue => e
|
162
|
+
puts e.inspect
|
163
|
+
break
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def client
|
169
|
+
::Contentful::Management::Client.new(config_data[:contentful][:access_token])
|
170
|
+
end
|
171
|
+
|
172
|
+
def environments
|
173
|
+
@environments ||= client.environments(config_data[:contentful][:space]).all
|
174
|
+
end
|
175
|
+
|
176
|
+
def master
|
177
|
+
@master ||= environments.find('master').first
|
178
|
+
end
|
179
|
+
|
180
|
+
def validation(options={})
|
181
|
+
validation = ::Contentful::Management::Validation.new
|
182
|
+
options.each do |k,v|
|
183
|
+
validation.send("#{k}=", v)
|
184
|
+
end
|
185
|
+
validation
|
186
|
+
end
|
187
|
+
|
188
|
+
def link(options={})
|
189
|
+
field = ::Contentful::Management::Field.new
|
190
|
+
field.type = "Link"
|
191
|
+
field.link_type = "Entry"
|
192
|
+
validation = ::Contentful::Management::Validation.new
|
193
|
+
validation.link_content_type = [options[:type]]
|
194
|
+
field.validations = [validation]
|
195
|
+
field
|
196
|
+
end
|
197
|
+
|
198
|
+
def image(sku, options={})
|
199
|
+
unless sku.image_url.blank?
|
200
|
+
image_file = ::Contentful::Management::File.new
|
201
|
+
image_file.properties[:contentType] = "image/jpeg"
|
202
|
+
image_file.properties[:fileName] = "#{sku.code}.jpg"
|
203
|
+
image_file.properties[:upload] = sku.image_url
|
204
|
+
image_file
|
205
|
+
image_asset = master.assets.create(title: sku.name, file: image_file)
|
206
|
+
image_asset.process_file
|
207
|
+
image_asset.publish
|
208
|
+
image_asset
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
@@ -16,6 +16,10 @@ module Commercelayer
|
|
16
16
|
},
|
17
17
|
"dato" => {
|
18
18
|
"api_key" => "YOUR-DATOCMS-APIKEY"
|
19
|
+
},
|
20
|
+
"contentful" => {
|
21
|
+
"space" => "YOUR-CONTENTFUL-SPACE-ID",
|
22
|
+
"access_token" => "YOUR-CONTENTFUL-ACCESS-TOKEN"
|
19
23
|
}
|
20
24
|
}.to_yaml
|
21
25
|
end
|
@@ -31,7 +35,7 @@ module Commercelayer
|
|
31
35
|
scope: config_data[:commercelayer][:scope],
|
32
36
|
site: config_data[:commercelayer][:site]
|
33
37
|
)
|
34
|
-
end
|
38
|
+
end
|
35
39
|
|
36
40
|
end
|
37
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: commercelayer-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Filippo Conforti
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: contentful-management
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: The Official Commerce Layer CLI
|
98
112
|
email:
|
99
113
|
- filippo@commercelayer.io
|
@@ -117,6 +131,7 @@ files:
|
|
117
131
|
- exe/commercelayer-cli
|
118
132
|
- lib/commercelayer/cli.rb
|
119
133
|
- lib/commercelayer/cli/bootstrappers.rb
|
134
|
+
- lib/commercelayer/cli/bootstrappers/contentful.rb
|
120
135
|
- lib/commercelayer/cli/bootstrappers/datocms.rb
|
121
136
|
- lib/commercelayer/cli/helpers.rb
|
122
137
|
- lib/commercelayer/cli/version.rb
|