-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·88 lines (74 loc) · 1.84 KB
/
Copy pathcli.js
File metadata and controls
executable file
·88 lines (74 loc) · 1.84 KB
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
#!/usr/bin/env node
'use strict';
const os = require('os');
const fs = require('fs-extra');
const path = require('path');
const meow = require('meow');
const distill = require('./index').distill;
const cli = meow(`
Usage
$ distiller [options] <package>
Options
-l, --list lists locally defined custom packages
-o, --output-dir destination for output
-t, --temp-dir destination for temporary build files
-k, --keep-temp do not remove the temporary directory
-h, --help shows usage help
`, {
flags: {
help: {
alias: 'h'
},
list: {
alias: 'l'
},
outputDir: {
alias: 'o'
},
tempDir: {
alias: 't'
},
keepTemp: {
alias: 'k',
type: 'boolean',
default: false
}
}
});
const packagesPath = path.join(__dirname, 'packages');
if (cli.flags.list) {
fs.readdir(packagesPath, (error, packages) => {
if (error) {
return console.log(error);
}
return packages.forEach(pkg => {
console.log(pkg);
});
});
} else {
if (!cli.input.length) {
console.error('Package name required');
process.exit(1);
}
const options = {};
let outputDir;
if (cli.flags.outputDir) {
outputDir = path.join(process.cwd(), cli.flags.outputDir);
} else if (process.env.DISTILLER_DIR) {
outputDir = `${process.env.DISTILLER_DIR}/${cli.input[0]}`;
} else {
outputDir = `${os.homedir()}/.distiller/dist/${cli.input[0]}`;
}
options.outputDir = outputDir;
if (cli.flags.tempDir) {
options.tempDir = cli.flags.tempDir;
}
options.keepTemp = Boolean(cli.flags.keepTemp) || false;
options.package = cli.input[0];
distill(options, error => {
if (error) {
return console.error(error);
}
console.log(`Distilled into: ${outputDir}`);
});
}