forked from JoshuaKGoldberg/create-typescript-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
89 lines (75 loc) · 2.09 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
85
86
87
88
89
import * as prompts from "@clack/prompts";
import chalk from "chalk";
import { parseArgs } from "node:util";
import { createRerunSuggestion } from "../create/createRerunSuggestion.js";
import { create } from "../create/index.js";
import { initialize } from "../initialize/index.js";
import { migrate } from "../migrate/index.js";
import { logLine } from "../shared/cli/lines.js";
import { StatusCodes } from "../shared/codes.js";
import { logHelpText } from "./help.js";
import { promptForMode } from "./mode.js";
import { getVersionFromPackageJson } from "./packageJson.js";
const operationMessage = (verb: string) =>
`Operation ${verb}. Exiting - maybe another time? 👋`;
export async function bin(args: string[]) {
console.clear();
const version = await getVersionFromPackageJson();
prompts.intro(
[
chalk.greenBright(`✨ Welcome to`),
chalk.bgGreenBright.black(`create-typescript-app`),
chalk.greenBright(
`${typeof version === "string" ? ` ${version}` : ""}! ✨`,
),
].join(" "),
);
logLine();
logLine(
chalk.yellow(
"⚠️ This template is early stage, opinionated, and not endorsed by the TypeScript team. ⚠️",
),
);
logLine(
chalk.yellow(
"⚠️ If any tooling it sets displeases you, you can always remove that portion manually. ⚠️",
),
);
const { values } = parseArgs({
args,
options: {
help: {
short: "h",
type: "boolean",
},
mode: { type: "string" },
},
strict: false,
});
const help = values.help;
if (help) {
logHelpText();
return 0;
}
const mode = await promptForMode(values.mode);
if (typeof mode !== "string") {
prompts.outro(chalk.red(mode?.message ?? operationMessage("cancelled")));
return 1;
}
const { code, options } = await { create, initialize, migrate }[mode](args);
prompts.log.info(
[
chalk.italic(`Tip: to run again with the same input values, use:`),
chalk.blue(createRerunSuggestion(mode, options)),
].join(" "),
);
if (code) {
logLine();
prompts.cancel(
code === StatusCodes.Cancelled
? operationMessage("cancelled")
: operationMessage("failed"),
);
}
return code;
}