implementing the push command (wip)

did committed Jan 17, 2013
commit d71ea3e1f97e1ad45b8ea3a7b451bcf8bf4d9aef
Showing 3 changed files with 76 additions and 37 deletions
TODO +10 -11
@@ @@ -16,33 +16,32 @@ x content types / liquid
x group_contents_by
x select_names
x params to launch the thin server (port, address ?)
- - nice error page (replace the default exception middleware) to display:
- - liquid errors
- - other exceptions
- - nice logs
- commands:
- - create
- - sites
+ ! create
+ ! sites
x blank
x twitter bootstrap + HAML
? localized
? boilerplate
- - copy Bundler / Gemfile (pending)
+ ! copy Bundler / Gemfile (pending)
x content types
x definitions
x data (Faker)
x page
- - snippet
+ x snippet
- push:
- option to select to push only some parts (pages, ...etc)
- --force option
+ - pass the shell to the mounter
- pull
-
+ - translations (Rod)
- version checkings:
- builder when running it
- engine when pushing a site
-
- - translations (Rod)
+ - nice error page (replace the default exception middleware) to display:
+ - liquid errors
+ - other exceptions
+ - nice logs
- tests (Rod/Did)
locomotive/builder.rb b/lib/locomotive/builder.rb +15 -6
@@ @@ -42,14 +42,23 @@ module Locomotive
generator.invoke_all
end
- # TODO
- def self.push(path, site_url, email, password)
+ # Push a site to a remote LocomotiveCMS engine described
+ # by the config/deploy.yml file of the site and for a specific environment.
+ #
+ # @param [ String ] path The path of the site
+ # @param [ Hash ] connection_info The information to get connected to the remote site
+ # @param [ Hash ] options The options passed to the push process
+ #
+ def self.push(path, connection_info, options = {})
require 'locomotive/mounter'
- reader = Locomotive::Mounter::Reader::FileSystem.instance
- reader.run!(path: path)
- writer = Locomotive::Mounter::Writer::Api.instance
- writer.run!(mounting_point: reader.mounting_point, uri: "#{site_url.chomp('/')}/locomotive/api", email: email, password: password)
+ puts "connection_info = #{connection_info}"
+
+ # reader = Locomotive::Mounter::Reader::FileSystem.instance
+ # reader.run!(path: path)
+ # writer = Locomotive::Mounter::Writer::Api.instance
+
+ # writer.run!(mounting_point: reader.mounting_point, uri: "#{site_url.chomp('/')}/locomotive/api", email: email, password: password)
end
# TODO
locomotive/builder/cli.rb b/lib/locomotive/builder/cli.rb +51 -20
@@ @@ -5,8 +5,35 @@ module Locomotive
module Builder
module CLI
+ module CheckPath
+
+ protected
+
+ # Check if the path given in option ('.' by default) points to a LocomotiveCMS
+ # site. It is also possible to pass a path other than the one from the options.
+ #
+ # @param [ String ] path The optional path instead of options['path']
+ #
+ # @return [ String ] The fullpath to the LocomotiveCMS site or nil if it is not a valid site.
+ #
+ def check_path!(path = nil)
+ path ||= options['path']
+
+ path = path == '.' ? Dir.pwd : File.expand_path(path)
+
+ (File.exists?(File.join(path, 'config', 'site.yml')) ? path : nil).tap do |_path|
+ if _path.nil?
+ say 'The path does not point to a LocomotiveCMS site', :red
+ end
+ end
+ end
+
+ end
+
class Generate < Thor
+ include Locomotive::Builder::CLI::CheckPath
+
class_option :path, aliases: '-p', type: :string, default: '.', optional: true, desc: 'if your LocomotiveCMS site is not in the current path'
desc 'content_type NAME FIELDS', 'Create a content type with NAME as the slug and FIELDS as the list of fields.'
@@ @@ -27,8 +54,6 @@ module Locomotive
if check_path!
Locomotive::Builder.generate :content_type, name, self.options['path'], fields
- else
- say 'The path does not point to a LocomotiveCMS site', :red
end
end
@@ @@ -46,8 +71,6 @@ module Locomotive
def page(fullpath)
if check_path!
Locomotive::Builder.generate :page, fullpath, self.options['path']
- else
- say 'The path does not point to a LocomotiveCMS site', :red
end
end
@@ @@ -63,28 +86,15 @@ module Locomotive
def snippet(slug)
if check_path!
Locomotive::Builder.generate :snippet, slug, self.options['path']
- else
- say 'The path does not point to a LocomotiveCMS site', :red
end
end
- protected
-
- # Check if the path given in option ('.' by default) points to a LocomotiveCMS
- # site.
- #
- # @return [ String ] The fullpath to the LocomotiveCMS site or nil if it is not a valid site.
- #
- def check_path!
- path = options['path'] == '.' ? Dir.pwd : File.expand_path(options['path'])
-
- File.exists?(File.join(path, 'config', 'site.yml')) ? path : nil
- end
-
end
class Main < Thor
+ include Locomotive::Builder::CLI::CheckPath
+
desc 'init NAME [PATH]', 'Create a brand new LocomotiveCMS site'
method_option :template, aliases: '-t', type: 'string', default: 'blank', desc: 'instead of building from a blank site, you can have a pre-fetched site with form a template (see the templates command)'
def init(name, path = '.')
@@ @@ -117,7 +127,27 @@ module Locomotive
method_option :host, aliases: '-h', type: 'string', default: '0.0.0.0', desc: 'The host (address) of the Thin server'
method_option :port, aliases: '-p', type: 'string', default: '3333', desc: 'The port of the Thin server'
def serve(path = '.')
- Locomotive::Builder.serve(path, options)
+ if check_path!(path)
+ Locomotive::Builder.serve(path, options)
+ end
+ end
+
+ desc 'push ENV [PATH]', 'Push a site to a remote LocomotiveCMS engine'
+ method_option :resources, aliases: '-r', type: 'array', default: [], desc: 'Only push the resource(s) passed in argument'
+ method_option :force, aliases: '-f', type: 'boolean', default: false, desc: 'Force the push of a resource'
+ def push(env, path = '.')
+ if check_path!(path)
+ begin
+ path_to_deploy_file = File.join(path, 'config', 'deploy.yml')
+ connection_info = YAML::load(File.open(path_to_deploy_file).read)[env.to_s]
+
+ raise "No #{env.to_s} environment found in the config/deploy.yml file" if connection_info.nil?
+
+ Locomotive::Builder.push(path, connection_info, options)
+ rescue Exception => e
+ say "Unable to read the information about the remote LocomotiveCMS site (#{e.message})", :red
+ end
+ end
end
# desc "push [PATH] SITE_URL EMAIL PASSWORD", "Push a site created by the builder to a remote LocomotiveCMS engine"
@@ @@ -130,6 +160,7 @@ module Locomotive
# say("ERROR: \"#{name}\" directory already exists", :red) and return if File.exists?(name)
# Locomotive::Builder.pull(name, site_url, email, password)
# end
+
end
end