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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 323c7e2132478df1476a90090aff3fe5bbbbab1c
4
- data.tar.gz: a1aee90b3034c4cb5dd65ab171c7ec9ad8906d34
3
+ metadata.gz: 5c743e66fd980bec933e0488d02b0d6f85547512
4
+ data.tar.gz: 7df707477237139411cdf4df36496e2155fc3d56
5
5
  SHA512:
6
- metadata.gz: af5d8c254070611af0884295b3c9461d6e47ec3699a0166c2c9921a35ecb05a40adeec874bf6c1211e1d21b3c12d540b5466485b34bb129a6cb69656f934f56d
7
- data.tar.gz: 4d5a7690e7618689b0025a09116fad46f0bf7c8024893fab2f4ee52973fe8d0a2b238db08adfcb947693a7bda08e1b196d2d026f601398157c2981627db63a9b
6
+ metadata.gz: 4b44de7a5501bce5051fa671131a454ad7322da7d263ea81d79a0cd0f43e2ddec93c80650e082afaab6d36c0989946c5c40268c700ca69b14aa15850c5183309
7
+ data.tar.gz: 7d7ae22f39fc691dc2d891dd928b2194088b4d739a183f57bc3711aee39c62f157a26c73cef1565e22bf8eb0cea4b201e5c7fed68f3967e485c4224302451c11
@@ -1,45 +1,113 @@
1
- require 'guard'
2
- require 'guard/guard'
3
-
4
- require 'uglifier'
1
+ require "guard"
2
+ require "guard/plugin"
3
+ require "guard/watcher"
4
+ require "uglifier"
5
5
 
6
6
  module Guard
7
- class Uglify < Guard
8
- def initialize(watchers=[], options={})
9
- super
10
- @input = options[:input]
11
- @output = options[:output]
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
- uglify
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
- uglify
51
+ run_all
20
52
  end
21
53
 
54
+ ###
55
+ # Run all
56
+ ###
22
57
  def run_all
23
- uglify
58
+ run_on_changes Watcher.match_files self, Dir[options[:input]]
24
59
  end
25
60
 
26
- def run_on_change(paths)
27
- uglify
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
- def uglify
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(@input))
34
- File.open(@output,'w'){ |f| f.write(uglified) }
35
- UI.info "Uglified #{@input} to #{@output}"
36
- Notifier.notify "Uglified #{@input} to #{@output}", :title => 'Uglify'
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 => e
39
- UI.error "Uglifying #{@input} failed: #{e}"
40
- Notifier.notify "Uglifying #{@input} failed: #{e}", :title => 'Uglify', :image => :failed
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
- guard 'uglify', :input => 'app/assets/javascripts/application.js', :output => "public/javascripts/application.js" do
2
- watch (%r{app/assets/javascripts/application.js})
3
- end
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"
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Guard
3
3
  module UglifyVersion
4
- VERSION = '0.2.0'
4
+ VERSION = "1.0.0"
5
5
  end
6
6
  end
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.2.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-06-08 00:00:00.000000000 Z
11
+ date: 2014-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard