guard-uglify 0.2.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/guard/uglify.rb +90 -22
- data/lib/guard/uglify/templates/Guardfile +9 -3
- data/lib/guard/uglify/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c743e66fd980bec933e0488d02b0d6f85547512
|
4
|
+
data.tar.gz: 7df707477237139411cdf4df36496e2155fc3d56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b44de7a5501bce5051fa671131a454ad7322da7d263ea81d79a0cd0f43e2ddec93c80650e082afaab6d36c0989946c5c40268c700ca69b14aa15850c5183309
|
7
|
+
data.tar.gz: 7d7ae22f39fc691dc2d891dd928b2194088b4d739a183f57bc3711aee39c62f157a26c73cef1565e22bf8eb0cea4b201e5c7fed68f3967e485c4224302451c11
|
data/lib/guard/uglify.rb
CHANGED
@@ -1,45 +1,113 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
|
4
|
-
require
|
1
|
+
require "guard"
|
2
|
+
require "guard/plugin"
|
3
|
+
require "guard/watcher"
|
4
|
+
require "uglifier"
|
5
5
|
|
6
6
|
module Guard
|
7
|
-
class Uglify <
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
class Uglify < Plugin
|
8
|
+
###
|
9
|
+
# Initializer
|
10
|
+
###
|
11
|
+
def initialize(options = {})
|
12
|
+
options = {
|
13
|
+
:input => "app/assets/javascripts/application.js",
|
14
|
+
:output => "public/javascripts/application.js",
|
15
|
+
:all_on_start => false,
|
16
|
+
:uglifier => {
|
17
|
+
:mangle => {
|
18
|
+
:toplevel => true
|
19
|
+
},
|
20
|
+
:compress => {
|
21
|
+
:drop_console => true
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}.merge(options)
|
25
|
+
|
26
|
+
super(options)
|
27
|
+
|
28
|
+
if options[:input]
|
29
|
+
watchers << Watcher.new(%r{#{options[:input]}})
|
30
|
+
end
|
12
31
|
end
|
13
32
|
|
33
|
+
###
|
34
|
+
# Run at start
|
35
|
+
###
|
14
36
|
def start
|
15
|
-
|
37
|
+
run_all if options[:run_at_start]
|
16
38
|
end
|
17
39
|
|
40
|
+
###
|
41
|
+
# Stop running
|
42
|
+
###
|
43
|
+
def stop
|
44
|
+
true
|
45
|
+
end
|
46
|
+
|
47
|
+
###
|
48
|
+
# On Guard reload
|
49
|
+
###
|
18
50
|
def reload
|
19
|
-
|
51
|
+
run_all
|
20
52
|
end
|
21
53
|
|
54
|
+
###
|
55
|
+
# Run all
|
56
|
+
###
|
22
57
|
def run_all
|
23
|
-
|
58
|
+
run_on_changes Watcher.match_files self, Dir[options[:input]]
|
24
59
|
end
|
25
60
|
|
26
|
-
|
27
|
-
|
61
|
+
###
|
62
|
+
# Run on changes to watched files
|
63
|
+
#
|
64
|
+
# @param {Array} paths
|
65
|
+
# Paths of changed files
|
66
|
+
###
|
67
|
+
def run_on_changes(paths)
|
68
|
+
paths.each do |file|
|
69
|
+
uglify file
|
70
|
+
end
|
28
71
|
end
|
29
72
|
|
30
73
|
private
|
31
|
-
|
74
|
+
|
75
|
+
###
|
76
|
+
# Run the Uglifier gem and write contents to output file
|
77
|
+
#
|
78
|
+
# @param {String} file
|
79
|
+
# Input file to pass to Uglifier
|
80
|
+
###
|
81
|
+
def uglify(file)
|
32
82
|
begin
|
33
|
-
uglified = Uglifier.new.compile(File.read(
|
34
|
-
|
35
|
-
|
36
|
-
|
83
|
+
uglified = ::Uglifier.new(options[:uglifier]).compile(File.read(file))
|
84
|
+
|
85
|
+
File.open(options[:output], "w") { |f| f.write uglified }
|
86
|
+
|
87
|
+
msg = color("Uglified #{options[:input]} to #{options[:output]}", ";32")
|
88
|
+
::Guard::UI.info msg
|
37
89
|
true
|
38
|
-
rescue Exception =>
|
39
|
-
|
40
|
-
|
90
|
+
rescue Exception => err
|
91
|
+
msg = color("Uglifying #{options[:input]} failed: #{err}", ";31")
|
92
|
+
::Guard::UI.error msg
|
41
93
|
false
|
42
94
|
end
|
43
95
|
end
|
96
|
+
|
97
|
+
###
|
98
|
+
# Set message color
|
99
|
+
#
|
100
|
+
# @param {String} message
|
101
|
+
# Text to color
|
102
|
+
# @param {String} color
|
103
|
+
# Color code
|
104
|
+
###
|
105
|
+
def color(message, color)
|
106
|
+
if ::Guard::UI.send(:color_enabled?)
|
107
|
+
"\e[0#{color}m#{message}\e[0m"
|
108
|
+
else
|
109
|
+
message
|
110
|
+
end
|
111
|
+
end
|
44
112
|
end
|
45
113
|
end
|
@@ -1,3 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
###
|
2
|
+
# Sample Guardfile block for Guard::Uglify
|
3
|
+
#
|
4
|
+
# :input - input file to compress
|
5
|
+
# :output - file to write compressed output to
|
6
|
+
# :run_at_start - compressed input file when guard starts
|
7
|
+
# :uglifier - options to be passed to the uglifier gem
|
8
|
+
###
|
9
|
+
guard "uglify", :input => "app/assets/javascripts/application.js", :output => "public/javascripts/application.js"
|
data/lib/guard/uglify/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-uglify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Cruz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: guard
|