jsus 0.1.6 → 0.1.7
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/CHANGELOG +6 -0
- data/Manifest +0 -1
- data/Rakefile +1 -1
- data/TODO +1 -4
- data/bin/jsus +41 -1
- data/jsus.gemspec +3 -3
- data/lib/jsus.rb +1 -0
- data/lib/jsus/container.rb +11 -0
- data/lib/jsus/pool.rb +16 -0
- data/lib/jsus/source_file.rb +1 -1
- data/spec/lib/jsus/container_spec.rb +14 -3
- data/spec/shared/class_stubs.rb +5 -0
- data/spec/spec_helper.rb +1 -1
- metadata +5 -14
- data/spec/spec.opts +0 -4
data/CHANGELOG
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
= Jsus Changelog
|
2
|
+
== Version 0.1.7
|
3
|
+
* Added caching to Jsus::Pool#lookup_direct_dependencies. This addresses some performance
|
4
|
+
issues appeared in 0.1.6
|
5
|
+
* Added --benchmark flag to jsus which shows total compile and total execution time
|
6
|
+
* Added --generate-includes option to jsus. If enabled, generates a set of includes into
|
7
|
+
includes.js file.
|
2
8
|
== Version 0.1.6
|
3
9
|
* Fixed an issue with jsus not including internal dependencies for external dependencies.
|
4
10
|
First robust solution handles this via Pool and eager dependency load.
|
data/Manifest
CHANGED
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
|
-
Echoe.new('jsus', '0.1.
|
4
|
+
Echoe.new('jsus', '0.1.7') do |g|
|
5
5
|
g.description = "Packager/compiler for js-files that resolves dependencies and can compile everything into one file, providing all the neccessary meta-info."
|
6
6
|
g.url = "http://github.com/markiz/jsus"
|
7
7
|
g.author = "Markiz, idea by Inviz (http://github.com/Inviz)"
|
data/TODO
CHANGED
data/bin/jsus
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'rubygems'
|
3
3
|
require 'jsus'
|
4
|
+
start_time = Time.now
|
4
5
|
require 'choice'
|
5
6
|
|
6
7
|
|
@@ -36,16 +37,55 @@ Choice.options do
|
|
36
37
|
"with tree structure of your package."
|
37
38
|
end
|
38
39
|
|
40
|
+
option "generate_includes", :required => false do
|
41
|
+
short "-g"
|
42
|
+
long "--generate-includes=[ROOT]"
|
43
|
+
desc "Generates includes.js file that you may use for ad-hoc requiring" <<
|
44
|
+
"of the needed javascripts. Defaults to output_directory."
|
45
|
+
end
|
46
|
+
|
47
|
+
option "benchmark", :required => false do
|
48
|
+
long "--benchmark"
|
49
|
+
short "-b"
|
50
|
+
desc "Performs a benchmark, indicating how much time you needed to" <<
|
51
|
+
"compile the package"
|
52
|
+
end
|
53
|
+
|
39
54
|
end
|
40
55
|
|
41
56
|
|
42
57
|
pool = if Choice.choices[:dependencies]
|
43
58
|
Jsus::Pool.new(Choice.choices[:dependencies])
|
44
59
|
end
|
60
|
+
compile_start_time = Time.now
|
45
61
|
package = Jsus::Package.new(Choice.choices[:input_directory], :pool => pool)
|
46
62
|
package.include_dependencies! if Choice.choices[:dependencies]
|
47
63
|
package.include_extensions! if Choice.choices[:dependencies]
|
48
64
|
output_directory = Choice.choices[:output_directory]
|
49
65
|
package.compile(output_directory)
|
50
66
|
package.generate_scripts_info(output_directory) unless Choice.choices[:without_scripts_info]
|
51
|
-
package.generate_tree(output_directory) unless Choice.choices[:without_tree]
|
67
|
+
package.generate_tree(output_directory) unless Choice.choices[:without_tree]
|
68
|
+
|
69
|
+
|
70
|
+
# Hack, hack, hack :[
|
71
|
+
if Choice.choices[:generate_includes]
|
72
|
+
root = Choice.choices[:generate_includes] == true ? Choice.choices[:output_directory] : Choice.choices[:generate_includes]
|
73
|
+
File.open(File.join(Choice.choices[:output_directory], "includes.js"), "w") do |f|
|
74
|
+
c = Jsus::Container.new(*(package.source_files.to_a + package.linked_external_dependencies.to_a))
|
75
|
+
script = %{(function(prefix) {
|
76
|
+
var sources = %sources%;
|
77
|
+
for (var i = 0, j = sources.length; i < j; i++) document.write('<scr' + 'ipt src="' + (prefix || '') + sources[i] + "></script>");
|
78
|
+
})(window.prefix);}.sub("%sources%", JSON.pretty_generate(c.required_files(root)))
|
79
|
+
f.puts script
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
finish_time = Time.now
|
86
|
+
|
87
|
+
|
88
|
+
if Choice.choices[:benchmark]
|
89
|
+
puts "Total execution time: #{(finish_time - start_time).round(3)}s"
|
90
|
+
puts "Total compilation time: #{(finish_time - compile_start_time).round(3)}s"
|
91
|
+
end
|
data/jsus.gemspec
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{jsus}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.7"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Markiz, idea by Inviz (http://github.com/Inviz)"]
|
9
|
-
s.date = %q{2010-08-
|
9
|
+
s.date = %q{2010-08-30}
|
10
10
|
s.default_executable = %q{jsus}
|
11
11
|
s.description = %q{Packager/compiler for js-files that resolves dependencies and can compile everything into one file, providing all the neccessary meta-info.}
|
12
12
|
s.email = %q{markizko@gmail.com}
|
13
13
|
s.executables = ["jsus"]
|
14
14
|
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "TODO", "bin/jsus", "lib/jsus.rb", "lib/jsus/container.rb", "lib/jsus/package.rb", "lib/jsus/packager.rb", "lib/jsus/pool.rb", "lib/jsus/source_file.rb", "lib/jsus/tag.rb"]
|
15
|
-
s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "TODO", "bin/jsus", "
|
15
|
+
s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "TODO", "bin/jsus", "lib/jsus.rb", "lib/jsus/container.rb", "lib/jsus/package.rb", "lib/jsus/packager.rb", "lib/jsus/pool.rb", "lib/jsus/source_file.rb", "lib/jsus/tag.rb", "spec/data/Basic/README", "spec/data/Basic/app/javascripts/Orwik/Source/Library/Color.js", "spec/data/Basic/app/javascripts/Orwik/Source/Widget/Input/Input.Color.js", "spec/data/Basic/app/javascripts/Orwik/Source/Widget/Input/Input.js", "spec/data/Basic/app/javascripts/Orwik/Source/Widget/Widget.js", "spec/data/Basic/app/javascripts/Orwik/package.yml", "spec/data/ChainDependencies/app/javascripts/Class/Source/Class.js", "spec/data/ChainDependencies/app/javascripts/Class/package.yml", "spec/data/ChainDependencies/app/javascripts/Hash/Source/Hash.js", "spec/data/ChainDependencies/app/javascripts/Hash/package.yml", "spec/data/ChainDependencies/app/javascripts/Mash/Source/Mash.js", "spec/data/ChainDependencies/app/javascripts/Mash/package.yml", "spec/data/Extensions/app/javascripts/Core/Source/Class.js", "spec/data/Extensions/app/javascripts/Core/package.yml", "spec/data/Extensions/app/javascripts/Orwik/Extensions/Class.js", "spec/data/Extensions/app/javascripts/Orwik/package.yml", "spec/data/ExternalDependencies/app/javascripts/Orwik/Source/Test.js", "spec/data/ExternalDependencies/app/javascripts/Orwik/package.yml", "spec/data/ExternalInternalDependencies/Core/Class/Source/Class.js", "spec/data/ExternalInternalDependencies/Core/Class/Source/Type.js", "spec/data/ExternalInternalDependencies/Core/Class/package.yml", "spec/data/ExternalInternalDependencies/Core/Hash/Source/Hash.js", "spec/data/ExternalInternalDependencies/Core/Hash/package.yml", "spec/data/ExternalInternalDependencies/Core/Mash/Source/Mash.js", "spec/data/ExternalInternalDependencies/Core/Mash/package.yml", "spec/data/ExternalInternalDependencies/Test/Source/Library/Color.js", "spec/data/ExternalInternalDependencies/Test/Source/Widget/Input/Input.Color.js", "spec/data/ExternalInternalDependencies/Test/Source/Widget/Input/Input.js", "spec/data/ExternalInternalDependencies/Test/Source/Widget/Widget.js", "spec/data/ExternalInternalDependencies/Test/package.yml", "spec/data/OutsideDependencies/README", "spec/data/OutsideDependencies/app/javascripts/Core/Source/Class/Class.Extras.js", "spec/data/OutsideDependencies/app/javascripts/Core/Source/Class/Class.js", "spec/data/OutsideDependencies/app/javascripts/Core/Source/Native/Hash.js", "spec/data/OutsideDependencies/app/javascripts/Core/package.yml", "spec/data/OutsideDependencies/app/javascripts/Orwik/Source/Library/Color.js", "spec/data/OutsideDependencies/app/javascripts/Orwik/Source/Widget/Input/Input.Color.js", "spec/data/OutsideDependencies/app/javascripts/Orwik/Source/Widget/Input/Input.js", "spec/data/OutsideDependencies/app/javascripts/Orwik/Source/Widget/Widget.js", "spec/data/OutsideDependencies/app/javascripts/Orwik/package.yml", "spec/data/bad_test_source_one.js", "spec/data/bad_test_source_two.js", "spec/data/test_source_one.js", "spec/lib/jsus/container_spec.rb", "spec/lib/jsus/package_spec.rb", "spec/lib/jsus/packager_spec.rb", "spec/lib/jsus/pool_spec.rb", "spec/lib/jsus/source_file_spec.rb", "spec/lib/jsus/tag_spec.rb", "spec/shared/class_stubs.rb", "spec/spec_helper.rb", "jsus.gemspec"]
|
16
16
|
s.homepage = %q{http://github.com/markiz/jsus}
|
17
17
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Jsus", "--main", "README"]
|
18
18
|
s.require_paths = ["lib"]
|
data/lib/jsus.rb
CHANGED
data/lib/jsus/container.rb
CHANGED
@@ -59,6 +59,17 @@ module Jsus
|
|
59
59
|
self
|
60
60
|
end
|
61
61
|
|
62
|
+
# Lists all the required files (dependencies and extensions) for
|
63
|
+
# the sources in the container.
|
64
|
+
def required_files(root = nil)
|
65
|
+
files = sources.map {|s| s.required_files }.flatten
|
66
|
+
if root
|
67
|
+
root = Pathname.new(File.expand_path(root))
|
68
|
+
files = files.map {|f| Pathname.new(File.expand_path(f)).relative_path_from(root).to_s }
|
69
|
+
end
|
70
|
+
files
|
71
|
+
end
|
72
|
+
|
62
73
|
def inspect # :nodoc:
|
63
74
|
"#<#{self.class.name}:#{self.object_id} #{self.sources.inspect}>"
|
64
75
|
end
|
data/lib/jsus/pool.rb
CHANGED
@@ -26,6 +26,7 @@ module Jsus
|
|
26
26
|
Package.new(File.dirname(package_path), :pool => self)
|
27
27
|
end
|
28
28
|
end
|
29
|
+
flush_cache!
|
29
30
|
end
|
30
31
|
|
31
32
|
|
@@ -123,15 +124,30 @@ module Jsus
|
|
123
124
|
self
|
124
125
|
end
|
125
126
|
|
127
|
+
#
|
128
|
+
# Drops any cached info
|
129
|
+
#
|
130
|
+
def flush_cache!
|
131
|
+
@cached_dependencies = {}
|
132
|
+
end
|
133
|
+
|
126
134
|
(Array.instance_methods - self.instance_methods).each {|m| delegate m, :to => :sources }
|
127
135
|
# Private API
|
128
136
|
|
129
137
|
#
|
130
138
|
# Looks up direct dependencies for the given source_file or provides tag.
|
131
139
|
# You probably will find yourself using #include_dependencies instead.
|
140
|
+
# This method caches results locally, use flush_cache! to drop.
|
132
141
|
#
|
133
142
|
def lookup_direct_dependencies(source_or_source_key)
|
134
143
|
source = lookup(source_or_source_key)
|
144
|
+
@cached_dependencies[source] ||= lookup_direct_dependencies!(source)
|
145
|
+
end
|
146
|
+
|
147
|
+
#
|
148
|
+
# Performs the actual lookup for #lookup_direct_dependencies
|
149
|
+
#
|
150
|
+
def lookup_direct_dependencies!(source)
|
135
151
|
result = source ? (source.dependencies + source.external_dependencies).map {|d| lookup(d)} : []
|
136
152
|
Container.new(*result)
|
137
153
|
end
|
data/lib/jsus/source_file.rb
CHANGED
@@ -169,7 +169,7 @@ module Jsus
|
|
169
169
|
#
|
170
170
|
# Returns an array of files required by this files including all the filenames for extensions.
|
171
171
|
# SourceFile filename always goes first, all the extensions are unordered.
|
172
|
-
#
|
172
|
+
#
|
173
173
|
def required_files
|
174
174
|
[filename, extensions.map {|e| e.filename}].flatten
|
175
175
|
end
|
@@ -2,9 +2,9 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
|
4
4
|
describe Jsus::Container do
|
5
|
-
let(:simple_source) { Source.new(:provides => [0], :dependencies => [], :content => "// simple") }
|
6
|
-
let(:another_simple_source) { Source.new(:provides => [1], :dependencies => [], :content => "// simple 2") }
|
7
|
-
let(:dependant_source) { Source.new(:provides => [3], :dependencies => [0], :content => "// simple 3") }
|
5
|
+
let(:simple_source) { Source.new(:provides => [0], :dependencies => [], :content => "// simple", :filename => "/home/jsus/simple.js") }
|
6
|
+
let(:another_simple_source) { Source.new(:provides => [1], :dependencies => [], :content => "// simple 2", :filename => "/home/jsus/other/simple2.js") }
|
7
|
+
let(:dependant_source) { Source.new(:provides => [3], :dependencies => [0], :content => "// simple 3", :filename => "/home/dependencies/simple3.js") }
|
8
8
|
|
9
9
|
let(:simple_container) { Jsus::Container.new(simple_source, another_simple_source) }
|
10
10
|
let(:container_with_dependency) { Jsus::Container.new(dependant_source, simple_source) }
|
@@ -53,4 +53,15 @@ describe Jsus::Container do
|
|
53
53
|
}.should_not raise_error
|
54
54
|
end
|
55
55
|
end
|
56
|
+
|
57
|
+
describe "#required_files" do
|
58
|
+
subject { container_with_dependency }
|
59
|
+
it "should return includes for all the sources" do
|
60
|
+
subject.required_files.should == [simple_source.filename, dependant_source.filename]
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should generate routes from given root" do
|
64
|
+
subject.required_files("/home/jsus").should == ["simple.js", "../dependencies/simple3.js"]
|
65
|
+
end
|
66
|
+
end
|
56
67
|
end
|
data/spec/shared/class_stubs.rb
CHANGED
@@ -5,12 +5,17 @@ class Source
|
|
5
5
|
attr_accessor :provides
|
6
6
|
attr_accessor :dependencies
|
7
7
|
attr_accessor :content
|
8
|
+
attr_accessor :filename
|
8
9
|
|
9
10
|
def initialize(options = {})
|
10
11
|
options.each do |attr, value|
|
11
12
|
send("#{attr}=", value)
|
12
13
|
end
|
13
14
|
end
|
15
|
+
|
16
|
+
def required_files
|
17
|
+
[filename]
|
18
|
+
end
|
14
19
|
end
|
15
20
|
|
16
21
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 23
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
8
|
+
- 7
|
9
|
+
version: 0.1.7
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Markiz, idea by Inviz (http://github.com/Inviz)
|
@@ -15,8 +14,8 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-08-
|
19
|
-
default_executable:
|
17
|
+
date: 2010-08-30 00:00:00 +04:00
|
18
|
+
default_executable: jsus
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: activesupport
|
@@ -26,7 +25,6 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
28
|
segments:
|
31
29
|
- 0
|
32
30
|
version: "0"
|
@@ -40,7 +38,6 @@ dependencies:
|
|
40
38
|
requirements:
|
41
39
|
- - ">="
|
42
40
|
- !ruby/object:Gem::Version
|
43
|
-
hash: 3
|
44
41
|
segments:
|
45
42
|
- 0
|
46
43
|
version: "0"
|
@@ -54,7 +51,6 @@ dependencies:
|
|
54
51
|
requirements:
|
55
52
|
- - ">="
|
56
53
|
- !ruby/object:Gem::Version
|
57
|
-
hash: 3
|
58
54
|
segments:
|
59
55
|
- 0
|
60
56
|
version: "0"
|
@@ -68,7 +64,6 @@ dependencies:
|
|
68
64
|
requirements:
|
69
65
|
- - ">="
|
70
66
|
- !ruby/object:Gem::Version
|
71
|
-
hash: 3
|
72
67
|
segments:
|
73
68
|
- 0
|
74
69
|
version: "0"
|
@@ -82,7 +77,6 @@ dependencies:
|
|
82
77
|
requirements:
|
83
78
|
- - ">="
|
84
79
|
- !ruby/object:Gem::Version
|
85
|
-
hash: 3
|
86
80
|
segments:
|
87
81
|
- 0
|
88
82
|
version: "0"
|
@@ -115,7 +109,6 @@ files:
|
|
115
109
|
- Rakefile
|
116
110
|
- TODO
|
117
111
|
- bin/jsus
|
118
|
-
- jsus.gemspec
|
119
112
|
- lib/jsus.rb
|
120
113
|
- lib/jsus/container.rb
|
121
114
|
- lib/jsus/package.rb
|
@@ -173,8 +166,8 @@ files:
|
|
173
166
|
- spec/lib/jsus/source_file_spec.rb
|
174
167
|
- spec/lib/jsus/tag_spec.rb
|
175
168
|
- spec/shared/class_stubs.rb
|
176
|
-
- spec/spec.opts
|
177
169
|
- spec/spec_helper.rb
|
170
|
+
- jsus.gemspec
|
178
171
|
has_rdoc: true
|
179
172
|
homepage: http://github.com/markiz/jsus
|
180
173
|
licenses: []
|
@@ -194,7 +187,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
194
187
|
requirements:
|
195
188
|
- - ">="
|
196
189
|
- !ruby/object:Gem::Version
|
197
|
-
hash: 3
|
198
190
|
segments:
|
199
191
|
- 0
|
200
192
|
version: "0"
|
@@ -203,7 +195,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
195
|
requirements:
|
204
196
|
- - ">="
|
205
197
|
- !ruby/object:Gem::Version
|
206
|
-
hash: 11
|
207
198
|
segments:
|
208
199
|
- 1
|
209
200
|
- 2
|
data/spec/spec.opts
DELETED