locomotivecms_wagon 2.0.0.rc4 → 2.0.0.rc5

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
  SHA1:
3
- metadata.gz: 19ad90755ba57d30b5940644109731167eb1244b
4
- data.tar.gz: cf68675f04cd78369b69cd23883ea9973453f027
3
+ metadata.gz: 3ec6622d8b17580c78b7d74ce43267db20a84f32
4
+ data.tar.gz: c155e38db2000ce5c619260f44ab08fed2d6fb2a
5
5
  SHA512:
6
- metadata.gz: b57f24c856de5513c12b10654a675fb9ca9daec3bf0541fffee3823c83e41da9864d45c2a2046ad173d17d1b541b2da429e1d3fcfe9dd4c07a1f5bb71e829314
7
- data.tar.gz: 98e831a0ed6f811713b853878222d73730c73ea33f78814282efa98ca9c9cafd4d147cc4e7fc9c2bb8797ac4d9d7c22cd08e6a6cd5b482185b97fe2fc639bbc5
6
+ metadata.gz: f32d26356b9d0a6ed28015d47b64d4370c212d6eca3179a38685ad550ff9be89ddd6ea531eecb533165e09fc4684b81d66d71e9e3cca54397011df39855b10b9
7
+ data.tar.gz: 2faf0ca74f7f472d3c2316824a26e893c1b4fc2673992ad9f3ee7b5b7a7e5010c003c74676e58c6831ca023ad1c158ae7cbeac8c2f17591ab0d65b2c01abdead
data/Gemfile CHANGED
@@ -8,7 +8,7 @@ gem 'rb-fsevent', '~> 0.9.1'
8
8
  gem 'therubyracer'
9
9
 
10
10
  # Development
11
- # gem 'locomotivecms_steam', github: 'locomotivecms/steam', ref: '25e6852', require: false
11
+ # gem 'locomotivecms_steam', github: 'locomotivecms/steam', ref: '0aa777b', require: false
12
12
  # gem 'locomotivecms_coal', github: 'locomotivecms/coal', ref: '32b2844', require: false
13
13
  # gem 'locomotivecms_common', github: 'locomotivecms/common', ref: '3046b79893', require: false
14
14
 
@@ -346,15 +346,23 @@ module Locomotive
346
346
  end
347
347
  end
348
348
 
349
- desc 'destroy ENV [PATH]', 'Destroy a remote Locomotive site'
350
- def destroy(env, path = '.')
351
- if check_path!(path)
352
- if ask('Are you sure?', limited_to: %w(yes no)) == 'yes'
353
- Locomotive::Wagon.destroy(env, path)
354
- else
355
- say 'The destroy operation has been cancelled', :red
356
- exit(1)
357
- end
349
+ desc 'delete ENV RESOURCE [SLUG] [PATH]', 'Delete a resource from a remote Locomotive Engine.'
350
+ long_desc <<-LONGDESC
351
+ Deletes a site, page, content_type, snippet, theme_asset or translation from the remote Locomotive Engine.
352
+
353
+ It can also delete all the items of a resource if you pass: content_types, snippets, theme_assets or translations as the RESOURCE.
354
+
355
+ If you need to delete the whole site for the current ENV, just pass site as the RESOURCE.
356
+
357
+ RESOURCE can be set to site, page, content_type(s), snippet(s), theme_asset(s) or translation(s).
358
+ SLUG is the slug of the specific resource to delete
359
+ LONGDESC
360
+ def delete(env, resource, slug = nil, path = '.')
361
+ if ask('Are you sure?', limited_to: %w(yes no)) == 'yes'
362
+ Locomotive::Wagon.delete(env, path, resource, slug, shell)
363
+ else
364
+ say 'The delete operation has been cancelled', :red
365
+ exit(1)
358
366
  end
359
367
  end
360
368
 
@@ -44,6 +44,10 @@ module Locomotive::Wagon
44
44
  end
45
45
  end
