upgrade guard and pin development gems

this also upgrades our custom guard plugins to watch the correct
directories for plugins files.  they were never updated after plugins
moved from vendor/plugins to gems/plugins.

Note: there is a small inconsistency between the latest guard and latest
thor gems resulting in a warning being printed on guard startup:
  "Expected string default value for '--listen-on'; got false (boolean)"
I have a pull request open to fix this here:
  https://github.com/guard/guard/pull/862

refs CNVS-34084

test plan:
- run guard
- change files
- guard should do the right thing

Change-Id: Iffc0297a458f6261130e12c151d37ecbc38ee0ec
Reviewed-on: https://gerrit.instructure.com/98657
Tested-by: Jenkins
Reviewed-by: Rob Orton <rob@instructure.com>
Product-Review: Simon Williams <simon@instructure.com>
QA-Review: Simon Williams <simon@instructure.com>
This commit is contained in:
Simon Williams 2016-12-30 15:34:25 -07:00
parent 7a0289f644
commit 320d36469d
13 changed files with 108 additions and 117 deletions

View File

@ -1,23 +1,17 @@
group :development do
gem 'guard', '1.8.0'
gem 'guard-gulp', '~>0.0.2', require: false
gem 'guard-shell', '~>0.6.1', require: false
gem 'listen', '~>1.3' # pinned to fix guard error
gem 'rb-inotify', '~>0.9.0', require: false
gem 'rb-fsevent', require: false
gem 'rb-fchange', require: false
gem 'colorize', require: false
gem "letter_opener"
gem 'spring', '>= 1.3.2'
gem 'spring-commands-rspec', '1.0.2'
gem 'guard', '2.14.0'
gem 'listen', '3.1.5', require: false
gem 'rb-inotify', '0.9.7', require: false
gem 'rb-fsevent', '0.9.8', require: false
gem 'colorize', '0.8.1', require: false
gem 'letter_opener', '1.4.1'
gem 'spring', '2.0.0'
gem 'spring-commands-rspec', '1.0.4'
# Option to DISABLE_RUBY_DEBUGGING is helpful IDE-based debugging.
# The ruby debug gems conflict with the IDE-based debugger gem.
# Set this option in your dev environment to disable.
unless ENV['DISABLE_RUBY_DEBUGGING']
gem 'byebug', '~> 9.0', platform: :mri
gem 'byebug', '9.0.6', platform: :mri
end
end

View File

@ -1,26 +1,23 @@
$LOAD_PATH << File.dirname(__FILE__)
require 'guard-gulp'
ignore! Listen::DirectoryRecord::DEFAULT_IGNORED_DIRECTORIES - ['vendor'] + [%r{vendor/(?!plugins)}]
# whitelist what directories to watch
directories %w(app spec gems/plugins)
# this means that we can't watch files in the root directory
# (like Gemfile, package.json, gulpfile.js, etc). See:
# https://github.com/guard/listen/wiki/Duplicate-directory-errors
# for why we've chosen to whitelist directories
guard :shell, all_on_start: true do
watch('package.json') do
`npm install`
end
end
guard :brandable_css
guard 'coffeescript', :input => 'app/coffeescripts', :output => 'public/javascripts/compiled'
guard 'coffeescript', :input => 'spec/coffeescripts', :output => 'spec/javascripts/compiled'
guard 'coffeescript', :input => 'spec_canvas/coffeescripts', :output => 'spec_canvas/javascripts'
guard 'jst', :input => 'app/views/jst', :output => 'public/javascripts/jst'
guard 'jstcss', :input => 'app/stylesheets/jst'
guard :ember_templates
guard :coffeescript, input: 'app/coffeescripts', output: 'public/javascripts/compiled'
guard :coffeescript, input: 'spec/coffeescripts', output: 'spec/javascripts/compiled'
guard :coffeescript, input: 'spec_canvas/coffeescripts', output: 'spec_canvas/javascripts'
guard :ember_bundles
guard :styleguide
guard :ember_templates
guard :js_extensions
guard :jst, input: 'app/views/jst', output: 'public/javascripts/jst'
guard :jstcss, input: 'app/stylesheets/jst'
guard :jsx
guard :styleguide
guard 'gulp' do
watch(%r{^gulpfile.babel.js$})
end
# these just kick off other watcher processes
guard :brandable_css
guard :gulp

View File

@ -195,7 +195,7 @@ module CanvasRails
#
# Easiest way to avoid the warning for now is to patch thor
def validate_default_type!
return if switch_name == "--serializer"
return if switch_name == "--serializer"
super
end
end

View File

@ -1,9 +1,8 @@
require 'guard'
require 'guard/guard'
require 'guard/plugin'
module Guard
class BrandableCSS < Guard
class BrandableCSS < Plugin
def start
@pid = spawn("./node_modules/.bin/brandable_css --watch")
end

View File

@ -23,23 +23,23 @@
#
require 'guard'
require 'guard/guard'
require 'guard/plugin'
require 'guard/watcher'
require 'coffee_script'
module Guard
class CoffeeScript < Guard
class CoffeeScript < Plugin
module Formatter
class << self
def info(message, options = { }); ::Guard::UI.info(message, options); end
def info(message, options = {}); ::Guard::UI.info(message, options); end
def error(message, options = { }); ::Guard::UI.error(color(message, ';31'), options); end
def error(message, options = {}); ::Guard::UI.error(color(message, ';31'), options); end
def success(message, options = { }); ::Guard::UI.info(color(message, ';32'), options); end
def success(message, options = {}); ::Guard::UI.info(color(message, ';32'), options); end
def notify(message, options = { }); ::Guard::Notifier.notify(message, options); end
def notify(message, options = {}); ::Guard::Notifier.notify(message, options); end
private
def color(text, color_code); ::Guard::UI.send(:color_enabled?) ? "\e[0#{ color_code }m#{ text }\e[0m" : text; end
end
@ -54,7 +54,6 @@ module Guard
compile_files(plugin_files, watchers, options.merge(:output => "#{prefix}#{options[:output]}"))
end
notify_result(changed_files, errors, options)
[changed_files, errors.empty?]
end
@ -62,7 +61,7 @@ module Guard
def partition_by_plugin(files, &block)
groupings = files.inject({}) { |hash, file|
prefix = file =~ %r{\Avendor/plugins/.*?/} ? $& : ''
prefix = file =~ %r{\Agems/plugins/.*?/} ? $& : ''
hash[prefix] ||= []
hash[prefix] << file
hash
@ -143,7 +142,7 @@ module Guard
directories = { }
watchers.product(files).each do |watcher, file|
if matches = file.match(watcher.pattern)
if matches = watcher.pattern.match(file)
target = matches[1] ? File.join(options[:output], File.dirname(matches[1])).gsub(/\/\.$/, '') : options[:output]
if directories[target]
directories[target] << file
@ -177,16 +176,16 @@ module Guard
:all_on_start => false
}
def initialize(watchers = [], options = {})
watchers = [] if !watchers
def initialize(options = {})
options[:watchers] ||= []
defaults = DEFAULT_OPTIONS.clone
if options[:input]
defaults.merge!({ :output => options[:input] })
watchers << ::Guard::Watcher.new(%r{\A(?:vendor/plugins/.*?/)?#{ Regexp.escape(options.delete(:input)) }/(.+\.coffee)\z})
options[:watchers] << ::Guard::Watcher.new(%r{\A(?:gems/plugins/.*?/)?#{ Regexp.escape(options.delete(:input)) }/(.+\.coffee)\z})
end
super(watchers, defaults.merge(options))
super(defaults.merge(options))
end
def start
@ -194,17 +193,16 @@ module Guard
end
def run_all
run_on_change(Watcher.match_files(self, Dir.glob(File.join('**/*/**', '*.coffee'))))
run_on_modifications(Watcher.match_files(self, Dir.glob(File.join('**/*/**', '*.coffee'))))
end
def run_on_change(paths)
def run_on_modifications(paths)
changed_files, success = Runner.run(clean(paths), watchers, options)
notify changed_files
throw :task_has_failed unless success
end
def run_on_deletion(paths)
def run_on_removals(paths)
clean(paths).each do |file|
javascript = file.gsub(/(js\.coffee|coffee)$/, 'js')
File.remove(javascript) if File.exist?(javascript)
@ -213,18 +211,10 @@ module Guard
private
def notify(changed_files)
::Guard.guards.each do |guard|
paths = Watcher.match_files(guard, changed_files)
guard.run_on_change paths unless paths.empty?
end
end
def clean(paths)
paths.uniq!
paths.compact!
paths.select { |p| p =~ /.coffee$/ && File.exist?(p) }
end
end
end

View File

@ -1,24 +1,25 @@
require 'guard'
require 'guard/guard'
require 'guard/plugin'
require 'lib/ember_bundle'
module Guard
class EmberBundles < Guard
class EmberBundles < Plugin
DEFAULT_OPTIONS = {
:hide_success => false,
:all_on_start => false
}
def initialize(watchers=[], options={})
super([::Guard::Watcher.new(/(app\/coffeescripts\/ember\/)/)], {})
def initialize(options={})
options[:watchers] = [::Guard::Watcher.new(/(app\/coffeescripts\/ember\/)/)]
super(options)
end
def start
run_all if options[:all_on_start]
end
def run_on_change(paths)
def run_on_changes(paths)
build_bundles(paths)
end
@ -40,10 +41,6 @@ module Guard
EmberBundle.new(app).build
end
end
def run_on_deletion(paths)
build_bundles(paths)
end
end
end

View File

@ -1,24 +1,25 @@
require 'guard'
require 'guard/guard'
require 'guard/plugin'
require 'handlebars_tasks'
module Guard
class EmberTemplates < Guard
class EmberTemplates < Plugin
DEFAULT_OPTIONS = {
:hide_success => false,
:all_on_start => false
}
def initialize(watchers=[], options={})
super([::Guard::Watcher.new(/(app\/coffeescripts\/ember\/.*.hbs)\z/)], {})
def initialize(options={})
options[:watchers] = [::Guard::Watcher.new(/(app\/coffeescripts\/ember\/.*.hbs)\z/)]
super(options)
end
def start
run_all if options[:all_on_start]
end
def run_on_change(paths)
def run_on_modifications(paths)
paths.each do |path|
begin
UI.info "Compiling Ember template: #{path}"
@ -43,8 +44,8 @@ module Guard
end
def run_on_deletion(paths)
puts "TODO: run_on_deletion not implemented"
def run_on_removals(paths)
puts "TODO: run_on_removals not implemented"
end
end
end

14
guard/gulp.rb Normal file
View File

@ -0,0 +1,14 @@
require 'guard'
require 'guard/plugin'
module Guard
class Gulp < Plugin
def start
@pid = spawn("./node_modules/.bin/gulp watch")
end
def stop
Process.kill(:INT, @pid)
end
end
end

View File

@ -1,15 +1,16 @@
require 'guard'
require 'guard/guard'
require 'guard/plugin'
require 'lib/canvas/require_js/plugin_extension'
module Guard
class JsExtensions < Guard
def initialize(watchers = [], options = {})
pattern = %r{vendor/plugins/[^/]+/app/coffeescripts/extensions/(.+\.coffee)$}
super [::Guard::Watcher.new(pattern)], options
class JsExtensions < Plugin
def initialize(options = {})
pattern = %r{gems/plugins/[^/]+/app/coffeescripts/extensions/(.+\.coffee)$}
options[:watchers] = [::Guard::Watcher.new(pattern)]
super(options)
end
def run_on_additions(paths)
def run_on_modifications(paths)
UI.info "Generating plugin extensions for #{paths.join(", ")}"
paths.each do |path|
path = path.gsub(%r{.*?/extensions/}, '')

View File

@ -1,11 +1,11 @@
require 'guard'
require 'guard/guard'
require 'guard/plugin'
require 'fileutils'
require 'handlebars_tasks'
require 'parallel'
module Guard
class JST < Guard
class JST < Plugin
DEFAULT_OPTIONS = {
@ -15,23 +15,22 @@ module Guard
# Initialize Guard::JST.
#
# @param [Array<Guard::Watcher>] watchers the watchers in the Guard block
# @param [Hash] options the options for the Guard
# @option options [String] :input the input directory
# @option options [String] :output the output directory
# @option options [Boolean] :hide_success hide success message notification
# @option options [Boolean] :all_on_start generate all JavaScripts files on start
#
def initialize(watchers = [], options = {})
watchers = [] if !watchers
def initialize(options = {})
options[:watchers] ||= []
defaults = DEFAULT_OPTIONS.clone
if options[:input]
defaults.merge!({ :output => options[:input] })
watchers << ::Guard::Watcher.new(%r{\A(?:vendor/plugins/.*?/)?#{ Regexp.escape(options[:input]) }/(.+\.handlebars)\z})
options[:watchers] << ::Guard::Watcher.new(%r{\A(?:vendor/plugins/.*?/)?#{ Regexp.escape(options[:input]) }/(.+\.handlebars)\z})
end
super(watchers, defaults.merge(options))
super(defaults.merge(options))
end
# Gets called once when Guard starts.
@ -49,7 +48,7 @@ module Guard
# @raise [:task_has_failed] when stop has failed
#
# Compiles templates from app/views/jst to public/javascripts/jst
def run_on_change(paths)
def run_on_modifications(paths)
paths = paths.map{ |path|
prefix = path =~ %r{\Avendor/plugins/.*?/} ? $& : ''
[prefix, path]
@ -77,11 +76,7 @@ module Guard
# Called on file(s) deletions that the Guard watches.
#
# @param [Array<String>] paths the deleted files or paths
# @raise [:task_has_failed] when run_on_change has failed
#
def run_on_deletion(paths)
def run_on_removals(paths)
paths.each do |file|
javascript = file.sub(%r{\A#{Regexp.escape(@options[:input])}/(.*?)\.handlebars}, "#{@options[:output]}/\\1.js")
UI.info "Removing: #{javascript}"

View File

@ -1,5 +1,5 @@
require 'guard'
require 'guard/guard'
require 'guard/plugin'
require 'fileutils'
# The only thing this guard does is make sure to touch the
@ -7,19 +7,19 @@ require 'fileutils'
# doing so will trigger the handlebars guard to regenerate the
# .handlebars file with the new css injected into
module Guard
class JSTCSS < Guard
class JSTCSS < Plugin
def initialize(watchers = [], options = {})
watchers = [] if !watchers
def initialize(options = {})
options[:watchers] ||= []
if options[:input]
watchers << ::Guard::Watcher.new(%r{\A(?:vendor/plugins/.*?/)?#{ Regexp.escape(options[:input]) }/(.+\.s[ca]ss)\z})
options[:watchers] << ::Guard::Watcher.new(%r{\A(?:vendor/plugins/.*?/)?#{ Regexp.escape(options[:input]) }/(.+\.s[ca]ss)\z})
end
super(watchers, options)
super(options)
end
def run_on_change(paths)
def run_on_modifications(paths)
paths.each { |p| touch_handlebars_file(p) }
end
@ -29,4 +29,4 @@ module Guard
end
end
end
end

View File

@ -1,15 +1,18 @@
require 'guard'
require 'guard/guard'
require 'guard/plugin'
module Guard
class JSX < Guard
class JSX < Plugin
def initialize(watchers=[], options={})
super([::Guard::Watcher.new(%r{app/jsx/.*}),
::Guard::Watcher.new(%r{spec/javascripts/jsx/.*})], {})
def initialize(options={})
options[:watchers] = [
::Guard::Watcher.new(%r{app/jsx/.*}),
::Guard::Watcher.new(%r{spec/javascripts/jsx/.*})
]
super(options)
end
def run_on_change(paths)
def run_on_modifications(paths)
# naive right now, will be better when we rework the front-end build
run_all
end
@ -24,4 +27,3 @@ module Guard
end
end

View File

@ -1,10 +1,11 @@
require 'guard'
require 'guard/guard'
require 'guard/plugin'
module Guard
class Styleguide < Guard
def initialize(watchers=[], options={})
super([::Guard::Watcher.new(/(app\/stylesheets.*)/)], {})
class Styleguide < Plugin
def initialize(options={})
options[:watchers] = [::Guard::Watcher.new(/(app\/stylesheets.*)/)]
super(options)
end
def run_on_change(paths)