@nestia/migrate 0.11.4 → 0.11.5
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/bundles/NEST_TEMPLATE.js +5 -5
- package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
- package/lib/bundles/SDK_TEMPLATE.js +1 -1
- package/lib/utils/openapi-down-convert/converter.js +2 -2
- package/package.json +2 -2
- package/src/MigrateApplication.ts +81 -81
- package/src/analyzers/MigrateAnalyzer.ts +9 -9
- package/src/analyzers/MigrateControllerAnalyzer.ts +135 -135
- package/src/analyzers/MigrateMethodAnalyzer.ts +439 -439
- package/src/archivers/MigrateFileArchiver.ts +38 -38
- package/src/bundles/NEST_TEMPLATE.ts +5 -5
- package/src/bundles/SDK_TEMPLATE.ts +1 -1
- package/src/executable/bundle.ts +110 -110
- package/src/internal/MigrateCommander.ts +70 -70
- package/src/internal/MigrateInquirer.ts +86 -86
- package/src/module.ts +14 -14
- package/src/programmers/MigrateApiFileProgrammer.ts +53 -53
- package/src/programmers/MigrateApiFunctionProgrammer.ts +199 -199
- package/src/programmers/MigrateApiNamespaceProgrammer.ts +431 -431
- package/src/programmers/MigrateApiProgrammer.ts +170 -170
- package/src/programmers/MigrateApiSimulatationProgrammer.ts +327 -327
- package/src/programmers/MigrateApiStartProgrammer.ts +194 -194
- package/src/programmers/MigrateDtoProgrammer.ts +78 -78
- package/src/programmers/MigrateE2eFileProgrammer.ts +117 -117
- package/src/programmers/MigrateE2eProgrammer.ts +36 -36
- package/src/programmers/MigrateImportProgrammer.ts +121 -121
- package/src/programmers/MigrateNestControllerProgrammer.ts +50 -50
- package/src/programmers/MigrateNestMethodProgrammer.ts +250 -250
- package/src/programmers/MigrateNestModuleProgrammer.ts +63 -63
- package/src/programmers/MigrateNestProgrammer.ts +74 -74
- package/src/programmers/MigrateSchemaProgrammer.ts +267 -267
- package/src/structures/IMigrateDto.ts +8 -8
- package/src/structures/IMigrateProgram.ts +27 -27
- package/src/structures/IMigrateRoute.ts +51 -51
- package/src/structures/ISwagger.ts +23 -23
- package/src/structures/ISwaggerComponents.ts +14 -14
- package/src/structures/ISwaggerRoute.ts +20 -20
- package/src/structures/ISwaggerRouteBodyContent.ts +15 -15
- package/src/structures/ISwaggerRouteParameter.ts +14 -14
- package/src/structures/ISwaggerRouteRequestBody.ts +12 -12
- package/src/structures/ISwaggerRouteResponse.ts +11 -11
- package/src/structures/ISwaggerSchema.ts +90 -90
- package/src/structures/ISwaggerSecurityScheme.ts +47 -47
- package/src/structures/ISwaggerV20.ts +10 -10
- package/src/structures/ISwaggerV31.ts +10 -10
- package/src/utils/FilePrinter.ts +36 -36
- package/src/utils/OpenApiConverter.ts +19 -19
- package/src/utils/StringUtil.ts +60 -60
- package/src/utils/SwaggerComponentsExplorer.ts +43 -43
- package/src/utils/SwaggerTypeChecker.ts +67 -67
- package/src/utils/openapi-down-convert/RefVisitor.ts +139 -139
- package/src/utils/openapi-down-convert/converter.ts +527 -527
@@ -1,38 +1,38 @@
|
|
1
|
-
import { IMigrateFile } from "../structures/IMigrateFile";
|
2
|
-
|
3
|
-
export namespace MigrateFileArchiver {
|
4
|
-
export interface IOperator {
|
5
|
-
mkdir(path: string): Promise<void>;
|
6
|
-
writeFile(path: string, content: string): Promise<void>;
|
7
|
-
}
|
8
|
-
|
9
|
-
export const archive =
|
10
|
-
(operator: IOperator) =>
|
11
|
-
(output: string) =>
|
12
|
-
async (files: IMigrateFile[]): Promise<void> => {
|
13
|
-
const visited: Set<string> = new Set();
|
14
|
-
for (const f of files) {
|
15
|
-
await mkdir(operator.mkdir)(output)(visited)(f.location);
|
16
|
-
await operator.writeFile(
|
17
|
-
[output, f.location, f.file].join("/"),
|
18
|
-
f.content,
|
19
|
-
);
|
20
|
-
}
|
21
|
-
};
|
22
|
-
|
23
|
-
const mkdir =
|
24
|
-
(creator: (path: string) => void) =>
|
25
|
-
(output: string) =>
|
26
|
-
(visited: Set<string>) =>
|
27
|
-
async (path: string): Promise<void> => {
|
28
|
-
const sequence: string[] = path
|
29
|
-
.split("/")
|
30
|
-
.map((_str, i, entire) => entire.slice(0, i + 1).join("/"));
|
31
|
-
for (const s of sequence)
|
32
|
-
if (visited.has(s) === false)
|
33
|
-
try {
|
34
|
-
await creator([output, s].join("/"));
|
35
|
-
visited.add(s);
|
36
|
-
} catch {}
|
37
|
-
};
|
38
|
-
}
|
1
|
+
import { IMigrateFile } from "../structures/IMigrateFile";
|
2
|
+
|
3
|
+
export namespace MigrateFileArchiver {
|
4
|
+
export interface IOperator {
|
5
|
+
mkdir(path: string): Promise<void>;
|
6
|
+
writeFile(path: string, content: string): Promise<void>;
|
7
|
+
}
|
8
|
+
|
9
|
+
export const archive =
|
10
|
+
(operator: IOperator) =>
|
11
|
+
(output: string) =>
|
12
|
+
async (files: IMigrateFile[]): Promise<void> => {
|
13
|
+
const visited: Set<string> = new Set();
|
14
|
+
for (const f of files) {
|
15
|
+
await mkdir(operator.mkdir)(output)(visited)(f.location);
|
16
|
+
await operator.writeFile(
|
17
|
+
[output, f.location, f.file].join("/"),
|
18
|
+
f.content,
|
19
|
+
);
|
20
|
+
}
|
21
|
+
};
|
22
|
+
|
23
|
+
const mkdir =
|
24
|
+
(creator: (path: string) => void) =>
|
25
|
+
(output: string) =>
|
26
|
+
(visited: Set<string>) =>
|
27
|
+
async (path: string): Promise<void> => {
|
28
|
+
const sequence: string[] = path
|
29
|
+
.split("/")
|
30
|
+
.map((_str, i, entire) => entire.slice(0, i + 1).join("/"));
|
31
|
+
for (const s of sequence)
|
32
|
+
if (visited.has(s) === false)
|
33
|
+
try {
|
34
|
+
await creator([output, s].join("/"));
|
35
|
+
visited.add(s);
|
36
|
+
} catch {}
|
37
|
+
};
|
38
|
+
}
|
@@ -12,7 +12,7 @@ export const NEST_TEMPLATE = [
|
|
12
12
|
{
|
13
13
|
"location": ".github/workflows",
|
14
14
|
"file": "build.yml",
|
15
|
-
"content": "name: build\r\non: \r\n push:\r\n paths:\r\n - 'src/**'\r\n - 'test/**'\r\n pull_request:\r\n paths:\r\n - 'src/**'\r\n - 'test/**'\r\n\r\njobs:\r\n Ubuntu:\r\n runs-on: ubuntu-latest\r\n steps:\r\n - uses: actions/checkout@v4\r\n - uses: actions/setup-node@v4\r\n with:\r\n node-version: 20.x\r\n - uses: pnpm/action-setup@v2\r\n with:\r\n version: 8\r\n \r\n - name: Install Backend-Server\r\n run: pnpm install\r\n\r\n - name: Build Swagger\r\n run: npm run build:swagger\r\n\r\n - name: Build SDK\r\n run: npm run build:sdk\r\n\r\n - name: Compile Backend-Server\r\n run: npm run build\r\n\r\n - name: Run Test Program\r\n run: npm run test\r\n\r\n - name: Test Webpack\r\n run: npm run webpack && npm run test:webpack\r\n\r\n - name: EsLint\r\n run: npm run eslint\r\n"
|
15
|
+
"content": "name: build\r\non: \r\n push:\r\n paths:\r\n - package.json\r\n - 'src/**'\r\n - 'test/**'\r\n pull_request:\r\n paths:\r\n - package.json\r\n - 'src/**'\r\n - 'test/**'\r\n\r\njobs:\r\n Ubuntu:\r\n runs-on: ubuntu-latest\r\n steps:\r\n - uses: actions/checkout@v4\r\n - uses: actions/setup-node@v4\r\n with:\r\n node-version: 20.x\r\n - uses: pnpm/action-setup@v2\r\n with:\r\n version: 8\r\n \r\n - name: Install Backend-Server\r\n run: pnpm install\r\n\r\n - name: Build Swagger\r\n run: npm run build:swagger\r\n\r\n - name: Build SDK\r\n run: npm run build:sdk\r\n\r\n - name: Compile Backend-Server\r\n run: npm run build\r\n\r\n - name: Run Test Program\r\n run: npm run test\r\n\r\n - name: Test Webpack\r\n run: npm run webpack && npm run test:webpack\r\n\r\n - name: EsLint\r\n run: npm run eslint\r\n"
|
16
16
|
},
|
17
17
|
{
|
18
18
|
"location": "",
|
@@ -47,7 +47,7 @@ export const NEST_TEMPLATE = [
|
|
47
47
|
{
|
48
48
|
"location": "",
|
49
49
|
"file": "package.json",
|
50
|
-
"content": "{\r\n \"private\": true,\r\n \"name\": \"@ORGANIZATION/PROJECT\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"Starter kit of Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"scripts\": {\r\n \"test\": \"node bin/test\",\r\n \"test:webpack\": \"npm run webpack && node bin/test/webpack.js\",\r\n \"------------------------BUILDS------------------------\": \"\",\r\n \"build\": \"npm run build:sdk && npm run build:main && npm run build:test\",\r\n \"build:api\": \"rimraf packages/api/lib && npm run build:sdk && tsc -p packages/api/tsconfig.json\",\r\n \"build:main\": \"rimraf lib && tsc\",\r\n \"build:sdk\": \"rimraf src/api/functional && nestia sdk\",\r\n \"build:swagger\": \"npx nestia swagger\",\r\n \"build:test\": \"rimraf bin && tsc -p test/tsconfig.json\",\r\n \"dev\": \"npm run build:test -- --watch\",\r\n \"eslint\": \"eslint src && eslint test\",\r\n \"eslint:fix\": \"eslint --fix src && eslint --fix test\",\r\n \"prepare\": \"ts-patch install && typia patch\",\r\n \"prettier\": \"prettier src --write && prettier test --write\",\r\n \"------------------------WEBPACK------------------------\": \"\",\r\n \"webpack\": \"rimraf dist && webpack\",\r\n \"webpack:start\": \"cd dist && node dist/server\",\r\n \"------------------------DEPLOYS------------------------\": \"\",\r\n \"package:api\": \"npm run build:swagger && npm run build:api && cd packages/api && npm publish\",\r\n \"start\": \"node lib/executable/server\",\r\n \"start:swagger\": \"ts-node src/executable/swagger.ts\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia-start\"\r\n },\r\n \"keywords\": [\r\n \"nestia\",\r\n \"template\",\r\n \"boilerplate\"\r\n ],\r\n \"author\": \"AUTHOR\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia-start/issues\"\r\n },\r\n \"homepage\": \"https://github.com/samchon/nestia-start#readme\",\r\n \"devDependencies\": {\r\n \"@nestia/e2e\": \"^0.4.2\",\r\n \"@nestia/sdk\": \"^2.6.
|
50
|
+
"content": "{\r\n \"private\": true,\r\n \"name\": \"@ORGANIZATION/PROJECT\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"Starter kit of Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"scripts\": {\r\n \"test\": \"node bin/test\",\r\n \"test:webpack\": \"npm run webpack && node bin/test/webpack.js\",\r\n \"------------------------BUILDS------------------------\": \"\",\r\n \"build\": \"npm run build:sdk && npm run build:main && npm run build:test\",\r\n \"build:api\": \"rimraf packages/api/lib && npm run build:sdk && tsc -p packages/api/tsconfig.json\",\r\n \"build:main\": \"rimraf lib && tsc\",\r\n \"build:sdk\": \"rimraf src/api/functional && nestia sdk\",\r\n \"build:swagger\": \"npx nestia swagger\",\r\n \"build:test\": \"rimraf bin && tsc -p test/tsconfig.json\",\r\n \"dev\": \"npm run build:test -- --watch\",\r\n \"eslint\": \"eslint src && eslint test\",\r\n \"eslint:fix\": \"eslint --fix src && eslint --fix test\",\r\n \"prepare\": \"ts-patch install && typia patch\",\r\n \"prettier\": \"prettier src --write && prettier test --write\",\r\n \"------------------------WEBPACK------------------------\": \"\",\r\n \"webpack\": \"rimraf dist && webpack\",\r\n \"webpack:start\": \"cd dist && node dist/server\",\r\n \"------------------------DEPLOYS------------------------\": \"\",\r\n \"package:api\": \"npm run build:swagger && npm run build:api && cd packages/api && npm publish\",\r\n \"start\": \"node lib/executable/server\",\r\n \"start:swagger\": \"ts-node src/executable/swagger.ts\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia-start\"\r\n },\r\n \"keywords\": [\r\n \"nestia\",\r\n \"template\",\r\n \"boilerplate\"\r\n ],\r\n \"author\": \"AUTHOR\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia-start/issues\"\r\n },\r\n \"homepage\": \"https://github.com/samchon/nestia-start#readme\",\r\n \"devDependencies\": {\r\n \"@nestia/e2e\": \"^0.4.2\",\r\n \"@nestia/sdk\": \"^2.6.3\",\r\n \"@trivago/prettier-plugin-sort-imports\": \"^4.3.0\",\r\n \"@types/cli\": \"^0.11.21\",\r\n \"@types/express\": \"^4.17.21\",\r\n \"@types/inquirer\": \"^8.2.5\",\r\n \"@types/node\": \"^18.11.0\",\r\n \"@types/uuid\": \"^8.3.4\",\r\n \"@typescript-eslint/eslint-plugin\": \"^6.19.1\",\r\n \"@typescript-eslint/parser\": \"^6.19.1\",\r\n \"chalk\": \"^4.1.0\",\r\n \"cli\": \"^1.0.1\",\r\n \"copy-webpack-plugin\": \"^11.0.0\",\r\n \"eslint-plugin-deprecation\": \"^2.0.0\",\r\n \"express\": \"^4.18.2\",\r\n \"nestia\": \"^5.3.0\",\r\n \"prettier\": \"^3.2.4\",\r\n \"prettier-plugin-prisma\": \"^5.0.0\",\r\n \"rimraf\": \"^3.0.2\",\r\n \"source-map-support\": \"^0.5.21\",\r\n \"swagger-ui-express\": \"^5.0.0\",\r\n \"ts-loader\": \"^9.5.1\",\r\n \"ts-node\": \"^10.9.1\",\r\n \"ts-patch\": \"^3.0.2\",\r\n \"typescript\": \"^5.3.2\",\r\n \"typescript-transform-paths\": \"^3.4.6\",\r\n \"webpack\": \"^5.89.0\",\r\n \"webpack-cli\": \"^5.1.4\",\r\n \"write-file-webpack-plugin\": \"^4.5.1\"\r\n },\r\n \"dependencies\": {\r\n \"@nestia/core\": \"^2.6.3\",\r\n \"@nestia/fetcher\": \"^2.6.3\",\r\n \"@nestjs/common\": \"^10.3.7\",\r\n \"@nestjs/core\": \"^10.3.7\",\r\n \"@nestjs/platform-express\": \"^10.3.7\",\r\n \"commander\": \"10.0.0\",\r\n \"dotenv\": \"^16.3.1\",\r\n \"dotenv-expand\": \"^10.0.0\",\r\n \"inquirer\": \"8.2.5\",\r\n \"serialize-error\": \"^4.1.0\",\r\n \"tstl\": \"^3.0.0\",\r\n \"typia\": \"^5.5.7\",\r\n \"uuid\": \"^9.0.0\"\r\n },\r\n \"stackblitz\": {\r\n \"startCommand\": \"npm run prepare && npm run build:test && npm run test\"\r\n }\r\n}"
|
51
51
|
},
|
52
52
|
{
|
53
53
|
"location": "packages/api",
|
@@ -62,7 +62,7 @@ export const NEST_TEMPLATE = [
|
|
62
62
|
{
|
63
63
|
"location": "packages/api",
|
64
64
|
"file": "package.json",
|
65
|
-
"content": "{\r\n \"name\": \"@ORGANIZATION/PROJECT-api\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"SDK library generated by Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"typings\": \"lib/index.d.ts\",\r\n \"scripts\": {\r\n \"build\": \"npm run build:sdk && npm run compile\",\r\n \"build:sdk\": \"rimraf ../../src/api/functional && cd ../.. && npx nestia sdk && cd packages/api\",\r\n \"compile\": \"rimraf lib && tsc\",\r\n \"deploy\": \"npm run build && npm publish\",\r\n \"prepare\": \"ts-patch install && typia patch\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia\"\r\n },\r\n \"author\": \"Jeongho Nam\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia/issues\"\r\n },\r\n \"homepage\": \"https://nestia.io\",\r\n \"files\": [\r\n \"lib\",\r\n \"swagger.json\",\r\n \"package.json\",\r\n \"README.md\"\r\n ],\r\n \"devDependencies\": {\r\n \"rimraf\": \"^5.0.5\",\r\n \"ts-node\": \"^10.9.2\",\r\n \"ts-patch\": \"^3.1.2\",\r\n \"typescript\": \"^5.3.3\"\r\n },\r\n \"dependencies\": {\r\n \"@nestia/fetcher\": \"^2.6.
|
65
|
+
"content": "{\r\n \"name\": \"@ORGANIZATION/PROJECT-api\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"SDK library generated by Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"typings\": \"lib/index.d.ts\",\r\n \"scripts\": {\r\n \"build\": \"npm run build:sdk && npm run compile\",\r\n \"build:sdk\": \"rimraf ../../src/api/functional && cd ../.. && npx nestia sdk && cd packages/api\",\r\n \"compile\": \"rimraf lib && tsc\",\r\n \"deploy\": \"npm run build && npm publish\",\r\n \"prepare\": \"ts-patch install && typia patch\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia\"\r\n },\r\n \"author\": \"Jeongho Nam\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia/issues\"\r\n },\r\n \"homepage\": \"https://nestia.io\",\r\n \"files\": [\r\n \"lib\",\r\n \"swagger.json\",\r\n \"package.json\",\r\n \"README.md\"\r\n ],\r\n \"devDependencies\": {\r\n \"rimraf\": \"^5.0.5\",\r\n \"ts-node\": \"^10.9.2\",\r\n \"ts-patch\": \"^3.1.2\",\r\n \"typescript\": \"^5.3.3\"\r\n },\r\n \"dependencies\": {\r\n \"@nestia/fetcher\": \"^2.6.3\",\r\n \"typia\": \"^5.5.7\"\r\n }\r\n}"
|
66
66
|
},
|
67
67
|
{
|
68
68
|
"location": "packages/api",
|
@@ -127,7 +127,7 @@ export const NEST_TEMPLATE = [
|
|
127
127
|
{
|
128
128
|
"location": "src/executable",
|
129
129
|
"file": "server.ts",
|
130
|
-
"content": "import fs from \"fs\";\r\nimport { randint } from \"tstl
|
130
|
+
"content": "import fs from \"fs\";\r\nimport { Singleton, randint } from \"tstl\";\r\n\r\nimport { MyBackend } from \"../MyBackend\";\r\nimport { MyConfiguration } from \"../MyConfiguration\";\r\nimport { ErrorUtil } from \"../utils/ErrorUtil\";\r\n\r\nconst EXTENSION = __filename.substring(__filename.length - 2);\r\nif (EXTENSION === \"js\") require(\"source-map-support/register\");\r\n\r\nconst directory = new Singleton(async () => {\r\n await mkdir(`${MyConfiguration.ROOT}/assets`);\r\n await mkdir(`${MyConfiguration.ROOT}/assets/logs`);\r\n await mkdir(`${MyConfiguration.ROOT}/assets/logs/errors`);\r\n});\r\n\r\nfunction cipher(val: number): string {\r\n if (val < 10) return \"0\" + val;\r\n else return String(val);\r\n}\r\n\r\nasync function mkdir(path: string): Promise<void> {\r\n try {\r\n await fs.promises.mkdir(path);\r\n } catch {}\r\n}\r\n\r\nasync function handle_error(exp: any): Promise<void> {\r\n try {\r\n const date: Date = new Date();\r\n const fileName: string = `${date.getFullYear()}${cipher(\r\n date.getMonth() + 1,\r\n )}${cipher(date.getDate())}${cipher(date.getHours())}${cipher(\r\n date.getMinutes(),\r\n )}${cipher(date.getSeconds())}.${randint(0, Number.MAX_SAFE_INTEGER)}`;\r\n const content: string = JSON.stringify(ErrorUtil.toJSON(exp), null, 4);\r\n\r\n await directory.get();\r\n await fs.promises.writeFile(\r\n `${MyConfiguration.ROOT}/assets/logs/errors/${fileName}.log`,\r\n content,\r\n \"utf8\",\r\n );\r\n } catch {}\r\n}\r\n\r\nasync function main(): Promise<void> {\r\n // BACKEND SEVER\r\n const backend: MyBackend = new MyBackend();\r\n await backend.open();\r\n\r\n // UNEXPECTED ERRORS\r\n global.process.on(\"uncaughtException\", handle_error);\r\n global.process.on(\"unhandledRejection\", handle_error);\r\n}\r\nmain().catch((exp) => {\r\n console.log(exp);\r\n process.exit(-1);\r\n});\r\n"
|
131
131
|
},
|
132
132
|
{
|
133
133
|
"location": "src/executable",
|
@@ -152,7 +152,7 @@ export const NEST_TEMPLATE = [
|
|
152
152
|
{
|
153
153
|
"location": "src/utils",
|
154
154
|
"file": "ErrorUtil.ts",
|
155
|
-
"content": "import fs from \"fs\";\r\nimport { randint } from \"tstl
|
155
|
+
"content": "import fs from \"fs\";\r\nimport { Singleton, randint } from \"tstl\";\r\n\r\nimport { MyConfiguration } from \"../MyConfiguration\";\r\n\r\nimport serializeError = require(\"serialize-error\");\r\n\r\nexport namespace ErrorUtil {\r\n export const toJSON = (err: any): object =>\r\n err instanceof Object && err.toJSON instanceof Function\r\n ? err.toJSON()\r\n : serializeError(err);\r\n\r\n export const log =\r\n (prefix: string) =>\r\n async (error: string | object | Error): Promise<void> => {\r\n try {\r\n if (error instanceof Error) error = toJSON(error);\r\n\r\n const date: Date = new Date();\r\n const fileName: string = `${date.getFullYear()}${cipher(\r\n date.getMonth() + 1,\r\n )}${cipher(date.getDate())}${cipher(date.getHours())}${cipher(\r\n date.getMinutes(),\r\n )}${cipher(date.getSeconds())}.${randint(0, Number.MAX_SAFE_INTEGER)}`;\r\n const content: string = JSON.stringify(error, null, 4);\r\n\r\n await directory.get();\r\n await fs.promises.writeFile(\r\n `${MyConfiguration.ROOT}/assets/logs/errors/${prefix}_${fileName}.log`,\r\n content,\r\n \"utf8\",\r\n );\r\n } catch {}\r\n };\r\n}\r\n\r\nconst cipher = (val: number): string => String(val).padStart(2, \"0\");\r\nconst directory = new Singleton(async () => {\r\n await mkdir(`${MyConfiguration.ROOT}/assets/logs`);\r\n await mkdir(`${MyConfiguration.ROOT}/assets/logs/errors`);\r\n});\r\nasync function mkdir(path: string): Promise<void> {\r\n try {\r\n await fs.promises.mkdir(path);\r\n } catch {}\r\n}\r\n"
|
156
156
|
},
|
157
157
|
{
|
158
158
|
"location": "src/utils",
|
@@ -22,7 +22,7 @@ export const SDK_TEMPLATE = [
|
|
22
22
|
{
|
23
23
|
"location": "",
|
24
24
|
"file": "package.json",
|
25
|
-
"content": "{\r\n \"name\": \"@ORGANIZATION/PROJECT-api\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"SDK library generated by Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"typings\": \"lib/index.d.ts\",\r\n \"scripts\": {\r\n \"build\": \"rimraf lib && tsc\",\r\n \"build:test\": \"rimraf bin && tsc --project test/tsconfig.json\",\r\n \"deploy\": \"npm run build && npm publish\",\r\n \"dev\": \"npm run build:test -- --watch\",\r\n \"prepare\": \"ts-patch install && typia patch\",\r\n \"start\": \"npx ts-node test/start.ts\",\r\n \"test\": \"npx ts-node test/index.ts\",\r\n \"test:simulate\": \"npx ts-node test/index.ts --simulate true\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia\"\r\n },\r\n \"author\": \"Jeongho Nam\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia/issues\"\r\n },\r\n \"homepage\": \"https://nestia.io\",\r\n \"files\": [\r\n \"lib\",\r\n \"swagger.json\",\r\n \"package.json\",\r\n \"README.md\"\r\n ],\r\n \"devDependencies\": {\r\n \"@nestia/e2e\": \"^0.4.1\",\r\n \"@types/inquirer\": \"8.2.5\",\r\n \"commander\": \"^10.0.0\",\r\n \"inquirer\": \"8.2.5\",\r\n \"prettier\": \"^3.2.5\",\r\n \"rimraf\": \"^5.0.5\",\r\n \"ts-node\": \"^10.9.2\",\r\n \"ts-patch\": \"^3.1.2\",\r\n \"typescript\": \"^5.3.3\",\r\n \"typescript-transform-paths\": \"^3.4.6\"\r\n },\r\n \"dependencies\": {\r\n \"@nestia/fetcher\": \"^2.6.
|
25
|
+
"content": "{\r\n \"name\": \"@ORGANIZATION/PROJECT-api\",\r\n \"version\": \"0.1.0\",\r\n \"description\": \"SDK library generated by Nestia\",\r\n \"main\": \"lib/index.js\",\r\n \"typings\": \"lib/index.d.ts\",\r\n \"scripts\": {\r\n \"build\": \"rimraf lib && tsc\",\r\n \"build:test\": \"rimraf bin && tsc --project test/tsconfig.json\",\r\n \"deploy\": \"npm run build && npm publish\",\r\n \"dev\": \"npm run build:test -- --watch\",\r\n \"prepare\": \"ts-patch install && typia patch\",\r\n \"start\": \"npx ts-node test/start.ts\",\r\n \"test\": \"npx ts-node test/index.ts\",\r\n \"test:simulate\": \"npx ts-node test/index.ts --simulate true\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/samchon/nestia\"\r\n },\r\n \"author\": \"Jeongho Nam\",\r\n \"license\": \"MIT\",\r\n \"bugs\": {\r\n \"url\": \"https://github.com/samchon/nestia/issues\"\r\n },\r\n \"homepage\": \"https://nestia.io\",\r\n \"files\": [\r\n \"lib\",\r\n \"swagger.json\",\r\n \"package.json\",\r\n \"README.md\"\r\n ],\r\n \"devDependencies\": {\r\n \"@nestia/e2e\": \"^0.4.1\",\r\n \"@types/inquirer\": \"8.2.5\",\r\n \"commander\": \"^10.0.0\",\r\n \"inquirer\": \"8.2.5\",\r\n \"prettier\": \"^3.2.5\",\r\n \"rimraf\": \"^5.0.5\",\r\n \"ts-node\": \"^10.9.2\",\r\n \"ts-patch\": \"^3.1.2\",\r\n \"typescript\": \"^5.3.3\",\r\n \"typescript-transform-paths\": \"^3.4.6\"\r\n },\r\n \"dependencies\": {\r\n \"@nestia/fetcher\": \"^2.6.3\",\r\n \"typia\": \"^5.5.7\"\r\n }\r\n}"
|
26
26
|
},
|
27
27
|
{
|
28
28
|
"location": "",
|
package/src/executable/bundle.ts
CHANGED
@@ -1,110 +1,110 @@
|
|
1
|
-
import cp from "child_process";
|
2
|
-
import fs from "fs";
|
3
|
-
|
4
|
-
import { IMigrateFile } from "../structures/IMigrateFile";
|
5
|
-
|
6
|
-
const ROOT: string = `${__dirname}/../..`;
|
7
|
-
const ASSETS: string = `${ROOT}/assets`;
|
8
|
-
|
9
|
-
const bundle = async (props: {
|
10
|
-
mode: "nest" | "sdk";
|
11
|
-
repository: string;
|
12
|
-
exceptions?: string[];
|
13
|
-
}): Promise<void> => {
|
14
|
-
const root: string = `${__dirname}/../..`;
|
15
|
-
const assets: string = `${root}/assets`;
|
16
|
-
const template: string = `${assets}/${props.mode}`;
|
17
|
-
|
18
|
-
const clone = async () => {
|
19
|
-
// CLONE REPOSITORY
|
20
|
-
if (fs.existsSync(template))
|
21
|
-
await fs.promises.rm(template, { recursive: true });
|
22
|
-
else
|
23
|
-
try {
|
24
|
-
await fs.promises.mkdir(ASSETS);
|
25
|
-
} catch {}
|
26
|
-
|
27
|
-
cp.execSync(
|
28
|
-
`git clone https://github.com/samchon/${props.repository} ${props.mode}`,
|
29
|
-
{
|
30
|
-
cwd: ASSETS,
|
31
|
-
},
|
32
|
-
);
|
33
|
-
|
34
|
-
// REMOVE VUNLERABLE FILES
|
35
|
-
for (const location of props.exceptions ?? [])
|
36
|
-
await fs.promises.rm(`${template}/${location}`, { recursive: true });
|
37
|
-
};
|
38
|
-
|
39
|
-
const iterate = (collection: IMigrateFile[]) => async (location: string) => {
|
40
|
-
const directory: string[] = await fs.promises.readdir(location);
|
41
|
-
for (const file of directory) {
|
42
|
-
const absolute: string = location + "/" + file;
|
43
|
-
const stats: fs.Stats = await fs.promises.stat(absolute);
|
44
|
-
if (stats.isDirectory()) await iterate(collection)(absolute);
|
45
|
-
else {
|
46
|
-
const content: string = await fs.promises.readFile(absolute, "utf-8");
|
47
|
-
collection.push({
|
48
|
-
location: (() => {
|
49
|
-
const str: string = location.replace(template, "");
|
50
|
-
return str[0] === "/" ? str.substring(1) : str;
|
51
|
-
})(),
|
52
|
-
file,
|
53
|
-
content,
|
54
|
-
});
|
55
|
-
}
|
56
|
-
}
|
57
|
-
};
|
58
|
-
|
59
|
-
const archive = async (collection: IMigrateFile[]): Promise<void> => {
|
60
|
-
const name: string = `${props.mode.toUpperCase()}_TEMPLATE`;
|
61
|
-
const body: string = JSON.stringify(collection, null, 2);
|
62
|
-
const content: string = `export const ${name} = ${body}`;
|
63
|
-
|
64
|
-
try {
|
65
|
-
await fs.promises.mkdir(`${ROOT}/src/bundles`);
|
66
|
-
} catch {}
|
67
|
-
await fs.promises.writeFile(
|
68
|
-
`${ROOT}/src/bundles/${name}.ts`,
|
69
|
-
content,
|
70
|
-
"utf8",
|
71
|
-
);
|
72
|
-
};
|
73
|
-
|
74
|
-
const collection: IMigrateFile[] = [];
|
75
|
-
await clone();
|
76
|
-
await iterate(collection)(template);
|
77
|
-
await archive(collection);
|
78
|
-
};
|
79
|
-
|
80
|
-
const main = async (): Promise<void> => {
|
81
|
-
await bundle({
|
82
|
-
mode: "nest",
|
83
|
-
repository: "nestia-start",
|
84
|
-
exceptions: [
|
85
|
-
".git",
|
86
|
-
".github/dependabot.yml",
|
87
|
-
"src/api/functional",
|
88
|
-
"src/controllers",
|
89
|
-
"src/MyModule.ts",
|
90
|
-
"src/providers",
|
91
|
-
"test/features",
|
92
|
-
],
|
93
|
-
});
|
94
|
-
await bundle({
|
95
|
-
mode: "sdk",
|
96
|
-
repository: "nestia-sdk-template",
|
97
|
-
exceptions: [
|
98
|
-
".git",
|
99
|
-
".github/dependabot.yml",
|
100
|
-
".github/workflows/build.yml",
|
101
|
-
"src/functional",
|
102
|
-
"src/structures",
|
103
|
-
"test/features",
|
104
|
-
],
|
105
|
-
});
|
106
|
-
};
|
107
|
-
main().catch((exp) => {
|
108
|
-
console.error(exp);
|
109
|
-
process.exit(-1);
|
110
|
-
});
|
1
|
+
import cp from "child_process";
|
2
|
+
import fs from "fs";
|
3
|
+
|
4
|
+
import { IMigrateFile } from "../structures/IMigrateFile";
|
5
|
+
|
6
|
+
const ROOT: string = `${__dirname}/../..`;
|
7
|
+
const ASSETS: string = `${ROOT}/assets`;
|
8
|
+
|
9
|
+
const bundle = async (props: {
|
10
|
+
mode: "nest" | "sdk";
|
11
|
+
repository: string;
|
12
|
+
exceptions?: string[];
|
13
|
+
}): Promise<void> => {
|
14
|
+
const root: string = `${__dirname}/../..`;
|
15
|
+
const assets: string = `${root}/assets`;
|
16
|
+
const template: string = `${assets}/${props.mode}`;
|
17
|
+
|
18
|
+
const clone = async () => {
|
19
|
+
// CLONE REPOSITORY
|
20
|
+
if (fs.existsSync(template))
|
21
|
+
await fs.promises.rm(template, { recursive: true });
|
22
|
+
else
|
23
|
+
try {
|
24
|
+
await fs.promises.mkdir(ASSETS);
|
25
|
+
} catch {}
|
26
|
+
|
27
|
+
cp.execSync(
|
28
|
+
`git clone https://github.com/samchon/${props.repository} ${props.mode}`,
|
29
|
+
{
|
30
|
+
cwd: ASSETS,
|
31
|
+
},
|
32
|
+
);
|
33
|
+
|
34
|
+
// REMOVE VUNLERABLE FILES
|
35
|
+
for (const location of props.exceptions ?? [])
|
36
|
+
await fs.promises.rm(`${template}/${location}`, { recursive: true });
|
37
|
+
};
|
38
|
+
|
39
|
+
const iterate = (collection: IMigrateFile[]) => async (location: string) => {
|
40
|
+
const directory: string[] = await fs.promises.readdir(location);
|
41
|
+
for (const file of directory) {
|
42
|
+
const absolute: string = location + "/" + file;
|
43
|
+
const stats: fs.Stats = await fs.promises.stat(absolute);
|
44
|
+
if (stats.isDirectory()) await iterate(collection)(absolute);
|
45
|
+
else {
|
46
|
+
const content: string = await fs.promises.readFile(absolute, "utf-8");
|
47
|
+
collection.push({
|
48
|
+
location: (() => {
|
49
|
+
const str: string = location.replace(template, "");
|
50
|
+
return str[0] === "/" ? str.substring(1) : str;
|
51
|
+
})(),
|
52
|
+
file,
|
53
|
+
content,
|
54
|
+
});
|
55
|
+
}
|
56
|
+
}
|
57
|
+
};
|
58
|
+
|
59
|
+
const archive = async (collection: IMigrateFile[]): Promise<void> => {
|
60
|
+
const name: string = `${props.mode.toUpperCase()}_TEMPLATE`;
|
61
|
+
const body: string = JSON.stringify(collection, null, 2);
|
62
|
+
const content: string = `export const ${name} = ${body}`;
|
63
|
+
|
64
|
+
try {
|
65
|
+
await fs.promises.mkdir(`${ROOT}/src/bundles`);
|
66
|
+
} catch {}
|
67
|
+
await fs.promises.writeFile(
|
68
|
+
`${ROOT}/src/bundles/${name}.ts`,
|
69
|
+
content,
|
70
|
+
"utf8",
|
71
|
+
);
|
72
|
+
};
|
73
|
+
|
74
|
+
const collection: IMigrateFile[] = [];
|
75
|
+
await clone();
|
76
|
+
await iterate(collection)(template);
|
77
|
+
await archive(collection);
|
78
|
+
};
|
79
|
+
|
80
|
+
const main = async (): Promise<void> => {
|
81
|
+
await bundle({
|
82
|
+
mode: "nest",
|
83
|
+
repository: "nestia-start",
|
84
|
+
exceptions: [
|
85
|
+
".git",
|
86
|
+
".github/dependabot.yml",
|
87
|
+
"src/api/functional",
|
88
|
+
"src/controllers",
|
89
|
+
"src/MyModule.ts",
|
90
|
+
"src/providers",
|
91
|
+
"test/features",
|
92
|
+
],
|
93
|
+
});
|
94
|
+
await bundle({
|
95
|
+
mode: "sdk",
|
96
|
+
repository: "nestia-sdk-template",
|
97
|
+
exceptions: [
|
98
|
+
".git",
|
99
|
+
".github/dependabot.yml",
|
100
|
+
".github/workflows/build.yml",
|
101
|
+
"src/functional",
|
102
|
+
"src/structures",
|
103
|
+
"test/features",
|
104
|
+
],
|
105
|
+
});
|
106
|
+
};
|
107
|
+
main().catch((exp) => {
|
108
|
+
console.error(exp);
|
109
|
+
process.exit(-1);
|
110
|
+
});
|
@@ -1,70 +1,70 @@
|
|
1
|
-
import fs from "fs";
|
2
|
-
import path from "path";
|
3
|
-
import { format } from "prettier";
|
4
|
-
import { IValidation } from "typia";
|
5
|
-
|
6
|
-
import { MigrateApplication } from "../MigrateApplication";
|
7
|
-
import { MigrateFileArchiver } from "../archivers/MigrateFileArchiver";
|
8
|
-
import { ISwagger } from "../structures/ISwagger";
|
9
|
-
import { MigrateInquirer } from "./MigrateInquirer";
|
10
|
-
|
11
|
-
export namespace MigrateCommander {
|
12
|
-
export const main = async (): Promise<void> => {
|
13
|
-
const resolve = (str: string | undefined) =>
|
14
|
-
str ? path.resolve(str).split("\\").join("/") : undefined;
|
15
|
-
const options: MigrateInquirer.IOutput = await MigrateInquirer.parse();
|
16
|
-
|
17
|
-
// VALIDATE OUTPUT DIRECTORY
|
18
|
-
const parent: string = resolve(options.output + "/..")!;
|
19
|
-
if (fs.existsSync(options.output)) halt("Output directory alreay exists.");
|
20
|
-
else if (fs.existsSync(parent) === false)
|
21
|
-
halt("Output directory's parent directory does not exist.");
|
22
|
-
else if (fs.statSync(parent).isDirectory() === false)
|
23
|
-
halt("Output directory's parent is not a directory.");
|
24
|
-
|
25
|
-
// READ SWAGGER
|
26
|
-
const swagger: ISwagger = (() => {
|
27
|
-
if (fs.existsSync(options.input) === false)
|
28
|
-
halt("Unable to find the input swagger.json file.");
|
29
|
-
const stats: fs.Stats = fs.statSync(options.input);
|
30
|
-
if (stats.isFile() === false)
|
31
|
-
halt("The input swagger.json is not a file.");
|
32
|
-
const content: string = fs.readFileSync(options.input, "utf-8");
|
33
|
-
const swagger: ISwagger = JSON.parse(content);
|
34
|
-
return swagger;
|
35
|
-
})();
|
36
|
-
|
37
|
-
const result: IValidation<MigrateApplication> =
|
38
|
-
await MigrateApplication.create(swagger);
|
39
|
-
if (result.success === false) {
|
40
|
-
console.log(result.errors);
|
41
|
-
throw new Error(
|
42
|
-
`Invalid swagger file (must follow the OpenAPI 3.0 spec).`,
|
43
|
-
);
|
44
|
-
}
|
45
|
-
|
46
|
-
const app: MigrateApplication = result.data;
|
47
|
-
const { files } =
|
48
|
-
options.mode === "nest" ? app.nest(options) : app.sdk(options);
|
49
|
-
await MigrateFileArchiver.archive({
|
50
|
-
mkdir: fs.promises.mkdir,
|
51
|
-
writeFile: async (file, content) =>
|
52
|
-
fs.promises.writeFile(file, await beautify(content), "utf-8"),
|
53
|
-
})(options.output)(files);
|
54
|
-
};
|
55
|
-
|
56
|
-
const beautify = async (script: string): Promise<string> => {
|
57
|
-
try {
|
58
|
-
return await format(script, {
|
59
|
-
parser: "typescript",
|
60
|
-
});
|
61
|
-
} catch {
|
62
|
-
return script;
|
63
|
-
}
|
64
|
-
};
|
65
|
-
|
66
|
-
const halt = (desc: string): never => {
|
67
|
-
console.error(desc);
|
68
|
-
process.exit(-1);
|
69
|
-
};
|
70
|
-
}
|
1
|
+
import fs from "fs";
|
2
|
+
import path from "path";
|
3
|
+
import { format } from "prettier";
|
4
|
+
import { IValidation } from "typia";
|
5
|
+
|
6
|
+
import { MigrateApplication } from "../MigrateApplication";
|
7
|
+
import { MigrateFileArchiver } from "../archivers/MigrateFileArchiver";
|
8
|
+
import { ISwagger } from "../structures/ISwagger";
|
9
|
+
import { MigrateInquirer } from "./MigrateInquirer";
|
10
|
+
|
11
|
+
export namespace MigrateCommander {
|
12
|
+
export const main = async (): Promise<void> => {
|
13
|
+
const resolve = (str: string | undefined) =>
|
14
|
+
str ? path.resolve(str).split("\\").join("/") : undefined;
|
15
|
+
const options: MigrateInquirer.IOutput = await MigrateInquirer.parse();
|
16
|
+
|
17
|
+
// VALIDATE OUTPUT DIRECTORY
|
18
|
+
const parent: string = resolve(options.output + "/..")!;
|
19
|
+
if (fs.existsSync(options.output)) halt("Output directory alreay exists.");
|
20
|
+
else if (fs.existsSync(parent) === false)
|
21
|
+
halt("Output directory's parent directory does not exist.");
|
22
|
+
else if (fs.statSync(parent).isDirectory() === false)
|
23
|
+
halt("Output directory's parent is not a directory.");
|
24
|
+
|
25
|
+
// READ SWAGGER
|
26
|
+
const swagger: ISwagger = (() => {
|
27
|
+
if (fs.existsSync(options.input) === false)
|
28
|
+
halt("Unable to find the input swagger.json file.");
|
29
|
+
const stats: fs.Stats = fs.statSync(options.input);
|
30
|
+
if (stats.isFile() === false)
|
31
|
+
halt("The input swagger.json is not a file.");
|
32
|
+
const content: string = fs.readFileSync(options.input, "utf-8");
|
33
|
+
const swagger: ISwagger = JSON.parse(content);
|
34
|
+
return swagger;
|
35
|
+
})();
|
36
|
+
|
37
|
+
const result: IValidation<MigrateApplication> =
|
38
|
+
await MigrateApplication.create(swagger);
|
39
|
+
if (result.success === false) {
|
40
|
+
console.log(result.errors);
|
41
|
+
throw new Error(
|
42
|
+
`Invalid swagger file (must follow the OpenAPI 3.0 spec).`,
|
43
|
+
);
|
44
|
+
}
|
45
|
+
|
46
|
+
const app: MigrateApplication = result.data;
|
47
|
+
const { files } =
|
48
|
+
options.mode === "nest" ? app.nest(options) : app.sdk(options);
|
49
|
+
await MigrateFileArchiver.archive({
|
50
|
+
mkdir: fs.promises.mkdir,
|
51
|
+
writeFile: async (file, content) =>
|
52
|
+
fs.promises.writeFile(file, await beautify(content), "utf-8"),
|
53
|
+
})(options.output)(files);
|
54
|
+
};
|
55
|
+
|
56
|
+
const beautify = async (script: string): Promise<string> => {
|
57
|
+
try {
|
58
|
+
return await format(script, {
|
59
|
+
parser: "typescript",
|
60
|
+
});
|
61
|
+
} catch {
|
62
|
+
return script;
|
63
|
+
}
|
64
|
+
};
|
65
|
+
|
66
|
+
const halt = (desc: string): never => {
|
67
|
+
console.error(desc);
|
68
|
+
process.exit(-1);
|
69
|
+
};
|
70
|
+
}
|