locomotivecms_wagon 1.5.8 → 2.0.0.pre.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -1
- data/.rspec +0 -1
- data/Gemfile +17 -2
- data/README.md +2 -6
- data/Rakefile +3 -20
- data/lib/locomotive/wagon/cli.rb +34 -39
- data/lib/locomotive/wagon/commands/authenticate_command.rb +65 -0
- data/lib/locomotive/wagon/commands/concerns/api_concern.rb +57 -0
- data/lib/locomotive/wagon/commands/concerns/deploy_file_concern.rb +32 -0
- data/lib/locomotive/wagon/commands/concerns/instrumentation_concern.rb +16 -0
- data/lib/locomotive/wagon/commands/concerns/netrc_concern.rb +21 -0
- data/lib/locomotive/wagon/commands/concerns/steam_concern.rb +24 -0
- data/lib/locomotive/wagon/commands/generate_command.rb +29 -0
- data/lib/locomotive/wagon/commands/init_command.rb +19 -0
- data/lib/locomotive/wagon/commands/loggers/push_logger.rb +59 -0
- data/lib/locomotive/wagon/commands/push_command.rb +116 -0
- data/lib/locomotive/wagon/commands/push_sub_commands/push_base_command.rb +68 -0
- data/lib/locomotive/wagon/commands/push_sub_commands/push_content_assets_command.rb +54 -0
- data/lib/locomotive/wagon/commands/push_sub_commands/push_content_entries_command.rb +85 -0
- data/lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb +70 -0
- data/lib/locomotive/wagon/commands/push_sub_commands/push_pages_command.rb +71 -0
- data/lib/locomotive/wagon/commands/push_sub_commands/push_snippets_command.rb +23 -0
- data/lib/locomotive/wagon/commands/push_sub_commands/push_theme_assets_command.rb +70 -0
- data/lib/locomotive/wagon/commands/push_sub_commands/push_translations_command.rb +23 -0
- data/lib/locomotive/wagon/commands/serve_command.rb +131 -0
- data/lib/locomotive/wagon/decorators/concerns/persist_assets_concern.rb +20 -0
- data/lib/locomotive/wagon/decorators/concerns/to_hash_concern.rb +25 -0
- data/lib/locomotive/wagon/decorators/content_asset_decorator.rb +29 -0
- data/lib/locomotive/wagon/decorators/content_entry_decorator.rb +100 -0
- data/lib/locomotive/wagon/decorators/content_type_decorator.rb +78 -0
- data/lib/locomotive/wagon/decorators/content_type_field_decorator.rb +76 -0
- data/lib/locomotive/wagon/decorators/editable_element_decorator.rb +32 -0
- data/lib/locomotive/wagon/decorators/page_decorator.rb +81 -0
- data/lib/locomotive/wagon/decorators/site_decorator.rb +25 -0
- data/lib/locomotive/wagon/decorators/snippet_decorator.rb +29 -0
- data/lib/locomotive/wagon/decorators/theme_asset_decorator.rb +53 -0
- data/lib/locomotive/wagon/decorators/translation_decorator.rb +19 -0
- data/lib/locomotive/wagon/exceptions.rb +3 -55
- data/lib/locomotive/wagon/generators/site/unzip.rb +2 -2
- data/lib/locomotive/wagon/tools/deployment_connection.rb +120 -0
- data/lib/locomotive/wagon/tools/hosting_api.rb +117 -0
- data/lib/locomotive/wagon/tools/listen.rb +51 -0
- data/lib/locomotive/wagon/{misc → tools}/livereload.rb +5 -3
- data/lib/locomotive/wagon/{misc → tools}/tcp_port.rb +0 -0
- data/lib/locomotive/wagon/{misc → tools}/thor.rb +0 -0
- data/lib/locomotive/wagon/version.rb +1 -1
- data/lib/locomotive/wagon.rb +34 -162
- data/locomotivecms_wagon.gemspec +11 -24
- data/spec/fixtures/cassettes/authenticate.yml +425 -0
- data/spec/fixtures/cassettes/push.yml +34737 -0
- data/spec/fixtures/default/app/views/pages/events.liquid.haml +2 -1
- data/spec/fixtures/default/app/views/pages/index.liquid.haml +3 -2
- data/spec/fixtures/default/app/views/pages/layouts/simple.liquid.haml +1 -1
- data/spec/fixtures/default/app/views/snippets/footer.liquid.haml +1 -1
- data/spec/fixtures/default/app/views/snippets/song.liquid +3 -3
- data/spec/fixtures/default/config/site.yml +2 -4
- data/spec/fixtures/default/data/events.yml +3 -2
- data/spec/fixtures/default/data/songs.yml +1 -1
- data/spec/integration/cli_spec.rb +35 -12
- data/spec/integration/commands/authenticate_command_spec.rb +60 -0
- data/spec/integration/commands/push_command_spec.rb +55 -0
- data/spec/integration/generators/page_spec.rb +9 -9
- data/spec/integration/generators/relationship_spec.rb +6 -6
- data/spec/integration/integration_helper.rb +11 -11
- data/spec/integration/sites_spec.rb +48 -48
- data/spec/spec_helper.rb +3 -4
- data/spec/support/api_settings.rb +5 -0
- data/spec/support/helpers.rb +6 -19
- data/spec/support/pry.rb +4 -0
- data/spec/support/thor.rb +12 -0
- data/spec/support/vcr.rb +10 -0
- data/spec/unit/decorators/site_decorator_spec.rb +36 -0
- metadata +88 -309
- data/lib/locomotive/wagon/liquid/drops/base.rb +0 -49
- data/lib/locomotive/wagon/liquid/drops/content_entry.rb +0 -49
- data/lib/locomotive/wagon/liquid/drops/content_types.rb +0 -119
- data/lib/locomotive/wagon/liquid/drops/page.rb +0 -84
- data/lib/locomotive/wagon/liquid/drops/session_proxy.rb +0 -18
- data/lib/locomotive/wagon/liquid/drops/site.rb +0 -26
- data/lib/locomotive/wagon/liquid/errors.rb +0 -17
- data/lib/locomotive/wagon/liquid/filters/date.rb +0 -136
- data/lib/locomotive/wagon/liquid/filters/html.rb +0 -188
- data/lib/locomotive/wagon/liquid/filters/misc.rb +0 -49
- data/lib/locomotive/wagon/liquid/filters/resize.rb +0 -18
- data/lib/locomotive/wagon/liquid/filters/text.rb +0 -55
- data/lib/locomotive/wagon/liquid/filters/translate.rb +0 -28
- data/lib/locomotive/wagon/liquid/patches.rb +0 -47
- data/lib/locomotive/wagon/liquid/scopeable.rb +0 -151
- data/lib/locomotive/wagon/liquid/tags/consume.rb +0 -100
- data/lib/locomotive/wagon/liquid/tags/csrf.rb +0 -34
- data/lib/locomotive/wagon/liquid/tags/editable/base.rb +0 -50
- data/lib/locomotive/wagon/liquid/tags/editable/control.rb +0 -19
- data/lib/locomotive/wagon/liquid/tags/editable/file.rb +0 -15
- data/lib/locomotive/wagon/liquid/tags/editable/long_text.rb +0 -15
- data/lib/locomotive/wagon/liquid/tags/editable/short_text.rb +0 -20
- data/lib/locomotive/wagon/liquid/tags/editable/text.rb +0 -15
- data/lib/locomotive/wagon/liquid/tags/editable.rb +0 -6
- data/lib/locomotive/wagon/liquid/tags/extends.rb +0 -25
- data/lib/locomotive/wagon/liquid/tags/fetch_page.rb +0 -41
- data/lib/locomotive/wagon/liquid/tags/google_analytics.rb +0 -28
- data/lib/locomotive/wagon/liquid/tags/hybrid.rb +0 -27
- data/lib/locomotive/wagon/liquid/tags/inline_editor.rb +0 -16
- data/lib/locomotive/wagon/liquid/tags/link_to.rb +0 -56
- data/lib/locomotive/wagon/liquid/tags/locale_switcher.rb +0 -106
- data/lib/locomotive/wagon/liquid/tags/model_form.rb +0 -67
- data/lib/locomotive/wagon/liquid/tags/nav.rb +0 -287
- data/lib/locomotive/wagon/liquid/tags/paginate.rb +0 -105
- data/lib/locomotive/wagon/liquid/tags/path_helper.rb +0 -97
- data/lib/locomotive/wagon/liquid/tags/path_to.rb +0 -36
- data/lib/locomotive/wagon/liquid/tags/seo.rb +0 -74
- data/lib/locomotive/wagon/liquid/tags/session_assign.rb +0 -41
- data/lib/locomotive/wagon/liquid/tags/snippet.rb +0 -63
- data/lib/locomotive/wagon/liquid/tags/with_scope.rb +0 -48
- data/lib/locomotive/wagon/liquid.rb +0 -21
- data/lib/locomotive/wagon/listen.rb +0 -65
- data/lib/locomotive/wagon/logger.rb +0 -58
- data/lib/locomotive/wagon/misc/better_errors.rb +0 -70
- data/lib/locomotive/wagon/misc/core_ext.rb +0 -62
- data/lib/locomotive/wagon/misc/deployment_connection.rb +0 -120
- data/lib/locomotive/wagon/misc/dragonfly.rb +0 -78
- data/lib/locomotive/wagon/misc/haml.rb +0 -15
- data/lib/locomotive/wagon/misc/hosting_api.rb +0 -117
- data/lib/locomotive/wagon/misc/httparty.rb +0 -55
- data/lib/locomotive/wagon/misc/i18n.rb +0 -2
- data/lib/locomotive/wagon/misc/markdown.rb +0 -27
- data/lib/locomotive/wagon/misc/mounter.rb +0 -32
- data/lib/locomotive/wagon/misc/will_paginate.rb +0 -16
- data/lib/locomotive/wagon/misc.rb +0 -9
- data/lib/locomotive/wagon/server/dynamic_assets.rb +0 -33
- data/lib/locomotive/wagon/server/entry_submission.rb +0 -151
- data/lib/locomotive/wagon/server/favicon.rb +0 -17
- data/lib/locomotive/wagon/server/locale.rb +0 -42
- data/lib/locomotive/wagon/server/logging.rb +0 -32
- data/lib/locomotive/wagon/server/middleware.rb +0 -63
- data/lib/locomotive/wagon/server/page.rb +0 -67
- data/lib/locomotive/wagon/server/path.rb +0 -34
- data/lib/locomotive/wagon/server/renderer.rb +0 -118
- data/lib/locomotive/wagon/server/templatized_page.rb +0 -32
- data/lib/locomotive/wagon/server/timezone.rb +0 -18
- data/lib/locomotive/wagon/server.rb +0 -86
- data/lib/locomotive/wagon/standalone_server.rb +0 -28
- data/locales/de.yml +0 -157
- data/locales/en.yml +0 -189
- data/locales/es.yml +0 -133
- data/locales/et.yml +0 -154
- data/locales/fr.yml +0 -148
- data/locales/it.yml +0 -155
- data/locales/nb.yml +0 -191
- data/locales/nl.yml +0 -160
- data/locales/pl.yml +0 -203
- data/locales/pt-BR.yml +0 -139
- data/locales/ru.yml +0 -224
- data/spec/integration/server/basic_spec.rb +0 -169
- data/spec/integration/server/contact_form_spec.rb +0 -111
- data/spec/integration/server/liquid_spec.rb +0 -98
- data/spec/integration/server/new_contact_form_spec.rb +0 -67
- data/spec/integration/server/with_scope_spec.rb +0 -30
- data/spec/unit/locomotive/wagon/liquid/drops/page_spec.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 739043b4c31b8face271da2d37048fcc126cc8ca
|
4
|
+
data.tar.gz: 5d10493f0944c8d441532881ff2347ff680e7d0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 124f103b49617bc7f6185945dbe753259bc19ce350d6e9ba5a5bd44436508e4258a2f54739163d2821952d58df623b705f4c3aba1bcaf294ca97245106ab738c
|
7
|
+
data.tar.gz: 96f069b17d7d062dd831cc5580a525b53a24e2be3ae40c345989ddd20398a5e04335159a9d90b9fa17916b8bf261557001373f1b1d47488adefb206fc8ce718f
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/Gemfile
CHANGED
@@ -13,7 +13,22 @@ gem 'rb-fsevent', '~> 0.9.1'
|
|
13
13
|
|
14
14
|
gem 'therubyracer'
|
15
15
|
|
16
|
+
# gem 'locomotivecms_steam', github: 'locomotivecms/steam', ref: 'b2de77e', require: false
|
17
|
+
# gem 'locomotivecms_coal', github: 'locomotivecms/coal', ref: '32b2844', require: false
|
18
|
+
# gem 'locomotivecms_common', github: 'locomotivecms/common', ref: '3046b79893', require: false
|
19
|
+
|
20
|
+
# gem 'locomotivecms_coal', path: '../in_progress/coal', require: false
|
21
|
+
# gem 'locomotivecms_steam', path: '../in_progress/steam', require: false
|
22
|
+
# gem 'locomotivecms_common', path: '../in_progress/common', require: false
|
23
|
+
|
16
24
|
group :test do
|
17
|
-
gem '
|
18
|
-
gem '
|
25
|
+
gem 'rspec', '~> 3.2.0'
|
26
|
+
gem 'json_spec', '~> 1.1.4'
|
27
|
+
|
28
|
+
gem 'pry-byebug', '~> 3.1.0'
|
29
|
+
|
30
|
+
gem 'webmock'
|
31
|
+
gem 'vcr'
|
32
|
+
|
33
|
+
gem 'coveralls', '~> 0.7.11', require: false
|
19
34
|
end
|
data/README.md
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
# LocomotiveCMS::Wagon
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/locomotivecms_wagon.svg)](http://badge.fury.io/rb/locomotivecms_wagon)
|
4
|
-
[![Code Climate](https://codeclimate.com/github/locomotivecms/wagon.png)](https://codeclimate.com/github/locomotivecms/wagon)
|
5
|
-
[![Dependency Status](https://gemnasium.com/locomotivecms/wagon.png)](https://gemnasium.com/locomotivecms/wagon)
|
6
|
-
[![Build Status](https://travis-ci.org/locomotivecms/wagon.svg?branch=master)](https://travis-ci.org/locomotivecms/wagon)
|
7
|
-
[![Coverage Status](https://coveralls.io/repos/locomotivecms/wagon/badge.png)](https://coveralls.io/r/locomotivecms/wagon)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/locomotivecms_wagon.svg)](http://badge.fury.io/rb/locomotivecms_wagon) [![Code Climate](https://codeclimate.com/github/locomotivecms/wagon/badges/gpa.svg)](https://codeclimate.com/github/locomotivecms/wagon) [![Dependency Status](https://gemnasium.com/locomotivecms/wagon.png)](https://gemnasium.com/locomotivecms/wagon) [![Build Status](https://travis-ci.org/locomotivecms/wagon.svg?branch=master)](https://travis-ci.org/locomotivecms/wagon) [![Coverage Status](https://coveralls.io/repos/locomotivecms/wagon/badge.svg?branch=master)](https://coveralls.io/r/locomotivecms/wagon?branch=master)
|
8
4
|
|
9
5
|
Wagon is the official site generator for the LocomotiveCMS engine powered by all the efficient and modern HTML development tools (Haml, SASS, Compass, Less).
|
10
6
|
|
@@ -37,7 +33,7 @@ Please, visit the documentation website of LocomotiveCMS.
|
|
37
33
|
|
38
34
|
#### Run the server with a default site
|
39
35
|
|
40
|
-
$ bundle exec bin/wagon serve
|
36
|
+
$ bundle exec bin/wagon serve spec/fixtures/default
|
41
37
|
|
42
38
|
#### Push a site
|
43
39
|
|
data/Rakefile
CHANGED
@@ -25,23 +25,8 @@ task release: :gem do
|
|
25
25
|
sh "gem push pkg/locomotivecms_wagon-#{gemspec.version}.gem"
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
task :bootstrap do
|
31
|
-
VCR.configure do |c|
|
32
|
-
c.cassette_library_dir = File.expand_path(File.dirname(__FILE__) + '/spec/integration/cassettes')
|
33
|
-
c.hook_into :webmock # or :fakeweb
|
34
|
-
c.allow_http_connections_when_no_cassette = true
|
35
|
-
end
|
36
|
-
|
37
|
-
FileUtils.rm_rf(File.join(File.dirname(__FILE__), 'site'))
|
38
|
-
VCR.use_cassette('pull') do
|
39
|
-
exit unless Locomotive::Wagon.clone('site', '.', { host: 'sample.example.com:3000', email: 'admin@locomotivecms.com', password: 'locomotive' })
|
40
|
-
end
|
41
|
-
|
42
|
-
Locomotive::Wagon.push('site', {host: 'sample.example.com:3000', email: 'admin@locomotivecms.com', password: 'locomotive'}, force: true, translations: false, data: true)
|
43
|
-
end
|
44
|
-
end
|
28
|
+
require 'rspec/core/rake_task'
|
29
|
+
RSpec::Core::RakeTask.new('spec')
|
45
30
|
|
46
31
|
RSpec::Core::RakeTask.new('spec:unit') do |spec|
|
47
32
|
spec.pattern = 'spec/unit/**/*_spec.rb'
|
@@ -52,6 +37,4 @@ RSpec::Core::RakeTask.new('spec:integration') do |spec|
|
|
52
37
|
spec.pattern = 'spec/integration/**/*_spec.rb'
|
53
38
|
end
|
54
39
|
|
55
|
-
task
|
56
|
-
|
57
|
-
task default: :spec
|
40
|
+
task default: :spec
|
data/lib/locomotive/wagon/cli.rb
CHANGED
@@ -177,14 +177,16 @@ module Locomotive
|
|
177
177
|
say Locomotive::Wagon::VERSION
|
178
178
|
end
|
179
179
|
|
180
|
-
desc 'auth [EMAIL] [PASSWORD]', 'Log into
|
181
|
-
def auth(email = nil, password = nil)
|
182
|
-
say "
|
180
|
+
desc 'auth [EMAIL] [PASSWORD] [PLATFORM_URL]', 'Log into your Locomotive platform'
|
181
|
+
def auth(email = nil, password = nil, platform_url = nil)
|
182
|
+
say "Locomotive Sign in/up\n\n", :bold
|
183
183
|
|
184
|
-
|
185
|
-
|
184
|
+
platform_url ||= ask("Enter the URL of your platform? (default: #{Locomotive::Wagon::DEFAULT_PLATFORM_URL})")
|
185
|
+
platform_url = Locomotive::Wagon::DEFAULT_PLATFORM_URL if platform_url.strip == ''
|
186
|
+
while email.to_s.strip == ''; email = ask('Enter your e-mail?'); end
|
187
|
+
while password.to_s.strip == ''; password = ask('Enter your password?', echo: false); end
|
186
188
|
|
187
|
-
Locomotive::Wagon.authenticate(email, password, shell)
|
189
|
+
Locomotive::Wagon.authenticate(platform_url, email, password, shell)
|
188
190
|
end
|
189
191
|
|
190
192
|
desc 'init NAME [PATH] [GENERATOR_OPTIONS]', 'Create a brand new site'
|
@@ -297,24 +299,17 @@ module Locomotive
|
|
297
299
|
|
298
300
|
desc 'push ENV [PATH]', 'Push a site to a remote LocomotiveCMS Engine'
|
299
301
|
method_option :resources, aliases: '-r', type: 'array', default: nil, desc: 'Only push the resource(s) passed in argument'
|
300
|
-
method_option :force, aliases: '-f', type: 'boolean', default: false, desc: 'Force the push of a resource'
|
301
|
-
method_option :translations, aliases: '-t', type: 'boolean', default: false, desc: 'Push the local translations (by default, they are not)'
|
302
302
|
method_option :data, aliases: '-d', type: 'boolean', default: false, desc: 'Push the content entries and the editable elements (by default, they are not)'
|
303
|
-
method_option :only_resource, aliases: '-o', type: 'array', default: [], desc: 'Push only the resources whose slug / fullpath matches the list of strings passed in argument'
|
304
303
|
method_option :shell, type: 'boolean', default: true, desc: 'Use shell to ask for missing connection information like the subdomain (in this case, take a random one)'
|
305
304
|
method_option :verbose, aliases: '-v', type: 'boolean', default: false, desc: 'display the full error stack trace if an error occurs'
|
306
305
|
def push(env, path = '.')
|
307
306
|
force_color_if_asked(options)
|
308
307
|
|
309
308
|
if check_path!(path)
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
self.print_exception(e, options[:verbose])
|
315
|
-
exit(1)
|
316
|
-
end
|
317
|
-
else
|
309
|
+
begin
|
310
|
+
Locomotive::Wagon.push(env, path, options)
|
311
|
+
rescue Exception => e
|
312
|
+
self.print_exception(e, options[:verbose])
|
318
313
|
exit(1)
|
319
314
|
end
|
320
315
|
end
|
@@ -381,28 +376,28 @@ module Locomotive
|
|
381
376
|
end
|
382
377
|
end
|
383
378
|
|
384
|
-
# From a site specified by a path, retrieve the information of the connection
|
385
|
-
# for a environment located in the config/deploy.yml file of the site.
|
386
|
-
#
|
387
|
-
# @param [ String ] env The environment (development, staging, production, ...etc)
|
388
|
-
# @param [ String ] path The path of the local site
|
389
|
-
# @param [ Boolean ] use_shell True by default, use it to ask for missing information (subdomain for instance)
|
390
|
-
#
|
391
|
-
# @return [ Hash ] The information of the connection or nil if errors
|
392
|
-
#
|
393
|
-
def retrieve_connection_info(env, path, use_shell = true)
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
end
|
379
|
+
# # From a site specified by a path, retrieve the information of the connection
|
380
|
+
# # for a environment located in the config/deploy.yml file of the site.
|
381
|
+
# #
|
382
|
+
# # @param [ String ] env The environment (development, staging, production, ...etc)
|
383
|
+
# # @param [ String ] path The path of the local site
|
384
|
+
# # @param [ Boolean ] use_shell True by default, use it to ask for missing information (subdomain for instance)
|
385
|
+
# #
|
386
|
+
# # @return [ Hash ] The information of the connection or nil if errors
|
387
|
+
# #
|
388
|
+
# def retrieve_connection_info(env, path, use_shell = true)
|
389
|
+
# require 'locomotive/wagon/misc/deployment_connection'
|
390
|
+
|
391
|
+
# begin
|
392
|
+
# service = Locomotive::Wagon::DeploymentConnection.new(path, use_shell ? shell : nil)
|
393
|
+
|
394
|
+
# service.get_information(env)
|
395
|
+
|
396
|
+
# rescue Exception => e
|
397
|
+
# self.print_exception(e, options[:verbose])
|
398
|
+
# nil
|
399
|
+
# end
|
400
|
+
# end
|
406
401
|
|
407
402
|
end
|
408
403
|
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require_relative 'concerns/api_concern'
|
2
|
+
require_relative 'concerns/netrc_concern'
|
3
|
+
|
4
|
+
module Locomotive::Wagon
|
5
|
+
|
6
|
+
class AuthenticateCommand < Struct.new(:platform_url, :email, :password, :shell)
|
7
|
+
|
8
|
+
include ApiConcern
|
9
|
+
include NetrcConcern
|
10
|
+
|
11
|
+
def self.authenticate(platform_url, email, password, shell)
|
12
|
+
self.new(platform_url, email, password, shell).authenticate
|
13
|
+
end
|
14
|
+
|
15
|
+
def authenticate
|
16
|
+
if api_key = fetch_api_key
|
17
|
+
write_credentials_to_netrc(api_host, email, api_key)
|
18
|
+
else
|
19
|
+
shell.say "Sorry, we were unable to authenticate you on \"#{platform_url}\"", :red
|
20
|
+
end
|
21
|
+
|
22
|
+
!api_key.nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
def fetch_api_key
|
26
|
+
if my_account
|
27
|
+
my_account.api_key
|
28
|
+
else
|
29
|
+
shell.say "No account found for #{email} or invalid credentials", :yellow
|
30
|
+
|
31
|
+
# shall we create a new account?
|
32
|
+
if shell.yes?('Do you want to create a new account? [Y/N]')
|
33
|
+
create_account
|
34
|
+
else
|
35
|
+
false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_account
|
41
|
+
name = shell.ask 'What is your name?'
|
42
|
+
|
43
|
+
begin
|
44
|
+
account = api_client.my_account.create(name: name, email: email, password: password)
|
45
|
+
shell.say "Your account has been successfully created.", :green
|
46
|
+
account.api_key
|
47
|
+
rescue Locomotive::Coal::Error => e
|
48
|
+
shell.say "We were unable to create your account, reason(s): #{e.message}", :red
|
49
|
+
false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def my_account
|
56
|
+
begin
|
57
|
+
api_client.my_account.get
|
58
|
+
rescue Locomotive::Coal::UnauthorizedError
|
59
|
+
nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'locomotive/coal'
|
2
|
+
|
3
|
+
module Locomotive::Wagon
|
4
|
+
|
5
|
+
module ApiConcern
|
6
|
+
|
7
|
+
# Instance of the API client to request an account or his/her list of sites.
|
8
|
+
def api_client
|
9
|
+
@api_client ||= Locomotive::Coal::Client.new(api_uri, api_credentials)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Instance of the API client to request resources of a site: pages, theme_assets, ...etc.
|
13
|
+
def api_site_client(connection)
|
14
|
+
return @api_site_client if @api_site_client
|
15
|
+
|
16
|
+
_host, _credentials = connection['host'], connection.slice('email', 'api_key', 'password')
|
17
|
+
_options = connection.slice('ssl', 'handle')
|
18
|
+
|
19
|
+
@api_site_client = Locomotive::Coal::Client.new(_host, _credentials, _options)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Host (+ port) extracted from the platform_url instance variable.
|
23
|
+
# If port equals 80, do not add it to the host.
|
24
|
+
#
|
25
|
+
# Examples:
|
26
|
+
#
|
27
|
+
# www.myengine.com
|
28
|
+
# localhost:3000
|
29
|
+
#
|
30
|
+
def api_host
|
31
|
+
uri = api_uri
|
32
|
+
host, port = uri.host, uri.port
|
33
|
+
|
34
|
+
port == 80 ? uri.host : "#{uri.host}:#{uri.port}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def api_credentials
|
38
|
+
if respond_to?(:email)
|
39
|
+
{ email: email, password: password }
|
40
|
+
elsif respond_to?(:credentials)
|
41
|
+
credentials
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def api_uri
|
48
|
+
if (self.platform_url =~ /^https?:\/\//).nil?
|
49
|
+
self.platform_url = 'http://' + self.platform_url
|
50
|
+
end
|
51
|
+
|
52
|
+
URI(platform_url)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'locomotive/coal'
|
2
|
+
|
3
|
+
module Locomotive::Wagon
|
4
|
+
|
5
|
+
module DeployFileConcern
|
6
|
+
|
7
|
+
def write_deploy_setings(env, path, settings)
|
8
|
+
File.open(deploy_file(path), 'a+') do |f|
|
9
|
+
f.write({ env => settings }.to_yaml.sub(/^---/, ''))
|
10
|
+
end
|
11
|
+
|
12
|
+
settings
|
13
|
+
end
|
14
|
+
|
15
|
+
def read_deploy_settings(env, path)
|
16
|
+
# pre-processing: erb code to parse and render?
|
17
|
+
parsed_deploy_file = ERB.new(File.open(deploy_file(path)).read).result
|
18
|
+
|
19
|
+
# finally, get the hash from the YAML file
|
20
|
+
environments = YAML::load(parsed_deploy_file)
|
21
|
+
(environments.is_a?(Hash) ? environments : {})[env.to_s]
|
22
|
+
rescue Exception => e
|
23
|
+
raise "Unable to read the config/deploy.yml file (#{e.message})"
|
24
|
+
end
|
25
|
+
|
26
|
+
def deploy_file(path)
|
27
|
+
File.join(path, 'config', 'deploy.yml')
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Locomotive::Wagon
|
2
|
+
|
3
|
+
module InstrumentationConcern
|
4
|
+
|
5
|
+
def instrument(action, payload = {})
|
6
|
+
ActiveSupport::Notifications.instrument(instrument_scope_name(action), payload)
|
7
|
+
end
|
8
|
+
|
9
|
+
def instrument_scope_name(action)
|
10
|
+
name = self.class.name[/::(\w+)Command$/, 1].underscore
|
11
|
+
['wagon', name, action.to_s].compact.join('.')
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'netrc'
|
2
|
+
|
3
|
+
module Locomotive::Wagon
|
4
|
+
|
5
|
+
module NetrcConcern
|
6
|
+
|
7
|
+
def write_credentials_to_netrc(host, email, api_key)
|
8
|
+
netrc = Netrc.read
|
9
|
+
netrc[host] = email, api_key
|
10
|
+
netrc.save
|
11
|
+
end
|
12
|
+
|
13
|
+
def read_credentials_from_netrc(host)
|
14
|
+
if entry = Netrc.read[host]
|
15
|
+
{ email: entry.login, api_key: entry.password }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'locomotive/coal'
|
2
|
+
|
3
|
+
module Locomotive::Wagon
|
4
|
+
|
5
|
+
module SteamConcern
|
6
|
+
|
7
|
+
def steam_services
|
8
|
+
return @steam_services if @steam_services
|
9
|
+
|
10
|
+
Locomotive::Steam.configure do |config|
|
11
|
+
config.mode = :test
|
12
|
+
config.adapter = { name: :filesystem, path: path }
|
13
|
+
config.asset_path = File.expand_path(File.join(path, 'public'))
|
14
|
+
end
|
15
|
+
|
16
|
+
@steam_services = Locomotive::Steam::Services.build_instance.tap do |services|
|
17
|
+
repositories = services.repositories
|
18
|
+
services.set_site(repositories.site.all.first)
|
19
|
+
services.locale = services.current_site.default_locale
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Locomotive::Wagon
|
2
|
+
|
3
|
+
class GenerateCommand < Struct.new(:name, :args, :options)
|
4
|
+
|
5
|
+
def self.generate(name, args, options)
|
6
|
+
new(name, args, options).generate
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate
|
10
|
+
Bundler.require 'misc'
|
11
|
+
|
12
|
+
generator = generator_klass.new(args, options, { behavior: :skip })
|
13
|
+
generator.destination_root = args.last
|
14
|
+
generator.force_color_if_asked(options)
|
15
|
+
generator.invoke_all
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def generator_klass
|
21
|
+
lib = "locomotive/wagon/generators/#{name}"
|
22
|
+
require lib
|
23
|
+
|
24
|
+
lib.camelize.constantize
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Locomotive::Wagon
|
2
|
+
|
3
|
+
class InitCommand < Struct.new(:generator_klass, :args, :options)
|
4
|
+
|
5
|
+
def self.generate(klass, args, options)
|
6
|
+
new(klass, args, options).generate
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate
|
10
|
+
args, opts = Thor::Options.split(self.args)
|
11
|
+
|
12
|
+
generator = generator_klass.new(args, opts, {})
|
13
|
+
generator.force_color_if_asked(options)
|
14
|
+
generator.invoke_all
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Locomotive::Wagon
|
2
|
+
|
3
|
+
class PushLogger
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
subscribe 'site_created' do |event|
|
7
|
+
log "We created your site with the following handle: #{event.payload[:site].handle}", { mode: :bold }
|
8
|
+
end
|
9
|
+
|
10
|
+
subscribe :start do |event|
|
11
|
+
log "\n"
|
12
|
+
log "Pushing #{event.payload[:name].camelcase}", { color: :black, background: :white }
|
13
|
+
end
|
14
|
+
|
15
|
+
subscribe :persist do |event|
|
16
|
+
log "persisting #{event.payload[:label]}", :white, 2, true
|
17
|
+
end
|
18
|
+
|
19
|
+
subscribe :skip_persisting do |event|
|
20
|
+
log ' [' + 'skip'.colorize(:yellow) + ']'
|
21
|
+
end
|
22
|
+
|
23
|
+
subscribe :persist_with_success do |event|
|
24
|
+
log ' [' + 'done'.colorize(:green) + ']'
|
25
|
+
end
|
26
|
+
|
27
|
+
subscribe :persist_with_error do |event|
|
28
|
+
log ' [' + 'failed'.colorize(:red) + ']'
|
29
|
+
log event.payload[:message], :red, 4
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def log(message, color = nil, ident = nil, print = false)
|
36
|
+
ident = ' ' * (ident || 0)
|
37
|
+
|
38
|
+
message = "#{ident}#{message.gsub("\n", "\n" + ident)}"
|
39
|
+
message = message.colorize(color) if color
|
40
|
+
|
41
|
+
if print
|
42
|
+
print message
|
43
|
+
else
|
44
|
+
puts message
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def subscribe(action = nil, &block)
|
49
|
+
name = ['wagon', 'push', [*action]].flatten.compact.join('.')
|
50
|
+
|
51
|
+
ActiveSupport::Notifications.subscribe(name) do |*args|
|
52
|
+
event = ActiveSupport::Notifications::Event.new *args
|
53
|
+
yield(event)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'locomotive/steam'
|
2
|
+
|
3
|
+
require_relative 'loggers/push_logger'
|
4
|
+
|
5
|
+
require_relative_all 'concerns'
|
6
|
+
require_relative_all '../decorators/concerns'
|
7
|
+
require_relative_all '../decorators'
|
8
|
+
require_relative_all 'push_sub_commands'
|
9
|
+
|
10
|
+
module Locomotive::Wagon
|
11
|
+
|
12
|
+
class PushCommand < Struct.new(:env, :path, :options)
|
13
|
+
|
14
|
+
RESOURCES = %w(content_types content_entries pages snippets theme_assets translations).freeze
|
15
|
+
|
16
|
+
RESOURCES_WITH_CONTENT = %w(content_entries translations).freeze
|
17
|
+
|
18
|
+
include ApiConcern
|
19
|
+
include NetrcConcern
|
20
|
+
include DeployFileConcern
|
21
|
+
include SteamConcern
|
22
|
+
include InstrumentationConcern
|
23
|
+
|
24
|
+
attr_accessor :platform_url, :credentials
|
25
|
+
|
26
|
+
def self.push(env, path, options)
|
27
|
+
self.new(env, path, options).push
|
28
|
+
end
|
29
|
+
|
30
|
+
def push
|
31
|
+
PushLogger.new if options[:verbose]
|
32
|
+
|
33
|
+
api_client = api_site_client(connection_information)
|
34
|
+
|
35
|
+
content_assets_pusher = Locomotive::Wagon::PushContentAssetsCommand.new(api_client, steam_services)
|
36
|
+
|
37
|
+
each_resource do |klass|
|
38
|
+
klass.push(api_client, steam_services, content_assets_pusher)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def each_resource
|
45
|
+
RESOURCES.each do |name|
|
46
|
+
next if !options[:resources].blank? && !options[:resources].include?(name)
|
47
|
+
|
48
|
+
next if RESOURCES_WITH_CONTENT.include?(name) && !options[:data]
|
49
|
+
|
50
|
+
klass = "Locomotive::Wagon::Push#{name.camelcase}Command".constantize
|
51
|
+
|
52
|
+
yield klass
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def connection_information
|
57
|
+
if information = read_deploy_settings(self.env, self.path)
|
58
|
+
# the deployment env exists and contains all the information we need to move on
|
59
|
+
information
|
60
|
+
else
|
61
|
+
# mandatory to sign in
|
62
|
+
load_credentials_from_netrc
|
63
|
+
|
64
|
+
# create the remote site on the platform
|
65
|
+
site = create_remote_site
|
66
|
+
|
67
|
+
# update the deploy.yml by adding the new env since we've got all the information
|
68
|
+
write_deploy_setings(self.env, self.path, {
|
69
|
+
'host' => api_host,
|
70
|
+
'handle' => site.handle,
|
71
|
+
'email' => credentials[:email],
|
72
|
+
'api_key' => credentials[:api_key]
|
73
|
+
})
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def create_remote_site
|
78
|
+
# get an instance of the Steam services in order to load the information about the site (SiteRepository)
|
79
|
+
steam_services.current_site.tap do |site|
|
80
|
+
# ask for a handle if not found (blank: random one)
|
81
|
+
site[:handle] ||= shell.ask "What is the handle of your site?"
|
82
|
+
|
83
|
+
# create the site
|
84
|
+
attributes = SiteDecorator.new(site).to_hash
|
85
|
+
_site = api_client.sites.create(attributes)
|
86
|
+
site[:handle] = _site.handle
|
87
|
+
|
88
|
+
instrument :site_created, site: site
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def load_credentials_from_netrc
|
93
|
+
# ask for the platform URL (or LOCOMOTIVE_PLATFORM_URL env variable)
|
94
|
+
ask_for_platform_url
|
95
|
+
|
96
|
+
# retrieve email + api_key. If no entry present in the .netrc, raise an error
|
97
|
+
self.credentials = read_credentials_from_netrc(self.api_host)
|
98
|
+
|
99
|
+
raise 'You need to run wagon authenticate before going further' if self.credentials.nil?
|
100
|
+
end
|
101
|
+
|
102
|
+
def ask_for_platform_url
|
103
|
+
default = ENV['LOCOMOTIVE_PLATFORM_URL'] || DEFAULT_PLATFORM_URL
|
104
|
+
|
105
|
+
url = shell.ask "What is the URL of your platform? (default: #{default})"
|
106
|
+
|
107
|
+
self.platform_url = url.blank? ? default : url
|
108
|
+
end
|
109
|
+
|
110
|
+
def shell
|
111
|
+
options[:shell]
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|