UNPKG

8.85 kBMarkdownView Raw
1# Welcome to Buildr
2
3The (Java|Coffee)Script and (CSS|Less) (Builder|Bundler|Packer|Minifier|Merger|Checker)
4
5
6## Install
7
81. [Install Node.js](http://bevry.me/node/install)
9
101. Install dependencies for image compression
11
12 - On OSX
13
14 ruby -e "$(curl -fsSLk https://gist.github.com/raw/323731/install_homebrew.rb)"
15 brew install gifsicle libjpeg optipng pngcrush
16
17 - On Apt Linux
18
19 sudo apt-get update && sudo apt-get install gifsicle libjpeg-progs optipng pngcrush
20
21 - On Yum Linux
22
23 sudo yum -y install gifsicle libjpeg-progs optipng pngcrush
24
25 - Windows
26
27 > Hahahahaha
28
29
30## Configure
31
32Before you use Buildr, you must specify some configuration for it. The available configuration is:
33
34``` coffeescript
35{
36 # Options
37 name: null # (name to be outputted in log messages) String or null
38 log: true # (log status updates to console?) true or false
39 watch: false # (automatically rebuild on file change?) true or false
40
41 # Handlers
42 buildHandler: false # (fired when build completed) function or false
43 rebuildHandler: false # (fired when rebuild completed) function or false
44 successHandler: false # (fired when (re)build completed successfully) function or false
45
46 # Paths
47 srcPath: false # String
48 outPath: false # String or false
49
50 # Checking
51 checkScripts: true # Array or true or false
52 checkStyles: true # Array or true or false
53 jshintOptions: false # Object or false
54 csslintOptions: false # Object or false
55
56 # Compression (requires outPath)
57 compressScripts: true # Array or true or false
58 compressStyles: true # Array or true or false
59 compressImages: true # Array or true or false
60
61 # Order
62 scriptsOrder: false # Array or false
63 stylesOrder: false # Array or false
64
65 # Bundling (requires Order)
66 bundleScriptPath: false # String or false
67 bundleStylePath: false # String or false
68 deleteBundledFiles: true # (requires outPath) true or false
69
70 # Loaders (requires Order)
71 srcLoaderHeader: false # String or false
72 srcLoaderPath: false # String or false
73}
74```
75
76The above values are the default values for those options. The settings which are set to `true` will auto-detect the files for you.
77
78
79### Options
80
81There are currently two options available, the `log` and `watch` options.
82
83- The `log` option when enabled will output all status messages, by default this is enabled.
84- The `watch` option when enabled will allow buildr to run in the background watching for changes in our `srcPath`, if a change is detected then our project is automatically rebuilt for us, by default this is disabled.
85
86
87### Handlers
88
89There are two handlers you can configure, they are the `buildHandler` and the `rebuildHandler`.
90
91- The `buildHandler` is fired after our project has been built.
92- The `rebuildHandler` is fired after our project has been rebuilt. Our project is rebuilt when we utilise the `watch: true` config option, which scans for changes in the background and automatically rebuilds our project on change. If this isn't specified, then the `buildHandler` will automatically be used as the `rebuildHandler`.
93
94They are both passed a single argument called `err` which is either an `Error` instance, or `false` if no error occurred. They both also have default values, so you don't need to specify them if you don't want to.
95
96
97### Checking
98
99To pass your scripts through jshint and your styles through csslint, you'd want the following configuration:
100
101``` coffeescript
102{
103 # Paths
104 srcPath: 'src' # String
105
106 # Checking
107 checkScripts: true # Array or true or false
108 checkStyles: true # Array or true or false
109 jshintOptions: false # Object or false
110 csslintOptions: false # Object or false
111}
112```
113
114
115### Compression
116
117To copy your `src` directory to an `out` directory, then compile and compress all your styles and scripts in the `out` directory, you'd want the following configuration:
118
119``` coffeescript
120{
121 # Paths
122 srcPath: 'src' # String
123 outPath: 'out' # String or false
124
125 # Compression (without outPath only the generated bundle files are compressed)
126 compressScripts: true # Array or true or false
127 compressStyles: true # Array or true or false
128 compressImages: true # Array or true or false
129}
130```
131
132If your `outPath` is the same as your `srcPath` then the only files which will be compressed are the generated bundle files.
133
134
135### Bundling
136
137To bundle all your style files into one file called `out/bundled.css` and all your script files into one file called `out/bundled.js`, you'd want the following configuration:
138
139``` coffeescript
140{
141 # Paths
142 srcPath: 'src' # String
143 outPath: 'out' # String or false
144
145 # Order
146 scriptsOrder: [
147 'script1.js'
148 'script2.coffee'
149 ] # Array or false
150 stylesOrder: [
151 'style1.css'
152 'style2.less'
153 ] # Array or false
154
155 # Bundling (requires Order)
156 bundleScriptPath: false # String or false
157 bundleStylePath: false # String or false
158 deleteBundledFiles: true # (requires outPath) true or false
159}
160```
161
162
163### Loaders
164
165To generate a source loader file called `src/loader.js` which will load in all your source styles and scripts into the page, you can use the following:
166
167``` coffeescript
168{
169 # Paths
170 srcPath: 'src' # String
171
172 # Order
173 scriptsOrder: [
174 'script1.js'
175 'script2.coffee'
176 ] # Array or false
177 stylesOrder: [
178 'style1.css'
179 'style2.less'
180 ] # Array or false
181
182 # Loaders (requires Order)
183 srcLoaderHeader: '''
184 # Prepare
185 myprojectEl = document.getElementById('myproject-include')
186 myprojectBaseUrl = myprojectEl.src.replace(/\\?.*$/,'').replace(/loader\\.js$/, '').replace(/\\/+$/, '')+'/'
187
188 # Load in with Buildr
189 myprojectBuildr = new window.Buildr {
190 baseUrl: myprojectBaseUrl
191 beforeEl: myprojectEl
192 serverCompilation: window.serverCompilation or false
193 scripts: scripts
194 styles: styles
195 }
196 myprojectBuildr.load()
197 ''' # note, all \ in this are escaped due to it being in a string
198 srcLoaderPath: 'src/myproject.loader.js' # String or false
199}
200```
201
202Then include into your page with the following html:
203
204``` html
205<script id="myproject-include" src="../../loader.js"></script>
206```
207
208This is incredibly useful for developing apps which have lots of files, as instead of updating all your demo page's html with the new script and style files all the time, you just include the loader.
209
210
211### Combining
212
213You can feel free to combine any of the configurations above to get something which checks, compiles, compresses, bundles, and generates loaders too. Though compression and bundling is dependent on having an `outPath` which is different from your `srcPath`.
214
215
216## Run
217
218### As a Command Line Tool
219
220Within your application folder
221
2221. Install Buildr Globally
223
224 npm -g install buildr
225
2262. Stick your configuration in `buildr.cson`
227
2283. Run the global buildr
229
230 buildr
231
232You may specify the filename for configuring by passing -f <filename> or --file <filename> on the command-line.
233
234### As a Module
235
236Within your application folder
237
2381. Install Buildr Locally
239
240 npm install buildr
241
2422. Code `buildr.coffee`
243
244 ``` coffeescript
245 buildr = require 'buildr'
246 config = {} # your configuration
247 myBuildr = buildr.createInstance(config)
248 myBuildr.process (err) ->
249 throw err if err
250 console.log 'Building completed'
251 ```
252
2533. Run your buildr file
254
255 coffee buildr.coffee
256
257
258## License
259
260Licensed under the [MIT License](http://creativecommons.org/licenses/MIT/)
261Copyright 2011 [Benjamin Arthur Lupton](http://balupton.com)
262
263
264## History
265
266### Changelog
267
268- v0.8.6 March 17, 2013
269 - Replace deprecated path.exists call with fs.exists.
270 - Fix build issue with Cakefile.
271 - Fix issue 32 and 33
272
273- v0.8.5 November 11, 2012
274 - Fix problem with copying of hidden directories like .svn/
275
276- v0.8.4 November 5, 2012
277 - Fix bug 31: Log level debug is always used, regardless of configuration.
278
279- v0.8.3 October 28, 2012
280 - Feature request #13: specify .cson file at command line
281 - Feature request #15: Macro preprocessor
282 - Fix bugs 8, 19, 20, 21, 23, 25, 27, 28, 30
283 - Use cake to build JavaScript, making buildr easier to run
284 - Updated dependencies to fix several bugs
285
286- v0.8 September 27, 2011
287 - Fixed concurrency support
288 - Fixed compression under certain configurations
289 - Added [Caterpillar](https://github.com/balupton/caterpillar.npm) for awesome console logging
290
291- v0.7 August 22, 2011
292 - Added `watch`, `buildHandler` and `rebuildHandler` options
293
294- v0.6 July 21, 2011
295 - v0.6.0 July 21, 2011
296 - Added javascript, image and css compression
297 - Added jshint and csslint checks
298 - v0.6.6 August 16, 2011
299 - Fixed relative paths between outPath and bundledPaths
300
301- v0.5 July 9, 2011
302 - Added srcLoader compilation
303
304- v0.4 July 1, 2011
305 - Extremely Simplified
306 - Only supports bundling of js|coffee and css|less files currently
307
308- v0.3 May 31, 2011
309 - Exploration into better architectures
310
311- v0.2 April 2, 2011
312 - Initial Release
313
314- v0.1 March 23, 2011
315 - Initial Commit
316
317### Todo
318
319- Needs auto file finding for bundling/orders
320- Needs no-config version
321- Needs unit tests