46
46
 
47
+ def connection_information_from_env_and_path
48
+ read_deploy_settings(self.env, self.path)
49
+ end
50
+
47
51
  private
48
52
 
49
53
  def api_uri
@@ -0,0 +1,77 @@
1
+ require_relative 'concerns/api_concern'
2
+ require_relative 'concerns/deploy_file_concern'
3
+ require 'active_support/inflector'
4
+
5
+ module Locomotive::Wagon
6
+ class DeleteCommand < Struct.new(:env, :path, :resource, :identifier, :shell)
7
+
8
+ include ApiConcern
9
+ include DeployFileConcern
10
+
11
+ SITE_RESOURCE = 'site'
12
+ SINGLE_RESOURCES = %w(page content_type snippet translation).freeze
13
+ ALL_RESOURCES = %w(content_types snippets theme_assets translations).freeze
14
+
15
+ # @param [ String ] env The environment to delete from
16
+ # @param [ String ] path The path to a wagon site to delete from
17
+ # @param [ String ] resource The resource type to delete. @see RESOURCES
18
+ # @param [ String ] identifier The id or handle of the resource entry to delete
19
+ def self.delete(*args)
20
+ new(*args).delete
21
+ end
22
+
23
+ # @raise [ ArgumentError ] unless the given resources is in SINGLE_RESOURCES or MULTIPLE_RESOURCES
24
+ def delete
25
+ if resource == SITE_RESOURCE
26
+ delete_site
27
+ elsif SINGLE_RESOURCES.include?(resource)
28
+ delete_single
29
+ elsif ALL_RESOURCES.include?(resource)
30
+ delete_all
31
+ else
32
+ raise ArgumentError, "Resource must be one of #{SINGLE_RESOURCES.join(?,)} if you pass an identifier OR be one of #{ALL_RESOURCES.join(?,)} if you want to delete all the items of that resource."
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def delete_site
39
+ if shell.ask('Please, type the handle of your site') == client.options[:handle]
40
+ client.current_site.destroy.tap do |response|
41
+ shell.say "The remote site specified in your #{env} environment has been deleted.", :green
42
+ end
43
+ else
44
+ shell.say 'The delete operation has been cancelled', :red
45
+ end
46
+ end
47
+
48
+ def delete_single
49
+ client.send(resource_method).destroy(identifier).tap do |response|
50
+ shell.say "The #{identifier} #{singular_resource_method} has been deleted.", :green
51
+ end
52
+ end
53
+
54
+ def delete_all
55
+ client.send(resource_method).destroy_all.tap do |response|
56
+ shell.say "#{response['deletions']} #{resource_method} have been deleted", :green
57
+ end
58
+ end
59
+
60
+ def resource_method
61
+ @resource_method ||= resource.pluralize
62
+ end
63
+
64
+ def singular_resource_method
65
+ @resource_method.singularize
66
+ end
67
+
68
+ def current_site
69
+ @current_site ||= client.current_site
70
+ end
71
+
72
+ def client
73
+ @api_site_client ||= api_site_client(connection_information_from_env_and_path)
74
+ end
75
+
76
+ end
77
+ end
@@ -37,6 +37,7 @@ module Locomotive::Wagon
37
37
 
38
38
  def _pull
39
39
  api_client = api_site_client(connection_information)
40
+
40
41
  site = api_client.current_site.get
41
42
 
42
43
  each_resource do |klass|
@@ -42,7 +42,7 @@ module Locomotive::Wagon
42
42
  folder, ext = File.dirname(filepath), File.extname(filepath)
43
43
  basename = File.basename(filepath, ext)
44
44
 
45
- find_unique_filepath(File.join(folder, "#{basename}-#{index}#{ext}"), binary, index + 1)
45
+ find_unique_filepath(File.join(folder, "#{basename}-#{index}#{ext}"), binary_file, index + 1)
46
46
  else
47
47
  filepath
48
48
  end
