/
index.ts
84 lines (74 loc) · 2.23 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
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
82
83
84
import { resolve } from "path";
import * as yargs from "yargs";
import newCommand from "./cmds/new";
import { synth } from "./synth";
import { discoverTaskCommands } from "./tasks";
import { PROJEN_RC, PROJEN_VERSION } from "../common";
import * as logging from "../logging";
import { TaskRuntime } from "../task-runtime";
import { getNodeMajorVersion } from "../util";
const DEFAULT_RC = resolve(PROJEN_RC);
async function main() {
const ya = yargs;
ya.command(newCommand);
const runtime = new TaskRuntime(".");
discoverTaskCommands(runtime, ya);
ya.recommendCommands();
ya.strictCommands();
ya.showHelpOnFail(false);
ya.wrap(yargs.terminalWidth());
ya.option("post", {
type: "boolean",
default: true,
desc: "Run post-synthesis steps such as installing dependencies. Use --no-post to skip",
});
ya.option("watch", {
type: "boolean",
default: false,
desc: "Keep running and resynthesize when projenrc changes",
alias: "w",
});
ya.options("debug", { type: "boolean", default: false, desc: "Debug logs" });
ya.options("rc", {
deprecated: true,
desc: "path to .projenrc.js file",
default: DEFAULT_RC,
type: "string",
});
ya.completion();
ya.help();
// do not use the default yargs '--version' implementation since it is
// global by default (it appears on all subcommands)
ya.version(false);
ya.option("version", {
type: "boolean",
description: "Show version number",
global: false,
});
const args = ya.argv;
if (args.debug) {
process.env.DEBUG = "true";
}
const nodeVersion = getNodeMajorVersion();
if (nodeVersion && nodeVersion < 16) {
logging.warn(
`WARNING: You are using Node v${nodeVersion}, which reaches end of life on April 30, 2023. Support for EOL Node releases may be dropped by projen in the future. Please consider upgrading to Node >= 16 as soon as possible.`
);
}
// no command means synthesize
if (args._.length === 0) {
if (args.version) {
console.log(PROJEN_VERSION);
process.exit(0);
}
await synth(runtime, {
post: args.post as boolean,
watch: args.watch as boolean,
rcfile: args.rc as string,
});
}
}
main().catch((e) => {
console.error(e.stack);
process.exit(1);
});