-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathindex.ts
40 lines (36 loc) · 1.24 KB
/
index.ts
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
#!/usr/bin/env node
import * as yargs from 'yargs';
import * as fs from 'fs';
import * as path from 'path';
import {StreamWriter, NopWriter, Emitter} from './lib/index';
const argv = yargs.usage('Usage: $0 [options] inputFile rootName')
.alias('i', 'interface-file')
.string('i')
.describe('i', 'Specify output file for interfaces')
.alias('p', 'proxy-file')
.string('p')
.describe('p', 'Specity output file for TypeScript proxy classes')
.help('h')
.alias('h', 'help')
.argv;
let interfaceWriter = new NopWriter();
let proxyWriter = interfaceWriter;
if (argv.i && argv.p && path.resolve(argv.i) === path.resolve(argv.p)) {
console.error(`Interfaces and proxies cannot be written to same file.`);
yargs.showHelp();
process.exit(1);
}
if (argv.i) {
interfaceWriter = new StreamWriter(fs.createWriteStream(argv.i));
}
if (argv.p) {
proxyWriter = new StreamWriter(fs.createWriteStream(argv.p));
}
if (argv._.length !== 2) {
console.error(`Please supply an input file with samples in a JSON array, and a symbol to use for the root interface / proxy.`);
yargs.showHelp();
process.exit(1);
}
const samples = JSON.parse(fs.readFileSync(argv._[0]).toString());
const e = new Emitter(interfaceWriter, proxyWriter);
e.emit(samples, argv._[1]);