@@ -31,27 +31,29 @@ module Locomotive::Wagon
31
31
  end
32
32
 
33
33
  def push
34
+ require_misc_gems
35
+
36
+ api_client = build_api_site_client(connection_information)
37
+
34
38
  if options[:verbose]
35
39
  PushLogger.new
36
- _push
40
+ _push(api_client)
37
41
  else
38
- show_wait_spinner('Deploying...') { _push }
42
+ show_wait_spinner('Deploying...') { _push(api_client) }
39
43
  end
40
44
  end
41
45
 
42
46
  private
43
47
 
44
- def _push
45
- require_misc_gems
46
-
47
- api_client = build_api_site_client(connection_information)
48
-
48
+ def _push(api_client)
49
49
  validate!
50
50
 
51
51
  content_assets_pusher = Locomotive::Wagon::PushContentAssetsCommand.new(api_client, steam_services)
52
52
 
53
53
  each_resource do |klass|
54
- klass.push(api_client, steam_services, content_assets_pusher, remote_site)
54
+ klass.push(api_client, steam_services, content_assets_pusher, remote_site) do |pusher|
55
+ pusher.with_data if options[:data]
56
+ end
55
57
  end
56
58
 
57
59
  print_result_message
@@ -7,7 +7,9 @@ module Locomotive::Wagon
7
7
  def_delegators :steam_services, :current_site, :locale, :repositories
8
8
 
9
9
  def self.push(api_client, steam_services, content_assets_pusher, remote_site)
10
- new(api_client, steam_services, content_assets_pusher, remote_site).push
10
+ instance = new(api_client, steam_services, content_assets_pusher, remote_site)
11
+ yield instance if block_given?
12
+ instance.push
11
13
  end
12
14
 
13
15
  def push
@@ -61,6 +63,14 @@ module Locomotive::Wagon
61
63
  File.expand_path(repositories.adapter.options[:path])
62
64
  end
63
65
 
66
+ def with_data
67
+ @with_data = true
68
+ end
69
+
70
+ def with_data?
71
+ !!@with_data
72
+ end
73
+
64
74
  class SkipPersistingException < Exception
65
75
  end
66
76
 
@@ -39,7 +39,8 @@ module Locomotive::Wagon
39
39
  private
40
40
 
41
41
  def _decorate(entity)
42
- PageDecorator.new(entity, default_locale, content_assets_pusher, remote_site.edited?)
42
+ persist_content = with_data? || !remote_site.edited?
43
+ PageDecorator.new(entity, default_locale, content_assets_pusher, persist_content)
43
44
  end
44
45
 
45
46
  def remote_entity_id(fullpath)
@@ -39,6 +39,7 @@ module Locomotive::Wagon
39
39
 
40
40
  def _sync
41
41
  api_client = api_site_client(connection_information)
42
+
42
43
  site = api_client.current_site.get
43
44
 
44
45
  each_resource do |klass|
@@ -87,8 +87,15 @@ module Locomotive
87
87
  end
88
88
 
89
89
  def decorate_many_to_many_field(value)
90
- return nil if value.nil?
91
- value.all.map { |entry| entry._slug.try(:[], __locale__) }.compact
90
+ entries = value.all
91
+
92
+ if entries.empty?
93
+ nil
94
+ elsif entries.size == 1 && entries.first == ''
95
+ [nil]
96
+ else
97
+ entries.map { |entry| entry._slug.try(:[], __locale__) }.compact
98
+ end.tap { |o| puts o.inspect }
92
99
  end
93
100
 
94
101
  def decorate_has_many_field(value)
@@ -6,11 +6,11 @@ module Locomotive
6
6
  include ToHashConcern
7
7
  include PersistAssetsConcern
8
8
 
9
- attr_accessor :__content_assets_pusher__, :__site_edited__
9
+ attr_accessor :__content_assets_pusher__, :__persist_content__
10
10
 
