-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpure-cjs.js
executable file
·38 lines (33 loc) · 1.17 KB
/
pure-cjs.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
#!/usr/bin/env node
var program = require('commander'),
cjs = require(__dirname + '/../lib/');
program
.version(require(__dirname + '/../package.json').version)
.option('-i, --input <file>', 'input file (required)')
.option('-o, --output <file>', 'output file (defaults to <input>.out.js)')
.option('-x, --extension <ext>', 'default extension for requires (defaults to "js")')
.option('-m, --map [file]', 'file to store source map to (optional)')
.option('-c, --comments', 'preserve comments in output')
.option('-e, --exports <id>', 'top module exports destination (optional)')
.option('-d, --module-dir <dir>', 'top level location to search for external modules (optional)')
.option('-s, --external [hash]', 'external modules (names or JSON hashes)', function (value, obj) {
try {
var add = JSON.parse(value);
for (var name in add) {
obj[name] = add[name];
}
} catch (e) {
obj[value] = true;
}
return obj;
}, {})
.parse(process.argv);
if (!program.input) {
program.help();
}
console.log('Building...');
cjs.transform(program).then(function (result) {
console.log('Built to:', result.options.output);
}, function (error) {
console.error(error.stack);
});