dependence 0.0.94 → 0.0.96
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/dependence +17 -25
- data/lib/dependence/compiler.rb +2 -3
- data/lib/dependence/concatenator.rb +9 -52
- data/lib/dependence/file_watcher.rb +1 -1
- data/lib/dependence/{js_compiler.rb → js_compressor.rb} +2 -3
- data/lib/dependence/js_module.rb +66 -0
- data/lib/dependence.rb +2 -1
- metadata +15 -14
data/bin/dependence
CHANGED
@@ -8,10 +8,10 @@ require 'optparse'
|
|
8
8
|
class DependenceCompiler
|
9
9
|
def initialize(config)
|
10
10
|
@config = config
|
11
|
-
@
|
12
|
-
|
13
|
-
|
14
|
-
)
|
11
|
+
@load_path = config[:src_dir]
|
12
|
+
|
13
|
+
ext_list = Dependence::Compiler.supported_extensions()
|
14
|
+
@source_type = "**/*{#{ext_list.join(',')}}"
|
15
15
|
end
|
16
16
|
|
17
17
|
def compile
|
@@ -26,7 +26,7 @@ class DependenceCompiler
|
|
26
26
|
private
|
27
27
|
|
28
28
|
def compile_with_watcher
|
29
|
-
FileWatcher.new(:load_path => @
|
29
|
+
FileWatcher.new(:load_path => @load_path, :glob_str => @source_type) do
|
30
30
|
print "File change detected. Recompiling... "
|
31
31
|
begin
|
32
32
|
run_compile
|
@@ -38,31 +38,26 @@ class DependenceCompiler
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def run_compile
|
41
|
-
|
42
|
-
stdout_compile_msg(module_name)
|
43
|
-
FileUtils::mkdir_p @config[:output]
|
44
|
-
|
45
|
-
compiled = module_content
|
46
|
-
compiled = ModuleInjector.modularize(module_name, module_content) unless @config[:bare]
|
41
|
+
create_output_directory()
|
47
42
|
|
48
|
-
|
49
|
-
|
43
|
+
module_dirs = Dir.glob("#{@load_path}/*/**/").map {|dir| File.expand_path(dir) }
|
44
|
+
module_dirs.delete(File.expand_path(@config[:output]))
|
50
45
|
|
51
|
-
|
52
|
-
|
46
|
+
module_dirs.each do |module_dir|
|
47
|
+
Dependence::JsModule.new(:source_dir => module_dir,
|
48
|
+
:output_dir => @config[:output],
|
49
|
+
:source_type => @source_type,
|
50
|
+
:bare => @config[:bare],
|
51
|
+
:compress => @config[:compress]).to_file
|
53
52
|
end
|
54
53
|
end
|
55
54
|
|
56
|
-
def
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
def stdout_compile_complete_msg(module_name, output)
|
61
|
-
puts Colors.green("Compiled #{module_name} to #{output}")
|
55
|
+
def create_output_directory
|
56
|
+
FileUtils.mkdir_p @config[:output]
|
62
57
|
end
|
63
58
|
|
64
59
|
def compress_code(source_file)
|
65
|
-
|
60
|
+
JsCompressor.new(source_file).compile
|
66
61
|
end
|
67
62
|
end
|
68
63
|
|
@@ -81,9 +76,6 @@ OptionParser.new do |opts|
|
|
81
76
|
options[:output] = dir
|
82
77
|
end
|
83
78
|
|
84
|
-
opts.on("-t", "--type TYPE", "Source file extension [js, coffee]") do |type|
|
85
|
-
end
|
86
|
-
|
87
79
|
opts.on("-w", "--watch", "Watch src_dir for changes and recompile") do |bool|
|
88
80
|
options[:watch] = bool
|
89
81
|
end
|
data/lib/dependence/compiler.rb
CHANGED
@@ -35,12 +35,11 @@ module Dependence
|
|
35
35
|
@@extensions
|
36
36
|
end
|
37
37
|
|
38
|
-
def compile(source_string, options = {})
|
38
|
+
def compile(source_string, options = {:bare => true})
|
39
39
|
CoffeeScript.compile(source_string, options)
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
43
|
-
class JavaScriptCompiler < Compiler
|
42
|
+
class JavaScriptCompiler < Compiler
|
44
43
|
@@extensions = [:js]
|
45
44
|
|
46
45
|
def self.extensions
|
@@ -1,63 +1,20 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require "dependence/colors"
|
3
|
-
|
4
1
|
module Dependence
|
5
|
-
# Take a load path + file glob and concat them into 1 file per directory
|
6
2
|
class Concatenator
|
7
|
-
|
8
|
-
|
9
|
-
:source_type => "**/*{#{Compiler.supported_extensions.join(',')}}"
|
10
|
-
}
|
11
|
-
|
12
|
-
def initialize(opts = {})
|
13
|
-
@options = @@defaults.merge(opts)
|
14
|
-
end
|
15
|
-
|
16
|
-
def concat(&block)
|
17
|
-
get_dirs.each { |dir| concat_module(dir, &block) }
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def concat_module(dir, &block)
|
23
|
-
module_name = File.basename(dir)
|
24
|
-
|
25
|
-
files = Dir.glob File.join(dir, @options[:source_type])
|
26
|
-
no_files_error if files.empty?
|
27
|
-
|
28
|
-
files_list = get_files_in_dependency_order(dir, files)
|
29
|
-
|
30
|
-
block.call module_name, concat_files(files_list)
|
3
|
+
def initialize(file_list)
|
4
|
+
@files = file_list
|
31
5
|
end
|
32
6
|
|
33
|
-
def
|
34
|
-
|
35
|
-
throw :no_files_to_concatenate
|
36
|
-
end
|
7
|
+
def concat_files(&block)
|
8
|
+
content = ""
|
37
9
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
10
|
+
@files.each do |f|
|
11
|
+
file_content = File.read(f)
|
12
|
+
# processing
|
13
|
+
file_content = block.call(f, file_content) if block
|
42
14
|
|
43
|
-
|
44
|
-
content = ""
|
45
|
-
file_list.each do |f|
|
46
|
-
content << compile_file(f)
|
47
|
-
content << "\n"
|
15
|
+
content << file_content
|
48
16
|
end
|
49
17
|
content
|
50
18
|
end
|
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
|
-
|
57
|
-
# Top level dirs only
|
58
|
-
def get_dirs
|
59
|
-
Dir.glob("#{@options[:load_path]}/*/**/")
|
60
|
-
end
|
61
|
-
|
62
19
|
end
|
63
20
|
end
|
@@ -1,14 +1,13 @@
|
|
1
|
-
require "dependence/dependency_resolver"
|
2
1
|
require "dependence/colors"
|
3
2
|
|
4
|
-
class
|
3
|
+
class JsCompressor
|
5
4
|
def initialize(source_file, output_file = nil)
|
6
5
|
output_file = source_file.gsub(".js", ".min.js") unless output_file
|
7
6
|
@source = source_file
|
8
7
|
@output = output_file
|
9
8
|
end
|
10
9
|
|
11
|
-
def
|
10
|
+
def compress
|
12
11
|
@cmd = cmd_prefix
|
13
12
|
puts Colors.green("Compressing: #{@source}")
|
14
13
|
puts Colors.red "Compressor Output:"
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'dependence/js_compressor'
|
2
|
+
require 'dependence/module_injector'
|
3
|
+
|
4
|
+
module Dependence
|
5
|
+
class JsModule
|
6
|
+
attr_reader :name
|
7
|
+
|
8
|
+
def initialize(config)
|
9
|
+
raise "need to pass :source_dir to constructor" unless config[:source_dir]
|
10
|
+
raise "need to pass :source_type to constructor" unless config[:source_type]
|
11
|
+
|
12
|
+
@config = config
|
13
|
+
@name = File.basename(config[:source_dir])
|
14
|
+
@output_file = File.join(@config[:output_dir], "#{@name}.js")
|
15
|
+
|
16
|
+
@file_list = get_file_list_for_module(@config[:source_dir], @config[:source_type])
|
17
|
+
@concat = Concatenator.new(@file_list)
|
18
|
+
end
|
19
|
+
|
20
|
+
def build
|
21
|
+
stdout_compile_msg(@name)
|
22
|
+
output = @concat.concat_files do |file_path, file_contents|
|
23
|
+
extension = File.extname(file_path)
|
24
|
+
compile(extension, file_contents)
|
25
|
+
end
|
26
|
+
|
27
|
+
output = ModuleInjector.modularize(@name, output) unless @config[:bare] == true
|
28
|
+
output
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_file
|
32
|
+
File.open(@output_file, 'w') do |f|
|
33
|
+
f.syswrite build()
|
34
|
+
end
|
35
|
+
|
36
|
+
JsCompressor.new(@output_file).compress if @config[:compress] == true
|
37
|
+
stdout_compile_complete_msg(@name, @output_file)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def compile(extension, source)
|
43
|
+
Compiler.get_compiler_for(extension).new.compile(source)
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_file_list_for_module(dir, source_type)
|
47
|
+
files = Dir.glob File.join(dir, source_type)
|
48
|
+
no_files_error(dir) if files.empty?
|
49
|
+
DependencyResolver.new(files, dir).sorted_files
|
50
|
+
end
|
51
|
+
|
52
|
+
def no_files_error(dir)
|
53
|
+
puts Colors.red("No source files were found in #{dir}")
|
54
|
+
throw :no_files_to_concatenate
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def stdout_compile_msg(module_name)
|
59
|
+
puts Colors.green("Compiling Module: #{module_name}")
|
60
|
+
end
|
61
|
+
|
62
|
+
def stdout_compile_complete_msg(module_name, output)
|
63
|
+
puts Colors.green("Compiled #{module_name} to #{output}")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/dependence.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require "dependence/dependency_resolver.rb"
|
2
2
|
require "dependence/module_injector.rb"
|
3
3
|
require "dependence/compiler.rb"
|
4
|
-
require "dependence/js_compiler.rb"
|
5
4
|
require "dependence/file_watcher.rb"
|
6
5
|
require "dependence/concatenator.rb"
|
6
|
+
require "dependence/js_module.rb"
|
7
|
+
require "dependence/js_compressor.rb"
|
7
8
|
|
8
9
|
module Dependence
|
9
10
|
end
|
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.96
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ 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: &2170518060 !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: *2170518060
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rb-inotify
|
27
|
-
requirement: &
|
27
|
+
requirement: &2170517620 !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: *2170517620
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: coffee-script
|
38
|
-
requirement: &
|
38
|
+
requirement: &2170517200 !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: *2170517200
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: therubyracer
|
49
|
-
requirement: &
|
49
|
+
requirement: &2170516780 !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: *2170516780
|
58
58
|
description:
|
59
59
|
email: jcarver989@gmail.com
|
60
60
|
executables:
|
@@ -64,13 +64,14 @@ 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
|
69
67
|
- lib/dependence/colors.rb
|
68
|
+
- lib/dependence/compiler.rb
|
70
69
|
- lib/dependence/concatenator.rb
|
71
|
-
- lib/dependence/module_injector.rb
|
72
|
-
- lib/dependence/file_watcher.rb
|
73
70
|
- lib/dependence/dependency_resolver.rb
|
71
|
+
- lib/dependence/file_watcher.rb
|
72
|
+
- lib/dependence/js_compressor.rb
|
73
|
+
- lib/dependence/js_module.rb
|
74
|
+
- lib/dependence/module_injector.rb
|
74
75
|
- lib/dependence.rb
|
75
76
|
homepage:
|
76
77
|
licenses: []
|
@@ -93,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
94
|
version: '0'
|
94
95
|
requirements: []
|
95
96
|
rubyforge_project:
|
96
|
-
rubygems_version: 1.8.
|
97
|
+
rubygems_version: 1.8.6
|
97
98
|
signing_key:
|
98
99
|
specification_version: 3
|
99
100
|
summary: An easy way to handle your client side javascript dependencies
|