@nestia/sdk 2.4.5 → 2.4.6
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/analyses/ConfigAnalyzer.js +1 -1
- package/lib/analyses/ConfigAnalyzer.js.map +1 -1
- package/lib/analyses/ControllerAnalyzer.js.map +1 -1
- package/lib/analyses/PathAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectAnalyzer.js.map +1 -1
- package/lib/executable/sdk.js +11 -11
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/SdkFunctionProgrammer.js +7 -7
- package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
- package/lib/generates/internal/SwaggerSchemaGenerator.js.map +1 -1
- package/package.json +3 -3
- package/src/INestiaConfig.ts +248 -248
- package/src/NestiaSdkApplication.ts +253 -253
- package/src/analyses/AccessorAnalyzer.ts +60 -60
- package/src/analyses/ConfigAnalyzer.ts +3 -3
- package/src/analyses/ControllerAnalyzer.ts +2 -2
- package/src/analyses/ExceptionAnalyzer.ts +115 -115
- package/src/analyses/GenericAnalyzer.ts +51 -51
- package/src/analyses/ImportAnalyzer.ts +138 -138
- package/src/analyses/PathAnalyzer.ts +14 -14
- package/src/analyses/ReflectAnalyzer.ts +9 -9
- package/src/analyses/SecurityAnalyzer.ts +20 -20
- package/src/executable/internal/CommandParser.ts +15 -15
- package/src/executable/internal/NestiaConfigLoader.ts +67 -67
- package/src/executable/internal/NestiaSdkCommand.ts +60 -60
- package/src/executable/sdk.ts +73 -73
- package/src/generates/E2eGenerator.ts +64 -64
- package/src/generates/SdkGenerator.ts +96 -96
- package/src/generates/SwaggerGenerator.ts +5 -5
- package/src/generates/internal/E2eFileProgrammer.ts +123 -123
- package/src/generates/internal/SdkDistributionComposer.ts +91 -91
- package/src/generates/internal/SdkDtoGenerator.ts +424 -424
- package/src/generates/internal/SdkFileProgrammer.ts +106 -106
- package/src/generates/internal/SdkFunctionProgrammer.ts +518 -518
- package/src/generates/internal/SdkImportWizard.ts +55 -55
- package/src/generates/internal/SdkRouteDirectory.ts +17 -17
- package/src/generates/internal/SdkSimulationProgrammer.ts +4 -4
- package/src/generates/internal/SdkTypeDefiner.ts +119 -119
- package/src/generates/internal/SwaggerSchemaGenerator.ts +16 -16
- package/src/generates/internal/SwaggerSchemaValidator.ts +198 -198
- package/src/index.ts +4 -4
- package/src/module.ts +2 -2
- package/src/structures/IController.ts +91 -91
- package/src/structures/IErrorReport.ts +6 -6
- package/src/structures/INestiaProject.ts +13 -13
- package/src/structures/INormalizedInput.ts +20 -20
- package/src/structures/IRoute.ts +52 -52
- package/src/structures/ISwagger.ts +91 -91
- package/src/structures/ISwaggerComponents.ts +29 -29
- package/src/structures/ISwaggerError.ts +8 -8
- package/src/structures/ISwaggerInfo.ts +80 -80
- package/src/structures/ISwaggerLazyProperty.ts +7 -7
- package/src/structures/ISwaggerLazySchema.ts +7 -7
- package/src/structures/ISwaggerRoute.ts +51 -51
- package/src/structures/ISwaggerSecurityScheme.ts +65 -65
- package/src/structures/ITypeTuple.ts +6 -6
- package/src/structures/MethodType.ts +5 -5
- package/src/structures/ParamCategory.ts +1 -1
- package/src/structures/TypeEntry.ts +22 -22
- package/src/utils/ArrayUtil.ts +26 -26
- package/src/utils/FileRetriever.ts +22 -22
- package/src/utils/ImportDictionary.ts +125 -125
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/PathUtil.ts +10 -10
- package/src/utils/SourceFinder.ts +66 -66
- package/src/utils/StripEnums.ts +5 -5
|
@@ -282,13 +282,13 @@ export namespace ReflectAnalyzer {
|
|
|
282
282
|
contentType: encrypted
|
|
283
283
|
? "text/plain"
|
|
284
284
|
: query
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
285
|
+
? "application/x-www-form-urlencoded"
|
|
286
|
+
: Reflect.getMetadata(Constants.HEADERS_METADATA, proto)?.find(
|
|
287
|
+
(h: Record<string, string>) =>
|
|
288
|
+
typeof h?.name === "string" &&
|
|
289
|
+
typeof h?.value === "string" &&
|
|
290
|
+
h.name.toLowerCase() === "content-type",
|
|
291
|
+
)?.value ?? "application/json",
|
|
292
292
|
security: _Get_securities(proto),
|
|
293
293
|
exceptions: _Get_exceptions(proto),
|
|
294
294
|
swaggerTags: [
|
|
@@ -393,8 +393,8 @@ export namespace ReflectAnalyzer {
|
|
|
393
393
|
param.factory.name === "EncryptedBody"
|
|
394
394
|
? "text/plain"
|
|
395
395
|
: param.factory.name === "TypedQueryBody"
|
|
396
|
-
|
|
397
|
-
|
|
396
|
+
? "application/x-www-form-urlencoded"
|
|
397
|
+
: "application/json",
|
|
398
398
|
};
|
|
399
399
|
else if (param.factory.name === "TypedHeaders")
|
|
400
400
|
return {
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { MapUtil } from "../utils/MapUtil";
|
|
2
|
-
|
|
3
|
-
export namespace SecurityAnalyzer {
|
|
4
|
-
export const merge = (...entire: Record<string, string[]>[]) => {
|
|
5
|
-
const dict: Map<string, Set<string>> = new Map();
|
|
6
|
-
for (const obj of entire)
|
|
7
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
8
|
-
const set = MapUtil.take(dict, key, () => new Set());
|
|
9
|
-
for (const val of value) set.add(val);
|
|
10
|
-
}
|
|
11
|
-
const output: Record<string, string[]>[] = [];
|
|
12
|
-
for (const [key, set] of dict) {
|
|
13
|
-
const obj = {
|
|
14
|
-
[key]: [...set],
|
|
15
|
-
};
|
|
16
|
-
output.push(obj);
|
|
17
|
-
}
|
|
18
|
-
return output;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
1
|
+
import { MapUtil } from "../utils/MapUtil";
|
|
2
|
+
|
|
3
|
+
export namespace SecurityAnalyzer {
|
|
4
|
+
export const merge = (...entire: Record<string, string[]>[]) => {
|
|
5
|
+
const dict: Map<string, Set<string>> = new Map();
|
|
6
|
+
for (const obj of entire)
|
|
7
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
8
|
+
const set = MapUtil.take(dict, key, () => new Set());
|
|
9
|
+
for (const val of value) set.add(val);
|
|
10
|
+
}
|
|
11
|
+
const output: Record<string, string[]>[] = [];
|
|
12
|
+
for (const [key, set] of dict) {
|
|
13
|
+
const obj = {
|
|
14
|
+
[key]: [...set],
|
|
15
|
+
};
|
|
16
|
+
output.push(obj);
|
|
17
|
+
}
|
|
18
|
+
return output;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export namespace CommandParser {
|
|
2
|
-
export function parse(argList: string[]): Record<string, string> {
|
|
3
|
-
const output: Record<string, string> = {};
|
|
4
|
-
argList.forEach((arg, i) => {
|
|
5
|
-
if (arg.startsWith("--") === false) return;
|
|
6
|
-
|
|
7
|
-
const key = arg.slice(2);
|
|
8
|
-
const value: string | undefined = argList[i + 1];
|
|
9
|
-
if (value === undefined || value.startsWith("--")) return;
|
|
10
|
-
|
|
11
|
-
output[key] = value;
|
|
12
|
-
});
|
|
13
|
-
return output;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
export namespace CommandParser {
|
|
2
|
+
export function parse(argList: string[]): Record<string, string> {
|
|
3
|
+
const output: Record<string, string> = {};
|
|
4
|
+
argList.forEach((arg, i) => {
|
|
5
|
+
if (arg.startsWith("--") === false) return;
|
|
6
|
+
|
|
7
|
+
const key = arg.slice(2);
|
|
8
|
+
const value: string | undefined = argList[i + 1];
|
|
9
|
+
if (value === undefined || value.startsWith("--")) return;
|
|
10
|
+
|
|
11
|
+
output[key] = value;
|
|
12
|
+
});
|
|
13
|
+
return output;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { register } from "ts-node";
|
|
4
|
-
import { parseNative } from "tsconfck";
|
|
5
|
-
import ts from "typescript";
|
|
6
|
-
import typia from "typia";
|
|
7
|
-
|
|
8
|
-
import { INestiaConfig } from "../../INestiaConfig";
|
|
9
|
-
|
|
10
|
-
export namespace NestiaConfigLoader {
|
|
11
|
-
export const compilerOptions = async (
|
|
12
|
-
project: string,
|
|
13
|
-
): Promise<ts.CompilerOptions> => {
|
|
14
|
-
const configFileName = ts.findConfigFile(
|
|
15
|
-
process.cwd(),
|
|
16
|
-
ts.sys.fileExists,
|
|
17
|
-
project,
|
|
18
|
-
);
|
|
19
|
-
if (!configFileName) throw new Error(`unable to find "${project}" file.`);
|
|
20
|
-
|
|
21
|
-
const { tsconfig } = await parseNative(configFileName);
|
|
22
|
-
const configFileText = JSON.stringify(tsconfig);
|
|
23
|
-
const { config } = ts.parseConfigFileTextToJson(
|
|
24
|
-
configFileName,
|
|
25
|
-
configFileText,
|
|
26
|
-
);
|
|
27
|
-
const configParseResult = ts.parseJsonConfigFileContent(
|
|
28
|
-
config,
|
|
29
|
-
ts.sys,
|
|
30
|
-
path.dirname(configFileName),
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
const { moduleResolution, ...result } =
|
|
34
|
-
configParseResult.raw.compilerOptions;
|
|
35
|
-
return result;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const config = async (
|
|
39
|
-
file: string,
|
|
40
|
-
options: ts.CompilerOptions,
|
|
41
|
-
): Promise<INestiaConfig> => {
|
|
42
|
-
if (fs.existsSync(path.resolve(file)) === false)
|
|
43
|
-
throw new Error(`Unable to find "${file}" file.`);
|
|
44
|
-
|
|
45
|
-
register({
|
|
46
|
-
emit: false,
|
|
47
|
-
compilerOptions: options,
|
|
48
|
-
require: options.baseUrl ? ["tsconfig-paths/register"] : undefined,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const loaded: INestiaConfig & { default?: INestiaConfig } = await import(
|
|
52
|
-
path.resolve(file)
|
|
53
|
-
);
|
|
54
|
-
const config: INestiaConfig =
|
|
55
|
-
typeof loaded?.default === "object" && loaded.default !== null
|
|
56
|
-
? loaded.default
|
|
57
|
-
: loaded;
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
return typia.assert(config);
|
|
61
|
-
} catch (exp) {
|
|
62
|
-
if (typia.is<typia.TypeGuardError>(exp))
|
|
63
|
-
exp.message = `invalid "${file}" data.`;
|
|
64
|
-
throw exp;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { register } from "ts-node";
|
|
4
|
+
import { parseNative } from "tsconfck";
|
|
5
|
+
import ts from "typescript";
|
|
6
|
+
import typia from "typia";
|
|
7
|
+
|
|
8
|
+
import { INestiaConfig } from "../../INestiaConfig";
|
|
9
|
+
|
|
10
|
+
export namespace NestiaConfigLoader {
|
|
11
|
+
export const compilerOptions = async (
|
|
12
|
+
project: string,
|
|
13
|
+
): Promise<ts.CompilerOptions> => {
|
|
14
|
+
const configFileName = ts.findConfigFile(
|
|
15
|
+
process.cwd(),
|
|
16
|
+
ts.sys.fileExists,
|
|
17
|
+
project,
|
|
18
|
+
);
|
|
19
|
+
if (!configFileName) throw new Error(`unable to find "${project}" file.`);
|
|
20
|
+
|
|
21
|
+
const { tsconfig } = await parseNative(configFileName);
|
|
22
|
+
const configFileText = JSON.stringify(tsconfig);
|
|
23
|
+
const { config } = ts.parseConfigFileTextToJson(
|
|
24
|
+
configFileName,
|
|
25
|
+
configFileText,
|
|
26
|
+
);
|
|
27
|
+
const configParseResult = ts.parseJsonConfigFileContent(
|
|
28
|
+
config,
|
|
29
|
+
ts.sys,
|
|
30
|
+
path.dirname(configFileName),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const { moduleResolution, ...result } =
|
|
34
|
+
configParseResult.raw.compilerOptions;
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const config = async (
|
|
39
|
+
file: string,
|
|
40
|
+
options: ts.CompilerOptions,
|
|
41
|
+
): Promise<INestiaConfig> => {
|
|
42
|
+
if (fs.existsSync(path.resolve(file)) === false)
|
|
43
|
+
throw new Error(`Unable to find "${file}" file.`);
|
|
44
|
+
|
|
45
|
+
register({
|
|
46
|
+
emit: false,
|
|
47
|
+
compilerOptions: options,
|
|
48
|
+
require: options.baseUrl ? ["tsconfig-paths/register"] : undefined,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const loaded: INestiaConfig & { default?: INestiaConfig } = await import(
|
|
52
|
+
path.resolve(file)
|
|
53
|
+
);
|
|
54
|
+
const config: INestiaConfig =
|
|
55
|
+
typeof loaded?.default === "object" && loaded.default !== null
|
|
56
|
+
? loaded.default
|
|
57
|
+
: loaded;
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
return typia.assert(config);
|
|
61
|
+
} catch (exp) {
|
|
62
|
+
if (typia.is<typia.TypeGuardError>(exp))
|
|
63
|
+
exp.message = `invalid "${file}" data.`;
|
|
64
|
+
throw exp;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { INestiaConfig } from "../../INestiaConfig";
|
|
4
|
-
import { NestiaSdkApplication } from "../../NestiaSdkApplication";
|
|
5
|
-
import { NestiaConfigLoader } from "./NestiaConfigLoader";
|
|
6
|
-
|
|
7
|
-
export namespace NestiaSdkCommand {
|
|
8
|
-
export const sdk = () => main((app) => app.sdk());
|
|
9
|
-
export const swagger = () => main((app) => app.swagger());
|
|
10
|
-
export const e2e = () => main((app) => app.e2e());
|
|
11
|
-
|
|
12
|
-
const main = async (task: (app: NestiaSdkApplication) => Promise<void>) => {
|
|
13
|
-
await generate(task);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const generate = async (
|
|
17
|
-
task: (app: NestiaSdkApplication) => Promise<void>,
|
|
18
|
-
) => {
|
|
19
|
-
// LOAD CONFIG INFO
|
|
20
|
-
const compilerOptions: ts.CompilerOptions =
|
|
21
|
-
await NestiaConfigLoader.compilerOptions(
|
|
22
|
-
getFileArgument({
|
|
23
|
-
type: "project",
|
|
24
|
-
extension: "json",
|
|
25
|
-
}) ?? "tsconfig.json",
|
|
26
|
-
);
|
|
27
|
-
const config: INestiaConfig = await NestiaConfigLoader.config(
|
|
28
|
-
getFileArgument({
|
|
29
|
-
type: "config",
|
|
30
|
-
extension: "ts",
|
|
31
|
-
}) ?? "nestia.config.ts",
|
|
32
|
-
compilerOptions,
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
// GENERATE
|
|
36
|
-
const app: NestiaSdkApplication = new NestiaSdkApplication(
|
|
37
|
-
config,
|
|
38
|
-
compilerOptions,
|
|
39
|
-
);
|
|
40
|
-
await task(app);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const getFileArgument = (props: {
|
|
44
|
-
type: string;
|
|
45
|
-
extension: string;
|
|
46
|
-
}): string | null => {
|
|
47
|
-
const argv: string[] = process.argv.slice(3);
|
|
48
|
-
if (argv.length === 0) return null;
|
|
49
|
-
|
|
50
|
-
const index: number = argv.findIndex((str) => str === `--${props.type}`);
|
|
51
|
-
if (index === -1) return null;
|
|
52
|
-
else if (argv.length === 1)
|
|
53
|
-
throw new Error(`${props.type} file must be provided`);
|
|
54
|
-
|
|
55
|
-
const file: string = argv[index + 1];
|
|
56
|
-
if (file.endsWith(props.extension) === false)
|
|
57
|
-
throw new Error(`${props.type} file must be ${props.extension} file`);
|
|
58
|
-
return file;
|
|
59
|
-
};
|
|
60
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { INestiaConfig } from "../../INestiaConfig";
|
|
4
|
+
import { NestiaSdkApplication } from "../../NestiaSdkApplication";
|
|
5
|
+
import { NestiaConfigLoader } from "./NestiaConfigLoader";
|
|
6
|
+
|
|
7
|
+
export namespace NestiaSdkCommand {
|
|
8
|
+
export const sdk = () => main((app) => app.sdk());
|
|
9
|
+
export const swagger = () => main((app) => app.swagger());
|
|
10
|
+
export const e2e = () => main((app) => app.e2e());
|
|
11
|
+
|
|
12
|
+
const main = async (task: (app: NestiaSdkApplication) => Promise<void>) => {
|
|
13
|
+
await generate(task);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const generate = async (
|
|
17
|
+
task: (app: NestiaSdkApplication) => Promise<void>,
|
|
18
|
+
) => {
|
|
19
|
+
// LOAD CONFIG INFO
|
|
20
|
+
const compilerOptions: ts.CompilerOptions =
|
|
21
|
+
await NestiaConfigLoader.compilerOptions(
|
|
22
|
+
getFileArgument({
|
|
23
|
+
type: "project",
|
|
24
|
+
extension: "json",
|
|
25
|
+
}) ?? "tsconfig.json",
|
|
26
|
+
);
|
|
27
|
+
const config: INestiaConfig = await NestiaConfigLoader.config(
|
|
28
|
+
getFileArgument({
|
|
29
|
+
type: "config",
|
|
30
|
+
extension: "ts",
|
|
31
|
+
}) ?? "nestia.config.ts",
|
|
32
|
+
compilerOptions,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
// GENERATE
|
|
36
|
+
const app: NestiaSdkApplication = new NestiaSdkApplication(
|
|
37
|
+
config,
|
|
38
|
+
compilerOptions,
|
|
39
|
+
);
|
|
40
|
+
await task(app);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const getFileArgument = (props: {
|
|
44
|
+
type: string;
|
|
45
|
+
extension: string;
|
|
46
|
+
}): string | null => {
|
|
47
|
+
const argv: string[] = process.argv.slice(3);
|
|
48
|
+
if (argv.length === 0) return null;
|
|
49
|
+
|
|
50
|
+
const index: number = argv.findIndex((str) => str === `--${props.type}`);
|
|
51
|
+
if (index === -1) return null;
|
|
52
|
+
else if (argv.length === 1)
|
|
53
|
+
throw new Error(`${props.type} file must be provided`);
|
|
54
|
+
|
|
55
|
+
const file: string = argv[index + 1];
|
|
56
|
+
if (file.endsWith(props.extension) === false)
|
|
57
|
+
throw new Error(`${props.type} file must be ${props.extension} file`);
|
|
58
|
+
return file;
|
|
59
|
+
};
|
|
60
|
+
}
|
package/src/executable/sdk.ts
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import cp from "child_process";
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import process from "process";
|
|
5
|
-
|
|
6
|
-
import { CommandParser } from "./internal/CommandParser";
|
|
7
|
-
import type { NestiaSdkCommand } from "./internal/NestiaSdkCommand";
|
|
8
|
-
|
|
9
|
-
const USAGE = `Wrong command has been detected. Use like below:
|
|
10
|
-
|
|
11
|
-
npx @nestia/sdk [command] [options?]
|
|
12
|
-
|
|
13
|
-
1. npx @nestia/sdk dependencies --manager (npm|pnpm|yarn)
|
|
14
|
-
- npx @nestia/sdk dependencies
|
|
15
|
-
- npx @nestia/sdk dependencies --manager pnpm
|
|
16
|
-
2. npx @nestia/sdk init
|
|
17
|
-
3. npx @nestia/sdk sdk --config? [config file]
|
|
18
|
-
4. npx @nestia/sdk swagger --config? [config file]
|
|
19
|
-
5. npx @nestia/sdk e2e --config? [config file]
|
|
20
|
-
`;
|
|
21
|
-
|
|
22
|
-
function halt(desc: string): never {
|
|
23
|
-
console.error(desc);
|
|
24
|
-
process.exit(-1);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function dependencies(argv: string[]): void {
|
|
28
|
-
// INSTALL DEPENDENCIES
|
|
29
|
-
const module = CommandParser.parse(argv).module ?? "npm";
|
|
30
|
-
const prefix: string = module === "yarn" ? "yarn add" : `${module} install`;
|
|
31
|
-
|
|
32
|
-
for (const lib of ["@nestia/fetcher", "typia"]) {
|
|
33
|
-
const command: string = `${prefix} ${lib}`;
|
|
34
|
-
console.log(`\n$ ${command}`);
|
|
35
|
-
cp.execSync(command, { stdio: "inherit" });
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async function initialize(): Promise<void> {
|
|
40
|
-
if (fs.existsSync("nestia.config.ts") === true)
|
|
41
|
-
halt(
|
|
42
|
-
`Error on nestia.sdk.initialize(): "nestia.config.ts" file already has been configured.`,
|
|
43
|
-
);
|
|
44
|
-
await fs.promises.copyFile(
|
|
45
|
-
`${__dirname}/../../assets/config/nestia.config.ts`,
|
|
46
|
-
"nestia.config.ts",
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async function execute(
|
|
51
|
-
closure: (commander: typeof NestiaSdkCommand) => Promise<void>,
|
|
52
|
-
): Promise<void> {
|
|
53
|
-
const module = await import("./internal/NestiaSdkCommand");
|
|
54
|
-
await closure(module.NestiaSdkCommand);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async function main() {
|
|
58
|
-
const type: string | undefined = process.argv[2];
|
|
59
|
-
const argv: string[] = process.argv.slice(3);
|
|
60
|
-
|
|
61
|
-
if (type === "dependencies") dependencies(argv);
|
|
62
|
-
else if (type === "init") await initialize();
|
|
63
|
-
else if (type === "sdk") await execute((c) => c.sdk());
|
|
64
|
-
else if (type === "swagger") await execute((c) => c.swagger());
|
|
65
|
-
else if (type === "e2e") await execute((c) => c.e2e());
|
|
66
|
-
else halt(USAGE);
|
|
67
|
-
|
|
68
|
-
process.exit(0);
|
|
69
|
-
}
|
|
70
|
-
main().catch((exp) => {
|
|
71
|
-
console.log(exp);
|
|
72
|
-
process.exit(-1);
|
|
73
|
-
});
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import cp from "child_process";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import process from "process";
|
|
5
|
+
|
|
6
|
+
import { CommandParser } from "./internal/CommandParser";
|
|
7
|
+
import type { NestiaSdkCommand } from "./internal/NestiaSdkCommand";
|
|
8
|
+
|
|
9
|
+
const USAGE = `Wrong command has been detected. Use like below:
|
|
10
|
+
|
|
11
|
+
npx @nestia/sdk [command] [options?]
|
|
12
|
+
|
|
13
|
+
1. npx @nestia/sdk dependencies --manager (npm|pnpm|yarn)
|
|
14
|
+
- npx @nestia/sdk dependencies
|
|
15
|
+
- npx @nestia/sdk dependencies --manager pnpm
|
|
16
|
+
2. npx @nestia/sdk init
|
|
17
|
+
3. npx @nestia/sdk sdk --config? [config file]
|
|
18
|
+
4. npx @nestia/sdk swagger --config? [config file]
|
|
19
|
+
5. npx @nestia/sdk e2e --config? [config file]
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
function halt(desc: string): never {
|
|
23
|
+
console.error(desc);
|
|
24
|
+
process.exit(-1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function dependencies(argv: string[]): void {
|
|
28
|
+
// INSTALL DEPENDENCIES
|
|
29
|
+
const module = CommandParser.parse(argv).module ?? "npm";
|
|
30
|
+
const prefix: string = module === "yarn" ? "yarn add" : `${module} install`;
|
|
31
|
+
|
|
32
|
+
for (const lib of ["@nestia/fetcher", "typia"]) {
|
|
33
|
+
const command: string = `${prefix} ${lib}`;
|
|
34
|
+
console.log(`\n$ ${command}`);
|
|
35
|
+
cp.execSync(command, { stdio: "inherit" });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function initialize(): Promise<void> {
|
|
40
|
+
if (fs.existsSync("nestia.config.ts") === true)
|
|
41
|
+
halt(
|
|
42
|
+
`Error on nestia.sdk.initialize(): "nestia.config.ts" file already has been configured.`,
|
|
43
|
+
);
|
|
44
|
+
await fs.promises.copyFile(
|
|
45
|
+
`${__dirname}/../../assets/config/nestia.config.ts`,
|
|
46
|
+
"nestia.config.ts",
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function execute(
|
|
51
|
+
closure: (commander: typeof NestiaSdkCommand) => Promise<void>,
|
|
52
|
+
): Promise<void> {
|
|
53
|
+
const module = await import("./internal/NestiaSdkCommand");
|
|
54
|
+
await closure(module.NestiaSdkCommand);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function main() {
|
|
58
|
+
const type: string | undefined = process.argv[2];
|
|
59
|
+
const argv: string[] = process.argv.slice(3);
|
|
60
|
+
|
|
61
|
+
if (type === "dependencies") dependencies(argv);
|
|
62
|
+
else if (type === "init") await initialize();
|
|
63
|
+
else if (type === "sdk") await execute((c) => c.sdk());
|
|
64
|
+
else if (type === "swagger") await execute((c) => c.swagger());
|
|
65
|
+
else if (type === "e2e") await execute((c) => c.e2e());
|
|
66
|
+
else halt(USAGE);
|
|
67
|
+
|
|
68
|
+
process.exit(0);
|
|
69
|
+
}
|
|
70
|
+
main().catch((exp) => {
|
|
71
|
+
console.log(exp);
|
|
72
|
+
process.exit(-1);
|
|
73
|
+
});
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
|
|
4
|
-
import { INestiaConfig } from "../INestiaConfig";
|
|
5
|
-
import { ConfigAnalyzer } from "../analyses/ConfigAnalyzer";
|
|
6
|
-
import { IRoute } from "../structures/IRoute";
|
|
7
|
-
import { E2eFileProgrammer } from "./internal/E2eFileProgrammer";
|
|
8
|
-
|
|
9
|
-
export namespace E2eGenerator {
|
|
10
|
-
export const generate =
|
|
11
|
-
(config: INestiaConfig) =>
|
|
12
|
-
async (routeList: IRoute[]): Promise<void> => {
|
|
13
|
-
console.log("Generating E2E Test Functions");
|
|
14
|
-
|
|
15
|
-
// PREPARE DIRECTORIES
|
|
16
|
-
const output: string = path.resolve(config.e2e!);
|
|
17
|
-
await mkdir(output);
|
|
18
|
-
await mkdir(path.join(output, "features"));
|
|
19
|
-
await mkdir(path.join(output, "features", "api"));
|
|
20
|
-
await mkdir(path.join(output, "features", "api", "automated"));
|
|
21
|
-
|
|
22
|
-
// GENERATE TEST INDEX FILE
|
|
23
|
-
await index(config)(path.join(config.e2e!, "index.ts"));
|
|
24
|
-
|
|
25
|
-
// GENERATE EACH TEST FILES
|
|
26
|
-
for (const route of routeList)
|
|
27
|
-
await E2eFileProgrammer.generate(config)({
|
|
28
|
-
api: path.resolve(config.output!),
|
|
29
|
-
current: path.join(output, "features", "api", "automated"),
|
|
30
|
-
})(route);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const index =
|
|
34
|
-
(config: INestiaConfig) =>
|
|
35
|
-
async (output: string): Promise<void> => {
|
|
36
|
-
if (fs.existsSync(output)) return;
|
|
37
|
-
|
|
38
|
-
const location: string = path.join(
|
|
39
|
-
__dirname,
|
|
40
|
-
"..",
|
|
41
|
-
"..",
|
|
42
|
-
"assets",
|
|
43
|
-
"bundle",
|
|
44
|
-
"e2e",
|
|
45
|
-
"index.ts",
|
|
46
|
-
);
|
|
47
|
-
const content: string = await fs.promises.readFile(location, "utf8");
|
|
48
|
-
|
|
49
|
-
await fs.promises.writeFile(
|
|
50
|
-
output,
|
|
51
|
-
content.replace(
|
|
52
|
-
"${input}",
|
|
53
|
-
JSON.stringify(await ConfigAnalyzer.input(config)),
|
|
54
|
-
),
|
|
55
|
-
"utf8",
|
|
56
|
-
);
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const mkdir = async (location: string): Promise<void> => {
|
|
61
|
-
try {
|
|
62
|
-
await fs.promises.mkdir(location);
|
|
63
|
-
} catch {}
|
|
64
|
-
};
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
import { INestiaConfig } from "../INestiaConfig";
|
|
5
|
+
import { ConfigAnalyzer } from "../analyses/ConfigAnalyzer";
|
|
6
|
+
import { IRoute } from "../structures/IRoute";
|
|
7
|
+
import { E2eFileProgrammer } from "./internal/E2eFileProgrammer";
|
|
8
|
+
|
|
9
|
+
export namespace E2eGenerator {
|
|
10
|
+
export const generate =
|
|
11
|
+
(config: INestiaConfig) =>
|
|
12
|
+
async (routeList: IRoute[]): Promise<void> => {
|
|
13
|
+
console.log("Generating E2E Test Functions");
|
|
14
|
+
|
|
15
|
+
// PREPARE DIRECTORIES
|
|
16
|
+
const output: string = path.resolve(config.e2e!);
|
|
17
|
+
await mkdir(output);
|
|
18
|
+
await mkdir(path.join(output, "features"));
|
|
19
|
+
await mkdir(path.join(output, "features", "api"));
|
|
20
|
+
await mkdir(path.join(output, "features", "api", "automated"));
|
|
21
|
+
|
|
22
|
+
// GENERATE TEST INDEX FILE
|
|
23
|
+
await index(config)(path.join(config.e2e!, "index.ts"));
|
|
24
|
+
|
|
25
|
+
// GENERATE EACH TEST FILES
|
|
26
|
+
for (const route of routeList)
|
|
27
|
+
await E2eFileProgrammer.generate(config)({
|
|
28
|
+
api: path.resolve(config.output!),
|
|
29
|
+
current: path.join(output, "features", "api", "automated"),
|
|
30
|
+
})(route);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const index =
|
|
34
|
+
(config: INestiaConfig) =>
|
|
35
|
+
async (output: string): Promise<void> => {
|
|
36
|
+
if (fs.existsSync(output)) return;
|
|
37
|
+
|
|
38
|
+
const location: string = path.join(
|
|
39
|
+
__dirname,
|
|
40
|
+
"..",
|
|
41
|
+
"..",
|
|
42
|
+
"assets",
|
|
43
|
+
"bundle",
|
|
44
|
+
"e2e",
|
|
45
|
+
"index.ts",
|
|
46
|
+
);
|
|
47
|
+
const content: string = await fs.promises.readFile(location, "utf8");
|
|
48
|
+
|
|
49
|
+
await fs.promises.writeFile(
|
|
50
|
+
output,
|
|
51
|
+
content.replace(
|
|
52
|
+
"${input}",
|
|
53
|
+
JSON.stringify(await ConfigAnalyzer.input(config)),
|
|
54
|
+
),
|
|
55
|
+
"utf8",
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const mkdir = async (location: string): Promise<void> => {
|
|
61
|
+
try {
|
|
62
|
+
await fs.promises.mkdir(location);
|
|
63
|
+
} catch {}
|
|
64
|
+
};
|