forked from samchon/typia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypiaGenerateWizard.ts
More file actions
89 lines (80 loc) · 2.72 KB
/
TypiaGenerateWizard.ts
File metadata and controls
89 lines (80 loc) · 2.72 KB
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 fs from "fs";
import { TypiaProgrammer } from "../programmers/TypiaProgrammer";
import { ArgumentParser } from "./setup/ArgumentParser";
import { PackageManager } from "./setup/PackageManager";
export namespace TypiaGenerateWizard {
export async function generate(): Promise<void> {
console.log("----------------------------------------");
console.log(" Typia Generate Wizard");
console.log("----------------------------------------");
// LOAD PACKAGE.JSON INFO
const pack: PackageManager = await PackageManager.mount();
const options: IArguments = await ArgumentParser.parse(pack, inquiry);
await TypiaProgrammer.build(options);
}
const inquiry: ArgumentParser.Inquiry<IArguments> = async (
_pack,
command,
prompt,
action,
) => {
// PREPARE ASSETS
command.argument("[files...]", "input .ts files (alternative to --input)");
command.option("--input [path]", "input directory");
command.option("--output [directory]", "output directory");
command.option("--project [project]", "tsconfig.json file location");
const questioned = { value: false };
const input = (name: string) => async (message: string) => {
const result = await prompt()({
type: "input",
name,
message,
default: "",
});
return result[name] as string;
};
const select =
(name: string) =>
(message: string) =>
async <Choice extends string>(choices: Choice[]): Promise<Choice> => {
questioned.value = true;
return (
await prompt()({
type: "list",
name: name,
message: message,
choices: choices,
})
)[name];
};
const configure = async (): Promise<string> => {
const files: string[] = await (
await fs.promises.readdir(process.cwd())
).filter(
(str) =>
str.substring(0, 8) === "tsconfig" &&
str.substring(str.length - 5) === ".json",
);
if (files.length === 0)
throw new URIError(`Unable to find "tsconfig.json" file.`);
else if (files.length === 1) return files[0]!;
return select("tsconfig")("TS Config File")(files);
};
return action(async (options) => {
// If files are provided, input directory is not required
const hasFiles = options.files && options.files.length > 0;
if (!hasFiles) {
options.input ??= await input("input")("input directory");
}
options.output ??= await input("output")("output directory");
options.project ??= await configure();
return options as IArguments;
});
};
export interface IArguments {
input: string;
output: string;
project: string;
files?: string[];
}
}