clone command + fix various bugs
did
committed Apr 12, 2013
commit 6868a9391986ca2a9af2c62253576398ce81b38d
Showing 20
changed files with
127 additions
and 28 deletions
Gemfile
+2
-2
| @@ | @@ -1,9 +1,9 @@ |
| - | source 'https://rubygems.org' |
| + | # source 'https://rubygems.org' |
| # Specify your gem's dependencies in wagon.gemspec | |
| gemspec | |
| # Development | |
| - | # gem 'locomotivecms_mounter', path: '../gems/mounter', require: false |
| + | gem 'locomotivecms_mounter', path: '../gems/mounter', require: false |
| gem 'rb-fsevent', '~> 0.9.1' | |
| \ No newline at end of file | |
Rakefile
+1
-1
| @@ | @@ -36,7 +36,7 @@ namespace :development do |
| FileUtils.rm_rf(File.join(File.dirname(__FILE__), 'site')) | |
| VCR.use_cassette('pull') do | |
| - | exit unless Locomotive::Wagon.clone('site', {'host' => 'http://locomotive.engine.dev:3000'}, 'email' => 'admin@locomotivecms.com', 'password' => 'locomotive') |
| + | exit unless Locomotive::Wagon.clone('site', '.', host: 'http://locomotive.engine.dev:3000', email: 'admin@locomotivecms.com', password: 'locomotive') |
| end | |
| Locomotive::Wagon.push('site', {'host' => 'http://locomotive.engine.dev:3000'}, 'email' => 'admin@locomotivecms.com', 'password' => 'locomotive', 'force' => true, 'data' => true) | |
generators/blank/Gemfile.tt
+1
-1
| @@ | @@ -6,7 +6,7 @@ gem 'locomotivecms_wagon', '<%= config[:version] -%>' |
| group :development do | |
| # Mac OS X | |
| - | gem 'rb-fsevent', '~> 0.9.1', :require => RUBY_PLATFORM.include?('darwin') && 'rb-fsevent' |
| + | gem 'rb-fsevent', '~> 0.9.1', require: RUBY_PLATFORM.include?('darwin') && 'rb-fsevent' |
| # TODO: Linux | |
generators/cloned/Gemfile.tt
+20
-0
| @@ | @@ -0,0 +1,20 @@ |
| + | source 'https://rubygems.org' |
| + | |
| + | # ruby '1.9.3' |
| + | |
| + | gem 'locomotivecms_wagon', '<%= config[:version] -%>' |
| + | |
| + | group :development do |
| + | # Mac OS X |
| + | gem 'rb-fsevent', '~> 0.9.1', require: RUBY_PLATFORM.include?('darwin') && 'rb-fsevent' |
| + | |
| + | # TODO: Linux |
| + | |
| + | # TODO: Windows |
| + | end |
| + | |
| + | group :misc do |
| + | # Add your extra gems here |
| + | # gem 'susy', require: 'susy' |
| + | # gem 'redcarpet', require: 'redcarpet' |
| + | end |
| \ No newline at end of file | |
generators/cloned/app/content_types/.empty_directory
+1
-0
| @@ | @@ -0,0 +1 @@ |
| + | .empty_directory |
| \ No newline at end of file | |
generators/cloned/app/views/pages/.empty_directory
+1
-0
| @@ | @@ -0,0 +1 @@ |
| + | .empty_directory |
| \ No newline at end of file | |
generators/cloned/app/views/snippets/.empty_directory
+1
-0
| @@ | @@ -0,0 +1 @@ |
| + | .empty_directory |
| \ No newline at end of file | |
generators/cloned/config.ru
+3
-0
| @@ | @@ -0,0 +1,3 @@ |
| + | require 'locomotive/wagon/standalone_server' |
| + | |
| + | run Locomotive::Wagon::StandaloneServer.new(File.expand_path('.')) |
| \ No newline at end of file | |
generators/cloned/config/deploy.yml.tt
+4
-0
| @@ | @@ -0,0 +1,4 @@ |
| + | production: |
| + | host: <%= config[:host] %> |
| + | email: <%= config[:email] %> |
| + | password: <%= config[:password] %> |
| \ No newline at end of file | |
generators/cloned/data/.empty_directory
+1
-0
| @@ | @@ -0,0 +1 @@ |
| + | .empty_directory |
| \ No newline at end of file | |
generators/cloned/public/fonts/.empty_directory
+1
-0
| @@ | @@ -0,0 +1 @@ |
| + | .empty_directory |
| \ No newline at end of file | |
generators/cloned/public/images/.empty_directory
+1
-0
| @@ | @@ -0,0 +1 @@ |
| + | .empty_directory |
| \ No newline at end of file | |
generators/cloned/public/javascripts/.empty_directory
+1
-0
| @@ | @@ -0,0 +1 @@ |
| + | .empty_directory |
| \ No newline at end of file | |
generators/cloned/public/samples/.empty_directory
+1
-0
| @@ | @@ -0,0 +1 @@ |
| + | .empty_directory |
| \ No newline at end of file | |
generators/cloned/public/stylesheets/.empty_directory
+1
-0
| @@ | @@ -0,0 +1 @@ |
| + | .empty_directory |
| \ No newline at end of file | |
locomotive/wagon.rb b/lib/locomotive/wagon.rb
+18
-17
| @@ | @@ -80,7 +80,7 @@ module Locomotive |
| def self.pull(path, connection_info, options = {}) | |
| self.require_mounter(path) | |
| - | Bundler.require 'misc' |
| + | Bundler.require 'misc' unless options[:disable_misc] |
| connection_info['uri'] = "#{connection_info.delete('host')}/locomotive/api" | |
| @@ | @@ -92,29 +92,30 @@ module Locomotive |
| writer = Locomotive::Mounter::Writer::FileSystem.instance | |
| writer.run!(mounting_point: reader.mounting_point, target_path: path) | |
| - | rescue Exception => e |
| - | puts e.backtrace |
| end | |
| - | def self.clone(path, connection_info, options = {}) |
| - | if File.exists?(path) |
| + | # Clone a site from a remote LocomotiveCMS engine. |
| + | # |
| + | # @param [ String ] name Name of the site (arbitrary) |
| + | # @param [ String ] path The root path where the site will be cloned |
| + | # @param [ Hash ] connection_info The host, email and password needed to access the remote engine |
| + | # @param [ Hash ] options The options for the API reader |
| + | # |
| + | def self.clone(name, path, connection_info, options = {}) |
| + | target_path = File.expand_path(File.join(path, name)) |
| + | |
| + | if File.exists?(target_path) |
| puts "Path already exists. If it's an existing site, you might want to pull instead of clone." | |
| return false | |
| end | |
| - | require 'locomotive/mounter' |
| - | connection_info['uri'] = "#{connection_info.delete('host')}/locomotive/api" |
| + | # generate an almost blank site |
| + | require 'locomotive/wagon/generators/site' |
| + | generator = Locomotive::Wagon::Generators::Site::Cloned |
| + | generator.start [name, path, connection_info] |
| - | _options = options.dup |
| - | _options[:only] = _options.delete(:resources) |
| - | |
| - | reader = Locomotive::Mounter::Reader::Api.instance |
| - | reader.run!(_options.merge(connection_info)) |
| - | |
| - | writer = Locomotive::Mounter::Writer::FileSystem.instance |
| - | writer.run!(mounting_point: reader.mounting_point, target_path: path) |
| - | # rescue Exception => e |
| - | # puts e.backtrace |
| + | # pull the remote site |
| + | self.pull(target_path, options.merge(connection_info).with_indifferent_access, { disable_misc: true }) |
| end | |
| # Destroy a remote site | |
locomotive/wagon/cli.rb b/lib/locomotive/wagon/cli.rb
+44
-6
| @@ | @@ -118,6 +118,7 @@ module Locomotive |
| 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)' | |
| + | method_option :verbose, aliases: '-v', type: 'boolean', default: false, desc: 'display the full error stack trace if an error occurs' |
| def init(name, path = '.') | |
| require 'locomotive/wagon/generators/site' | |
| generator = Locomotive::Wagon::Generators::Site.get(options[:template]) | |
| @@ | @@ -125,13 +126,27 @@ module Locomotive |
| say "Unknown site template '#{options[:template]}'", :red | |
| else | |
| begin | |
| - | Locomotive::Wagon.init(name, path, generator) |
| + | if Locomotive::Wagon.init(name, path, generator) |
| + | self.print_next_instructions_when_site_created(name, path) |
| + | end |
| rescue GeneratorException => e | |
| - | say e.message, :red |
| + | self.print_exception(e, options[:verbose]) |
| end | |
| end | |
| end | |
| + | desc 'clone NAME HOST EMAIL PASSWORD [PATH]', 'Clone a remote LocomotiveCMS site' |
| + | method_option :verbose, aliases: '-v', type: 'boolean', default: false, desc: 'display the full error stack trace if an error occurs' |
| + | def clone(name, host, email, password, path = '.') |
| + | begin |
| + | if Locomotive::Wagon.clone(name, path, host: host, email: email, password: password) |
| + | self.print_next_instructions_when_site_created(name, path) |
| + | end |
| + | rescue Exception => e |
| + | self.print_exception(e, options[:verbose]) |
| + | end |
| + | end |
| + | |
| desc 'generate TYPE ...ARGS', 'Generate resources (content_types, page, snippets) for a LocomotiveCMS site' | |
| subcommand 'generate', Generate | |
| @@ | @@ -165,13 +180,14 @@ module Locomotive |
| method_option :resources, aliases: '-r', type: 'array', default: nil, 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' | |
| method_option :data, aliases: '-d', type: 'boolean', default: false, desc: 'Push the content entries and the editable elements (by default, they are not)' | |
| + | method_option :verbose, aliases: '-v', type: 'boolean', default: false, desc: 'display the full error stack trace if an error occurs' |
| def push(env, path = '.') | |
| if check_path!(path) | |
| if connection_info = self.retrieve_connection_info(env, path) | |
| begin | |
| Locomotive::Wagon.push(path, connection_info, options) | |
| rescue Exception => e | |
| - | say e.message, :red |
| + | self.print_exception(e, options[:verbose]) |
| end | |
| end | |
| end | |
| @@ | @@ -179,15 +195,14 @@ module Locomotive |
| desc 'pull ENV [PATH]', 'Pull a site from a remote LocomotiveCMS engine' | |
| method_option :resources, aliases: '-r', type: 'array', default: nil, desc: 'Only pull the resource(s) passed in argument' | |
| - | # method_option :force, aliases: '-f', type: 'boolean', default: false, desc: 'Force the push of a resource' |
| - | # method_option :data, aliases: '-d', type: 'boolean', default: false, desc: 'Push the content entries and the editable elements (by default, they are not)' |
| + | method_option :verbose, aliases: '-v', type: 'boolean', default: false, desc: 'display the full error stack trace if an error occurs' |
| def pull(env, path = '.') | |
| if check_path!(path) | |
| if connection_info = self.retrieve_connection_info(env, path) | |
| begin | |
| Locomotive::Wagon.pull(path, connection_info, options) | |
| rescue Exception => e | |
| - | say e.message, :red |
| + | self.print_exception(e, options[:verbose]) |
| end | |
| end | |
| end | |
| @@ | @@ -208,6 +223,29 @@ module Locomotive |
| protected | |
| + | # Print a nice message when a site has been created. |
| + | # |
| + | # @param [ String ] name The name of the site |
| + | # @param [ String ] path The path of the local site |
| + | # |
| + | def print_next_instructions_when_site_created(name, path) |
| + | say "\nCongratulations, your site \"#{name}\" has been created successfully !", :green |
| + | say 'Next steps:', :bold |
| + | say "\tcd #{path}/#{name}\n\tbundle install\n\tbundle exec wagon serve\n\topen http://0.0.0.0:3333" |
| + | end |
| + | |
| + | # Print the exception. |
| + | # |
| + | # @param [ Object ] exception The raised exception |
| + | # @param [ Boolean ] verbose Print the full backtrace if true |
| + | # |
| + | def print_exception(exception, verbose) |
| + | say exception.message, :red |
| + | if verbose |
| + | say "\t" + exception.backtrace.join("\n\t") |
| + | end |
| + | end |
| + | |
| # From a site specified by a path, retrieve the information of the connection | |
| # for a environment located in the config/deploy.yml file of the site. | |
| # | |
locomotive/wagon/generators/site.rb b/lib/locomotive/wagon/generators/site.rb
+1
-0
| @@ | @@ -97,3 +97,4 @@ require 'locomotive/wagon/generators/site/blank' |
| require 'locomotive/wagon/generators/site/bootstrap' | |
| require 'locomotive/wagon/generators/site/foundation' | |
| require 'locomotive/wagon/generators/site/unzip' | |
| + | require 'locomotive/wagon/generators/site/cloned' |
locomotive/wagon/generators/site/cloned.rb b/lib/locomotive/wagon/generators/site/cloned.rb
+23
-0
| @@ | @@ -0,0 +1,23 @@ |
| + | module Locomotive |
| + | module Wagon |
| + | module Generators |
| + | module Site |
| + | |
| + | # Template used when the remote LocomotiveCMS site is cloned |
| + | # in order to have the minimal files. |
| + | class Cloned < Base |
| + | |
| + | argument :connection_info |
| + | |
| + | def copy_sources |
| + | directory('.', self.destination, { recursive: true }, { |
| + | name: self.name, |
| + | version: Locomotive::Wagon::VERSION |
| + | }.merge(self.connection_info)) |
| + | end |
| + | |
| + | end |
| + | end |
| + | end |
| + | end |
| + | end |
| \ No newline at end of file | |
locomotivecms_wagon.gemspec
+1
-1
| @@ | @@ -31,7 +31,7 @@ Gem::Specification.new do |gem| |
| gem.add_dependency 'httmultiparty', '0.3.8' | |
| gem.add_dependency 'will_paginate', '~> 3.0.3' | |
| - | gem.add_dependency 'locomotivecms_mounter', '1.0.2' |
| + | # gem.add_dependency 'locomotivecms_mounter', '1.0.2' |
| gem.add_dependency 'faker', '~> 0.9.5' | |