typia 12.0.0-dev.20260307-2 → 12.0.0-dev.20260310
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/executable/setup/PluginConfigurator.js +3 -3
- package/lib/executable/setup/PluginConfigurator.mjs +3 -3
- package/lib/executable/setup/PluginConfigurator.mjs.map +1 -1
- package/lib/executable/typia.js +15 -15
- package/lib/executable/typia.mjs +15 -15
- package/lib/internal/_coerceLlmArguments.d.ts +2 -0
- package/lib/internal/_coerceLlmArguments.js +7 -0
- package/lib/internal/_coerceLlmArguments.js.map +1 -0
- package/lib/internal/_coerceLlmArguments.mjs +6 -0
- package/lib/internal/_coerceLlmArguments.mjs.map +1 -0
- package/lib/internal/_llmApplicationFinalize.js +1 -1
- package/lib/internal/_llmApplicationFinalize.js.map +1 -1
- package/lib/internal/_llmApplicationFinalize.mjs +1 -0
- package/lib/internal/_llmApplicationFinalize.mjs.map +1 -1
- package/lib/internal/_parseLlmArguments.d.ts +2 -0
- package/lib/internal/_parseLlmArguments.js +7 -0
- package/lib/internal/_parseLlmArguments.js.map +1 -0
- package/lib/internal/_parseLlmArguments.mjs +6 -0
- package/lib/internal/_parseLlmArguments.mjs.map +1 -0
- package/lib/llm.d.ts +154 -1
- package/lib/llm.js +20 -0
- package/lib/llm.js.map +1 -1
- package/lib/llm.mjs +17 -1
- package/lib/llm.mjs.map +1 -1
- package/lib/re-exports.d.ts +1 -1
- package/lib/re-exports.js.map +1 -1
- package/package.json +5 -5
- package/src/TypeGuardError.ts +145 -145
- package/src/executable/TypiaGenerateWizard.ts +82 -82
- package/src/executable/TypiaPatchWizard.ts +45 -45
- package/src/executable/TypiaSetupWizard.ts +171 -171
- package/src/executable/setup/ArgumentParser.ts +42 -42
- package/src/executable/setup/CommandExecutor.ts +8 -8
- package/src/executable/setup/FileRetriever.ts +19 -19
- package/src/executable/setup/PackageManager.ts +87 -87
- package/src/executable/setup/PluginConfigurator.ts +74 -74
- package/src/executable/typia.ts +55 -55
- package/src/functional.ts +600 -600
- package/src/http.ts +843 -843
- package/src/index.ts +4 -4
- package/src/internal/_IProtobufWriter.ts +18 -18
- package/src/internal/_ProtobufReader.ts +187 -187
- package/src/internal/_ProtobufSizer.ts +137 -137
- package/src/internal/_ProtobufWriter.ts +135 -135
- package/src/internal/_accessExpressionAsString.ts +46 -46
- package/src/internal/_assertGuard.ts +13 -13
- package/src/internal/_coerceLlmArguments.ts +7 -0
- package/src/internal/_createStandardSchema.ts +133 -133
- package/src/internal/_functionalTypeGuardErrorFactory.ts +4 -4
- package/src/internal/_httpFormDataReadArray.ts +4 -4
- package/src/internal/_httpFormDataReadBigint.ts +18 -18
- package/src/internal/_httpFormDataReadBlob.ts +10 -10
- package/src/internal/_httpFormDataReadBoolean.ts +16 -16
- package/src/internal/_httpFormDataReadFile.ts +10 -10
- package/src/internal/_httpFormDataReadNumber.ts +15 -15
- package/src/internal/_httpFormDataReadString.ts +10 -10
- package/src/internal/_httpHeaderReadBigint.ts +10 -10
- package/src/internal/_httpHeaderReadBoolean.ts +8 -8
- package/src/internal/_httpHeaderReadNumber.ts +7 -7
- package/src/internal/_httpParameterReadBigint.ts +10 -10
- package/src/internal/_httpParameterReadBoolean.ts +8 -8
- package/src/internal/_httpParameterReadNumber.ts +7 -7
- package/src/internal/_httpParameterReadString.ts +2 -2
- package/src/internal/_httpQueryParseURLSearchParams.ts +12 -12
- package/src/internal/_httpQueryReadArray.ts +4 -4
- package/src/internal/_httpQueryReadBigint.ts +12 -12
- package/src/internal/_httpQueryReadBoolean.ts +14 -14
- package/src/internal/_httpQueryReadNumber.ts +9 -9
- package/src/internal/_httpQueryReadString.ts +4 -4
- package/src/internal/_isBetween.ts +2 -2
- package/src/internal/_isBigintString.ts +8 -8
- package/src/internal/_isFormatByte.ts +7 -7
- package/src/internal/_isFormatDate.ts +3 -3
- package/src/internal/_isFormatDateTime.ts +4 -4
- package/src/internal/_isFormatDuration.ts +4 -4
- package/src/internal/_isFormatEmail.ts +4 -4
- package/src/internal/_isFormatHostname.ts +4 -4
- package/src/internal/_isFormatIdnEmail.ts +4 -4
- package/src/internal/_isFormatIdnHostname.ts +4 -4
- package/src/internal/_isFormatIpv4.ts +4 -4
- package/src/internal/_isFormatIpv6.ts +4 -4
- package/src/internal/_isFormatIri.ts +3 -3
- package/src/internal/_isFormatIriReference.ts +4 -4
- package/src/internal/_isFormatJsonPointer.ts +3 -3
- package/src/internal/_isFormatPassword.ts +1 -1
- package/src/internal/_isFormatRegex.ts +8 -8
- package/src/internal/_isFormatRelativeJsonPointer.ts +4 -4
- package/src/internal/_isFormatTime.ts +4 -4
- package/src/internal/_isFormatUri.ts +6 -6
- package/src/internal/_isFormatUriReference.ts +5 -5
- package/src/internal/_isFormatUriTemplate.ts +4 -4
- package/src/internal/_isFormatUrl.ts +4 -4
- package/src/internal/_isFormatUuid.ts +3 -3
- package/src/internal/_isTypeFloat.ts +5 -5
- package/src/internal/_isTypeInt32.ts +5 -5
- package/src/internal/_isTypeInt64.ts +5 -5
- package/src/internal/_isTypeUint32.ts +5 -5
- package/src/internal/_isTypeUint64.ts +5 -5
- package/src/internal/_isUniqueItems.ts +159 -159
- package/src/internal/_jsonStringifyNumber.ts +12 -12
- package/src/internal/_jsonStringifyRest.ts +3 -3
- package/src/internal/_jsonStringifyString.ts +42 -42
- package/src/internal/_jsonStringifyTail.ts +2 -2
- package/src/internal/_llmApplicationFinalize.ts +24 -23
- package/src/internal/_miscCloneAny.ts +46 -46
- package/src/internal/_notationAny.ts +37 -37
- package/src/internal/_notationCamel.ts +13 -13
- package/src/internal/_notationPascal.ts +8 -8
- package/src/internal/_notationSnake.ts +43 -43
- package/src/internal/_parseLlmArguments.ts +7 -0
- package/src/internal/_randomArray.ts +21 -21
- package/src/internal/_randomBigint.ts +6 -6
- package/src/internal/_randomBoolean.ts +1 -1
- package/src/internal/_randomFormatByte.ts +3 -3
- package/src/internal/_randomFormatDate.ts +18 -18
- package/src/internal/_randomFormatDatetime.ts +16 -16
- package/src/internal/_randomFormatDuration.ts +27 -27
- package/src/internal/_randomFormatEmail.ts +11 -11
- package/src/internal/_randomFormatHostname.ts +6 -6
- package/src/internal/_randomFormatIdnEmail.ts +3 -3
- package/src/internal/_randomFormatIdnHostname.ts +3 -3
- package/src/internal/_randomFormatIpv4.ts +11 -11
- package/src/internal/_randomFormatIpv6.ts +11 -11
- package/src/internal/_randomFormatIri.ts +3 -3
- package/src/internal/_randomFormatIriReference.ts +3 -3
- package/src/internal/_randomFormatJsonPointer.ts +7 -7
- package/src/internal/_randomFormatPassword.ts +8 -8
- package/src/internal/_randomFormatRegex.ts +4 -4
- package/src/internal/_randomFormatRelativeJsonPointer.ts +8 -8
- package/src/internal/_randomFormatTime.ts +14 -14
- package/src/internal/_randomFormatUri.ts +3 -3
- package/src/internal/_randomFormatUriReference.ts +3 -3
- package/src/internal/_randomFormatUriTemplate.ts +3 -3
- package/src/internal/_randomFormatUrl.ts +11 -11
- package/src/internal/_randomFormatUuid.ts +6 -6
- package/src/internal/_randomInteger.ts +53 -53
- package/src/internal/_randomNumber.ts +80 -80
- package/src/internal/_randomPattern.ts +10 -10
- package/src/internal/_randomPick.ts +9 -9
- package/src/internal/_randomString.ts +24 -24
- package/src/internal/_throwTypeGuardError.ts +5 -5
- package/src/internal/_validateReport.ts +21 -21
- package/src/internal/private/__notationCapitalize.ts +2 -2
- package/src/internal/private/__notationUnsnake.ts +24 -24
- package/src/json.ts +553 -553
- package/src/llm.ts +408 -211
- package/src/misc.ts +448 -448
- package/src/module.ts +811 -811
- package/src/notations.ts +624 -624
- package/src/programmers/TypiaProgrammer.ts +8 -8
- package/src/protobuf.ts +499 -499
- package/src/re-exports.ts +33 -32
- package/src/reflect.ts +75 -75
- package/src/transform.ts +5 -5
- package/src/transformers/NoTransformConfigurationError.ts +16 -16
|
@@ -1,171 +1,171 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import { DetectResult, detect } from "package-manager-detector";
|
|
3
|
-
|
|
4
|
-
import { ArgumentParser } from "./setup/ArgumentParser";
|
|
5
|
-
import { CommandExecutor } from "./setup/CommandExecutor";
|
|
6
|
-
import { PackageManager } from "./setup/PackageManager";
|
|
7
|
-
import { PluginConfigurator } from "./setup/PluginConfigurator";
|
|
8
|
-
|
|
9
|
-
export namespace TypiaSetupWizard {
|
|
10
|
-
export interface IArguments {
|
|
11
|
-
manager: "npm" | "pnpm" | "yarn" | "bun";
|
|
12
|
-
project: string | null;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const setup = async (): Promise<void> => {
|
|
16
|
-
console.log("----------------------------------------");
|
|
17
|
-
console.log(" Typia Setup Wizard");
|
|
18
|
-
console.log("----------------------------------------");
|
|
19
|
-
|
|
20
|
-
// PREPARE ASSETS
|
|
21
|
-
const pack: PackageManager = await PackageManager.mount();
|
|
22
|
-
const args: IArguments = await ArgumentParser.parse(pack, inquiry);
|
|
23
|
-
|
|
24
|
-
// INSTALL TYPESCRIPT COMPILERS
|
|
25
|
-
pack.install({
|
|
26
|
-
dev: true,
|
|
27
|
-
modulo: "typescript",
|
|
28
|
-
version: await getTypeScriptVersion(),
|
|
29
|
-
});
|
|
30
|
-
pack.install({ dev: true, modulo: "ts-patch", version: "latest" });
|
|
31
|
-
args.project ??= (() => {
|
|
32
|
-
const runner: string = pack.manager === "npm" ? "npx" : pack.manager;
|
|
33
|
-
CommandExecutor.run(`${runner} tsc --init`);
|
|
34
|
-
return (args.project = "tsconfig.json");
|
|
35
|
-
})();
|
|
36
|
-
|
|
37
|
-
// SETUP TRANSFORMER
|
|
38
|
-
await pack.save((data) => {
|
|
39
|
-
// COMPOSE PREPARE COMMAND
|
|
40
|
-
data.scripts ??= {};
|
|
41
|
-
if (
|
|
42
|
-
typeof data.scripts.prepare === "string" &&
|
|
43
|
-
data.scripts.prepare.trim().length !== 0
|
|
44
|
-
) {
|
|
45
|
-
if (data.scripts.prepare.includes("ts-patch install") === false)
|
|
46
|
-
data.scripts.prepare = "ts-patch install && " + data.scripts.prepare;
|
|
47
|
-
} else data.scripts.prepare = "ts-patch install";
|
|
48
|
-
|
|
49
|
-
// NO MORE "typia patch" REQUIRED
|
|
50
|
-
data.scripts.prepare = data.scripts.prepare
|
|
51
|
-
.split("&&")
|
|
52
|
-
.map((str) => str.trim())
|
|
53
|
-
.filter((str) => str !== "typia patch")
|
|
54
|
-
.join(" && ");
|
|
55
|
-
|
|
56
|
-
// FOR OLDER VERSIONS
|
|
57
|
-
if (typeof data.scripts.postinstall === "string") {
|
|
58
|
-
data.scripts.postinstall = data.scripts.postinstall
|
|
59
|
-
.split("&&")
|
|
60
|
-
.map((str) => str.trim())
|
|
61
|
-
.filter((str) => str.indexOf("ts-patch install") === -1)
|
|
62
|
-
.join(" && ");
|
|
63
|
-
if (data.scripts.postinstall.length === 0)
|
|
64
|
-
delete data.scripts.postinstall;
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// CONFIGURE TYPIA
|
|
69
|
-
await PluginConfigurator.configure(args);
|
|
70
|
-
CommandExecutor.run(`${pack.manager} run prepare`);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const inquiry: ArgumentParser.Inquiry<IArguments> = async (
|
|
74
|
-
pack,
|
|
75
|
-
command,
|
|
76
|
-
prompt,
|
|
77
|
-
action,
|
|
78
|
-
) => {
|
|
79
|
-
// PREPARE ASSETS
|
|
80
|
-
command.option("--manager [manager", "package manager");
|
|
81
|
-
command.option("--project [project]", "tsconfig.json file location");
|
|
82
|
-
|
|
83
|
-
// INTERNAL PROCEDURES
|
|
84
|
-
const questioned = { value: false };
|
|
85
|
-
const select =
|
|
86
|
-
(name: string) =>
|
|
87
|
-
(message: string) =>
|
|
88
|
-
async <Choice extends string>(
|
|
89
|
-
choices: Choice[],
|
|
90
|
-
filter?: (choice: string) => Choice,
|
|
91
|
-
): Promise<Choice> => {
|
|
92
|
-
questioned.value = true;
|
|
93
|
-
return (
|
|
94
|
-
await prompt()({
|
|
95
|
-
type: "list",
|
|
96
|
-
name: name,
|
|
97
|
-
message: message,
|
|
98
|
-
choices: choices,
|
|
99
|
-
...(filter ? { filter } : {}),
|
|
100
|
-
})
|
|
101
|
-
)[name];
|
|
102
|
-
};
|
|
103
|
-
const configure = async (): Promise<string | null> => {
|
|
104
|
-
const fileList: string[] = await (
|
|
105
|
-
await fs.promises.readdir(process.cwd())
|
|
106
|
-
)
|
|
107
|
-
.filter(
|
|
108
|
-
(str) =>
|
|
109
|
-
str.substring(0, 8) === "tsconfig" &&
|
|
110
|
-
str.substring(str.length - 5) === ".json",
|
|
111
|
-
)
|
|
112
|
-
.sort((x, y) =>
|
|
113
|
-
x === "tsconfig.json"
|
|
114
|
-
? -1
|
|
115
|
-
: y === "tsconfig.json"
|
|
116
|
-
? 1
|
|
117
|
-
: x < y
|
|
118
|
-
? -1
|
|
119
|
-
: 1,
|
|
120
|
-
);
|
|
121
|
-
if (fileList.length === 0) {
|
|
122
|
-
if (process.cwd() !== pack.directory)
|
|
123
|
-
throw new URIError(`Unable to find "tsconfig.json" file.`);
|
|
124
|
-
return null;
|
|
125
|
-
} else if (fileList.length === 1) return fileList[0]!;
|
|
126
|
-
return select("tsconfig")("TS Config File")(fileList);
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
// DO CONSTRUCT
|
|
130
|
-
return action(async (options) => {
|
|
131
|
-
pack.manager = options.manager ??=
|
|
132
|
-
(await detectManager()) ??
|
|
133
|
-
(await select("manager")("Package Manager")(
|
|
134
|
-
[
|
|
135
|
-
"npm" as const,
|
|
136
|
-
"pnpm" as const,
|
|
137
|
-
"bun" as const,
|
|
138
|
-
"yarn (berry is not supported)" as "yarn",
|
|
139
|
-
],
|
|
140
|
-
(value) => value.split(" ")[0] as "yarn",
|
|
141
|
-
));
|
|
142
|
-
options.project ??= await configure();
|
|
143
|
-
|
|
144
|
-
if (questioned.value) console.log("");
|
|
145
|
-
return options as IArguments;
|
|
146
|
-
});
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
const detectManager = async (): Promise<
|
|
150
|
-
"npm" | "pnpm" | "yarn" | "bun" | null
|
|
151
|
-
> => {
|
|
152
|
-
const result: DetectResult | null = await detect({ cwd: process.cwd() });
|
|
153
|
-
switch (result?.name) {
|
|
154
|
-
case "npm":
|
|
155
|
-
case "deno":
|
|
156
|
-
return null; // NPM case is still selectable & Deno is not supported
|
|
157
|
-
default:
|
|
158
|
-
return result?.name ?? null;
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
const getTypeScriptVersion = async (): Promise<string> => {
|
|
163
|
-
const content: string = await fs.promises.readFile(
|
|
164
|
-
`${__dirname}/../../package.json`,
|
|
165
|
-
"utf-8",
|
|
166
|
-
);
|
|
167
|
-
const json: { devDependencies: { typescript: string } } =
|
|
168
|
-
JSON.parse(content);
|
|
169
|
-
return json.devDependencies.typescript;
|
|
170
|
-
};
|
|
171
|
-
}
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { DetectResult, detect } from "package-manager-detector";
|
|
3
|
+
|
|
4
|
+
import { ArgumentParser } from "./setup/ArgumentParser";
|
|
5
|
+
import { CommandExecutor } from "./setup/CommandExecutor";
|
|
6
|
+
import { PackageManager } from "./setup/PackageManager";
|
|
7
|
+
import { PluginConfigurator } from "./setup/PluginConfigurator";
|
|
8
|
+
|
|
9
|
+
export namespace TypiaSetupWizard {
|
|
10
|
+
export interface IArguments {
|
|
11
|
+
manager: "npm" | "pnpm" | "yarn" | "bun";
|
|
12
|
+
project: string | null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const setup = async (): Promise<void> => {
|
|
16
|
+
console.log("----------------------------------------");
|
|
17
|
+
console.log(" Typia Setup Wizard");
|
|
18
|
+
console.log("----------------------------------------");
|
|
19
|
+
|
|
20
|
+
// PREPARE ASSETS
|
|
21
|
+
const pack: PackageManager = await PackageManager.mount();
|
|
22
|
+
const args: IArguments = await ArgumentParser.parse(pack, inquiry);
|
|
23
|
+
|
|
24
|
+
// INSTALL TYPESCRIPT COMPILERS
|
|
25
|
+
pack.install({
|
|
26
|
+
dev: true,
|
|
27
|
+
modulo: "typescript",
|
|
28
|
+
version: await getTypeScriptVersion(),
|
|
29
|
+
});
|
|
30
|
+
pack.install({ dev: true, modulo: "ts-patch", version: "latest" });
|
|
31
|
+
args.project ??= (() => {
|
|
32
|
+
const runner: string = pack.manager === "npm" ? "npx" : pack.manager;
|
|
33
|
+
CommandExecutor.run(`${runner} tsc --init`);
|
|
34
|
+
return (args.project = "tsconfig.json");
|
|
35
|
+
})();
|
|
36
|
+
|
|
37
|
+
// SETUP TRANSFORMER
|
|
38
|
+
await pack.save((data) => {
|
|
39
|
+
// COMPOSE PREPARE COMMAND
|
|
40
|
+
data.scripts ??= {};
|
|
41
|
+
if (
|
|
42
|
+
typeof data.scripts.prepare === "string" &&
|
|
43
|
+
data.scripts.prepare.trim().length !== 0
|
|
44
|
+
) {
|
|
45
|
+
if (data.scripts.prepare.includes("ts-patch install") === false)
|
|
46
|
+
data.scripts.prepare = "ts-patch install && " + data.scripts.prepare;
|
|
47
|
+
} else data.scripts.prepare = "ts-patch install";
|
|
48
|
+
|
|
49
|
+
// NO MORE "typia patch" REQUIRED
|
|
50
|
+
data.scripts.prepare = data.scripts.prepare
|
|
51
|
+
.split("&&")
|
|
52
|
+
.map((str) => str.trim())
|
|
53
|
+
.filter((str) => str !== "typia patch")
|
|
54
|
+
.join(" && ");
|
|
55
|
+
|
|
56
|
+
// FOR OLDER VERSIONS
|
|
57
|
+
if (typeof data.scripts.postinstall === "string") {
|
|
58
|
+
data.scripts.postinstall = data.scripts.postinstall
|
|
59
|
+
.split("&&")
|
|
60
|
+
.map((str) => str.trim())
|
|
61
|
+
.filter((str) => str.indexOf("ts-patch install") === -1)
|
|
62
|
+
.join(" && ");
|
|
63
|
+
if (data.scripts.postinstall.length === 0)
|
|
64
|
+
delete data.scripts.postinstall;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// CONFIGURE TYPIA
|
|
69
|
+
await PluginConfigurator.configure(args);
|
|
70
|
+
CommandExecutor.run(`${pack.manager} run prepare`);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const inquiry: ArgumentParser.Inquiry<IArguments> = async (
|
|
74
|
+
pack,
|
|
75
|
+
command,
|
|
76
|
+
prompt,
|
|
77
|
+
action,
|
|
78
|
+
) => {
|
|
79
|
+
// PREPARE ASSETS
|
|
80
|
+
command.option("--manager [manager", "package manager");
|
|
81
|
+
command.option("--project [project]", "tsconfig.json file location");
|
|
82
|
+
|
|
83
|
+
// INTERNAL PROCEDURES
|
|
84
|
+
const questioned = { value: false };
|
|
85
|
+
const select =
|
|
86
|
+
(name: string) =>
|
|
87
|
+
(message: string) =>
|
|
88
|
+
async <Choice extends string>(
|
|
89
|
+
choices: Choice[],
|
|
90
|
+
filter?: (choice: string) => Choice,
|
|
91
|
+
): Promise<Choice> => {
|
|
92
|
+
questioned.value = true;
|
|
93
|
+
return (
|
|
94
|
+
await prompt()({
|
|
95
|
+
type: "list",
|
|
96
|
+
name: name,
|
|
97
|
+
message: message,
|
|
98
|
+
choices: choices,
|
|
99
|
+
...(filter ? { filter } : {}),
|
|
100
|
+
})
|
|
101
|
+
)[name];
|
|
102
|
+
};
|
|
103
|
+
const configure = async (): Promise<string | null> => {
|
|
104
|
+
const fileList: string[] = await (
|
|
105
|
+
await fs.promises.readdir(process.cwd())
|
|
106
|
+
)
|
|
107
|
+
.filter(
|
|
108
|
+
(str) =>
|
|
109
|
+
str.substring(0, 8) === "tsconfig" &&
|
|
110
|
+
str.substring(str.length - 5) === ".json",
|
|
111
|
+
)
|
|
112
|
+
.sort((x, y) =>
|
|
113
|
+
x === "tsconfig.json"
|
|
114
|
+
? -1
|
|
115
|
+
: y === "tsconfig.json"
|
|
116
|
+
? 1
|
|
117
|
+
: x < y
|
|
118
|
+
? -1
|
|
119
|
+
: 1,
|
|
120
|
+
);
|
|
121
|
+
if (fileList.length === 0) {
|
|
122
|
+
if (process.cwd() !== pack.directory)
|
|
123
|
+
throw new URIError(`Unable to find "tsconfig.json" file.`);
|
|
124
|
+
return null;
|
|
125
|
+
} else if (fileList.length === 1) return fileList[0]!;
|
|
126
|
+
return select("tsconfig")("TS Config File")(fileList);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// DO CONSTRUCT
|
|
130
|
+
return action(async (options) => {
|
|
131
|
+
pack.manager = options.manager ??=
|
|
132
|
+
(await detectManager()) ??
|
|
133
|
+
(await select("manager")("Package Manager")(
|
|
134
|
+
[
|
|
135
|
+
"npm" as const,
|
|
136
|
+
"pnpm" as const,
|
|
137
|
+
"bun" as const,
|
|
138
|
+
"yarn (berry is not supported)" as "yarn",
|
|
139
|
+
],
|
|
140
|
+
(value) => value.split(" ")[0] as "yarn",
|
|
141
|
+
));
|
|
142
|
+
options.project ??= await configure();
|
|
143
|
+
|
|
144
|
+
if (questioned.value) console.log("");
|
|
145
|
+
return options as IArguments;
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const detectManager = async (): Promise<
|
|
150
|
+
"npm" | "pnpm" | "yarn" | "bun" | null
|
|
151
|
+
> => {
|
|
152
|
+
const result: DetectResult | null = await detect({ cwd: process.cwd() });
|
|
153
|
+
switch (result?.name) {
|
|
154
|
+
case "npm":
|
|
155
|
+
case "deno":
|
|
156
|
+
return null; // NPM case is still selectable & Deno is not supported
|
|
157
|
+
default:
|
|
158
|
+
return result?.name ?? null;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const getTypeScriptVersion = async (): Promise<string> => {
|
|
163
|
+
const content: string = await fs.promises.readFile(
|
|
164
|
+
`${__dirname}/../../package.json`,
|
|
165
|
+
"utf-8",
|
|
166
|
+
);
|
|
167
|
+
const json: { devDependencies: { typescript: string } } =
|
|
168
|
+
JSON.parse(content);
|
|
169
|
+
return json.devDependencies.typescript;
|
|
170
|
+
};
|
|
171
|
+
}
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import commander from "commander";
|
|
2
|
-
import inquirer from "inquirer";
|
|
3
|
-
|
|
4
|
-
import { PackageManager } from "./PackageManager";
|
|
5
|
-
|
|
6
|
-
export namespace ArgumentParser {
|
|
7
|
-
export type Inquiry<T> = (
|
|
8
|
-
pack: PackageManager,
|
|
9
|
-
command: commander.Command,
|
|
10
|
-
prompt: (opt?: inquirer.StreamOptions) => inquirer.PromptModule,
|
|
11
|
-
action: (closure: (options: Partial<T>) => Promise<T>) => Promise<T>,
|
|
12
|
-
) => Promise<T>;
|
|
13
|
-
|
|
14
|
-
export const parse = async <T>(
|
|
15
|
-
pack: PackageManager,
|
|
16
|
-
inquiry: (
|
|
17
|
-
pack: PackageManager,
|
|
18
|
-
command: commander.Command,
|
|
19
|
-
prompt: (opt?: inquirer.StreamOptions) => inquirer.PromptModule,
|
|
20
|
-
action: (closure: (options: Partial<T>) => Promise<T>) => Promise<T>,
|
|
21
|
-
) => Promise<T>,
|
|
22
|
-
): Promise<T> => {
|
|
23
|
-
// TAKE OPTIONS
|
|
24
|
-
const action = (closure: (options: Partial<T>) => Promise<T>) =>
|
|
25
|
-
new Promise<T>((resolve, reject) => {
|
|
26
|
-
commander.program.action(async (options) => {
|
|
27
|
-
try {
|
|
28
|
-
resolve(await closure(options));
|
|
29
|
-
} catch (exp) {
|
|
30
|
-
reject(exp);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
commander.program.parseAsync().catch(reject);
|
|
34
|
-
});
|
|
35
|
-
return inquiry(
|
|
36
|
-
pack,
|
|
37
|
-
commander.program,
|
|
38
|
-
inquirer.createPromptModule,
|
|
39
|
-
action,
|
|
40
|
-
);
|
|
41
|
-
};
|
|
42
|
-
}
|
|
1
|
+
import commander from "commander";
|
|
2
|
+
import inquirer from "inquirer";
|
|
3
|
+
|
|
4
|
+
import { PackageManager } from "./PackageManager";
|
|
5
|
+
|
|
6
|
+
export namespace ArgumentParser {
|
|
7
|
+
export type Inquiry<T> = (
|
|
8
|
+
pack: PackageManager,
|
|
9
|
+
command: commander.Command,
|
|
10
|
+
prompt: (opt?: inquirer.StreamOptions) => inquirer.PromptModule,
|
|
11
|
+
action: (closure: (options: Partial<T>) => Promise<T>) => Promise<T>,
|
|
12
|
+
) => Promise<T>;
|
|
13
|
+
|
|
14
|
+
export const parse = async <T>(
|
|
15
|
+
pack: PackageManager,
|
|
16
|
+
inquiry: (
|
|
17
|
+
pack: PackageManager,
|
|
18
|
+
command: commander.Command,
|
|
19
|
+
prompt: (opt?: inquirer.StreamOptions) => inquirer.PromptModule,
|
|
20
|
+
action: (closure: (options: Partial<T>) => Promise<T>) => Promise<T>,
|
|
21
|
+
) => Promise<T>,
|
|
22
|
+
): Promise<T> => {
|
|
23
|
+
// TAKE OPTIONS
|
|
24
|
+
const action = (closure: (options: Partial<T>) => Promise<T>) =>
|
|
25
|
+
new Promise<T>((resolve, reject) => {
|
|
26
|
+
commander.program.action(async (options) => {
|
|
27
|
+
try {
|
|
28
|
+
resolve(await closure(options));
|
|
29
|
+
} catch (exp) {
|
|
30
|
+
reject(exp);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
commander.program.parseAsync().catch(reject);
|
|
34
|
+
});
|
|
35
|
+
return inquiry(
|
|
36
|
+
pack,
|
|
37
|
+
commander.program,
|
|
38
|
+
inquirer.createPromptModule,
|
|
39
|
+
action,
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import cp from "child_process";
|
|
2
|
-
|
|
3
|
-
export namespace CommandExecutor {
|
|
4
|
-
export const run = (str: string): void => {
|
|
5
|
-
console.log(`\n$ ${str}`);
|
|
6
|
-
cp.execSync(str, { stdio: "inherit" });
|
|
7
|
-
};
|
|
8
|
-
}
|
|
1
|
+
import cp from "child_process";
|
|
2
|
+
|
|
3
|
+
export namespace CommandExecutor {
|
|
4
|
+
export const run = (str: string): void => {
|
|
5
|
+
console.log(`\n$ ${str}`);
|
|
6
|
+
cp.execSync(str, { stdio: "inherit" });
|
|
7
|
+
};
|
|
8
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
|
|
4
|
-
export namespace FileRetriever {
|
|
5
|
-
export const directory = (props: {
|
|
6
|
-
file: string;
|
|
7
|
-
location: string;
|
|
8
|
-
depth?: number;
|
|
9
|
-
}): string | null => {
|
|
10
|
-
const location: string = path.join(props.location, props.file);
|
|
11
|
-
if (fs.existsSync(location)) return props.location;
|
|
12
|
-
else if ((props.depth ?? 0) > 2) return null;
|
|
13
|
-
return directory({
|
|
14
|
-
file: props.file,
|
|
15
|
-
location: path.join(props.location, ".."),
|
|
16
|
-
depth: (props.depth ?? 0) + 1,
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
}
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
export namespace FileRetriever {
|
|
5
|
+
export const directory = (props: {
|
|
6
|
+
file: string;
|
|
7
|
+
location: string;
|
|
8
|
+
depth?: number;
|
|
9
|
+
}): string | null => {
|
|
10
|
+
const location: string = path.join(props.location, props.file);
|
|
11
|
+
if (fs.existsSync(location)) return props.location;
|
|
12
|
+
else if ((props.depth ?? 0) > 2) return null;
|
|
13
|
+
return directory({
|
|
14
|
+
file: props.file,
|
|
15
|
+
location: path.join(props.location, ".."),
|
|
16
|
+
depth: (props.depth ?? 0) + 1,
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
|
|
4
|
-
import { CommandExecutor } from "./CommandExecutor";
|
|
5
|
-
import { FileRetriever } from "./FileRetriever";
|
|
6
|
-
|
|
7
|
-
export class PackageManager {
|
|
8
|
-
public manager: Manager = "npm";
|
|
9
|
-
public get file(): string {
|
|
10
|
-
return path.join(this.directory, "package.json");
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
public static async mount(): Promise<PackageManager> {
|
|
14
|
-
const location: string | null = await FileRetriever.directory({
|
|
15
|
-
file: "package.json",
|
|
16
|
-
location: process.cwd(),
|
|
17
|
-
});
|
|
18
|
-
if (location === null)
|
|
19
|
-
throw new URIError(`Unable to find "package.json" file`);
|
|
20
|
-
|
|
21
|
-
return new PackageManager(
|
|
22
|
-
location,
|
|
23
|
-
await this.load(path.join(location, "package.json")),
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public async save(modifier: (data: Package.Data) => void): Promise<void> {
|
|
28
|
-
const content: string = await fs.promises.readFile(this.file, "utf8");
|
|
29
|
-
this.data = JSON.parse(content);
|
|
30
|
-
modifier(this.data);
|
|
31
|
-
|
|
32
|
-
return fs.promises.writeFile(
|
|
33
|
-
this.file,
|
|
34
|
-
JSON.stringify(this.data, null, 2),
|
|
35
|
-
"utf8",
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public install(props: {
|
|
40
|
-
dev: boolean;
|
|
41
|
-
modulo: string;
|
|
42
|
-
version: string;
|
|
43
|
-
}): boolean {
|
|
44
|
-
const middle: string = [
|
|
45
|
-
installCmdTable[this.manager],
|
|
46
|
-
props.dev ? devOptionTable[this.manager] : "",
|
|
47
|
-
]
|
|
48
|
-
.filter((str) => !!str.length)
|
|
49
|
-
.join(" ");
|
|
50
|
-
const modulo: string = `${props.modulo}${props.version ? `@${props.version}` : ""}`;
|
|
51
|
-
CommandExecutor.run([this.manager, middle, modulo].join(" "));
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
private constructor(
|
|
56
|
-
public readonly directory: string,
|
|
57
|
-
public data: Package.Data,
|
|
58
|
-
) {}
|
|
59
|
-
|
|
60
|
-
private static async load(file: string): Promise<Package.Data> {
|
|
61
|
-
const content: string = await fs.promises.readFile(file, "utf8");
|
|
62
|
-
return JSON.parse(content);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
export namespace Package {
|
|
66
|
-
export interface Data {
|
|
67
|
-
scripts?: Record<string, string>;
|
|
68
|
-
dependencies?: Record<string, string>;
|
|
69
|
-
devDependencies?: Record<string, string>;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
type Manager = "npm" | "pnpm" | "yarn" | "bun";
|
|
74
|
-
|
|
75
|
-
const installCmdTable = {
|
|
76
|
-
npm: "i",
|
|
77
|
-
pnpm: "add",
|
|
78
|
-
yarn: "add",
|
|
79
|
-
bun: "add",
|
|
80
|
-
} as const satisfies Record<Manager, string>;
|
|
81
|
-
|
|
82
|
-
const devOptionTable = {
|
|
83
|
-
npm: "-D",
|
|
84
|
-
pnpm: "-D",
|
|
85
|
-
yarn: "-D",
|
|
86
|
-
bun: "-d",
|
|
87
|
-
} as const satisfies Record<Manager, string>;
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
import { CommandExecutor } from "./CommandExecutor";
|
|
5
|
+
import { FileRetriever } from "./FileRetriever";
|
|
6
|
+
|
|
7
|
+
export class PackageManager {
|
|
8
|
+
public manager: Manager = "npm";
|
|
9
|
+
public get file(): string {
|
|
10
|
+
return path.join(this.directory, "package.json");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public static async mount(): Promise<PackageManager> {
|
|
14
|
+
const location: string | null = await FileRetriever.directory({
|
|
15
|
+
file: "package.json",
|
|
16
|
+
location: process.cwd(),
|
|
17
|
+
});
|
|
18
|
+
if (location === null)
|
|
19
|
+
throw new URIError(`Unable to find "package.json" file`);
|
|
20
|
+
|
|
21
|
+
return new PackageManager(
|
|
22
|
+
location,
|
|
23
|
+
await this.load(path.join(location, "package.json")),
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public async save(modifier: (data: Package.Data) => void): Promise<void> {
|
|
28
|
+
const content: string = await fs.promises.readFile(this.file, "utf8");
|
|
29
|
+
this.data = JSON.parse(content);
|
|
30
|
+
modifier(this.data);
|
|
31
|
+
|
|
32
|
+
return fs.promises.writeFile(
|
|
33
|
+
this.file,
|
|
34
|
+
JSON.stringify(this.data, null, 2),
|
|
35
|
+
"utf8",
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public install(props: {
|
|
40
|
+
dev: boolean;
|
|
41
|
+
modulo: string;
|
|
42
|
+
version: string;
|
|
43
|
+
}): boolean {
|
|
44
|
+
const middle: string = [
|
|
45
|
+
installCmdTable[this.manager],
|
|
46
|
+
props.dev ? devOptionTable[this.manager] : "",
|
|
47
|
+
]
|
|
48
|
+
.filter((str) => !!str.length)
|
|
49
|
+
.join(" ");
|
|
50
|
+
const modulo: string = `${props.modulo}${props.version ? `@${props.version}` : ""}`;
|
|
51
|
+
CommandExecutor.run([this.manager, middle, modulo].join(" "));
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private constructor(
|
|
56
|
+
public readonly directory: string,
|
|
57
|
+
public data: Package.Data,
|
|
58
|
+
) {}
|
|
59
|
+
|
|
60
|
+
private static async load(file: string): Promise<Package.Data> {
|
|
61
|
+
const content: string = await fs.promises.readFile(file, "utf8");
|
|
62
|
+
return JSON.parse(content);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export namespace Package {
|
|
66
|
+
export interface Data {
|
|
67
|
+
scripts?: Record<string, string>;
|
|
68
|
+
dependencies?: Record<string, string>;
|
|
69
|
+
devDependencies?: Record<string, string>;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
type Manager = "npm" | "pnpm" | "yarn" | "bun";
|
|
74
|
+
|
|
75
|
+
const installCmdTable = {
|
|
76
|
+
npm: "i",
|
|
77
|
+
pnpm: "add",
|
|
78
|
+
yarn: "add",
|
|
79
|
+
bun: "add",
|
|
80
|
+
} as const satisfies Record<Manager, string>;
|
|
81
|
+
|
|
82
|
+
const devOptionTable = {
|
|
83
|
+
npm: "-D",
|
|
84
|
+
pnpm: "-D",
|
|
85
|
+
yarn: "-D",
|
|
86
|
+
bun: "-d",
|
|
87
|
+
} as const satisfies Record<Manager, string>;
|