|
2 | 2 |
|
3 | 3 | var browserifyIncremental = require('../');
|
4 | 4 | var fs = require('fs');
|
5 |
| -var path = require('path'); |
6 | 5 | var fromArgs = require('browserify/bin/args');
|
7 |
| -var xtend = require('xtend'); |
8 | 6 | var JSONStream = require('JSONStream');
|
9 | 7 | var through = require('through2');
|
10 | 8 |
|
11 |
| -process.stdout.on('error', process.exit); |
| 9 | +function run() { |
| 10 | + process.stdout.on('error', process.exit); |
12 | 11 |
|
13 |
| -var b, outfile, verbose, cachefile; |
| 12 | + var b, outfile, verbose, cachefile; |
14 | 13 |
|
15 |
| -var b_ = fromArgs(process.argv.slice(2), browserifyIncremental.args) |
16 |
| -cachefile = b_.argv.cachefile || './browserify-cache.json' |
17 |
| -outfile = b_.argv.o || b_.argv.outfile; |
18 |
| -verbose = (b_.argv.v || b_.argv.verbose); |
19 |
| -b = browserifyIncremental(b_, {cacheFile: cachefile}); |
| 14 | + var b_ = fromArgs(process.argv.slice(2), browserifyIncremental.args); |
| 15 | + cachefile = b_.argv.cachefile || './browserify-cache.json'; |
| 16 | + outfile = b_.argv.o || b_.argv.outfile; |
| 17 | + verbose = (b_.argv.v || b_.argv.verbose); |
| 18 | + b = browserifyIncremental(b_, {cacheFile: cachefile}); |
20 | 19 |
|
21 |
| -b.on('update', function(changes) { |
22 |
| - if (verbose && changes.length) console.error('changed files:\n'+changes.join('\n')); |
23 |
| -}); |
| 20 | + b.on('update', function(changes) { |
| 21 | + if (verbose && changes.length) console.error('changed files:\n' + changes.join('\n')); |
| 22 | + }); |
24 | 23 |
|
25 |
| -if (b.argv.version) { |
| 24 | + if (b.argv.version) { |
26 | 25 | return console.log(require('../package.json').version);
|
27 |
| -} |
| 26 | + } |
28 | 27 |
|
29 |
| -b.on('error', errorExit); |
| 28 | + b.on('error', errorExit); |
30 | 29 |
|
31 |
| -if (b.argv.pack) { |
| 30 | + if (b.argv.pack) { |
32 | 31 | process.stdin.pipe(b.pack()).pipe(process.stdout);
|
33 | 32 | process.stdin.resume();
|
34 | 33 | return;
|
35 |
| -} |
| 34 | + } |
36 | 35 |
|
37 |
| -if (b.argv.deps) { |
| 36 | + if (b.argv.deps) { |
38 | 37 | var stringify = JSONStream.stringify();
|
39 | 38 | stringify.pipe(process.stdout);
|
40 | 39 | b.pipeline.get('deps').push(through.obj(
|
41 |
| - function (row, enc, next) { stringify.write(row); next() }, |
42 |
| - function () { stringify.end() } |
| 40 | + function(row, enc, next) { stringify.write(row); next(); }, |
| 41 | + function() { stringify.end(); } |
43 | 42 | ));
|
44 | 43 | return b.bundle();
|
45 |
| -} |
| 44 | + } |
46 | 45 |
|
47 |
| -if (b.argv.list) { |
48 |
| - b.pipeline.get('deps').push(through.obj( |
49 |
| - function (row, enc, next) { |
50 |
| - console.log(row.file || row.id); |
51 |
| - next() |
52 |
| - } |
53 |
| - )); |
| 46 | + if (b.argv.list) { |
| 47 | + b.pipeline.get('deps').push(through.obj(function(row, enc, next) { |
| 48 | + console.log(row.file || row.id); |
| 49 | + next(); |
| 50 | + })); |
54 | 51 | return b.bundle();
|
55 |
| -} |
| 52 | + } |
56 | 53 |
|
57 |
| -var bytes, time; |
58 |
| -b.on('bytes', function (b) { bytes = b }); |
59 |
| -b.on('time', function (t) { time = t }); |
| 54 | + var bytes, time; |
| 55 | + b.on('bytes', function(b) { bytes = b; }); |
| 56 | + b.on('time', function(t) { time = t; }); |
60 | 57 |
|
61 |
| -var bundle = b.bundle(); |
62 |
| -bundle.on('error', errorExit); |
| 58 | + var bundle = b.bundle(); |
| 59 | + bundle.on('error', errorExit); |
63 | 60 |
|
64 |
| -bundle.on('end', function () { |
| 61 | + bundle.on('end', function() { |
65 | 62 | if (verbose) {
|
66 |
| - console.error(bytes + ' bytes written to ' + (outfile || "stdout") |
67 |
| - + ' (' + (time / 1000).toFixed(2) + ' seconds)' |
68 |
| - ); |
| 63 | + console.error(bytes + ' bytes written to ' + (outfile || 'stdout') |
| 64 | + + ' (' + (time / 1000).toFixed(2) + ' seconds)' |
| 65 | + ); |
69 | 66 | }
|
70 |
| -}); |
| 67 | + }); |
71 | 68 |
|
72 |
| -if (outfile) { |
| 69 | + if (outfile) { |
73 | 70 | bundle.pipe(fs.createWriteStream(outfile));
|
74 |
| -} |
75 |
| -else { |
| 71 | + } |
| 72 | + else { |
76 | 73 | bundle.pipe(process.stdout);
|
| 74 | + } |
77 | 75 | }
|
78 | 76 |
|
79 | 77 | function errorExit(err) {
|
80 |
| - if (err.stack) { |
81 |
| - console.error(err.stack); |
82 |
| - } |
83 |
| - else { |
84 |
| - console.error(String(err)); |
85 |
| - } |
86 |
| - process.exit(1); |
| 78 | + if (err.stack) { |
| 79 | + console.error(err.stack); |
| 80 | + } |
| 81 | + else { |
| 82 | + console.error(String(err)); |
| 83 | + } |
| 84 | + process.exit(1); |
87 | 85 | }
|
| 86 | + |
| 87 | +run(); |
0 commit comments