Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 212 lines (135 sloc) 5.336 kb
944e8f8 @ismasan Removed "in progress" because it already does what it says in the can
authored
1 ## JBundle
b235015 @ismasan Basic README
authored
2
b805b0e @ismasan Added intro to README so people don't go WTF what's this about
authored
3 Ruby utility to help in developing JavaScript libraries. Lets you declare JavaScript libraries composed of multiple files. Easily bundle and minify your JavaScript bundles when you're done. Includes a Rack server for easy testing.
4
112f2ca @ismasan Installation pointers
authored
5 ## Installation
6
7 JBundle is a Ruby gem.
8
9 gem install jbundle
10
11 ## Usage
12
b235015 @ismasan Basic README
authored
13 Define a set of javascript files to bundle and minify
14
15 JBundle.config do
16 version '1.6.1'
17
18 src_dir File.dirname(__FILE__) + '/src'
19
20 bundle 'foo.js' do
21 file 'file1.js'
22 file 'file2.js'
23 end
24
25 bundle 'foo2.js' do
26 file 'file3.js'
27 file 'file4.js'
28 end
29
30 file 'file4.js'
31
32 file 'text.txt'
33
34 # Filters can be use for string substitution
35 filter do |src, config|
7a7183f @ismasan You can now declare different filters for full source and minified ou…
authored
36 src.gsub(/<VERSION>/, config.version)
b235015 @ismasan Basic README
authored
37 end
ab21a96 @ismasan Removed JBundle.write_to. Now you must add Config#target_dir and run …
authored
38
39 target_dir 'dist'
b235015 @ismasan Basic README
authored
40
41 end
42
ab21a96 @ismasan Removed JBundle.write_to. Now you must add Config#target_dir and run …
authored
43 Then write them to the configured target directory
b235015 @ismasan Basic README
authored
44
ab21a96 @ismasan Removed JBundle.write_to. Now you must add Config#target_dir and run …
authored
45 JBundle.write!
b235015 @ismasan Basic README
authored
46
c67bce2 @ismasan JBundle.write! returns a list of written file paths
authored
47 JBundle.write! returns an array of paths of all files written.
48
b235015 @ismasan Basic README
authored
49 This will write the following files:
50
51 'dist/1.6.1/foo.js'
52 'dist/1.6.1/foo.min.js'
53 'dist/1.6.1/foo2.js'
54 'dist/1.6.1/foo2.min.js'
55 'dist/1.6.1/file4.js'
56 'dist/1.6.1/file4.min.js'
57 'dist/1.6.1/text.txt'
58
59 'dist/1.6/foo.js'
60 'dist/1.6/foo.min.js'
61 'dist/1.6/foo2.js'
62 'dist/1.6/foo2.min.js'
63 'dist/1.6/file4.js'
64 'dist/1.6/file4.min.js'
65 'dist/1.6/text.txt'
66
1dde19e @ismasan Added to README
authored
67 Or you can build a single bundle/file dinamically (ie. for testing, or for serving and caching dinamically)
b4a724f @ismasan JBundle.config_from_file 'some_file' so it's easy to use dynamically …
authored
68
69 JBundle.config_from_file './JFile'
b235015 @ismasan Basic README
authored
70 JBundle.build('foo.js').src
71
72 Or
73
b4a724f @ismasan JBundle.config_from_file 'some_file' so it's easy to use dynamically …
authored
74 JBundle.config_from_file './JFile'
b235015 @ismasan Basic README
authored
75 JBundle.build('foo.js').min
76
274253e @ismasan Typo
authored
77 You can bundle licenses in bundles. Licenses will not be minified even though they end up being part of minified files
05715dc @ismasan Added license text support. Licenses are not minified.
authored
78
79 bundle 'foo2.js' do
80 license 'license.txt'
81 file 'file3.js'
82 file 'file4.js'
83 end
84
b235015 @ismasan Basic README
authored
85 All defined filters will run on the src for all these cases.
b34ada0 @ismasan TODO
authored
86
7a7183f @ismasan You can now declare different filters for full source and minified ou…
authored
87 ## Filters
88
89 You can filter both minified and un-minified source and license content with the filter method
90
91 # Filters can be use for string substitution
92 filter do |src, config|
93 src.gsub(/<VERSION>/, config.version)
94 end
95
96 You can declare filters that run on un-minified output only
97
98 filter :src do |src, config|
99 src.gsub(/<SRC_MODE>/, 'full source')
100 end
101
102 ... And minified output only
103
104 filter :min do |src, config|
105 src.gsub(/<SRC_MODE>/, 'minified source')
106 end
107
108 All filters must return a copy of the source, so use src.gsub instead of src.gsub!
109
fadbc67 @ismasan Dumb change to test Travis
authored
110
c33270c @ismasan It's "JFile", not "Jfile"
authored
111 ## JFile
579913d @ismasan Config#target_dir
authored
112
c33270c @ismasan It's "JFile", not "Jfile"
authored
113 You can add configuration in a JFile in the root of your project.
579913d @ismasan Config#target_dir
authored
114
115 version '1.0.1'
116
117 src_dir './'
118
119 bundle 'foo.js' do
120 license 'license.txt'
121 file 'file1.js'
122 file 'file2.js'
123 end
124
125 file 'page.html'
126
127 filter do |src, config|
bf49a58 @ismasan JBundle.config.version is an instance of JBundle::Version
authored
128 src.gsub! /<VERSION>/, config.version.to_s
579913d @ismasan Config#target_dir
authored
129 end
130
131 target_dir 'dist'
132
133 Then you can bundle everything up with the command line tool
134
135 $ jbundle
136
c12dead @ismasan 0.0.6 release: after_write blocks for JFile. Allows to run arbitrary …
authored
137 You can run arbitrary code after writing all versioned files by registering an after_write block in your JFile. The following example copies a .swf file from the src dir to all versioned directories
138
139 after_write do |config|
140
141 config.version.releaseable.each do |version|
142 from = "#{config.src_dir}/foo.swf"
143 to = "#{config.target_dir}/#{version}/foo.swf"
144 puts "copying #{to}"
145 FileUtils.cp(from, to)
146 end
147
148 end
149
150 config.version.releaseble returns an array with with all created versions (ie. ['1.6.1', '1.6'] or just ['1.6.1-pre'] for prereleases).
d5e41c7 @ismasan Copy files to nested directories or different file names. Bumped to 0…
authored
151
152 Files in subdirectories in the src directory will keep the local directory tree, so
153
154 file 'foo/text.txt'
155
156 Ends up as ./dist/1.6/foo/text.txt and ./dist/1.6.1/foo/text.txt
157
158 You can also copy to a different file name in the target directory using hash notation
159
160 file 'foo/text.txt' => 'bar.txt'
c12dead @ismasan 0.0.6 release: after_write blocks for JFile. Allows to run arbitrary …
authored
161
579913d @ismasan Config#target_dir
authored
162 ## Pre-releases
163
164 If you want a prerelease not to overwrite the previous point release, suffix it with "-pre", as in:
165
166 version '1.0.1-pre'
167
fc8b4ac @ismasan Added README on JBundle server command
authored
168 ## Test server
579913d @ismasan Config#target_dir
authored
169
fc8b4ac @ismasan Added README on JBundle server command
authored
170 JBundle command-line comes with a built-in Rack server that makes it easy to test you JavaScript bundles as you develop them.
171
172 jbundle server
173
80d655c @ismasan More informative server prompt in README
authored
174 Starting test server on http://localhost:5555. Available bundles:
175 - /foo.js
176
177 That serves bundles defined in your JFile in port 5555. Pass the -p option for a different port.
fc8b4ac @ismasan Added README on JBundle server command
authored
178
179 Learn more about the JBundle command-line with
180
181 jbundle help # all commands
182 jbundle help server # server command options
5ed98c4 @ismasan jbundle init foo.js generator create stub lib, license, JFile and tes…
authored
183
184 ## Generator
185
186 The command line has a quick generator that creates stub files for your library code, an example file and tests using Qunit.
187
188 jsbundle init my_library.js
fc8b4ac @ismasan Added README on JBundle server command
authored
189
5ed98c4 @ismasan jbundle init foo.js generator create stub lib, license, JFile and tes…
authored
190 create JFile
191 create src
192 create src/license.txt
193 create src/my_library.js
194 create test
195 create test/index.html
196 create test/tests.js
197 create test/qunit.js
198 create test/qunit.css
199 create dist
200 Done. Try it!
201
202 jbundle s
203 open test/index.html
204
205 At the moment only Qunit is supported in the generator but others (like Jasmine) would be easy to add.
206
207 If you don't need the test stubs run the command with --no-tests
208
b34ada0 @ismasan TODO
authored
209 ## TODO
210
579913d @ismasan Config#target_dir
authored
211 - DRY up stuff, better error handling for missing config
b235015 @ismasan Basic README
authored
212
Something went wrong with that request. Please try again.