-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
55 lines (48 loc) · 1.78 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env node
import { spawnSync, SpawnOptions } from 'child_process';
import path = require('path');
import { program } from 'commander';
const spawnOptions: SpawnOptions = {
cwd: process.cwd(),
detached: true,
stdio: 'inherit',
};
function main() {
program
.version('1.0.0', '-v, --version');
program
.command('schema <source> <destination>')
.description('Create a json project schema file.')
.action((source: string, destination: string) => {
spawnSync('node', [
path.join(__dirname, 'lib/project.js'),
path.resolve(process.cwd(), source),
path.resolve(process.cwd(), destination),
], spawnOptions);
});
program
.command('swift <source> <destination>')
.description('Create a swift class file.')
.action((source: string, destination: string) => {
console.log('Swift creator.');
spawnSync('quicktype', [
'-s', 'schema', path.resolve(process.cwd(), source),
'-o', path.resolve(process.cwd(), destination),
'--coding-keys',
'--no-initializers',
'--type-prefix', 'SDUI',
'--access-level', 'public',
'--density', 'normal',
'--protocol', 'hashable',
'--acronym-style', 'camel',
'-t', 'Schema',
'--struct-or-class', 'struct',
'--swift-5-support',
], spawnOptions);
spawnSync('node', [path.join(__dirname, 'swift/optimize-project.js'), path.resolve(process.cwd(), destination), path.resolve(process.cwd(), source)], spawnOptions);
});
program.parse();
}
if (require.main === module) {
main();
}