@nestia/migrate 11.0.0-dev.20260313-4 → 11.0.0-dev.20260314

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.
@@ -1,65 +1,65 @@
1
- import ts from "typescript";
2
-
3
- import { INestiaMigrateController } from "../structures/INestiaMigrateController";
4
- import { FilePrinter } from "../utils/FilePrinter";
5
-
6
- export namespace NestiaMigrateNestModuleProgrammer {
7
- export const write = (
8
- controllers: INestiaMigrateController[],
9
- ): ts.Statement[] => [
10
- $import("@nestjs/common")("Module"),
11
- ...(controllers.length ? [FilePrinter.newLine()] : []),
12
- ...controllers.map((c) =>
13
- $import(`${c.location.replace("src/", "./")}/${c.name}`)(c.name),
14
- ),
15
- ...(controllers.length ? [FilePrinter.newLine()] : []),
16
- ts.factory.createClassDeclaration(
17
- [
18
- ts.factory.createDecorator(
19
- ts.factory.createCallExpression(
20
- ts.factory.createIdentifier("Module"),
21
- undefined,
22
- [
23
- ts.factory.createObjectLiteralExpression(
24
- [
25
- ts.factory.createPropertyAssignment(
26
- ts.factory.createIdentifier("controllers"),
27
- ts.factory.createArrayLiteralExpression(
28
- controllers.map((c) =>
29
- ts.factory.createIdentifier(c.name),
30
- ),
31
- true,
32
- ),
33
- ),
34
- ],
35
- true,
36
- ),
37
- ],
38
- ),
39
- ),
40
- ts.factory.createToken(ts.SyntaxKind.ExportKeyword),
41
- ],
42
- "MyModule",
43
- undefined,
44
- undefined,
45
- [],
46
- ),
47
- ];
48
- }
49
-
50
- const $import = (file: string) => (instance: string) =>
51
- ts.factory.createImportDeclaration(
52
- undefined,
53
- ts.factory.createImportClause(
54
- false,
55
- undefined,
56
- ts.factory.createNamedImports([
57
- ts.factory.createImportSpecifier(
58
- false,
59
- undefined,
60
- ts.factory.createIdentifier(instance),
61
- ),
62
- ]),
63
- ),
64
- ts.factory.createStringLiteral(file),
65
- );
1
+ import ts from "typescript";
2
+
3
+ import { INestiaMigrateController } from "../structures/INestiaMigrateController";
4
+ import { FilePrinter } from "../utils/FilePrinter";
5
+
6
+ export namespace NestiaMigrateNestModuleProgrammer {
7
+ export const write = (
8
+ controllers: INestiaMigrateController[],
9
+ ): ts.Statement[] => [
10
+ $import("@nestjs/common")("Module"),
11
+ ...(controllers.length ? [FilePrinter.newLine()] : []),
12
+ ...controllers.map((c) =>
13
+ $import(`${c.location.replace("src/", "./")}/${c.name}`)(c.name),
14
+ ),
15
+ ...(controllers.length ? [FilePrinter.newLine()] : []),
16
+ ts.factory.createClassDeclaration(
17
+ [
18
+ ts.factory.createDecorator(
19
+ ts.factory.createCallExpression(
20
+ ts.factory.createIdentifier("Module"),
21
+ undefined,
22
+ [
23
+ ts.factory.createObjectLiteralExpression(
24
+ [
25
+ ts.factory.createPropertyAssignment(
26
+ ts.factory.createIdentifier("controllers"),
27
+ ts.factory.createArrayLiteralExpression(
28
+ controllers.map((c) =>
29
+ ts.factory.createIdentifier(c.name),
30
+ ),
31
+ true,
32
+ ),
33
+ ),
34
+ ],
35
+ true,
36
+ ),
37
+ ],
38
+ ),
39
+ ),
40
+ ts.factory.createToken(ts.SyntaxKind.ExportKeyword),
41
+ ],
42
+ "MyModule",
43
+ undefined,
44
+ undefined,
45
+ [],
46
+ ),
47
+ ];
48
+ }
49
+
50
+ const $import = (file: string) => (instance: string) =>
51
+ ts.factory.createImportDeclaration(
52
+ undefined,
53
+ ts.factory.createImportClause(
54
+ false,
55
+ undefined,
56
+ ts.factory.createNamedImports([
57
+ ts.factory.createImportSpecifier(
58
+ false,
59
+ undefined,
60
+ ts.factory.createIdentifier(instance),
61
+ ),
62
+ ]),
63
+ ),
64
+ ts.factory.createStringLiteral(file),
65
+ );
@@ -1,88 +1,88 @@
1
- import ts from "typescript";
2
-
3
- import { NestiaMigrateControllerAnalyzer } from "../analyzers/NestiaMigrateControllerAnalyzer";
4
- import { INestiaMigrateContext } from "../structures/INestiaMigrateContext";
5
- import { INestiaMigrateController } from "../structures/INestiaMigrateController";
6
- import { FilePrinter } from "../utils/FilePrinter";
7
- import { NestiaMigrateDtoProgrammer } from "./NestiaMigrateDtoProgrammer";
8
- import { NestiaMigrateImportProgrammer } from "./NestiaMigrateImportProgrammer";
9
- import { NestiaMigrateNestControllerProgrammer } from "./NestiaMigrateNestControllerProgrammer";
10
- import { NestiaMigrateNestModuleProgrammer } from "./NestiaMigrateNestModuleProgrammer";
11
-
12
- export namespace NestiaMigrateNestProgrammer {
13
- export const write = (
14
- context: INestiaMigrateContext,
15
- ): Record<string, string> => {
16
- const controllers: INestiaMigrateController[] =
17
- NestiaMigrateControllerAnalyzer.analyze(context.application.routes);
18
- const statements: [string, ts.Statement[]][] = [
19
- ["src/MyModule.ts", NestiaMigrateNestModuleProgrammer.write(controllers)],
20
- ...controllers.map(
21
- (c) =>
22
- [
23
- `${c.location}/${c.name}.ts`,
24
- NestiaMigrateNestControllerProgrammer.write({
25
- config: context.config,
26
- components: context.application.document().components,
27
- controller: c,
28
- }),
29
- ] satisfies [string, ts.Statement[]],
30
- ),
31
- ...[
32
- ...NestiaMigrateDtoProgrammer.compose({
33
- config: context.config,
34
- components: context.application.document().components,
35
- }).entries(),
36
- ].map(
37
- ([key, value]) =>
38
- [`src/api/structures/${key}.ts`, writeDtoFile(key, value)] satisfies [
39
- string,
40
- ts.Statement[],
41
- ],
42
- ),
43
- ];
44
- return Object.fromEntries(
45
- statements.map(([key, value]) => [
46
- key,
47
- FilePrinter.write({ statements: value }),
48
- ]),
49
- );
50
- };
51
-
52
- const writeDtoFile = (
53
- key: string,
54
- modulo: NestiaMigrateDtoProgrammer.IModule,
55
- ): ts.Statement[] => {
56
- const importer = new NestiaMigrateImportProgrammer();
57
- const statements: ts.Statement[] = iterate(importer)(modulo);
58
- if (statements.length === 0) return [];
59
-
60
- return [
61
- ...importer.toStatements((name) => `./${name}`, key),
62
- ...(importer.empty() ? [] : [FilePrinter.newLine()]),
63
- ...statements,
64
- ];
65
- };
66
-
67
- const iterate =
68
- (importer: NestiaMigrateImportProgrammer) =>
69
- (modulo: NestiaMigrateDtoProgrammer.IModule): ts.Statement[] => {
70
- const output: ts.Statement[] = [];
71
- if (modulo.programmer !== null) output.push(modulo.programmer(importer));
72
- if (modulo.children.size) {
73
- const internal: ts.Statement[] = [];
74
- for (const child of modulo.children.values())
75
- internal.push(...iterate(importer)(child));
76
- output.push(
77
- ts.factory.createModuleDeclaration(
78
- [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
79
- ts.factory.createIdentifier(modulo.name),
80
- ts.factory.createModuleBlock(internal),
81
- ts.NodeFlags.Namespace,
82
- ),
83
- );
84
- }
85
- output.push(FilePrinter.newLine());
86
- return output;
87
- };
88
- }
1
+ import ts from "typescript";
2
+
3
+ import { NestiaMigrateControllerAnalyzer } from "../analyzers/NestiaMigrateControllerAnalyzer";
4
+ import { INestiaMigrateContext } from "../structures/INestiaMigrateContext";
5
+ import { INestiaMigrateController } from "../structures/INestiaMigrateController";
6
+ import { FilePrinter } from "../utils/FilePrinter";
7
+ import { NestiaMigrateDtoProgrammer } from "./NestiaMigrateDtoProgrammer";
8
+ import { NestiaMigrateImportProgrammer } from "./NestiaMigrateImportProgrammer";
9
+ import { NestiaMigrateNestControllerProgrammer } from "./NestiaMigrateNestControllerProgrammer";
10
+ import { NestiaMigrateNestModuleProgrammer } from "./NestiaMigrateNestModuleProgrammer";
11
+
12
+ export namespace NestiaMigrateNestProgrammer {
13
+ export const write = (
14
+ context: INestiaMigrateContext,
15
+ ): Record<string, string> => {
16
+ const controllers: INestiaMigrateController[] =
17
+ NestiaMigrateControllerAnalyzer.analyze(context.application.routes);
18
+ const statements: [string, ts.Statement[]][] = [
19
+ ["src/MyModule.ts", NestiaMigrateNestModuleProgrammer.write(controllers)],
20
+ ...controllers.map(
21
+ (c) =>
22
+ [
23
+ `${c.location}/${c.name}.ts`,
24
+ NestiaMigrateNestControllerProgrammer.write({
25
+ config: context.config,
26
+ components: context.application.document().components,
27
+ controller: c,
28
+ }),
29
+ ] satisfies [string, ts.Statement[]],
30
+ ),
31
+ ...[
32
+ ...NestiaMigrateDtoProgrammer.compose({
33
+ config: context.config,
34
+ components: context.application.document().components,
35
+ }).entries(),
36
+ ].map(
37
+ ([key, value]) =>
38
+ [`src/api/structures/${key}.ts`, writeDtoFile(key, value)] satisfies [
39
+ string,
40
+ ts.Statement[],
41
+ ],
42
+ ),
43
+ ];
44
+ return Object.fromEntries(
45
+ statements.map(([key, value]) => [
46
+ key,
47
+ FilePrinter.write({ statements: value }),
48
+ ]),
49
+ );
50
+ };
51
+
52
+ const writeDtoFile = (
53
+ key: string,
54
+ modulo: NestiaMigrateDtoProgrammer.IModule,
55
+ ): ts.Statement[] => {
56
+ const importer = new NestiaMigrateImportProgrammer();
57
+ const statements: ts.Statement[] = iterate(importer)(modulo);
58
+ if (statements.length === 0) return [];
59
+
60
+ return [
61
+ ...importer.toStatements((name) => `./${name}`, key),
62
+ ...(importer.empty() ? [] : [FilePrinter.newLine()]),
63
+ ...statements,
64
+ ];
65
+ };
66
+
67
+ const iterate =
68
+ (importer: NestiaMigrateImportProgrammer) =>
69
+ (modulo: NestiaMigrateDtoProgrammer.IModule): ts.Statement[] => {
70
+ const output: ts.Statement[] = [];
71
+ if (modulo.programmer !== null) output.push(modulo.programmer(importer));
72
+ if (modulo.children.size) {
73
+ const internal: ts.Statement[] = [];
74
+ for (const child of modulo.children.values())
75
+ internal.push(...iterate(importer)(child));
76
+ output.push(
77
+ ts.factory.createModuleDeclaration(
78
+ [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
79
+ ts.factory.createIdentifier(modulo.name),
80
+ ts.factory.createModuleBlock(internal),
81
+ ts.NodeFlags.Namespace,
82
+ ),
83
+ );
84
+ }
85
+ output.push(FilePrinter.newLine());
86
+ return output;
87
+ };
88
+ }
@@ -1,19 +1,19 @@
1
- import ts from "typescript";
2
-
3
- import { NestiaMigrateNestMethodProgrammer } from "../programmers/NestiaMigrateNestMethodProgrammer";
4
-
5
- export interface INestiaMigrateConfig {
6
- simulate: boolean;
7
- e2e: boolean;
8
- package?: string;
9
- keyword?: boolean;
10
- author?: {
11
- tag: string;
12
- value: string;
13
- };
14
- programmer?: {
15
- controllerMethod?: (
16
- ctx: NestiaMigrateNestMethodProgrammer.IContext,
17
- ) => ts.MethodDeclaration;
18
- };
19
- }
1
+ import ts from "typescript";
2
+
3
+ import { NestiaMigrateNestMethodProgrammer } from "../programmers/NestiaMigrateNestMethodProgrammer";
4
+
5
+ export interface INestiaMigrateConfig {
6
+ simulate: boolean;
7
+ e2e: boolean;
8
+ package?: string;
9
+ keyword?: boolean;
10
+ author?: {
11
+ tag: string;
12
+ value: string;
13
+ };
14
+ programmer?: {
15
+ controllerMethod?: (
16
+ ctx: NestiaMigrateNestMethodProgrammer.IContext,
17
+ ) => ts.MethodDeclaration;
18
+ };
19
+ }
@@ -1,5 +1,5 @@
1
- export interface INestiaMigrateFile {
2
- location: string;
3
- file: string;
4
- content: string;
5
- }
1
+ export interface INestiaMigrateFile {
2
+ location: string;
3
+ file: string;
4
+ content: string;
5
+ }
@@ -1,4 +1,4 @@
1
- export interface INestiaMigrateSchema {
2
- name: string;
3
- children: INestiaMigrateSchema[];
4
- }
1
+ export interface INestiaMigrateSchema {
2
+ name: string;
3
+ children: INestiaMigrateSchema[];
4
+ }
@@ -1,13 +1,13 @@
1
- export namespace MapUtil {
2
- export const take =
3
- <Key, T>(dict: Map<Key, T>) =>
4
- (key: Key) =>
5
- (generator: () => T): T => {
6
- const oldbie: T | undefined = dict.get(key);
7
- if (oldbie) return oldbie;
8
-
9
- const value: T = generator();
10
- dict.set(key, value);
11
- return value;
12
- };
13
- }
1
+ export namespace MapUtil {
2
+ export const take =
3
+ <Key, T>(dict: Map<Key, T>) =>
4
+ (key: Key) =>
5
+ (generator: () => T): T => {
6
+ const oldbie: T | undefined = dict.get(key);
7
+ if (oldbie) return oldbie;
8
+
9
+ const value: T = generator();
10
+ dict.set(key, value);
11
+ return value;
12
+ };
13
+ }
@@ -1,12 +1,12 @@
1
- import cp from "child_process";
2
-
3
- export namespace SetupWizard {
4
- export const setup = (output: string) => {
5
- execute(output)("npm install");
6
- };
7
-
8
- const execute = (cwd: string) => (command: string, fake?: string) => {
9
- console.log(fake ?? command);
10
- cp.execSync(command, { cwd, stdio: "inherit" });
11
- };
12
- }
1
+ import cp from "child_process";
2
+
3
+ export namespace SetupWizard {
4
+ export const setup = (output: string) => {
5
+ execute(output)("npm install");
6
+ };
7
+
8
+ const execute = (cwd: string) => (command: string, fake?: string) => {
9
+ console.log(fake ?? command);
10
+ cp.execSync(command, { cwd, stdio: "inherit" });
11
+ };
12
+ }