dependence 0.0.93 → 0.0.94
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/dependence +6 -12
- data/lib/dependence/compiler.rb +54 -0
- data/lib/dependence/concatenator.rb +10 -2
- data/lib/dependence.rb +1 -0
- metadata +15 -14
data/bin/dependence
CHANGED
@@ -8,10 +8,9 @@ require 'optparse'
|
|
8
8
|
class DependenceCompiler
|
9
9
|
def initialize(config)
|
10
10
|
@config = config
|
11
|
-
@src_glob = "
|
11
|
+
@src_glob = "**/*"
|
12
12
|
@concatenator = Dependence::Concatenator.new(
|
13
|
-
:load_path => @config[:src_dir]
|
14
|
-
:source_type => @src_glob
|
13
|
+
:load_path => @config[:src_dir]
|
15
14
|
)
|
16
15
|
end
|
17
16
|
|
@@ -42,9 +41,11 @@ class DependenceCompiler
|
|
42
41
|
@concatenator.concat do |module_name, module_content|
|
43
42
|
stdout_compile_msg(module_name)
|
44
43
|
FileUtils::mkdir_p @config[:output]
|
44
|
+
|
45
|
+
compiled = module_content
|
46
|
+
compiled = ModuleInjector.modularize(module_name, module_content) unless @config[:bare]
|
47
|
+
|
45
48
|
output = File.join(@config[:output], "#{module_name}.js")
|
46
|
-
compiled = compile_code(module_content)
|
47
|
-
compiled = ModuleInjector.modularize(module_name, compiled) unless @config[:bare]
|
48
49
|
File.open(output, 'w') { |f| f.syswrite compiled }
|
49
50
|
|
50
51
|
stdout_compile_complete_msg(module_name, output)
|
@@ -60,11 +61,6 @@ class DependenceCompiler
|
|
60
61
|
puts Colors.green("Compiled #{module_name} to #{output}")
|
61
62
|
end
|
62
63
|
|
63
|
-
def compile_code(raw_code)
|
64
|
-
return CoffeeScript.compile(raw_code, :bare => true) if @config[:type] == "coffee"
|
65
|
-
raw_code
|
66
|
-
end
|
67
|
-
|
68
64
|
def compress_code(source_file)
|
69
65
|
JsCompiler.new(source_file).compile
|
70
66
|
end
|
@@ -73,7 +69,6 @@ end
|
|
73
69
|
|
74
70
|
options = {
|
75
71
|
:output => ".",
|
76
|
-
:type => "js",
|
77
72
|
:watch => false,
|
78
73
|
:bare => false,
|
79
74
|
:compress => false
|
@@ -87,7 +82,6 @@ OptionParser.new do |opts|
|
|
87
82
|
end
|
88
83
|
|
89
84
|
opts.on("-t", "--type TYPE", "Source file extension [js, coffee]") do |type|
|
90
|
-
options[:type] = type
|
91
85
|
end
|
92
86
|
|
93
87
|
opts.on("-w", "--watch", "Watch src_dir for changes and recompile") do |bool|
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Dependence
|
2
|
+
class Compiler
|
3
|
+
class << self
|
4
|
+
@@compilers ||= []
|
5
|
+
|
6
|
+
def inherited(compiler)
|
7
|
+
@@compilers << compiler
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_compiler_for(extension)
|
11
|
+
extension.gsub!(/^\./, "")
|
12
|
+
@@compilers.find do |compiler|
|
13
|
+
compiler.extensions.include?(extension.to_sym)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def supported_extensions
|
18
|
+
@@compilers.map { |c| c.extensions }.flatten.map {|e| ".#{e.to_s}" }
|
19
|
+
end
|
20
|
+
|
21
|
+
def compile(*args)
|
22
|
+
self.new.compile(*args)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def compile
|
27
|
+
raise "abstract method"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class CoffeeScriptCompiler < Compiler
|
32
|
+
@@extensions = [:cs, :coffee]
|
33
|
+
|
34
|
+
def self.extensions
|
35
|
+
@@extensions
|
36
|
+
end
|
37
|
+
|
38
|
+
def compile(source_string, options = {})
|
39
|
+
CoffeeScript.compile(source_string, options)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class JavaScriptCompiler < Compiler
|
44
|
+
@@extensions = [:js]
|
45
|
+
|
46
|
+
def self.extensions
|
47
|
+
@@extensions
|
48
|
+
end
|
49
|
+
|
50
|
+
def compile(source_string, options = {})
|
51
|
+
source_string
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -6,7 +6,7 @@ module Dependence
|
|
6
6
|
class Concatenator
|
7
7
|
@@defaults = {
|
8
8
|
:load_path => ".",
|
9
|
-
:source_type => "
|
9
|
+
:source_type => "**/*{#{Compiler.supported_extensions.join(',')}}"
|
10
10
|
}
|
11
11
|
|
12
12
|
def initialize(opts = {})
|
@@ -42,10 +42,18 @@ module Dependence
|
|
42
42
|
|
43
43
|
def concat_files(file_list)
|
44
44
|
content = ""
|
45
|
-
file_list.each
|
45
|
+
file_list.each do |f|
|
46
|
+
content << compile_file(f)
|
47
|
+
content << "\n"
|
48
|
+
end
|
46
49
|
content
|
47
50
|
end
|
48
51
|
|
52
|
+
def compile_file(file)
|
53
|
+
compiler = Compiler.get_compiler_for(File.extname(file))
|
54
|
+
compiler.new.compile(File.read(file))
|
55
|
+
end
|
56
|
+
|
49
57
|
# Top level dirs only
|
50
58
|
def get_dirs
|
51
59
|
Dir.glob("#{@options[:load_path]}/*/**/")
|
data/lib/dependence.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dependence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.94
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-13 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rgl
|
16
|
-
requirement: &
|
16
|
+
requirement: &15461820 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *15461820
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rb-inotify
|
27
|
-
requirement: &
|
27
|
+
requirement: &15461380 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *15461380
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: coffee-script
|
38
|
-
requirement: &
|
38
|
+
requirement: &15460960 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *15460960
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: therubyracer
|
49
|
-
requirement: &
|
49
|
+
requirement: &15460540 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *15460540
|
58
58
|
description:
|
59
59
|
email: jcarver989@gmail.com
|
60
60
|
executables:
|
@@ -64,12 +64,13 @@ extra_rdoc_files: []
|
|
64
64
|
files:
|
65
65
|
- bin/dependence
|
66
66
|
- compiler/compiler.jar
|
67
|
+
- lib/dependence/compiler.rb
|
68
|
+
- lib/dependence/js_compiler.rb
|
67
69
|
- lib/dependence/colors.rb
|
68
70
|
- lib/dependence/concatenator.rb
|
69
|
-
- lib/dependence/dependency_resolver.rb
|
70
|
-
- lib/dependence/file_watcher.rb
|
71
|
-
- lib/dependence/js_compiler.rb
|
72
71
|
- lib/dependence/module_injector.rb
|
72
|
+
- lib/dependence/file_watcher.rb
|
73
|
+
- lib/dependence/dependency_resolver.rb
|
73
74
|
- lib/dependence.rb
|
74
75
|
homepage:
|
75
76
|
licenses: []
|
@@ -92,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
93
|
version: '0'
|
93
94
|
requirements: []
|
94
95
|
rubyforge_project:
|
95
|
-
rubygems_version: 1.8.
|
96
|
+
rubygems_version: 1.8.10
|
96
97
|
signing_key:
|
97
98
|
specification_version: 3
|
98
99
|
summary: An easy way to handle your client side javascript dependencies
|