|
35 | 35 | /*--------------------------------------------------------------------------*/
|
36 | 36 |
|
37 | 37 | /**
|
38 |
| - * The exposed `minify` function minifies a given `source` and invokes the |
39 |
| - * `onComplete` callback when finished. |
| 38 | + * The exposed `minify` function minifies a given Lo-Dash `source` and invokes |
| 39 | + * the `onComplete` callback when finished. |
40 | 40 | *
|
41 | 41 | * @param {String} source The source to minify.
|
42 | 42 | * @param {String} workingName The name to give temporary files creates during the minification process.
|
|
58 | 58 | function Minify(source, workingName, onComplete) {
|
59 | 59 | // create the destination directory if it doesn't exist
|
60 | 60 | if (!fs.existsSync(distPath)) {
|
61 |
| - fs.mkdirSync(distPath); |
| 61 | + // avoid errors when called as a npm executable |
| 62 | + try { |
| 63 | + fs.mkdirSync(distPath); |
| 64 | + } catch(e) { } |
62 | 65 | }
|
63 | 66 |
|
64 | 67 | this.compiled = {};
|
|
291 | 294 | name = this.workingName,
|
292 | 295 | uglified = this.uglified;
|
293 | 296 |
|
294 |
| - // save the Closure Compiled version to disk |
295 |
| - fs.writeFileSync(path.join(distPath, name + '.compiler.js'), compiled.source); |
296 |
| - fs.writeFileSync(path.join(distPath, name + '.compiler.js.gz'), compiled.gzip); |
| 297 | + // avoid errors when called as a npm executable |
| 298 | + try { |
| 299 | + // save the Closure Compiled version to disk |
| 300 | + fs.writeFileSync(path.join(distPath, name + '.compiler.js'), compiled.source); |
| 301 | + fs.writeFileSync(path.join(distPath, name + '.compiler.js.gz'), compiled.gzip); |
297 | 302 |
|
298 |
| - // save the Uglified version to disk |
299 |
| - fs.writeFileSync(path.join(distPath, name + '.uglify.js'), uglified.source); |
300 |
| - fs.writeFileSync(path.join(distPath, name + <
8000
span class="pl-s">'.uglify.js.gz'), uglified.gzip); |
| 303 | + // save the Uglified version to disk |
| 304 | + fs.writeFileSync(path.join(distPath, name + '.uglify.js'), uglified.source); |
| 305 | + fs.writeFileSync(path.join(distPath, name + '.uglify.js.gz'), uglified.gzip); |
301 | 306 |
|
302 |
| - // save the hybrid minified version to disk |
303 |
| - fs.writeFileSync(path.join(distPath, name + '.hybrid.js'), hybrid.source); |
304 |
| - fs.writeFileSync(path.join(distPath, name + '.hybrid.js.gz'), hybrid.gzip); |
| 307 | + // save the hybrid minified version to disk |
| 308 | + fs.writeFileSync(path.join(distPath, name + '.hybrid.js'), hybrid.source); |
| 309 | + fs.writeFileSync(path.join(distPath, name + '.hybrid.js.gz'), hybrid.gzip); |
| 310 | + } catch(e) { } |
305 | 311 |
|
306 | 312 | // select the smallest gzipped file and use its minified counterpart as the
|
307 | 313 | // official minified release (ties go to Closure Compiler)
|
|
324 | 330 | module.exports = minify;
|
325 | 331 | }
|
326 | 332 | else {
|
327 |
| - // read the JavaScript source file from the first argument if the script |
| 333 | + // read the Lo-Dash source file from the first argument if the script |
328 | 334 | // was invoked directly (e.g. `node minify.js source.js`) and write to
|
329 | 335 | // the same file
|
330 | 336 | (function() {
|
|
0 commit comments