jumbler 0.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.
- data/bin/jumbler +21 -0
- data/lib/jumbler.rb +102 -0
- metadata +80 -0
data/bin/jumbler
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'jumbler'
|
4
|
+
|
5
|
+
# create the jumbler
|
6
|
+
j = Jumbler.new ARGV
|
7
|
+
|
8
|
+
=begin
|
9
|
+
def help
|
10
|
+
print "
|
11
|
+
Usage: #{__FILE__} watch --in_folder --out_folder
|
12
|
+
"
|
13
|
+
end
|
14
|
+
|
15
|
+
if ARGV.empty?
|
16
|
+
help
|
17
|
+
exit
|
18
|
+
else
|
19
|
+
j = Jumbler.new ARGV
|
20
|
+
end
|
21
|
+
=end
|
data/lib/jumbler.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Application to watch folders containg javascript
|
3
|
+
# and passing them to Googles closure compiler upon modification
|
4
|
+
# resulting in a minified file in a specified directory
|
5
|
+
#
|
6
|
+
# Inspired by Compass and Google's Closure Compiler
|
7
|
+
#
|
8
|
+
# Uses Listen library
|
9
|
+
#
|
10
|
+
# Requires java
|
11
|
+
# Requires java to be add to PATH
|
12
|
+
#
|
13
|
+
|
14
|
+
require 'listen'
|
15
|
+
require 'find'
|
16
|
+
#require 'debugger'
|
17
|
+
|
18
|
+
class Jumbler
|
19
|
+
# initialize jumbler
|
20
|
+
def initialize args
|
21
|
+
@gcc_path = File.join(File.dirname(__FILE__),'gcc','compiler.jar')
|
22
|
+
@java_exec = 'java'
|
23
|
+
|
24
|
+
@current_dir = Dir.pwd
|
25
|
+
@watch_dir = @current_dir
|
26
|
+
@output_file = File.join(@watch_dir, 'jumbled.min.js')
|
27
|
+
# get all js files to be comiled
|
28
|
+
@js_file_paths = self.get_js @watch_dir
|
29
|
+
|
30
|
+
puts 'Jumbler is now looking for changes'
|
31
|
+
# listen to the specified folder for changes to js files
|
32
|
+
@listener = Listen.to(@watch_dir, :relative_paths => true, :filter => /\.js$/, :ignore => %r{ignored/path/}) do |modified, added, removed|
|
33
|
+
puts 'changes detected'
|
34
|
+
|
35
|
+
all_changes = modified + added + removed
|
36
|
+
|
37
|
+
puts all_changes
|
38
|
+
# stop if the change was the compiled file
|
39
|
+
unless(all_changes.length == 1 && "#{File.join(@watch_dir, all_changes[0])}" == @output_file)
|
40
|
+
|
41
|
+
puts 'recompilation needed'
|
42
|
+
if(added.length > 0)
|
43
|
+
# if a new file is added we need to add it to the array
|
44
|
+
added.each{|item|
|
45
|
+
@js_file_paths << File.join(@watch_dir, item)
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
if(removed.length > 0)
|
50
|
+
# if a file is removed we need to remove it from the array
|
51
|
+
removed.each{|item|
|
52
|
+
@js_file_paths.any? {|path|
|
53
|
+
if(path == File.join(@watch_dir, item))
|
54
|
+
@js_file_paths.delete(path)
|
55
|
+
end
|
56
|
+
}
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
# compile the new js file
|
61
|
+
self.jumble
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# recursively finds all js files from a specified directory
|
67
|
+
def get_js root_dir
|
68
|
+
file_paths = []
|
69
|
+
|
70
|
+
Find.find(root_dir) do |path|
|
71
|
+
file_paths << path if path =~ /.*\.js$/
|
72
|
+
end
|
73
|
+
|
74
|
+
return file_paths
|
75
|
+
end
|
76
|
+
|
77
|
+
# creates the command to be used to run the closure compiler
|
78
|
+
def jumble
|
79
|
+
command = ''
|
80
|
+
|
81
|
+
@js_file_paths.each {|item|
|
82
|
+
command += '--js "' + item + '" '
|
83
|
+
}
|
84
|
+
|
85
|
+
command += ' --js_output_file "' + @output_file + '"'
|
86
|
+
|
87
|
+
self.exjar command
|
88
|
+
end
|
89
|
+
|
90
|
+
# executes the closure compiler
|
91
|
+
def exjar args
|
92
|
+
# move to the compilers directory
|
93
|
+
Dir.chdir("#{File.dirname(@gcc_path)}") do
|
94
|
+
# execute the compiler
|
95
|
+
retResult = system("#{@java_exec} -jar #{File.basename(@gcc_path)} #{args}")
|
96
|
+
puts retResult
|
97
|
+
end #chdir
|
98
|
+
|
99
|
+
# move back to original directory
|
100
|
+
Dir.chdir(@current_dir)
|
101
|
+
end
|
102
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jumbler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Adam Cox
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: listen
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.6.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.6.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: wdm
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.0.3
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.0.3
|
46
|
+
description: Uses Googles Closure Compiler to combine JS files into a single, better
|
47
|
+
formed javascript
|
48
|
+
email: adamdama@hotmail.com
|
49
|
+
executables:
|
50
|
+
- jumbler
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- lib/jumbler.rb
|
55
|
+
- bin/jumbler
|
56
|
+
homepage: https://github.com/adamdama/jumbler
|
57
|
+
licenses: []
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 1.8.24
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: Jumbler JS Combiner
|
80
|
+
test_files: []
|