guard-coffeescript 1.4.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/guard/coffeescript.rb +38 -28
- data/lib/guard/coffeescript.rb.orig +88 -0
- data/lib/guard/coffeescript/formatter.rb +11 -14
- data/lib/guard/coffeescript/formatter.rb.orig +74 -0
- data/lib/guard/coffeescript/inspector.rb +1 -4
- data/lib/guard/coffeescript/runner.rb +39 -44
- data/lib/guard/coffeescript/runner.rb.orig +269 -0
- data/lib/guard/coffeescript/templates/Guardfile +9 -1
- data/lib/guard/coffeescript/templates/Guardfile.orig +1 -0
- data/lib/guard/coffeescript/version.rb +1 -2
- data/lib/guard/coffeescript/version.rb.orig +6 -0
- metadata +20 -33
- data/lib/guard/coffeescript.rbc +0 -1536
- data/lib/guard/coffeescript/formatter.rbc +0 -1031
- data/lib/guard/coffeescript/runner.rbc +0 -2785
- data/lib/guard/coffeescript/version.rbc +0 -203
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 887d4228743c3c6c58f84dc764a8405e970d27be
|
4
|
+
data.tar.gz: 8d2b16ee663c98be7a22c730909bec4a5c9fd384
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2fec52e08b973acfa91184d7e471fa86bf39a16b7c3ada117fa3f0514a8ae15800ead30c80faaf6e0458685ce829e24ddd677e4f70a4f72809b284773d94e38
|
7
|
+
data.tar.gz: 3c541bcb267c644d37aa5b9690fdc3110422fa13e40e3313066608259d10b91ea39e6f868c876e0618b20031ac95391f6523a49de71e896a50dba1022ed3ea33
|
data/lib/guard/coffeescript.rb
CHANGED
@@ -1,34 +1,31 @@
|
|
1
|
-
require 'guard'
|
2
|
-
require 'guard/guard'
|
3
|
-
require 'guard/watcher'
|
1
|
+
require 'guard/compat/plugin'
|
4
2
|
|
5
3
|
module Guard
|
6
|
-
|
7
4
|
# The CoffeeScript guard that gets notifications about the following
|
8
5
|
# Guard events: `start`, `stop`, `reload`, `run_all` and `run_on_change`.
|
9
6
|
#
|
10
|
-
class CoffeeScript <
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
autoload :Runner, 'guard/coffeescript/runner'
|
7
|
+
class CoffeeScript < Plugin
|
8
|
+
require 'guard/coffeescript/formatter'
|
9
|
+
require 'guard/coffeescript/inspector'
|
10
|
+
require 'guard/coffeescript/runner'
|
15
11
|
|
16
12
|
DEFAULT_OPTIONS = {
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
13
|
+
bare: false,
|
14
|
+
shallow: false,
|
15
|
+
hide_success: false,
|
16
|
+
noop: false,
|
17
|
+
error_to_js: false,
|
18
|
+
all_on_start: false,
|
19
|
+
source_map: false
|
24
20
|
}
|
25
21
|
|
26
22
|
# Initialize Guard::CoffeeScript.
|
27
23
|
#
|
28
|
-
|
24
|
+
|
29
25
|
# @param [Hash] options the options for the Guard
|
30
26
|
# @option options [String] :input the input directory
|
31
27
|
# @option options [String] :output the output directory
|
28
|
+
# @option options [Array<Guard::Watcher>] :watchers the watchers in the Guard block
|
32
29
|
# @option options [Boolean] :bare do not wrap the output in a top level function
|
33
30
|
# @option options [Boolean] :shallow do not create nested directories
|
34
31
|
# @option options [Boolean] :hide_success hide success message notification
|
@@ -36,16 +33,23 @@ module Guard
|
|
36
33
|
# @option options [Boolean] :noop do not generate an output file
|
37
34
|
# @option options [Boolean] :source_map generate the source map files
|
38
35
|
#
|
39
|
-
|
40
|
-
|
36
|
+
|
37
|
+
attr_reader :patterns
|
38
|
+
|
39
|
+
def initialize(options = {})
|
41
40
|
defaults = DEFAULT_OPTIONS.clone
|
42
41
|
|
43
|
-
|
44
|
-
defaults.merge!({ :output => options[:input] })
|
45
|
-
watchers << ::Guard::Watcher.new(%r{^#{ options[:input] }/(.+\.(?:coffee|coffee\.md|litcoffee))$})
|
46
|
-
end
|
42
|
+
@patterns = options.dup.delete(:patterns) || []
|
47
43
|
|
48
|
-
|
44
|
+
msg = 'Invalid :patterns argument. Expected: Array, got %s'
|
45
|
+
fail ArgumentError, format(msg, @patterns.inspect) unless @patterns.is_a?(Array)
|
46
|
+
|
47
|
+
msg = ':input option not provided (see current template Guardfile)'
|
48
|
+
fail msg unless options[:input]
|
49
|
+
|
50
|
+
options[:output] = options[:input] unless options[:output]
|
51
|
+
|
52
|
+
super(defaults.merge(options))
|
49
53
|
end
|
50
54
|
|
51
55
|
# Gets called once when Guard starts.
|
@@ -61,7 +65,14 @@ module Guard
|
|
61
65
|
# @raise [:task_has_failed] when stop has failed
|
62
66
|
#
|
63
67
|
def run_all
|
64
|
-
|
68
|
+
found = Dir.glob('**{,/*/**}/*.{coffee,coffee.md,litcoffee}')
|
69
|
+
found.select! do |file|
|
70
|
+
@patterns.any? do |pattern|
|
71
|
+
pattern.match(file)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
run_on_modifications(found)
|
65
76
|
end
|
66
77
|
|
67
78
|
# Gets called when watched paths and files have changes.
|
@@ -70,7 +81,7 @@ module Guard
|
|
70
81
|
# @raise [:task_has_failed] when stop has failed
|
71
82
|
#
|
72
83
|
def run_on_modifications(paths)
|
73
|
-
|
84
|
+
_changed_files, success = Runner.run(Inspector.clean(paths), @patterns, options)
|
74
85
|
|
75
86
|
throw :task_has_failed unless success
|
76
87
|
end
|
@@ -81,8 +92,7 @@ module Guard
|
|
81
92
|
# @raise [:task_has_failed] when run_on_change has failed
|
82
93
|
#
|
83
94
|
def run_on_removals(paths)
|
84
|
-
Runner.remove(Inspector.clean(paths, :
|
95
|
+
Runner.remove(Inspector.clean(paths, missing_ok: true), @patterns, options)
|
85
96
|
end
|
86
|
-
|
87
97
|
end
|
88
98
|
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'guard'
|
2
|
+
require 'guard/guard'
|
3
|
+
require 'guard/watcher'
|
4
|
+
|
5
|
+
module Guard
|
6
|
+
|
7
|
+
# The CoffeeScript guard that gets notifications about the following
|
8
|
+
# Guard events: `start`, `stop`, `reload`, `run_all` and `run_on_change`.
|
9
|
+
#
|
10
|
+
class CoffeeScript < Guard
|
11
|
+
|
12
|
+
autoload :Formatter, 'guard/coffeescript/formatter'
|
13
|
+
autoload :Inspector, 'guard/coffeescript/inspector'
|
14
|
+
autoload :Runner, 'guard/coffeescript/runner'
|
15
|
+
|
16
|
+
DEFAULT_OPTIONS = {
|
17
|
+
:bare => false,
|
18
|
+
:shallow => false,
|
19
|
+
:hide_success => false,
|
20
|
+
:noop => false,
|
21
|
+
:error_to_js => false,
|
22
|
+
:all_on_start => false,
|
23
|
+
:source_map => false
|
24
|
+
}
|
25
|
+
|
26
|
+
# Initialize Guard::CoffeeScript.
|
27
|
+
#
|
28
|
+
# @param [Array<Guard::Watcher>] watchers the watchers in the Guard block
|
29
|
+
# @param [Hash] options the options for the Guard
|
30
|
+
# @option options [String] :input the input directory
|
31
|
+
# @option options [String] :output the output directory
|
32
|
+
# @option options [Boolean] :bare do not wrap the output in a top level function
|
33
|
+
# @option options [Boolean] :shallow do not create nested directories
|
34
|
+
# @option options [Boolean] :hide_success hide success message notification
|
35
|
+
# @option options [Boolean] :all_on_start generate all JavaScripts files on start
|
36
|
+
# @option options [Boolean] :noop do not generate an output file
|
37
|
+
# @option options [Boolean] :source_map generate the source map files
|
38
|
+
#
|
39
|
+
def initialize(watchers = [], options = {})
|
40
|
+
watchers = [] if !watchers
|
41
|
+
defaults = DEFAULT_OPTIONS.clone
|
42
|
+
|
43
|
+
if options[:input]
|
44
|
+
defaults.merge!({ :output => options[:input] })
|
45
|
+
watchers << ::Guard::Watcher.new(%r{^#{ options[:input] }/(.+\.(?:coffee|coffee\.md|litcoffee))$})
|
46
|
+
end
|
47
|
+
|
48
|
+
super(watchers, defaults.merge(options))
|
49
|
+
end
|
50
|
+
|
51
|
+
# Gets called once when Guard starts.
|
52
|
+
#
|
53
|
+
# @raise [:task_has_failed] when stop has failed
|
54
|
+
#
|
55
|
+
def start
|
56
|
+
run_all if options[:all_on_start]
|
57
|
+
end
|
58
|
+
|
59
|
+
# Gets called when all files should be regenerated.
|
60
|
+
#
|
61
|
+
# @raise [:task_has_failed] when stop has failed
|
62
|
+
#
|
63
|
+
def run_all
|
64
|
+
run_on_modifications(Watcher.match_files(self, Dir.glob('**{,/*/**}/*.{coffee,coffee.md,litcoffee}')))
|
65
|
+
end
|
66
|
+
|
67
|
+
# Gets called when watched paths and files have changes.
|
68
|
+
#
|
69
|
+
# @param [Array<String>] paths the changed paths and files
|
70
|
+
# @raise [:task_has_failed] when stop has failed
|
71
|
+
#
|
72
|
+
def run_on_modifications(paths)
|
73
|
+
changed_files, success = Runner.run(Inspector.clean(paths), watchers, options)
|
74
|
+
|
75
|
+
throw :task_has_failed unless success
|
76
|
+
end
|
77
|
+
|
78
|
+
# Called on file(s) deletions that the Guard watches.
|
79
|
+
#
|
80
|
+
# @param [Array<String>] paths the deleted files or paths
|
81
|
+
# @raise [:task_has_failed] when run_on_change has failed
|
82
|
+
#
|
83
|
+
def run_on_removals(paths)
|
84
|
+
Runner.remove(Inspector.clean(paths, :missing_ok => true), watchers, options)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
@@ -1,21 +1,19 @@
|
|
1
1
|
module Guard
|
2
2
|
class CoffeeScript
|
3
|
-
|
4
3
|
# The Guard::CoffeeScript formatter collects console and
|
5
4
|
# system notification methods and enhances them with
|
6
5
|
# some color information.
|
7
6
|
#
|
8
7
|
module Formatter
|
9
8
|
class << self
|
10
|
-
|
11
9
|
# Print an info message to the console.
|
12
10
|
#
|
13
11
|
# @param [String] message the message to print
|
14
12
|
# @param [Hash] options the output options
|
15
13
|
# @option options [Boolean] :reset reset the UI
|
16
14
|
#
|
17
|
-
def info(message, options = {
|
18
|
-
::
|
15
|
+
def info(message, options = {})
|
16
|
+
Compat::UI.info(message, options)
|
19
17
|
end
|
20
18
|
|
21
19
|
# Print a debug message to the console.
|
@@ -24,8 +22,8 @@ module Guard
|
|
24
22
|
# @param [Hash] options the output options
|
25
23
|
# @option options [Boolean] :reset reset the UI
|
26
24
|
#
|
27
|
-
def debug(message, options = {
|
28
|
-
::
|
25
|
+
def debug(message, options = {})
|
26
|
+
Compat::UI.debug(message, options)
|
29
27
|
end
|
30
28
|
|
31
29
|
# Print a red error message to the console.
|
@@ -34,8 +32,8 @@ module Guard
|
|
34
32
|
# @param [Hash] options the output options
|
35
33
|
# @option options [Boolean] :reset reset the UI
|
36
34
|
#
|
37
|
-
def error(message, options = {
|
38
|
-
::
|
35
|
+
def error(message, options = {})
|
36
|
+
Compat::UI.error(color(message, ';31'), options)
|
39
37
|
end
|
40
38
|
|
41
39
|
# Print a green success message to the console.
|
@@ -44,9 +42,9 @@ module Guard
|
|
44
42
|
# @param [Hash] options the output options
|
45
43
|
# @option options [Boolean] :reset reset the UI
|
46
44
|
#
|
47
|
-
def success(message, options = {
|
45
|
+
def success(message, options = {})
|
48
46
|
stamped_message = "#{Time.now.strftime('%r')} #{message}"
|
49
|
-
::
|
47
|
+
Compat::UI.info(color(stamped_message, ';32'), options)
|
50
48
|
end
|
51
49
|
|
52
50
|
# Outputs a system notification.
|
@@ -56,8 +54,8 @@ module Guard
|
|
56
54
|
# @option options [Symbol, String] :image the image to use, either :failed, :pending or :success, or an image path
|
57
55
|
# @option options [String] :title the title of the system notification
|
58
56
|
#
|
59
|
-
def notify(message, options = {
|
60
|
-
::
|
57
|
+
def notify(message, options = {})
|
58
|
+
Compat::UI.notify(message, options)
|
61
59
|
end
|
62
60
|
|
63
61
|
private
|
@@ -68,9 +66,8 @@ module Guard
|
|
68
66
|
# @param [String] color_code the color code
|
69
67
|
#
|
70
68
|
def color(text, color_code)
|
71
|
-
::
|
69
|
+
Compat::UI.send(:color_enabled?) ? "\e[0#{ color_code }m#{ text }\e[0m" : text
|
72
70
|
end
|
73
|
-
|
74
71
|
end
|
75
72
|
end
|
76
73
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Guard
|
2
|
+
class CoffeeScript
|
3
|
+
# The Guard::CoffeeScript formatter collects console and
|
4
|
+
# system notification methods and enhances them with
|
5
|
+
# some color information.
|
6
|
+
#
|
7
|
+
module Formatter
|
8
|
+
class << self
|
9
|
+
# Print an info message to the console.
|
10
|
+
#
|
11
|
+
# @param [String] message the message to print
|
12
|
+
# @param [Hash] options the output options
|
13
|
+
# @option options [Boolean] :reset reset the UI
|
14
|
+
#
|
15
|
+
def info(message, options = {})
|
16
|
+
::Guard::UI.info(message, options)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Print a debug message to the console.
|
20
|
+
#
|
21
|
+
# @param [String] message the message to print
|
22
|
+
# @param [Hash] options the output options
|
23
|
+
# @option options [Boolean] :reset reset the UI
|
24
|
+
#
|
25
|
+
def debug(message, options = {})
|
26
|
+
::Guard::UI.debug(message, options)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Print a red error message to the console.
|
30
|
+
#
|
31
|
+
# @param [String] message the message to print
|
32
|
+
# @param [Hash] options the output options
|
33
|
+
# @option options [Boolean] :reset reset the UI
|
34
|
+
#
|
35
|
+
def error(message, options = {})
|
36
|
+
::Guard::UI.error(color(message, ';31'), options)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Print a green success message to the console.
|
40
|
+
#
|
41
|
+
# @param [String] message the message to print
|
42
|
+
# @param [Hash] options the output options
|
43
|
+
# @option options [Boolean] :reset reset the UI
|
44
|
+
#
|
45
|
+
def success(message, options = {})
|
46
|
+
stamped_message = "#{Time.now.strftime('%r')} #{message}"
|
47
|
+
::Guard::UI.info(color(stamped_message, ';32'), options)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Outputs a system notification.
|
51
|
+
#
|
52
|
+
# @param [String] message the message to print
|
53
|
+
# @param [Hash] options the output options
|
54
|
+
# @option options [Symbol, String] :image the image to use, either :failed, :pending or :success, or an image path
|
55
|
+
# @option options [String] :title the title of the system notification
|
56
|
+
#
|
57
|
+
def notify(message, options = {})
|
58
|
+
::Guard::Notifier.notify(message, options)
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
# Print a info message to the console.
|
64
|
+
#
|
65
|
+
# @param [String] text the text to colorize
|
66
|
+
# @param [String] color_code the color code
|
67
|
+
#
|
68
|
+
def color(text, color_code)
|
69
|
+
::Guard::UI.send(:color_enabled?) ? "\e[0#{ color_code }m#{ text }\e[0m" : text
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
module Guard
|
2
2
|
class CoffeeScript
|
3
|
-
|
4
3
|
# The inspector verifies of the changed paths are valid
|
5
4
|
# for Guard::CoffeeScript.
|
6
5
|
#
|
7
6
|
module Inspector
|
8
7
|
class << self
|
9
|
-
|
10
8
|
# Clean the changed paths and return only valid
|
11
9
|
# CoffeeScript files.
|
12
10
|
#
|
@@ -31,9 +29,8 @@ module Guard
|
|
31
29
|
# @return [Boolean] when the file valid
|
32
30
|
#
|
33
31
|
def coffee_file?(path, options)
|
34
|
-
path =~ /\.(?:coffee|coffee\.md|litcoffee)$/ && (options[:missing_ok] || File.
|
32
|
+
path =~ /\.(?:coffee|coffee\.md|litcoffee)$/ && (options[:missing_ok] || File.exist?(path))
|
35
33
|
end
|
36
|
-
|
37
34
|
end
|
38
35
|
end
|
39
36
|
end
|
@@ -4,7 +4,6 @@ module Guard
|
|
4
4
|
class CoffeeScript
|
5
5
|
module Runner
|
6
6
|
class << self
|
7
|
-
|
8
7
|
attr_accessor :last_run_failed
|
9
8
|
|
10
9
|
# The CoffeeScript runner handles the CoffeeScript compilation,
|
@@ -12,7 +11,7 @@ module Guard
|
|
12
11
|
# to the console and triggers optional system notifications.
|
13
12
|
#
|
14
13
|
# @param [Array<String>] files the spec files or directories
|
15
|
-
# @param [Array<
|
14
|
+
# @param [Array<Regexp>] patterns the patterns in the block
|
16
15
|
# @param [Hash] options the options for the execution
|
17
16
|
# @option options [String] :input the input directory
|
18
17
|
# @option options [String] :output the output directory
|
@@ -23,11 +22,10 @@ module Guard
|
|
23
22
|
# @option options [Boolean] :source_map generate the source map files
|
24
23
|
# @return [Array<Array<String>, Boolean>] the result for the compilation run
|
25
24
|
#
|
26
|
-
def run(files,
|
25
|
+
def run(files, patterns, options = {})
|
27
26
|
notify_start(files, options)
|
28
|
-
changed_files, errors = compile_files(files,
|
27
|
+
changed_files, errors = compile_files(files, patterns, options)
|
29
28
|
notify_result(changed_files, errors, options)
|
30
|
-
|
31
29
|
[changed_files, errors.empty?]
|
32
30
|
end
|
33
31
|
|
@@ -35,30 +33,30 @@ module Guard
|
|
35
33
|
# locating the output javascript file and removing it.
|
36
34
|
#
|
37
35
|
# @param [Array<String>] files the spec files or directories
|
38
|
-
# @param [Array<
|
36
|
+
# @param [Array<Regexp>] patterns the patterns in the block
|
39
37
|
# @param [Hash] options the options for the removal
|
40
38
|
# @option options [String] :output the output directory
|
41
39
|
# @option options [Boolean] :shallow do not create nested directories
|
42
40
|
#
|
43
|
-
def remove(files,
|
41
|
+
def remove(files, patterns, options = {})
|
44
42
|
removed_files = []
|
45
|
-
directories = detect_nested_directories(
|
43
|
+
directories = detect_nested_directories(files, patterns, options)
|
46
44
|
|
47
45
|
directories.each do |directory, scripts|
|
48
46
|
scripts.each do |file|
|
49
47
|
javascript = javascript_file_name(file, directory)
|
50
|
-
if File.
|
48
|
+
if File.exist?(javascript)
|
51
49
|
FileUtils.remove_file(javascript)
|
52
50
|
removed_files << javascript
|
53
51
|
end
|
54
52
|
end
|
55
53
|
end
|
56
54
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
55
|
+
return unless removed_files.length > 0
|
56
|
+
|
57
|
+
message = "Removed #{ removed_files.join(', ') }"
|
58
|
+
Formatter.success(message)
|
59
|
+
Formatter.notify(message, title: 'CoffeeScript results')
|
62
60
|
end
|
63
61
|
|
64
62
|
private
|
@@ -71,20 +69,19 @@ module Guard
|
|
71
69
|
#
|
72
70
|
def notify_start(files, options)
|
73
71
|
message = options[:message] || (options[:noop] ? 'Verify ' : 'Compile ') + files.join(', ')
|
74
|
-
Formatter.info(message, :
|
72
|
+
Formatter.info(message, reset: true)
|
75
73
|
end
|
76
74
|
|
77
75
|
# Compiles all CoffeeScript files and writes the JavaScript files.
|
78
76
|
#
|
79
77
|
# @param [Array<String>] files the files to compile
|
80
|
-
# @param [Array<Guard::Watcher>] watchers the Guard watchers in the block
|
81
78
|
# @param [Hash] options the options for the execution
|
82
79
|
# @return [Array<Array<String>, Array<String>] the result for the compilation run
|
83
80
|
#
|
84
|
-
def compile_files(files,
|
81
|
+
def compile_files(files, patterns, options)
|
85
82
|
errors = []
|
86
83
|
changed_files = []
|
87
|
-
directories = detect_nested_directories(
|
84
|
+
directories = detect_nested_directories(files, patterns, options)
|
88
85
|
|
89
86
|
directories.each do |directory, scripts|
|
90
87
|
scripts.each do |file|
|
@@ -92,7 +89,7 @@ module Guard
|
|
92
89
|
js, map = compile(file, options)
|
93
90
|
changed_files << write_javascript_file(js, map, file, directory, options)
|
94
91
|
|
95
|
-
rescue => e
|
92
|
+
rescue RuntimeError, ::CoffeeScript::EngineError, ::CoffeeScript::CompilationError => e
|
96
93
|
error_message = file + ': ' + e.message.to_s
|
97
94
|
|
98
95
|
if options[:error_to_js]
|
@@ -123,6 +120,7 @@ module Guard
|
|
123
120
|
if options[:source_map]
|
124
121
|
file_options.merge! options_for_source_map(filename, options)
|
125
122
|
result = ::CoffeeScript.compile(file, file_options)
|
123
|
+
fail 'CoffeeScript.compile returned nil' if result.nil?
|
126
124
|
js, map = result['js'], result['v3SourceMap']
|
127
125
|
else
|
128
126
|
js = ::CoffeeScript.compile(file, file_options)
|
@@ -147,9 +145,7 @@ module Guard
|
|
147
145
|
file_options[:bare] = file_options[:bare].include?(filename)
|
148
146
|
end
|
149
147
|
|
150
|
-
if file[/\.(?:coffee\.md|litcoffee)$/]
|
151
|
-
file_options[:literate] = true
|
152
|
-
end
|
148
|
+
file_options[:literate] = true if file[/\.(?:coffee\.md|litcoffee)$/]
|
153
149
|
|
154
150
|
file_options
|
155
151
|
end
|
@@ -164,10 +160,10 @@ module Guard
|
|
164
160
|
filename = Pathname.new(filename).relative_path_from(Pathname.new(options[:input])).to_s if options[:input]
|
165
161
|
|
166
162
|
{
|
167
|
-
:
|
168
|
-
:
|
169
|
-
:
|
170
|
-
:
|
163
|
+
sourceMap: true,
|
164
|
+
generatedFile: filename.gsub(/((?:js\.)?(?:coffee|coffee\.md|litcoffee))$/, 'js'),
|
165
|
+
sourceFiles: [filename],
|
166
|
+
sourceRoot: options[:source_root] || options[:input] || ''
|
171
167
|
}
|
172
168
|
end
|
173
169
|
|
@@ -190,10 +186,10 @@ module Guard
|
|
190
186
|
|
191
187
|
if options[:source_map]
|
192
188
|
map_name = filename + '.map'
|
193
|
-
js += "\n
|
189
|
+
js += "\n//# sourceMappingURL=#{File.basename(map_name)}\n"
|
194
190
|
end
|
195
191
|
|
196
|
-
FileUtils.mkdir_p(File.expand_path(directory))
|
192
|
+
FileUtils.mkdir_p(File.expand_path(directory)) unless File.directory?(directory)
|
197
193
|
File.open(File.expand_path(filename), 'w') { |f| f.write(js) }
|
198
194
|
|
199
195
|
if options[:source_map]
|
@@ -215,28 +211,28 @@ module Guard
|
|
215
211
|
end
|
216
212
|
|
217
213
|
# Detects the output directory for each CoffeeScript file. Builds
|
218
|
-
# the product of all
|
214
|
+
# the product of all patterns and assigns to each directory
|
219
215
|
# the files to which it belongs to.
|
220
216
|
#
|
221
|
-
# @param [Array<Guard::Watcher>] watchers the Guard watchers in the block
|
222
217
|
# @param [Array<String>] files the CoffeeScript files
|
218
|
+
# @param [Array<Regexp>] patterns the patterns in the block
|
223
219
|
# @param [Hash] options the options for the execution
|
224
220
|
# @option options [String] :output the output directory
|
225
221
|
# @option options [Boolean] :shallow do not create nested directories
|
226
222
|
#
|
227
|
-
def detect_nested_directories(
|
223
|
+
def detect_nested_directories(files, patterns, options)
|
228
224
|
return { options[:output] => files } if options[:shallow]
|
229
225
|
|
230
|
-
directories = {
|
226
|
+
directories = {}
|
231
227
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
228
|
+
patterns.product(files).each do |pattern, file|
|
229
|
+
next unless (matches = file.match(pattern))
|
230
|
+
|
231
|
+
target = matches[1] ? File.join(options[:output], File.dirname(matches[1])).gsub(/\/\.$/, '') : options[:output] || File.dirname(file)
|
232
|
+
if directories[target]
|
233
|
+
directories[target] << file
|
234
|
+
else
|
235
|
+
directories[target] = [file]
|
240
236
|
end
|
241
237
|
end
|
242
238
|
|
@@ -251,18 +247,17 @@ module Guard
|
|
251
247
|
# @option options [Boolean] :hide_success hide success message notification
|
252
248
|
# @option options [Boolean] :noop do not generate an output file
|
253
249
|
#
|
254
|
-
def notify_result(changed_files, errors, options = {
|
250
|
+
def notify_result(changed_files, errors, options = {})
|
255
251
|
if !errors.empty?
|
256
252
|
self.last_run_failed = true
|
257
|
-
Formatter.notify(errors.join("\n"), :
|
253
|
+
Formatter.notify(errors.join("\n"), title: 'CoffeeScript results', image: :failed, priority: 2)
|
258
254
|
elsif !options[:hide_success] || last_run_failed
|
259
255
|
self.last_run_failed = false
|
260
256
|
message = "Successfully #{ options[:noop] ? 'verified' : 'generated' } #{ changed_files.join(', ') }"
|
261
257
|
Formatter.success(message)
|
262
|
-
Formatter.notify(message, :
|
258
|
+
Formatter.notify(message, title: 'CoffeeScript results')
|
263
259
|
end
|
264
260
|
end
|
265
|
-
|
266
261
|
end
|
267
262
|
end
|
268
263
|
end
|