/
recipe2plan-cli.ts
81 lines (67 loc) · 2 KB
/
recipe2plan-cli.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
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
/**
* @license
* Copyright (c) 2020 Google Inc. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt
* Code distributed by Google as part of this project is also
* subject to an additional IP rights grant found at
* http://polymer.github.io/PATENTS.txt
*/
import minimist from 'minimist';
import fs from 'fs';
import path from 'path';
import {Runtime} from '../runtime/runtime.js';
import {recipe2plan} from './recipe2plan.js';
import {Flags} from '../runtime/flags.js';
const opts = minimist(process.argv.slice(2), {
string: ['outdir', 'outfile', 'package'],
alias: {d: 'outdir', f: 'outfile', p: 'package'},
default: {outdir: '.'}
});
if (opts.help || opts._.length === 0) {
console.log(`
Usage
$ tools/sigh recipe2plan [options] path/to/manifest.arcs
Description
Generates Kotlin plans from recipes in a manifest.
Options
--outfile, -f output filename; required
--outdir, -d output directory; defaults to '.'
--package, -p kotlin package.
--help usage info
`);
process.exit(0);
}
if (!opts.outfile) {
console.error(`Parameter --outfile is required.`);
process.exit(1);
}
if (!opts.package) {
console.error(`Parameter --package is required.`);
process.exit(1);
}
// TODO(alxr): Support generation from multiple manifests
if (opts._.length > 1) {
console.error(`Only a single manifest is allowed`);
process.exit(1);
}
if (opts._.some((file) => !file.endsWith('.arcs'))) {
console.error(`Only Arcs manifests ('*.arcs') are allowed.`);
process.exit(1);
}
async function main() {
try {
Runtime.init('../..');
fs.mkdirSync(opts.outdir, {recursive: true});
const plans: string = await recipe2plan(opts._[0], opts.package);
const outPath = path.join(opts.outdir, opts.outfile);
console.log(outPath);
const outFile = fs.openSync(outPath, 'w');
fs.writeSync(outFile, plans);
fs.closeSync(outFile);
} catch (e) {
console.error(e);
process.exit(1);
}
}
void main();