-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.ts
executable file
·52 lines (44 loc) · 1.14 KB
/
main.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
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env node
import meow from 'meow';
import { generateCode } from './src/main';
const cli = meow(`
Usage
$ tlb <tlbpath>
Options
--output, -o Output file, default = tlbpath with .ts extension e.g. ./path/to/file.tlb -> ./path/to/file.ts
--language, -l Programming language result. Supported languages: ["typescript"]. Default: "typescript"
Examples
$ tlb ./path/to/file.tlb
> Generated code is saved to ./path/to/file.ts
$ tlb -o ./path/to/output.ts ./path/to/file.tlb
> Generated code is saved to ./path/to/output.ts
$ tlb -l typescript ./path/to/file.tlb
> Generated code is saved to ./path/to/file.ts
`, {
flags: {
output: {
type: 'string',
alias: 'o'
},
language: {
type: 'string',
alias: 'l'
}
}
});
let input = cli.input.at(0)
if (input) {
if (input.match(/\.tlb$/) == null) {
console.error('Input file must have .tlb extension')
process.exit(1)
}
let output = input.replace('.tlb', '.ts')
if (cli.flags.output) {
output = cli.flags.output;
}
let language = 'typescript'
if (cli.flags.language) {
language = cli.flags.language
}
generateCode(input, output, language);
}