jscompiler 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +37 -16
- data/bin/jsc +2 -1
- data/lib/jscompiler.rb +1 -1
- data/lib/jscompiler/cli.rb +1 -1
- data/lib/jscompiler/commands/{clojure.rb → closure.rb} +2 -2
- data/lib/jscompiler/commands/uglifier.rb +44 -0
- data/lib/jscompiler/config.rb +4 -2
- data/lib/jscompiler/version.rb +1 -1
- data/lib/templates/jscompiler.yml.erb +1 -1
- data/vendor/{clojure → closure}/COPYING +0 -0
- data/vendor/{clojure → closure}/README +0 -0
- data/vendor/{clojure → closure}/compiler.jar +0 -0
- metadata +38 -5
data/README.rdoc
CHANGED
@@ -7,6 +7,29 @@ This CLI utility simplifies the process of compiling your JS files by letting yo
|
|
7
7
|
$ jsc compile
|
8
8
|
|
9
9
|
|
10
|
+
= Supported Compilers
|
11
|
+
|
12
|
+
|
13
|
+
=== Google Closure
|
14
|
+
|
15
|
+
https://developers.google.com/closure/
|
16
|
+
|
17
|
+
The Closure Compiler compiles JavaScript into compact, high-performance code. The compiler removes dead code and rewrites and minimizes what's left so that it downloads and runs quickly. It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls. These checks and optimizations help you write apps that are less buggy and easier to maintain.
|
18
|
+
|
19
|
+
=== YUI Compressor
|
20
|
+
|
21
|
+
http://yui.github.io/yuicompressor/
|
22
|
+
|
23
|
+
The YUI Compressor is written in Java (requires Java >= 1.4) and relies on Rhino to tokenize the source JavaScript file. It starts by analyzing the source JavaScript file to understand how it is structured. It then prints out the token stream, omitting as many white space characters as possible, and replacing all local symbols by a 1 (or 2, or 3) letter symbol wherever such a substitution is appropriate (in the face of evil features such as eval or with, the YUI Compressor takes a defensive approach by not obfuscating any of the scopes containing the evil statement).
|
24
|
+
|
25
|
+
=== Uglifier
|
26
|
+
|
27
|
+
https://github.com/lautis/uglifier
|
28
|
+
|
29
|
+
Ruby wrapper for UglifyJS JavaScript compressor.
|
30
|
+
|
31
|
+
|
32
|
+
|
10
33
|
= Installation
|
11
34
|
|
12
35
|
gem install jscompiler
|
@@ -20,27 +43,25 @@ To setup your project with some default parameters, run the following command:
|
|
20
43
|
|
21
44
|
This command will ask you a few questions about your project. If you don't like being asked questions and prefer to configure your project manually, just create a .jscompiler file in your project folder and provide the following information:
|
22
45
|
|
23
|
-
source_root: "src"
|
46
|
+
source_root: "src" # Relative path from the project root to Where your JavaScript files are located
|
24
47
|
compiler:
|
25
|
-
name:
|
26
|
-
groups:
|
48
|
+
name: "closure" # Name of the compiler to use. By default "closure" compiler will be used
|
49
|
+
groups: # Groups of files you wish to compile
|
27
50
|
default:
|
28
|
-
files:
|
29
|
-
|
30
|
-
|
31
|
-
|
51
|
+
files: # List of the JS files in the order they will be compiled
|
52
|
+
- src/file1.js
|
53
|
+
- src/file2.js
|
54
|
+
- src/file3.js
|
32
55
|
output:
|
33
|
-
|
34
|
-
debug: true # Wether you want to produce an uncompiled version as well
|
35
|
-
path: "build" # Relative path to where the output files should be created
|
56
|
+
path: "build/default.min.js" # Relative path to where the output files should be created
|
36
57
|
just1and3:
|
37
|
-
|
38
|
-
|
39
|
-
|
58
|
+
compiler: # You can even specify different compilers for different groups
|
59
|
+
name: "yahoo"
|
60
|
+
files:
|
61
|
+
- src/file1.js
|
62
|
+
- src/file3.js
|
40
63
|
output:
|
41
|
-
|
42
|
-
debug: true
|
43
|
-
path: "build"
|
64
|
+
path: "build/just1and3.min.js"
|
44
65
|
|
45
66
|
|
46
67
|
You can configure any number of groups. The files in the groups will be concatenated and compiled in the order you entered them in.
|
data/bin/jsc
CHANGED
@@ -29,8 +29,9 @@ Signal.trap(:INT) { abort "\nAborting jscompiler task." }
|
|
29
29
|
[ 'cli.rb',
|
30
30
|
'config.rb',
|
31
31
|
'commands/base.rb',
|
32
|
-
'commands/
|
32
|
+
'commands/closure.rb',
|
33
33
|
'commands/yahoo.rb',
|
34
|
+
'commands/uglifier.rb',
|
34
35
|
].each do |f|
|
35
36
|
require File.expand_path(File.join(File.dirname(__FILE__), "../lib/jscompiler/#{f}"))
|
36
37
|
end
|
data/lib/jscompiler.rb
CHANGED
@@ -25,6 +25,6 @@ module Jscompiler
|
|
25
25
|
autoload :Cli, 'jscompiler/cli'
|
26
26
|
autoload :Config, 'jscompiler/config'
|
27
27
|
autoload :Base, 'jscompiler/commands/base'
|
28
|
-
autoload :
|
28
|
+
autoload :Closure, 'jscompiler/commands/closure'
|
29
29
|
autoload :Yahoo, 'jscompiler/commands/yahoo'
|
30
30
|
end
|
data/lib/jscompiler/cli.rb
CHANGED
@@ -146,7 +146,7 @@ module Jscompiler
|
|
146
146
|
|
147
147
|
def ask_for_compiler(opts = {})
|
148
148
|
say("Which compiler would you like to use?")
|
149
|
-
compilers = ["
|
149
|
+
compilers = ["closure", "yahoo", "uglifier"]
|
150
150
|
if opts[:default]
|
151
151
|
compilers.unshift("default")
|
152
152
|
end
|
@@ -24,10 +24,10 @@
|
|
24
24
|
module Jscompiler
|
25
25
|
module Commands
|
26
26
|
|
27
|
-
class
|
27
|
+
class Closure < Base
|
28
28
|
|
29
29
|
def compiler_path
|
30
|
-
File.expand_path(File.join(File.dirname(__FILE__), "../../../vendor/
|
30
|
+
File.expand_path(File.join(File.dirname(__FILE__), "../../../vendor/closure/compiler.jar"))
|
31
31
|
end
|
32
32
|
|
33
33
|
def args
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2013 Michael Berkovich
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
require 'uglifier'
|
25
|
+
|
26
|
+
module Jscompiler
|
27
|
+
module Commands
|
28
|
+
|
29
|
+
class Uglifier < Base
|
30
|
+
|
31
|
+
def run
|
32
|
+
generate_temp_file
|
33
|
+
|
34
|
+
File.open(output_file_path, 'w') do |file|
|
35
|
+
file.write(::Uglifier.compile(File.read(temp_file_path)))
|
36
|
+
end
|
37
|
+
|
38
|
+
save_or_delete_temp_file
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
data/lib/jscompiler/config.rb
CHANGED
@@ -64,10 +64,12 @@ module Jscompiler
|
|
64
64
|
cmplr = opts[:compiler] || compiler(group)["name"]
|
65
65
|
|
66
66
|
case cmplr
|
67
|
-
when '
|
68
|
-
Jscompiler::Commands::
|
67
|
+
when 'closure'
|
68
|
+
Jscompiler::Commands::Closure
|
69
69
|
when 'yahoo'
|
70
70
|
Jscompiler::Commands::Yahoo
|
71
|
+
when 'uglifier'
|
72
|
+
Jscompiler::Commands::Uglifier
|
71
73
|
else
|
72
74
|
raise("Unsupported compiler")
|
73
75
|
end
|
data/lib/jscompiler/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
source_root: <%=@root%> # Relative path from the project root to Where your JavaScript files are located
|
3
3
|
compiler:
|
4
|
-
name: <%=@compiler%> # Name of the compiler to use. By default "
|
4
|
+
name: <%=@compiler%> # Name of the compiler to use. By default "closure" compiler will be used
|
5
5
|
warning_level: QUIET
|
6
6
|
groups: # Groups of files you wish to compile
|
7
7
|
default:
|
File without changes
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jscompiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 0.16.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.7.7
|
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: 1.7.7
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: fssm
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -43,6 +59,22 @@ dependencies:
|
|
43
59
|
- - ! '>='
|
44
60
|
- !ruby/object:Gem::Version
|
45
61
|
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: uglifier
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
46
78
|
description: Utility that allows you to use various JS compilers to compress and uglify
|
47
79
|
your JavaScript code.
|
48
80
|
email:
|
@@ -55,15 +87,16 @@ files:
|
|
55
87
|
- bin/jsc
|
56
88
|
- lib/jscompiler/cli.rb
|
57
89
|
- lib/jscompiler/commands/base.rb
|
58
|
-
- lib/jscompiler/commands/
|
90
|
+
- lib/jscompiler/commands/closure.rb
|
91
|
+
- lib/jscompiler/commands/uglifier.rb
|
59
92
|
- lib/jscompiler/commands/yahoo.rb
|
60
93
|
- lib/jscompiler/config.rb
|
61
94
|
- lib/jscompiler/version.rb
|
62
95
|
- lib/jscompiler.rb
|
63
96
|
- lib/templates/jscompiler.yml.erb
|
64
|
-
- vendor/
|
65
|
-
- vendor/
|
66
|
-
- vendor/
|
97
|
+
- vendor/closure/compiler.jar
|
98
|
+
- vendor/closure/COPYING
|
99
|
+
- vendor/closure/README
|
67
100
|
- vendor/yahoo/LICENSE
|
68
101
|
- vendor/yahoo/README
|
69
102
|
- vendor/yahoo/yuicompressor-2.4.2.jar
|