jake 1.0.1 → 1.1.0

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/README.txt DELETED
@@ -1,284 +0,0 @@
1
- = Jake
2
-
3
- * http://github.com/jcoglan/jake
4
-
5
- Jake is a command line tool for building JavaScript packages from source
6
- code. Using simple YAML config files, you can specify any number of build
7
- files to be generated by concatenating and minifying groups of source files.
8
- It allows ERB to be used inside source files to generate code, and provides
9
- event hooks into the build process so you can extend it for your own needs.
10
-
11
-
12
- == Features
13
-
14
- * Concatenate and minify groups of source files for distribution
15
- * Configured using simple YAML files
16
- * Easily generate multiple distros with different compression settings
17
- * Use ERB templating to generate source code
18
- * Extensible using Ruby/ERB and event hooks during the build process
19
- * Tested on Ruby 1.8.6, 1.8.7, 1.9.1
20
-
21
-
22
- == Installation
23
-
24
- sudo gem install jake
25
-
26
-
27
- == Usage
28
-
29
- To begin with, create a file called <tt>jake.yml</tt> in the root directory
30
- of your project; you will run the +jake+ command from here. A basic config
31
- looks like this:
32
-
33
- ---
34
- source_directory: source
35
- build_directory: build
36
-
37
- layout: together
38
-
39
- header: COPYRIGHT
40
-
41
- builds:
42
- src:
43
- packer: false
44
- min:
45
- shrink_vars: true
46
- private: true
47
-
48
- packages:
49
- [ DESCRIBED BELOW ]
50
-
51
- * +source_directory+ is the directory relative to <tt>jake.yml</tt> where
52
- your source files are, and +build_directory+ is where all the generated
53
- build files will be placed.
54
- * +layout+ describes whether files from separate builds should go in
55
- separate directories. For example if you have a package called +foo+,
56
- with the above config the +together+ layout will generate
57
- <tt>build/foo-src.js</tt> and <tt>build/foo-min.js</tt>, whereas a
58
- +layout+ value of +apart+ will generate <tt>build/src/foo.js</tt> and
59
- <tt>build/min/foo.js</tt>.
60
- * +header+ specifies a file whose content should appear at the top of
61
- all generated build files. The content of this file will typically be
62
- JavaScript comments containing copyright and license information. This
63
- content is never minified. The +header+ option may be omitted.
64
-
65
-
66
- === Build listing
67
-
68
- The build listing, given by the +builds+ option in the config file, lists
69
- all the builds you want to produce for distribution, and what minification
70
- settings each build should use. JavaScript projects typically distribute
71
- both compressed and uncompressed copies of their code to suit both production
72
- and development environments.
73
-
74
- You can have as many builds as you like and the names are up to you. I'm
75
- using +src+ and +min+ as readily understood examples. Each build may specify
76
- some combination of the following options:
77
-
78
- * <tt>packer: false</tt> - disables minification for this build. This
79
- precludes use of further minification options.
80
- * <tt>shrink_vars: true</tt> - tells the minifier to compress local
81
- variable names inside functions.
82
- * <tt>private: true</tt> - tells the minifier to obfuscate 'private'
83
- variables with numeric replacements. JavaScript convention is that any
84
- name beginning with an underscore, e.g. <tt>_foo</tt> or <tt>obj._bar</tt>
85
- should be considered private. They are replaced with <tt>_0</tt>,
86
- <tt>_1</tt>, etc.
87
- * <tt>base62: true</tt> - produces base-62 encoded minification.
88
- * <tt>suffix: false</tt> - files from this build should not have a
89
- suffix if using the +together+ layout, so you get <tt>build/foo.js</tt>
90
- rather than <tt>build/foo-src.js</tt>, for example. Only one build
91
- may use this option, otherwise file name clashes will occur.
92
-
93
-
94
- === Package listing
95
-
96
- The package listing, given under the +packages+ config option, describes
97
- the packages you want to produce and which source files are used to generate
98
- them. A package is named using the path under +build_directory+ where it
99
- should be generated, e.g. <tt>foo</tt> or <tt>ext/awesome</tt> (you may
100
- omit the <tt>.js</tt> extension). Each package lists one or more source
101
- files used to build it, and may optionally list some extra options as described
102
- below.
103
-
104
- For the examples, assume the source directory is +src+ and the build
105
- directory is +dist+. This package uses a single source file <tt>src/foo.js</tt>
106
- and generates <tt>dist/foo_dist.js</tt>:
107
-
108
- foo_dist: foo
109
-
110
- This package generates <tt>dist/bar.js</tt> from <tt>src/bar1.js</tt> and
111
- <tt>src/bar2.js</tt>
112
-
113
- bar:
114
- - bar1
115
- - bar2
116
-
117
- This generates a package at <tt>dist/sub/dir.js</tt> from <tt>src/path/file.js</tt>
118
- and <tt>src/path/baz.js</tt>:
119
-
120
- sub/dir:
121
- - path/file
122
- - path/baz
123
-
124
- If all the source files for a package live in the same subdirectory, you
125
- can tidy things up using the +directory+ option. If you use any package-level
126
- options, you must list the files under the +files+ option (the above examples
127
- are just syntactic shorthands for this):
128
-
129
- sub/dir:
130
- directory: path
131
- files:
132
- - file
133
- - baz
134
-
135
- The full list of package options is as follows:
136
-
137
- * +files+ - lists the source files used to build the package. Shorthand may
138
- be used as above if no further options are used.
139
- * +extends+ - name of another package from which to inherit configuration.
140
- Useful for making a package that includes all the files from another,]
141
- plus a few extras.
142
- * +directory+ - the directory under +source_directory+ in which to find
143
- source files. May be omitted.
144
- * +header+ - a custom header file to use on this package. Overrides the
145
- root +header+ option. May be omitted.
146
- * +packer+ - lists minification settings that override settings being used
147
- for the current build. If a build listed above uses <tt>packer: false</tt>,
148
- this takes precedence over package-specific instructions. Typically used
149
- to override options for the minified build.
150
- * +meta+ - should be a YAML dictionary containing arbitrary data useful to
151
- user-defined build events. May be omitted. See 'Event hooks' below.
152
-
153
- For example, here's a package listing that uses all the options:
154
-
155
- packages:
156
- foo_dist: foo
157
-
158
- bar:
159
- - bar1
160
- - bar2
161
-
162
- sub/whizz:
163
- extends: foo_dist
164
- directory: path
165
- header: CUSTOM_HEADER
166
- files:
167
- - file1
168
- - file2
169
-
170
- last:
171
- packer:
172
- private: false
173
- meta:
174
- requires:
175
- - jQuery
176
- - GMap2
177
- files:
178
- - one_file
179
- - another_file
180
-
181
- In conjunction with the build options listed above, this matches the
182
- following project layout (omitting build name suffixes for brevity):
183
-
184
- - build/
185
- - sub/
186
- - whizz.js
187
- - bar.js
188
- - foo_dist.js
189
- - last.js
190
- - source/
191
- - path/
192
- - CUSTOM_HEADER
193
- - file1.js
194
- - file2.js
195
- - another_file.js
196
- - bar1.js
197
- - bar2.js
198
- - foo.js
199
- - one_file.js
200
- - COPYRIGHT
201
- - jake.yml
202
-
203
-
204
- === Using ERB in source files
205
-
206
- Jake lets you use Ruby's ERB templating system within your source code so
207
- you can insert values generated from Ruby functions. To use this feature,
208
- you need to create a file called <tt>Jakefile</tt> in the root of your project.
209
- This contains helper functions that are called in your source code to inject data.
210
-
211
- For example, say you want to extract a version number from your version control
212
- system and inject it into your code along with the build name. Your source code
213
- should contain something like this:
214
-
215
- MyJavaScriptLib.VERSION = "<%= version %>-<%= build %>";
216
-
217
- And your <tt>Jakefile</tt> should contain a helper called +version+:
218
-
219
- jake_helper :version do
220
- # extract version number from svn, git, whatever
221
- # e.g. return '1.0'
222
- end
223
-
224
- Jake has a built-in helper called +build+ that returns the current build
225
- name. When built, the output would contain the following:
226
-
227
- MyJavaScriptLib.VERSION = "1.0-src"; // or "1.0-min" for the 'min' build
228
-
229
-
230
- === Event hooks
231
-
232
- The +Jakefile+ may also define event hooks that are fired during a build when
233
- interesting things happen. This allows you to extend your build process using
234
- configuration data from Jake. All event callbacks are passed a +Build+ object
235
- as the first argument, and may receive additional arguments depending on the
236
- event type. We currently have two events:
237
-
238
- +file_created+ is fired whenever a new build file is created. The callback is
239
- passed the +Buildable+ package object, the current build type (+src+ or +min+
240
- using the above examples), and the full path to the newly created file.
241
- The package object may contain metadata (set using the +meta+ option, see
242
- above) which you can use for further code generation.
243
-
244
- +build_complete+ is fired after a build has finished running, that is after
245
- all sets of minification options have been run. At this point you can use any
246
- metadata you've gathered to generate more code, copy files to your distribution
247
- directory, etc.
248
-
249
- $register = {}
250
-
251
- jake_hook :file_created do |build, pkg, build_type, path|
252
- $register[path] = pkg.meta
253
- end
254
-
255
- jake_hook :build_complete do |build|
256
- FileUtils.cp 'README', build.build_directory + '/README'
257
- # generate code from $register
258
- end
259
-
260
-
261
- == License
262
-
263
- (The MIT License)
264
-
265
- Copyright (c) 2008-2009 James Coglan
266
-
267
- Permission is hereby granted, free of charge, to any person obtaining
268
- a copy of this software and associated documentation files (the
269
- 'Software'), to deal in the Software without restriction, including
270
- without limitation the rights to use, copy, modify, merge, publish,
271
- distribute, sublicense, and/or sell copies of the Software, and to
272
- permit persons to whom the Software is furnished to do so, subject to
273
- the following conditions:
274
-
275
- The above copyright notice and this permission notice shall be
276
- included in all copies or substantial portions of the Software.
277
-
278
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
279
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
280
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
281
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
282
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
283
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
284
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile DELETED
@@ -1,13 +0,0 @@
1
- # -*- ruby -*-
2
-
3
- require 'rubygems'
4
- require 'hoe'
5
- require './lib/jake.rb'
6
-
7
- Hoe.spec('jake') do |p|
8
- # p.rubyforge_name = 'jakex' # if different than lowercase project name
9
- p.developer('James Coglan', 'jcoglan@googlemail.com')
10
- p.extra_deps = %w(eventful packr oyster)
11
- end
12
-
13
- # vim: syntax=Ruby
@@ -1,22 +0,0 @@
1
- jake_helper :version do
2
- "0.5.0"
3
- end
4
-
5
- FILES = []
6
- DEPS = {}
7
-
8
- jake_hook :file_created do |build, package, build_type, path|
9
- FILES << File.basename(path)
10
- DEPS[path] = package.meta if build_type == :min
11
- end
12
-
13
- jake_hook :build_complete do |build|
14
- write = lambda do |file, content|
15
- File.open(File.join(build.build_dir, file), 'w') { |f| f.write(content) }
16
- end
17
- write['README', 'Should be generated after build']
18
- write['LISTING', FILES.sort * "\n"]
19
-
20
- write['packages.js', ERB.new(File.read('packages.erb')).result(binding)]
21
- end
22
-
@@ -1,10 +0,0 @@
1
- bar-min.js
2
- bar.js
3
- basic-min.js
4
- basic.js
5
- box-min.js
6
- box.js
7
- ext-min.js
8
- ext.js
9
- foo-min.js
10
- foo.js
@@ -1 +0,0 @@
1
- Should be generated after build
@@ -1,7 +0,0 @@
1
- /**
2
- * Jake test files should all include this
3
- * even if they have been minified.
4
- * 0.5.0-min
5
- **/
6
-
7
- Basic={VERSION:"0.5.0-min",function(a){var b=4;return b+this._0+a}};
@@ -1,14 +0,0 @@
1
- /**
2
- * Jake test files should all include this
3
- * even if they have been minified.
4
- * 0.5.0-src
5
- **/
6
-
7
- Basic = {
8
- VERSION: "0.5.0-src",
9
-
10
- function(something) {
11
- var myVar = 4;
12
- return myVar + this._foo + something;
13
- }
14
- };
@@ -1,8 +0,0 @@
1
- /**
2
- * Jake test files should all include this
3
- * even if they have been minified.
4
- * 0.5.0-min
5
- **/
6
-
7
- Foo=(function(b,c){var a=true;return{_0:null,field:a,global:foo}})(window,something);
8
- Basic={VERSION:"0.5.0-min",function(a){var b=4;return b+this._foo+a}};Basic.Ext="MIN";
@@ -1,28 +0,0 @@
1
- /**
2
- * Jake test files should all include this
3
- * even if they have been minified.
4
- * 0.5.0-src
5
- **/
6
-
7
- Foo = (function(my, vars) {
8
- var another = true;
9
-
10
- return {
11
- _priv: null,
12
- field: another,
13
- global: foo
14
- };
15
- })(window, something);
16
-
17
-
18
- Basic = {
19
- VERSION: "0.5.0-src",
20
-
21
- function(something) {
22
- var myVar = 4;
23
- return myVar + this._foo + something;
24
- }
25
- };
26
-
27
-
28
- Basic.Ext = "SRC";
@@ -1,7 +0,0 @@
1
- /**
2
- * Jake test files should all include this
3
- * even if they have been minified.
4
- * 0.5.0-min
5
- **/
6
-
7
- Basic={VERSION:"0.5.0-min",function(a){var b=4;return b+this._foo+a}};Basic.Ext="MIN";
@@ -1,17 +0,0 @@
1
- /**
2
- * Jake test files should all include this
3
- * even if they have been minified.
4
- * 0.5.0-src
5
- **/
6
-
7
- Basic = {
8
- VERSION: "0.5.0-src",
9
-
10
- function(something) {
11
- var myVar = 4;
12
- return myVar + this._foo + something;
13
- }
14
- };
15
-
16
-
17
- Basic.Ext = "SRC";
@@ -1,7 +0,0 @@
1
- /**
2
- * Jake test files should all include this
3
- * even if they have been minified.
4
- * 0.5.0-min
5
- **/
6
-
7
- Foo=(function(b,c){var a=true;return{_0:null,field:a,global:foo}})(window,something);
@@ -1,15 +0,0 @@
1
- /**
2
- * Jake test files should all include this
3
- * even if they have been minified.
4
- * 0.5.0-src
5
- **/
6
-
7
- Foo = (function(my, vars) {
8
- var another = true;
9
-
10
- return {
11
- _priv: null,
12
- field: another,
13
- global: foo
14
- };
15
- })(window, something);