UNPKG

1.21 kBJavaScriptView Raw
1var fs = require("fs");
2var _assign = require("lodash/assign");
3var stealTools = require("../../index");
4var _clone = require("lodash/cloneDeep");
5var makeStealConfig = require("./make_steal_config");
6var options = _clone(require("./options"));
7
8module.exports = {
9 command: "transform",
10
11 builder: _assign({}, options, {
12 out: {
13 alias: "o",
14 type: "string",
15 describe: "Specify an output file"
16 },
17 ignore: {
18 type: "string",
19 describe: "Comma-separated list of modules to not include in the output"
20 }
21 }),
22
23 describe: "Transform a module to other formats",
24
25 handler: function(argv) {
26 var ignore = [];
27 var options = argv;
28 var config = makeStealConfig(argv);
29
30 // ignore would be a comma-separated list like jquery,underscore,moment
31 if (argv.ignore) {
32 ignore = argv.ignore.split(",");
33 }
34
35 return stealTools.transform(config, options)
36 .then(function(transform){
37 return transform(null, {
38 ignore: ignore
39 });
40 }).then(function(result){
41 var code = result.code;
42 var map = result.map;
43
44 // Write out the contents
45 fs.writeFileSync(argv.out, code, "utf8");
46 if (map) {
47 fs.writeFileSync(argv.out + ".map", map.toString(), "utf8");
48 }
49 });
50 }
51};