1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | DryIce ====== DryIce is a CommonJS/RequireJS packaging tool for browser scripts. It is basically just a copy function. It takes input from a set of input files, which can be specified in various ways, optionally filters them and outputs them to something else. DryIce is licensed under the Apache License version 2 Why? ---- RequireJS has a build tool which is nice and works well, but it requires Rhino and therefore Java. With DryIce, your whole build process can be in JavaScript. DryIce produces a single file output that can include binary files (by base64 encoding them) How to install DryIce --------------------- sudo npm install dryice How does it work? ----------------- To copy a single file: copy({ source: 'foo.txt', dest: 'bar.txt' }); To cat a bunch of files together: copy({ source: [ 'file1.js', 'file2.js' ], dest: 'output.js' }); To cat together all the files in a directory: copy({ source: { root:'src' }, dest: 'built.js' }); As above, but only use the JavaScript files: copy({ source: { root:'src', include:/.*\.js$/ }, dest: 'built.js' }); As above, but exclude tests: copy({ source: { root:'src', include:/.*\.js$/: exclude:/test/ }, dest: 'built.js' }); If your set of files is very custom: copy({ source: function() { var files = [ 'file1.js' ]; if (baz) files.push('file2.js'); return files; }, dest: 'built.js' }); We can filter the files on the way: copy({ source: /src/.*\.js$/, filter: copy.filter.uglifyjs, dest: 'built.js' }); This includes running multiple custom filters: copy({ source: 'src/index.html', filter: [ function(data) { return data.replace(/Sun/, 'Oracle'); }, htmlCompressor ], dest: 'war/index.html' }); Results can be stored and then used/reused: var sources = copy.createDataObject(); copy({ source: { root: 'src1' }, dest: sources }); copy({ source: { root: 'src2' }, dest: sources }); copy({ source: sources, dest: 'sources-uncompressed.js' }); copy({ source: sources, filter: copy.filter.uglifyjs, dest: 'sources.js' }); Data objects are just JS objects with a 'value' member, so you can do all sorts of things with them: var test = copy.createDataObject(); copy({ source: 'README.txt', dest: test }); console.log(test.value); Or: copy({ source: { value: 'Hello, World!' }, dest: 'basic.txt' }); And you can mix and match your inputs: copy({ source: [ 'somefile.txt', thingDataObject, { root: 'src', include: /.*\.js$/ }, function() { return 'wibble.sh'; } ], dest: 'mess.bin' }); Common JS project dependency tracking: var project = copy.createCommonJsProject({ roots: [ '/path/to/source/tree/lib', '/some/other/project/lib' ] }); copy({ source: copy.source.commonjs({ project: project, require: [ 'main', 'plugin/main' ] }), dest: '' }); This digs around in the project source trees specified in the project for modules named in the 'require' statement. When it finds them it looks through them for require statements, and finds those, and so on. Formal Parameter Description ---------------------------- The copy function takes a single parameter which is an object with 2 or 3 members: `source`, `dest` and optionally `filter`. ### source There are 6 ways to specify the input source(s) * A *string* is expected to point to a filename. At some stage we may allow them to point at directories too, however this can be achieved today using a find object (see below) * A *find object* points to a directory with 2 optional RegExps specifying what to exclude and include. e.g. { root: '/' } -> The entire filesystem { root: 'src', include: /.*\.js$/ } -> All the JavaScript files in 'src' { root: 'src', exclude: /test/ } -> All non-test files under 'src' * A *data object* - something with a 'value' property. The implementation of `copy.createDataObject()` is simply `return { value: '' };`. We've batted around some ideas which involve making `copy.createDataObject()` smarter than it currently is, so it is advised to use this method rather than doing it yourself. * A *based object*. A based object is one with `base` and `path` members. They are roughly the same as the string baseObj.base + baseObj.path. Based objects are important when using CommonJS filters, because it tells the filter where the root of the hierarchy is, which lets us know the module name. For example: { base: '/etc', path:PATH } where BASE+PATH = filename * An *array* containing input source entries. The array does not have to be homogeneous. * A *function* which returns any input source entries. ### filter The filter member is optional. If it exists, it should contain either a function or an array of functions. The function should have the following signature: function filter(value, location) { .. return 'some string'; } Where the parameters are as follows: * value. Either a string or a node Buffer. Most filters will work only with strings, so they should begin: if (typeof value !== 'string') { value = value.toString(); } Some filters will only work with Buffers (for example the base64 encoding filter) so they should begin: if (typeof value === 'string') { throw new Error('base64 filter needs to be the first in a filter set'); } At some stage we may allow filters to be marked up as to their requirements. * location. This will be (where possible) a based object or it could be a string if a based object is not available. It will be common to use one of the following idioms to work on a filename: if (location.base) { location = location.path; } or if (location.base) { location = location.base + location.path; } There are 2 points in a copy run where filters could be used, either before the individual sources are concatenated, or after. Some filters should be used in before (like common-js munging filters) and some afterwards (like compressors). The default is to run filters after concatenation (when the location parameter will be undefined). To run filters before concatenation, the filter should be marked with `onRead = true`. For example: function makeBlank(value, location) { return ''; } makeBlank.onRead = true; DryIce currently comes with 4 filters: * _copy.filter.uglifyjs_: Calls uglify on the input. * _copy.filter.addDefines_: Wraps the input to inline files fetched using RequireJSs text import feature. * _copy.filter.base64_: Similar to addDefines, but assumes the input is binary and should be base64 encoded. * _copy.filter.moduleDefines_: Replaces define lines to include the module name e.g. `define(function(export, require, module) { ... });` is turned into `define('module/name', function(export, require, module) { ... });` ### dest The dest property should be either a filename to which the output should be written (existing files will be over-written without warning), or a data object to which the data should be appended. CommonJS Projects ----------------- CommonJS projects take a single object with the following properties: * `roots`: This is required. An array of directories that should be searched for your required modules and dependencies. * `ignores`: This is optional. An array of modules or dependencies that are required by your project that you would not like to be included in the build. For example, if you were making a build which did not need to support IE, you could do something like the following copy.createCommonJsProject({ roots: [ '/path/to/project' ], ignores: [ 'dom/ie-compat', 'event/ie-compat' ] }); then wherever you had `require('dom/ie-compat')` or `require('event/ie-compat')` inside your build, `undefined` would be returned by `require`. Where (is the project going)? ----------------------------- DryIce is useful in combining scripts for the browser, but it could also be used in a similar role on the server, we just need to enable 'pass through requires'. There are some tweaks we'd still like to make to enable more filters and multiple destinations: To recursively copy a directory: copy({ source: 'foo', destDir: 'bar' }); To rename files as we copy them: copy({ source: { root:'src', include:/.*\.png$/ }, destDir: { root:'built', replace:/png$/, with:'png.bak' } }); To create a tarball (this is only missing the targz filter): var version = copy.createDataObject(); copy({ source: 'VERSION.txt', dest: version }); copy({ source: { root:'.' }, filter: [ targz ], dest: 'scp://example.com/upload/myproject-' + version + '.tar.gz' }); I don't suppose you would ever actually want to do this, but in theory you could even do this: copy({ source: { root:'src', include:/.*\.java$/ }, filter: javac, destDir: { root:'classes', replace:/java$/, with:'class' } }); (Actually there would be issues with ordering that would make this hard, and Ant/Maven/etc is probably better. This is an illustration dammit!) |
Commit History @lintian-fixes/main
0
»»
- Use dh-sequence-nodejs auto install Xavier Guimard 3 years ago
- Enable CI Xavier Guimard 3 years ago
- Add debian/gbp.conf Xavier Guimard 3 years ago
- Change section to javascript Xavier Guimard 3 years ago
- Add "Rules-Requires-Root: no" Xavier Guimard 3 years ago
- Declare compliance with policy 4.5.0 Xavier Guimard 3 years ago
- Bump debhelper compatibility level to 13 Xavier Guimard 3 years ago
- Update Vcs-* headers to use salsa repository. Debian Janitor 4 years ago
- Remove unnecessary XS-Testsuite field in debian/control. Debian Janitor 4 years ago
- Set upstream metadata fields: Bug-Database, Bug-Submit, Repository, Repository-Browse. Debian Janitor 4 years ago
- Change priority extra to priority optional. Debian Janitor 4 years ago
- Set debhelper-compat version in Build-Depends. Debian Janitor 4 years ago
- Bump debhelper from deprecated 8 to 12. Debian Janitor 4 years ago
- Use secure copyright file specification URI. Debian Janitor 4 years ago
- Trim trailing whitespace. Debian Janitor 4 years ago
- Prepare for release: Update changelog. Jonas Smedegaard 5 years ago
- Fix depend on node-uglify (not uglifyjs). Jonas Smedegaard 5 years ago
- finalize Leo Iannacone 9 years ago
- patch to use uglifyjs version 2.x (closes: #765814) Leo Iannacone 9 years ago
- Bump Standards-Version 3.9.6 Leo Iannacone 9 years ago
- update Homepage to origin mozilla homepage Leo Iannacone 9 years ago
- summerize copyright author, since this is a merge branch of origin mozilla code Leo Iannacone 9 years ago
- add autopkgtest suite Leo Iannacone 9 years ago
- Update changelog (timestamp) Jérémy Lal 9 years ago
- Add missing copyright for mini_require.js Jérémy Lal 9 years ago
- Rephrase long description Jérémy Lal 9 years ago
- intial commit for debian files Leo Iannacone 9 years ago
- Imported Upstream version 0.4.10 Leo Iannacone 9 years ago
0
»»