- new command: destroy - enhance the push command - better exception system
did
committed Jan 21, 2013
commit 0be56a8336300e1dc06b147cf9c6e47e7260d93a
Showing 11
changed files with
157 additions
and 41 deletions
Gemfile
+1
-1
| @@ | @@ -3,6 +3,6 @@ source 'https://rubygems.org' |
| # Specify your gem's dependencies in builder.gemspec | |
| gemspec | |
| - | gem 'locomotivecms_mounter', path: '../gems/mounter' |
| + | gem 'locomotivecms_mounter', path: '../gems/mounter', require: false |
| gem 'rb-fsevent', '~> 0.9.1' | |
| \ No newline at end of file | |
TODO
+3
-3
| @@ | @@ -30,9 +30,9 @@ x params to launch the thin server (port, address ?) |
| x page | |
| x snippet | |
| - push: | |
| - | - option to select to push only some parts (pages, ...etc) |
| - | - --force option |
| - | - pass the shell to the mounter |
| + | x option to select to push only some parts (pages, ...etc) |
| + | x --force option |
| + | - more tests |
| - pull | |
| - translations (Rod) | |
| - version checkings: | |
generators/blank/config/site.yml.tt
+9
-0
| @@ | @@ -1,7 +1,16 @@ |
| + | # TODO: explain it |
| name: <%= config[:name] %> | |
| + | # TODO: explain it |
| + | # subdomain: sample |
| + | |
| + | # TODO: explain it |
| + | # domains: [www.example.com, example.com] |
| + | |
| + | # TODO: explain it |
| locales: [en] | |
| + | # TODO: explain it |
| seo_title: <%= @name %> | |
| meta_keywords: "some meta keywords" | |
| meta_description: "some meta description" | |
| \ No newline at end of file | |
generators/bootstrap/config/site.yml.tt
+9
-0
| @@ | @@ -1,7 +1,16 @@ |
| + | # TODO: explain it |
| name: <%= config[:name] %> | |
| + | # TODO: explain it |
| + | # subdomain: sample |
| + | |
| + | # TODO: explain it |
| + | # domains: [www.example.com, example.com] |
| + | |
| + | # TODO: explain it |
| locales: [en] | |
| + | # TODO: explain it |
| seo_title: <%= @name %> | |
| meta_keywords: "some meta keywords" | |
| meta_description: "some meta description" | |
| \ No newline at end of file | |
generators/content_type/app/content_types/%name%.yml.tt
+3
-1
| @@ | @@ -32,7 +32,9 @@ fields: <% config[:fields].each_with_index do |field, index| %> |
| type: <%= field.type %> | |
| required: <%= index == 0 ? true : field.required %> | |
| hint: A description of the field for the editors | |
| - | localized: false<% if field.type == 'select' -%> |
| + | localized: false<% if field.type == 'text' %> |
| + | # Enable or not the RTE [html|text] |
| + | # text_formatting: html<% end -%><% if field.type == 'select' -%> |
| # if localized, use | |
| # en: ['option1_en', 'option2_en'] | |
| # fr: ['option1_fr', 'option2_fr'] | |
generators/snippet/template.liquid.haml.tt
+2
-2
| @@ | @@ -1,4 +1,4 @@ |
| - | {% comment %} |
| + | {% raw %} |
| / To use your snippet, just add the following code in your page template | |
| / {% include <%= config[:slug] -%> %} | |
| - | {% endcomment %} |
| \ No newline at end of file | |
| + | {% endraw %} |
| \ No newline at end of file | |
generators/snippet/template.liquid.tt
+2
-2
| @@ | @@ -1,4 +1,4 @@ |
| - | {% comment %} |
| + | {% raw %} |
| <!-- To use your snippet, just add the following code in your page template--> | |
| <!-- {% include <%= config[:slug] -%> %} --> | |
| - | {% endcomment %} |
| \ No newline at end of file | |
| + | {% endraw %} |
| \ No newline at end of file | |
locomotive/builder.rb b/lib/locomotive/builder.rb
+61
-15
| @@ | @@ -1,4 +1,5 @@ |
| require 'locomotive/builder/version' | |
| + | require 'locomotive/builder/exceptions' |
| module Locomotive | |
| module Builder | |
| @@ | @@ -19,14 +20,14 @@ module Locomotive |
| # @param [ Hash ] options The options for the thin server (host, port) | |
| # | |
| def self.serve(path, options) | |
| - | require 'thin' |
| - | require 'locomotive/builder/server' |
| - | reader = Locomotive::Mounter::Reader::FileSystem.instance |
| - | reader.run!(path: path) |
| - | |
| - | server = Thin::Server.new(options[:host], options[:port], Locomotive::Builder::Server.new(reader)) |
| - | # server.threaded = true # TODO: make it an option ? |
| - | server.start |
| + | if reader = self.require_mounter(path, true) |
| + | require 'thin' |
| + | require 'locomotive/builder/server' |
| + | |
| + | server = Thin::Server.new(options[:host], options[:port], Locomotive::Builder::Server.new(reader)) |
| + | # server.threaded = true # TODO: make it an option ? |
| + | server.start |
| + | end |
| end | |
| # Generate components for the LocomotiveCMS site such as content types, snippets, pages. | |
| @@ | @@ -50,20 +51,36 @@ module Locomotive |
| # @param [ Hash ] options The options passed to the push process | |
| # | |
| def self.push(path, connection_info, options = {}) | |
| - | require 'locomotive/mounter' |
| + | if reader = self.require_mounter(path, true) |
| + | writer = Locomotive::Mounter::Writer::Api.instance |
| + | |
| + | connection_info['uri'] = "#{connection_info.delete('host')}/locomotive/api" |
| + | |
| + | _options = { mounting_point: reader.mounting_point, console: true }.merge(options) |
| + | _options[:only] = _options.delete(:resouces) |
| + | |
| + | writer.run!(_options.merge(connection_info)) |
| + | end |
| + | end |
| - | puts "connection_info = #{connection_info}" |
| + | # Destroy a remote site |
| + | # |
| + | # @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.destroy(path, connection_info, options = {}) |
| + | self.require_mounter(path) |
| - | # reader = Locomotive::Mounter::Reader::FileSystem.instance |
| - | # reader.run!(path: path) |
| - | # writer = Locomotive::Mounter::Writer::Api.instance |
| + | connection_info['uri'] = "#{connection_info.delete('host')}/locomotive/api" |
| - | # writer.run!(mounting_point: reader.mounting_point, uri: "#{site_url.chomp('/')}/locomotive/api", email: email, password: password) |
| + | Locomotive::Mounter::EngineApi.set_token connection_info.symbolize_keys |
| + | Locomotive::Mounter::EngineApi.delete('/current_site.json') |
| end | |
| # TODO | |
| def self.pull(path, site_url, email, password) | |
| - | require 'locomotive/mounter' |
| + | self.require_mounter(path) |
| reader = Locomotive::Mounter::Reader::Api.instance | |
| reader.run!(uri: "#{site_url.chomp('/')}/locomotive/api", email: email, password: password) | |
| @@ | @@ -71,5 +88,34 @@ module Locomotive |
| writer.run!(mounting_point: reader.mounting_point, target_path: path) | |
| end | |
| + | # Load the Locomotive::Mounter lib and set it up (logger, ...etc). |
| + | # If the second parameter is set to true, then the method builds |
| + | # an instance of the reader from the path passed in first parameter. |
| + | # |
| + | # @param [ String ] path The path to the local site |
| + | # @param [ Boolean ] get_reader Tell if it builds an instance of the reader. |
| + | # |
| + | # @param [ Object ] An instance of the reader is the get_reader parameter has been set. |
| + | # |
| + | def self.require_mounter(path, get_reader = false) |
| + | require 'locomotive/mounter' |
| + | |
| + | logfile = File.join(path, 'log', 'mounter.log') |
| + | FileUtils.mkdir_p(File.dirname(logfile)) |
| + | |
| + | Locomotive::Mounter.logger = ::Logger.new(logfile).tap do |log| |
| + | log.level = Logger::DEBUG |
| + | end |
| + | |
| + | begin |
| + | reader = Locomotive::Mounter::Reader::FileSystem.instance |
| + | reader.run!(path: path) |
| + | reader |
| + | rescue Exception => e |
| + | raise Locomotive::Builder::MounterException.new "Unable to read the local LocomotiveCMS site: #{e.message}\nPlease check the logs file (#{path}/log/mounter.log)" |
| + | end |
| + | end |
| + | |
| + | |
| end | |
| end | |
| \ No newline at end of file | |
locomotive/builder/cli.rb b/lib/locomotive/builder/cli.rb
+50
-15
| @@ | @@ -128,32 +128,42 @@ module Locomotive |
| method_option :port, aliases: '-p', type: 'string', default: '3333', desc: 'The port of the Thin server' | |
| def serve(path = '.') | |
| if check_path!(path) | |
| - | Locomotive::Builder.serve(path, options) |
| + | begin |
| + | Locomotive::Builder.serve(path, options) |
| + | rescue Exception => e |
| + | say e.message, :red |
| + | end |
| 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 :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)' |
| 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 |
| + | if connection_info = self.retrieve_connection_info(env, path) |
| + | begin |
| + | Locomotive::Builder.push(path, connection_info, options) |
| + | rescue Exception => e |
| + | say e.message, :red |
| + | end |
| end | |
| end | |
| end | |
| - | # desc "push [PATH] SITE_URL EMAIL PASSWORD", "Push a site created by the builder to a remote LocomotiveCMS engine" |
| - | # def push(path, site_url, email, password) |
| - | # Locomotive::Builder.push(path, site_url, email, password) |
| - | # end |
| + | desc 'destroy ENV [PATH]', 'Destroy a remote LocomotiveCMS engine' |
| + | def destroy(env, path = '.') |
| + | if check_path!(path) |
| + | if connection_info = self.retrieve_connection_info(env, path) |
| + | if ask('Are you sure ?', limited_to: %w(yes no)) == 'yes' |
| + | Locomotive::Builder.destroy(path, connection_info) |
| + | else |
| + | say 'The destroy operation has been cancelled', :red |
| + | end |
| + | end |
| + | end |
| + | end |
| # desc "pull NAME SITE_URL EMAIL PASSWORD", "Pull an existing LocomotiveCMS site powered by the engine" | |
| # def pull(name, site_url, email, password) | |
| @@ | @@ -161,6 +171,31 @@ module Locomotive |
| # Locomotive::Builder.pull(name, site_url, email, password) | |
| # end | |
| + | protected |
| + | |
| + | # 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. |
| + | # |
| + | # @param [ String ] env The environment (development, staging, production, ...etc) |
| + | # @param [ String ] path The path of the local site |
| + | # |
| + | # @return [ Hash ] The information of the connection or nil if errors |
| + | # |
| + | def retrieve_connection_info(env, path) |
| + | connection_info = nil |
| + | 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] |
| + | |
| + | if connection_info.nil? |
| + | raise "No #{env.to_s} environment found in the config/deploy.yml file" |
| + | end |
| + | rescue Exception => e |
| + | say "Unable to read the information about the remote LocomotiveCMS site (#{e.message})", :red |
| + | end |
| + | connection_info |
| + | end |
| + | |
| end | |
| end | |
locomotive/builder/exceptions.rb b/lib/locomotive/builder/exceptions.rb
+17
-0
| @@ | @@ -0,0 +1,17 @@ |
| + | module Locomotive |
| + | module Builder |
| + | |
| + | class DefaultException < ::Exception |
| + | |
| + | def initialize(message = nil) |
| + | # no specific treatment for now |
| + | super |
| + | end |
| + | |
| + | end |
| + | |
| + | class MounterException < DefaultException |
| + | end |
| + | |
| + | end |
| + | end |
locomotive/builder/server.rb b/lib/locomotive/builder/server.rb
+0
-2
| @@ | @@ -1,8 +1,6 @@ |
| require 'rack/showexceptions' | |
| require 'coffee_script' | |
| - | require 'locomotive/mounter' |
| - | |
| require 'locomotive/builder/listen' | |
| require 'locomotive/builder/server/middleware' | |
| require 'locomotive/builder/server/favicon' | |