11
- def initialize(object, locale = nil, content_assets_pusher, site_edited)
11
+ def initialize(object, locale = nil, content_assets_pusher, persist_content)
12
12
  self.__content_assets_pusher__ = content_assets_pusher
13
- self.__site_edited__ = site_edited
13
+ self.__persist_content__ = persist_content
14
14
  super(object, locale, nil)
15
15
  end
16
16
 
@@ -26,7 +26,7 @@ module Locomotive
26
26
  template)
27
27
 
28
28
  # remove the attributes that end-users might have modified in the back-office
29
- if persisted? && __site_edited__
29
+ if persisted? && !__persist_content__
30
30
  _attributes -= %i(title published listed position seo_title meta_keywords meta_description editable_elements)
31
31
  end
32
32
 
@@ -1,5 +1,5 @@
1
1
  module Locomotive
2
2
  module Wagon
3
- VERSION = '2.0.0.rc4'
3
+ VERSION = '2.0.0.rc5'
4
4
  end
5
5
  end
@@ -109,15 +109,15 @@ module Locomotive
109
109
  Locomotive::Wagon::CloneCommand.clone(name, path, options, shell)
110
110
  end
111
111
 
112
- # Destroy a remote site
112
+ # Delete one or all remote resource(s)
113
113
  #
114
114
  # @param [ String ] env The environment we use to deploy the site to
115
115
  # @param [ String ] path The path of the site
116
- # @param [ Hash ] options The options passed to the destroy command
117
- #
118
- def self.destroy(env, path, options = {})
119
- require_relative 'wagon/commands/destroy_command'
120
- Locomotive::Wagon::DestroyCommand.destroy(env, path, options)
116
+ # @param [ String ] resource The resource from which we want to delete an entry or all entries
117
+ # @param [ String ] slug The slug of the resource to delete
118
+ def self.delete(env, path, resource, slug, shell)
119
+ require_relative 'wagon/commands/delete_command'
120
+ Locomotive::Wagon::DeleteCommand.delete(env, path, resource, slug, shell)
121
121
  end
122
122
 
123
123
  end
@@ -27,8 +27,8 @@ Gem::Specification.new do |gem|
27
27
  gem.add_dependency 'netrc', '~> 0.10.3'
28
28
 
29
29
  gem.add_dependency 'locomotivecms_common', '~> 0.0.5'
30
- gem.add_dependency 'locomotivecms_coal', '~> 1.0.0.rc2'
31
- gem.add_dependency 'locomotivecms_steam', '~> 1.0.0.rc6'
30
+ gem.add_dependency 'locomotivecms_coal', '~> 1.0.0.rc3'
31
+ gem.add_dependency 'locomotivecms_steam', '~> 1.0.0.rc7'
32
32
 
33
33
  gem.add_dependency 'listen', '~> 3.0.4'
34
34
  gem.add_dependency 'rack-livereload', '~> 0.3.16'
@@ -27,16 +27,16 @@ http_interactions:
27
27
  Cache-Control:
28
28
  - no-cache
29
29
  X-Request-Id:
30
- - 696238a9-e3ed-46c9-a3b0-fbcddc5dc502
30
+ - 1eeb9688-e4f0-4a25-8bbb-8f79f152e003
31
31
  X-Runtime:
32
- - '0.385558'
32
+ - '0.019606'
33
33
  Content-Length:
34
34
  - '40'
35
35
  body:
36
36
  encoding: UTF-8
37
37
  string: '{"message":"Invalid email or password."}'
38
38
  http_version:
39
- recorded_at: Sun, 22 Nov 2015 22:41:27 GMT
39
+ recorded_at: Fri, 04 Dec 2015 14:21:16 GMT
40
40
  - request:
41
41
  method: post
42
42
  uri: http://localhost:3000/locomotive/api/v3/my_account.json
@@ -60,20 +60,20 @@ http_interactions:
60
60
  Content-Type:
61
61
  - application/json
62
62
  Etag:
