-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsimplifyify.js
executable file
·105 lines (98 loc) · 3.55 KB
/
simplifyify.js
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
#!/usr/bin/env node
'use strict';
var program = require('commander'),
path = require('path'),
manifest = require('../package'),
simplifyify = require('../');
/**
* Parse command-line arguments
*/
function parseArguments() {
// jscs:disable maximumLineLength
program
.version(manifest.version)
.description(manifest.description)
.arguments('<files...>')
.option('-o, --outfile <filespec>', 'The output file or directory. May include a filename pattern (e.g. "*.bundle.js")')
.option('-u, --exclude <filespec>', 'File path or glob pattern to exclude')
.option('-s, --standalone <name>', 'Export as a named UMD bundle')
.option('-b, --bundle', 'Create a non-minified bundle for development (.js)')
.option('-d, --debug', 'Create a source map for debugging (.js.map)')
.option('-m, --minify', 'Create a minified bundle for production (.min.js)')
.option('-v, --test', 'Create a bundle with code-coverage instrumentation for testing (.test.js)')
.option('-w, --watch', 'Watch source file(s) and rebuild the bundle(s) automatically')
.on('--help', function() {
console.log(
' Arguments:\n' +
'\n' +
' <files...> One or more entry-file paths and/or glob patterns.\n' +
' Don\'t forget to put quotes around glob patterns.\n' +
' A separate Browserify bundle will be created\n' +
' for each entry file.\n' +
'\n' +
' Examples:\n' +
'\n' +
' simplifyify src/index.js --outfile dist/bundle.js --bundle --debug --minify --test\n' +
'\n' +
' Output Files: \n' +
' dist/bundle.js\n' +
' dist/bundle.js.map\n' +
' dist/bundle.min.js\n' +
' dist/bundle.min.js.map\n' +
' dist/bundle.test.js\n' +
'\n' +
'\n' +
' simplifyify "src/module-*.js" --outfile "dist/*.bundle.js" --bundle --minify\n' +
'\n' +
' Output Files: \n' +
' dist/module-one.bundle.js\n' +
' dist/module-one.bundle.min.js\n' +
' dist/module-two.bundle.js\n' +
' dist/module-two.bundle.min.js\n'
);
})
.parse(process.argv);
// Show help if no options were given
if (program.args.length === 0) {
program.outputHelp();
process.exit(1);
}
}
/**
* Program entry point
*/
function main() {
parseArguments();
simplifyify(program.args, program)
.on('update', function(file) {
// Log that a file change has been detected
console.log('%s has changed', path.relative(process.cwd(), file));
})
.on('log', function(msg) {
// Log # of bytes written & time taken
console.log(msg);
})
.on('end', function(fileSet) {
// Log the output files that were written
console.log('%s --> %s', fileSet.entryFile, fileSet.outputFile);
if (fileSet.mapFile) {
console.log('%s --> %s', fileSet.entryFile, fileSet.mapFile);
}
})
.on('error', function(err, fileSet) {
// Log an error
if (fileSet && fileSet.entryFile) {
console.error('Error bundling %s\n%s', fileSet.entryFile, err);
}
else {
var message = process.env.DEBUG ? err.stack : err.message;
console.error(message);
}
// Exit the app with an error code,
// unless we're in "Watchify" mode, in which case, we just keep watching
if (!program.watch) {
process.exit(2);
}
});
}
main();