-
Notifications
You must be signed in to change notification settings - Fork 4
/
gift-cli.js
71 lines (71 loc) · 2.52 KB
/
gift-cli.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
#!/usr/bin/env node
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs-extra"));
const path = __importStar(require("path"));
const yargs = __importStar(require("yargs"));
const gift_1 = require("./gift");
main();
function main() {
yargs.demandOption(['i', 'r']);
yargs.alias('i', 'input').describe('i', 'The input file.');
yargs.alias('r', 'root').describe('r', 'The root module name.');
yargs.alias('n', 'name').describe('n', 'The generated module name.');
yargs.alias('o', 'output').describe('o', 'The output file.');
yargs.alias('u', 'shelter-name').describe('u', 'Name of the unexported symbols\' namespace.(defaulted to "__internal")');
yargs.alias('p', 'export-privates').describe('p', 'Indicates whether export private members of class.');
yargs.option('verbose', { type: 'boolean', default: false });
yargs.help();
const argv = yargs.parse(process.argv);
const { i, n, o, r, u, p, verbose } = argv;
let name;
if (typeof n === 'string') {
name = n;
}
else if (typeof o === 'string') {
name = path.basename(o, path.extname(o));
}
else {
console.error(`You must specify a name for the result module.`);
return -1;
}
let output;
if (typeof o !== 'string') {
output = path.join('.', 'gitf-out', `${name}.d.ts`);
}
else {
if (fs.existsSync(o) && fs.statSync(o).isDirectory() ||
!o.toLocaleLowerCase().endsWith('.d.ts')) {
output = path.join(o, `${name}.d.ts`);
}
else {
output = o;
}
}
const options = {
input: i,
name,
output,
rootModule: r,
shelterName: u,
exportPrivates: p,
verbose: verbose,
};
const bundleResult = gift_1.bundle(options);
if (bundleResult.error !== gift_1.GiftErrors.Ok) {
console.error(`Error occurred: ${gift_1.GiftErrors[bundleResult.error]}`);
return -1;
}
const outputPath = options.output;
fs.ensureDirSync(path.dirname(outputPath));
fs.writeFileSync(outputPath, bundleResult.code);
return 0;
}
//# sourceMappingURL=gift-cli.js.map