63
- - W/"74b2d44bf497a9fd738cca489f42fbb9"
63
+ - W/"7d05e74769a4e3a32ddc19de535ace0d"
64
64
  Cache-Control:
65
65
  - max-age=0, private, must-revalidate
66
66
  X-Request-Id:
67
- - 0f51511a-bd18-4e25-b445-1c417705be82
67
+ - 14d9561a-97bf-4b9f-adad-488353d1dc13
68
68
  X-Runtime:
69
- - '0.080074'
69
+ - '0.070429'
70
70
  Content-Length:
71
71
  - '250'
72
72
  body:
73
73
  encoding: UTF-8
74
- string: '{"_id":"56524497c36511cdf8000000","created_at":"2015-11-22T22:41:27Z","updated_at":"2015-11-22T22:41:27Z","name":"John","email":"john@doe.net","locale":"en","api_key":"5c57cd2719be65bf16693465814086c461304f27","super_admin":false,"local_admin":false}'
74
+ string: '{"_id":"5661a15c87f64302c9000043","created_at":"2015-12-04T14:21:16Z","updated_at":"2015-12-04T14:21:16Z","name":"John","email":"john@doe.net","locale":"en","api_key":"bebc2256830ef12eae85623a39158267e12e49c3","super_admin":false,"local_admin":false}'
75
75
  http_version:
76
- recorded_at: Sun, 22 Nov 2015 22:41:27 GMT
76
+ recorded_at: Fri, 04 Dec 2015 14:21:16 GMT
77
77
  - request:
78
78
  method: post
79
79
  uri: http://localhost:3000/locomotive/api/v3/tokens.json
@@ -97,23 +97,23 @@ http_interactions:
97
97
  Content-Type:
98
98
  - application/json
99
99
  Etag:
100
- - W/"3385da6413addda803c3126c1b4554b3"
100
+ - W/"9ad33576c3616b662c8993aff5fb3c0e"
101
101
  Cache-Control:
102
102
  - max-age=0, private, must-revalidate
103
103
  X-Request-Id:
104
- - afa7856b-4434-4526-b547-a84bd3ba5f42
104
+ - 03f2dcd0-5c95-4859-b556-dd95643dbc07
105
105
  X-Runtime:
106
- - '0.016850'
106
+ - '0.018220'
107
107
  Content-Length:
108
108
  - '32'
109
109
  body:
110
110
  encoding: UTF-8
111
- string: '{"token":"RTjjUayPdSpdSFfKVGja"}'
111
+ string: '{"token":"N-ddi-7z-19pXmkRRgq_"}'
112
112
  http_version:
113
- recorded_at: Sun, 22 Nov 2015 22:41:27 GMT
113
+ recorded_at: Fri, 04 Dec 2015 14:21:16 GMT
114
114
  - request:
115
115
  method: get
116
- uri: http://localhost:3000/locomotive/api/v3/my_account.json?auth_token=RTjjUayPdSpdSFfKVGja
116
+ uri: http://localhost:3000/locomotive/api/v3/my_account.json?auth_token=N-ddi-7z-19pXmkRRgq_
117
117
  body:
118
118
  encoding: US-ASCII
119
119
  string: ''
@@ -123,7 +123,7 @@ http_interactions:
123
123
  X-Locomotive-Account-Email:
124
124
  - admin@locomotivecms.com
125
125
  X-Locomotive-Account-Token:
126
- - RTjjUayPdSpdSFfKVGja
126
+ - N-ddi-7z-19pXmkRRgq_
127
127
  Accept-Encoding:
128
128
  - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
129
129
  User-Agent:
@@ -136,23 +136,23 @@ http_interactions:
136
136
  Content-Type:
137
137
  - application/json
138
138
  Etag:
139
- - W/"53f74d6bf74667cd139e3766f9cda048"
139
+ - W/"46c8dfee2ff366b7a6ec27cea9505afb"
140
140
  Cache-Control:
141
141
  - max-age=0, private, must-revalidate
