jbundle 0.0.12 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +24 -1
- data/lib/jbundle.rb +1 -1
- data/lib/jbundle/config.rb +9 -3
- data/lib/jbundle/version.rb +1 -1
- data/lib/jbundle/writer.rb +42 -9
- data/spec/jbundle_spec.rb +46 -0
- metadata +1 -1
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -64,7 +64,7 @@ This will write the following files:
|
|
64
64
|
'dist/1.6/file4.min.js'
|
65
65
|
'dist/1.6/text.txt'
|
66
66
|
|
67
|
-
Or you can build a single bundle/file
|
67
|
+
Or you can build a single bundle/file dynamically (ie. for testing, or for serving and caching on first serve)
|
68
68
|
|
69
69
|
JBundle.config_from_file './JFile'
|
70
70
|
JBundle.build('foo.js').src
|
@@ -84,6 +84,29 @@ You can bundle licenses in bundles. Licenses will not be minified even though th
|
|
84
84
|
|
85
85
|
All defined filters will run on the src for all these cases.
|
86
86
|
|
87
|
+
## Versiones file names, jQuery style
|
88
|
+
|
89
|
+
All of the examples above bundle to versioned directories in the "dist" directory. If you want jQuery-style file names, where there's no version directory and the version number is part of the file name, you can do this:
|
90
|
+
|
91
|
+
version '1.6.1', :directory => false
|
92
|
+
|
93
|
+
bundle 'foo2-[:version].js' do
|
94
|
+
license 'license.txt'
|
95
|
+
file 'file3.js'
|
96
|
+
file 'file4.js'
|
97
|
+
end
|
98
|
+
|
99
|
+
That will produce:
|
100
|
+
|
101
|
+
'dist/foo-1.6.1.js'
|
102
|
+
'dist/foo-1.6.1.min.js'
|
103
|
+
'dist/foo-1.6.js'
|
104
|
+
'dist/foo-1.6.min.js'
|
105
|
+
|
106
|
+
That works for single-file libraries too:
|
107
|
+
|
108
|
+
file 'jquery.lightbox.js' => 'jquery.lightbox-[:version].js'
|
109
|
+
|
87
110
|
## Filters
|
88
111
|
|
89
112
|
You can filter both minified and un-minified source and license content with the filter method
|
data/lib/jbundle.rb
CHANGED
@@ -43,7 +43,7 @@ module JBundle
|
|
43
43
|
_dist = config.target_dir || './dist'
|
44
44
|
clear_current_dist_dir(_dist)
|
45
45
|
out = output.map do |compiler|
|
46
|
-
Writer.new(compiler, config
|
46
|
+
Writer.new(compiler, config, _dist).write
|
47
47
|
end.flatten
|
48
48
|
run_after_write unless config.after_write_blocks.empty?
|
49
49
|
out
|
data/lib/jbundle/config.rb
CHANGED
@@ -9,21 +9,27 @@ module JBundle
|
|
9
9
|
@files = []
|
10
10
|
@filters = {:all => [], :min => [], :src => []}
|
11
11
|
@after_write_blocks = []
|
12
|
+
@version_options = {:directory => true}
|
12
13
|
end
|
13
14
|
|
14
|
-
def
|
15
|
+
def versioned_directories?
|
16
|
+
@version_options[:directory]
|
17
|
+
end
|
18
|
+
|
19
|
+
def version(v = nil, opts = {})
|
20
|
+
@version_options.merge! opts
|
15
21
|
@version = JBundle::Version.new(v) if v
|
16
22
|
@version
|
17
23
|
end
|
18
24
|
|
19
25
|
def src_dir(dir = nil)
|
20
26
|
@src_dir = dir if dir
|
21
|
-
@src_dir
|
27
|
+
@src_dir || './'
|
22
28
|
end
|
23
29
|
|
24
30
|
def target_dir(dir = nil)
|
25
31
|
@target_dir = dir if dir
|
26
|
-
@target_dir
|
32
|
+
@target_dir || './'
|
27
33
|
end
|
28
34
|
|
29
35
|
def bundle(name, &block)
|
data/lib/jbundle/version.rb
CHANGED
data/lib/jbundle/writer.rb
CHANGED
@@ -36,20 +36,39 @@ module JBundle
|
|
36
36
|
end
|
37
37
|
|
38
38
|
class Writer
|
39
|
+
# Interpolation tokens
|
40
|
+
TOKENS = {
|
41
|
+
:version => '[:version]'
|
42
|
+
}
|
39
43
|
|
40
|
-
def initialize(compiler,
|
41
|
-
@compiler, @version, @target_dir = compiler, version, target_dir
|
44
|
+
def initialize(compiler, config, target_dir)
|
45
|
+
@compiler, @config, @version, @target_dir = compiler, config, config.version, target_dir
|
42
46
|
@out = []
|
43
47
|
end
|
44
48
|
|
45
49
|
def write
|
46
|
-
|
47
|
-
versioned_target
|
48
|
-
if @compiler.buildable?
|
49
|
-
@out << write_file(
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
release_targets do |versioned_target, version_string|
|
51
|
+
puts versioned_target.inspect
|
52
|
+
if @compiler.buildable? # versionable JS file
|
53
|
+
@out << write_file(
|
54
|
+
@compiler.src,
|
55
|
+
versioned_target,
|
56
|
+
@compiler.dir,
|
57
|
+
interpolate(@compiler.name, TOKENS[:version] => version_string)
|
58
|
+
)
|
59
|
+
@out << write_file(
|
60
|
+
@compiler.min,
|
61
|
+
versioned_target,
|
62
|
+
@compiler.dir,
|
63
|
+
interpolate(@compiler.min_name, TOKENS[:version] => version_string)
|
64
|
+
)
|
65
|
+
else # Other files (HTML, SWF, etc)
|
66
|
+
@out << copy_file(
|
67
|
+
@compiler.src_path,
|
68
|
+
versioned_target,
|
69
|
+
@compiler.dir,
|
70
|
+
interpolate(@compiler.name, TOKENS[:version] => version_string)
|
71
|
+
)
|
53
72
|
end
|
54
73
|
end
|
55
74
|
@out
|
@@ -57,6 +76,20 @@ module JBundle
|
|
57
76
|
|
58
77
|
protected
|
59
78
|
|
79
|
+
def interpolate(string, tokens)
|
80
|
+
tokens.each do |key, value|
|
81
|
+
string = string.gsub(key, value)
|
82
|
+
end
|
83
|
+
string
|
84
|
+
end
|
85
|
+
|
86
|
+
def release_targets(&block)
|
87
|
+
@version.releaseable.each do |version_string|
|
88
|
+
versioned_target = @config.versioned_directories? ? ::File.join(@target_dir, version_string) : @target_dir
|
89
|
+
yield versioned_target, version_string
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
60
93
|
def copy_file(src, target, subdir, name)
|
61
94
|
sub = ::File.join([target, subdir].compact)
|
62
95
|
FileUtils.mkdir_p sub
|
data/spec/jbundle_spec.rb
CHANGED
@@ -120,3 +120,49 @@ describe "JBundle" do
|
|
120
120
|
end
|
121
121
|
|
122
122
|
end
|
123
|
+
|
124
|
+
describe 'JBundle', 'with no versioned directory and version in bundle name' do
|
125
|
+
|
126
|
+
before do
|
127
|
+
JBundle.reset!.config do
|
128
|
+
version '0.0.1', :directory => nil
|
129
|
+
|
130
|
+
src_dir ::File.dirname(__FILE__) + '/test_src'
|
131
|
+
target_dir DIST
|
132
|
+
|
133
|
+
bundle 'foo-[:version].js' do
|
134
|
+
license 'license.txt'
|
135
|
+
file 'file3.js'
|
136
|
+
end
|
137
|
+
|
138
|
+
file 'file3.js' => 'bar-[:version].js'
|
139
|
+
end
|
140
|
+
|
141
|
+
@written_files = JBundle.write!
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'should create versioned files in dist dir, with no versioned directories' do
|
145
|
+
@written_files.should == [
|
146
|
+
DIST + '/foo-0.0.1.js',
|
147
|
+
DIST + '/foo-0.0.1.min.js',
|
148
|
+
DIST + '/foo-0.0.js',
|
149
|
+
DIST + '/foo-0.0.min.js',
|
150
|
+
DIST + '/bar-0.0.1.js',
|
151
|
+
DIST + '/bar-0.0.1.min.js',
|
152
|
+
DIST + '/bar-0.0.js',
|
153
|
+
DIST + '/bar-0.0.min.js'
|
154
|
+
]
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'should create versioned files with no version directory' do
|
158
|
+
File.exist?(DIST + '/foo-0.0.1.js').should be_true
|
159
|
+
File.exist?(DIST + '/foo-0.0.1.min.js').should be_true
|
160
|
+
File.exist?(DIST + '/foo-0.0.js').should be_true
|
161
|
+
File.exist?(DIST + '/foo-0.0.min.js').should be_true
|
162
|
+
File.exist?(DIST + '/bar-0.0.1.js').should be_true
|
163
|
+
File.exist?(DIST + '/bar-0.0.1.min.js').should be_true
|
164
|
+
File.exist?(DIST + '/bar-0.0.js').should be_true
|
165
|
+
File.exist?(DIST + '/bar-0.0.min.js').should be_true
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|