From 9ed0796b4a346af3228d6cf880081f04ca6dc159 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Thu, 20 Aug 2015 17:45:18 -0700 Subject: [PATCH] Move some extension setup to ready event --- middleman-cli/lib/middleman-cli/config.rb | 5 +++++ middleman-core/lib/middleman-core/application.rb | 6 +++++- .../lib/middleman-core/core_extensions/show_exceptions.rb | 2 +- middleman-core/lib/middleman-core/extensions/asset_hash.rb | 2 +- middleman-core/lib/middleman-core/extensions/asset_host.rb | 2 +- .../lib/middleman-core/extensions/external_pipeline.rb | 2 +- middleman-core/lib/middleman-core/extensions/minify_css.rb | 2 +- .../lib/middleman-core/extensions/minify_javascript.rb | 2 +- .../lib/middleman-core/extensions/relative_assets.rb | 2 +- 9 files changed, 17 insertions(+), 8 deletions(-) diff --git a/middleman-cli/lib/middleman-cli/config.rb b/middleman-cli/lib/middleman-cli/config.rb index b5b64064..902ea216 100644 --- a/middleman-cli/lib/middleman-cli/config.rb +++ b/middleman-cli/lib/middleman-cli/config.rb @@ -13,12 +13,17 @@ module Middleman::Cli def console require 'json' require 'middleman-core' + require 'middleman-core/logger' opts = { environment: options['environment'] } + # Don't output info messages + ::Middleman::Logger.singleton(2, false) + app = ::Middleman::Application.new do + config[:exit_before_ready] = true config[:environment] = opts[:environment].to_sym if opts[:environment] end diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index 9d8a239d..ecd863f2 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -92,6 +92,10 @@ module Middleman # @return [String] define_setting :source, 'source', 'Name of the source directory' + # If we should exit before ready event. + # @return [Boolean] + define_setting :exit_before_ready, false, 'If we should exit before ready event.' + # Middleman mode. Defaults to :server, set to :build by the build process # @return [String] define_setting :mode, ((ENV['MM_ENV'] && ENV['MM_ENV'].to_sym) || :server), 'Middleman mode. Defaults to :server' @@ -274,7 +278,7 @@ module Middleman execute_callbacks(:after_configuration) # Everything is stable - execute_callbacks(:ready) + execute_callbacks(:ready) unless config[:exit_before_ready] end # Eval config diff --git a/middleman-core/lib/middleman-core/core_extensions/show_exceptions.rb b/middleman-core/lib/middleman-core/core_extensions/show_exceptions.rb index 6f01448a..b6407100 100644 --- a/middleman-core/lib/middleman-core/core_extensions/show_exceptions.rb +++ b/middleman-core/lib/middleman-core/core_extensions/show_exceptions.rb @@ -11,7 +11,7 @@ module Middleman::CoreExtensions app.config.define_setting :show_exceptions, ENV['TEST'] ? false : true, 'Whether to catch and display exceptions' end - def after_configuration + def ready app.use ::Rack::ShowExceptions if !app.build? && app.config[:show_exceptions] end end diff --git a/middleman-core/lib/middleman-core/extensions/asset_hash.rb b/middleman-core/lib/middleman-core/extensions/asset_hash.rb index bb1389e9..e3248bd5 100644 --- a/middleman-core/lib/middleman-core/extensions/asset_hash.rb +++ b/middleman-core/lib/middleman-core/extensions/asset_hash.rb @@ -17,7 +17,7 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension def after_configuration # Allow specifying regexes to ignore, plus always ignore apple touch icons @ignore = Array(options.ignore) + [/^apple-touch-icon/] - + app.use ::Middleman::Middleware::InlineURLRewriter, id: :asset_hash, url_extensions: options.exts, diff --git a/middleman-core/lib/middleman-core/extensions/asset_host.rb b/middleman-core/lib/middleman-core/extensions/asset_host.rb index 79e1813d..d0487591 100644 --- a/middleman-core/lib/middleman-core/extensions/asset_host.rb +++ b/middleman-core/lib/middleman-core/extensions/asset_host.rb @@ -7,7 +7,7 @@ class Middleman::Extensions::AssetHost < ::Middleman::Extension option :sources, %w(.htm .html .php .css .js), 'List of extensions that are searched for bustable assets.' option :ignore, [], 'Regexes of filenames to skip adding query strings to' - def after_configuration + def ready app.use ::Middleman::Middleware::InlineURLRewriter, id: :asset_host, url_extensions: options.exts, diff --git a/middleman-core/lib/middleman-core/extensions/external_pipeline.rb b/middleman-core/lib/middleman-core/extensions/external_pipeline.rb index 6fc82aa0..9c649f5e 100644 --- a/middleman-core/lib/middleman-core/extensions/external_pipeline.rb +++ b/middleman-core/lib/middleman-core/extensions/external_pipeline.rb @@ -16,7 +16,7 @@ class Middleman::Extensions::ExternalPipeline < ::Middleman::Extension latency: options[:latency] end - def after_configuration + def ready if app.build? logger.info "== Executing: `#{options[:command]}`" watch_command! diff --git a/middleman-core/lib/middleman-core/extensions/minify_css.rb b/middleman-core/lib/middleman-core/extensions/minify_css.rb index 75b2ca4b..df7d7567 100644 --- a/middleman-core/lib/middleman-core/extensions/minify_css.rb +++ b/middleman-core/lib/middleman-core/extensions/minify_css.rb @@ -9,7 +9,7 @@ class Middleman::Extensions::MinifyCss < ::Middleman::Extension SassCompressor }, 'Set the CSS compressor to use.' - def after_configuration + def ready # Setup Rack middleware to minify CSS app.use Rack, compressor: options[:compressor], ignore: Array(options[:ignore]) + [/\.min\./], diff --git a/middleman-core/lib/middleman-core/extensions/minify_javascript.rb b/middleman-core/lib/middleman-core/extensions/minify_javascript.rb index 5c90bd13..466fb133 100644 --- a/middleman-core/lib/middleman-core/extensions/minify_javascript.rb +++ b/middleman-core/lib/middleman-core/extensions/minify_javascript.rb @@ -9,7 +9,7 @@ class Middleman::Extensions::MinifyJavascript < ::Middleman::Extension ::Uglifier.new }, 'Set the JS compressor to use.' - def after_configuration + def ready # Setup Rack middleware to minify CSS app.use Rack, compressor: options[:compressor], ignore: Array(options[:ignore]) + [/\.min\./], diff --git a/middleman-core/lib/middleman-core/extensions/relative_assets.rb b/middleman-core/lib/middleman-core/extensions/relative_assets.rb index 58ba20c3..74d7d180 100644 --- a/middleman-core/lib/middleman-core/extensions/relative_assets.rb +++ b/middleman-core/lib/middleman-core/extensions/relative_assets.rb @@ -12,7 +12,7 @@ class Middleman::Extensions::RelativeAssets < ::Middleman::Extension require 'middleman-core/middleware/inline_url_rewriter' end - def after_configuration + def ready app.use ::Middleman::Middleware::InlineURLRewriter, id: :asset_hash, url_extensions: options.exts,