142
142
  X-Request-Id:
143
- - fd5d04d4-cad6-469e-8fe8-89fd61802def
143
+ - b43a45a2-0e95-4f9a-8abf-39b098fc98fc
144
144
  X-Runtime:
145
- - '0.034500'
145
+ - '0.028692'
146
146
  Content-Length:
147
147
  - '261'
148
148
  body:
149
149
  encoding: UTF-8
150
- string: '{"_id":"56524484c36511cdd5000000","created_at":"2015-11-22T22:41:08Z","updated_at":"2015-11-22T22:41:08Z","name":"Admin","email":"admin@locomotivecms.com","locale":"en","api_key":"d49cd50f6f0d2b163f48fc73cb249f0244c37074","super_admin":false,"local_admin":true}'
150
+ string: '{"_id":"5661a14f87f643077a000000","created_at":"2015-12-04T14:21:03Z","updated_at":"2015-12-04T14:21:03Z","name":"Admin","email":"admin@locomotivecms.com","locale":"en","api_key":"d49cd50f6f0d2b163f48fc73cb249f0244c37074","super_admin":false,"local_admin":true}'
151
151
  http_version:
152
- recorded_at: Sun, 22 Nov 2015 22:41:27 GMT
152
+ recorded_at: Fri, 04 Dec 2015 14:21:16 GMT
153
153
  - request:
154
154
  method: get
155
- uri: http://localhost:3000/locomotive/api/v3/my_account.json?auth_token=RTjjUayPdSpdSFfKVGja
155
+ uri: http://localhost:3000/locomotive/api/v3/my_account.json?auth_token=N-ddi-7z-19pXmkRRgq_
156
156
  body:
157
157
  encoding: US-ASCII
158
158
  string: ''
@@ -162,7 +162,7 @@ http_interactions:
162
162
  X-Locomotive-Account-Email:
163
163
  - admin@locomotivecms.com
164
164
  X-Locomotive-Account-Token:
165
- - RTjjUayPdSpdSFfKVGja
165
+ - N-ddi-7z-19pXmkRRgq_
166
166
  Accept-Encoding:
167
167
  - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
168
168
  User-Agent:
@@ -175,18 +175,18 @@ http_interactions:
175
175
  Content-Type:
176
176
  - application/json
177
177
  Etag:
178
- - W/"53f74d6bf74667cd139e3766f9cda048"
178
+ - W/"46c8dfee2ff366b7a6ec27cea9505afb"
179
179
  Cache-Control:
180
180
  - max-age=0, private, must-revalidate
181
181
  X-Request-Id:
182
- - 7da8b735-01ee-4549-9d81-da3281957b25
182
+ - a6cc68eb-4757-4dc3-a9ca-bb2652068468
183
183
  X-Runtime:
184
- - '0.018901'
184
+ - '0.017889'
185
185
  Content-Length:
186
186
  - '261'
187
187
  body:
188
188
  encoding: UTF-8
189
- string: '{"_id":"56524484c36511cdd5000000","created_at":"2015-11-22T22:41:08Z","updated_at":"2015-11-22T22:41:08Z","name":"Admin","email":"admin@locomotivecms.com","locale":"en","api_key":"d49cd50f6f0d2b163f48fc73cb249f0244c37074","super_admin":false,"local_admin":true}'
189
+ string: '{"_id":"5661a14f87f643077a000000","created_at":"2015-12-04T14:21:03Z","updated_at":"2015-12-04T14:21:03Z","name":"Admin","email":"admin@locomotivecms.com","locale":"en","api_key":"d49cd50f6f0d2b163f48fc73cb249f0244c37074","super_admin":false,"local_admin":true}'
190
190
  http_version:
191
- recorded_at: Sun, 22 Nov 2015 22:41:27 GMT
191
+ recorded_at: Fri, 04 Dec 2015 14:21:16 GMT
192
192
  recorded_with: VCR 2.9.3