@nestia/sdk 2.4.7 → 2.5.0-dev.20240128

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.
Files changed (34) hide show
  1. package/lib/generates/internal/SdkFileProgrammer.js +23 -10
  2. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  3. package/lib/generates/internal/SdkFunctionProgrammer.d.ts +6 -1
  4. package/lib/generates/internal/SdkFunctionProgrammer.js +73 -323
  5. package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -1
  6. package/lib/generates/internal/SdkNamespaceProgrammer.d.ts +11 -0
  7. package/lib/generates/internal/SdkNamespaceProgrammer.js +175 -0
  8. package/lib/generates/internal/SdkNamespaceProgrammer.js.map +1 -0
  9. package/lib/generates/internal/SdkRouteProgrammer.d.ts +7 -0
  10. package/lib/generates/internal/SdkRouteProgrammer.js +55 -0
  11. package/lib/generates/internal/SdkRouteProgrammer.js.map +1 -0
  12. package/lib/generates/internal/SdkSimulationProgrammer.d.ts +7 -1
  13. package/lib/generates/internal/SdkSimulationProgrammer.js +98 -88
  14. package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
  15. package/lib/utils/ImportDictionary.d.ts +2 -0
  16. package/lib/utils/ImportDictionary.js +45 -0
  17. package/lib/utils/ImportDictionary.js.map +1 -1
  18. package/lib/utils/NodeUtil.d.ts +5 -0
  19. package/lib/utils/NodeUtil.js +16 -0
  20. package/lib/utils/NodeUtil.js.map +1 -0
  21. package/package.json +6 -3
  22. package/src/analyses/ConfigAnalyzer.ts +147 -147
  23. package/src/analyses/ControllerAnalyzer.ts +390 -390
  24. package/src/analyses/PathAnalyzer.ts +110 -110
  25. package/src/analyses/ReflectAnalyzer.ts +464 -464
  26. package/src/generates/SwaggerGenerator.ts +376 -376
  27. package/src/generates/internal/SdkFileProgrammer.ts +42 -13
  28. package/src/generates/internal/SdkFunctionProgrammer.ts +176 -475
  29. package/src/generates/internal/SdkNamespaceProgrammer.ts +495 -0
  30. package/src/generates/internal/SdkRouteProgrammer.ts +82 -0
  31. package/src/generates/internal/SdkSimulationProgrammer.ts +359 -133
  32. package/src/generates/internal/SwaggerSchemaGenerator.ts +444 -444
  33. package/src/utils/ImportDictionary.ts +72 -0
  34. package/src/utils/NodeUtil.ts +19 -0
@@ -1,11 +1,14 @@
1
1
  import fs from "fs";
2
+ import { format } from "prettier";
3
+ import ts from "typescript";
2
4
 
3
5
  import { INestiaConfig } from "../../INestiaConfig";
4
6
  import { IRoute } from "../../structures/IRoute";
5
7
  import { ImportDictionary } from "../../utils/ImportDictionary";
6
8
  import { MapUtil } from "../../utils/MapUtil";
7
- import { SdkFunctionProgrammer } from "./SdkFunctionProgrammer";
9
+ import { NodeUtil } from "../../utils/NodeUtil";
8
10
  import { SdkRouteDirectory } from "./SdkRouteDirectory";
11
+ import { SdkRouteProgrammer } from "./SdkRouteProgrammer";
9
12
 
10
13
  export namespace SdkFileProgrammer {
11
14
  /* ---------------------------------------------------------
@@ -51,12 +54,21 @@ export namespace SdkFileProgrammer {
51
54
  } catch {}
52
55
 
53
56
  // ITERATE CHILDREN
54
- const content: string[] = [];
57
+ const statements: ts.Statement[] = [];
55
58
  for (const [key, value] of directory.children) {
56
59
  await iterate(config)(value)(`${outDir}/${key}`);
57
- content.push(`export * as ${key} from "./${key}";`);
60
+ statements.push(
61
+ ts.factory.createExportDeclaration(
62
+ undefined,
63
+ false,
64
+ ts.factory.createNamespaceExport(ts.factory.createIdentifier(key)),
65
+ ts.factory.createStringLiteral(`./${key}`),
66
+ undefined,
67
+ ),
68
+ );
58
69
  }
59
- if (content.length && directory.routes.length) content.push("");
70
+ if (statements.length && directory.routes.length)
71
+ statements.push(NodeUtil.enter());
60
72
 
61
73
  // ITERATE ROUTES
62
74
  const importer: ImportDictionary = new ImportDictionary(
@@ -80,17 +92,19 @@ export namespace SdkFileProgrammer {
80
92
  instance,
81
93
  type: true,
82
94
  });
83
-
84
- content.push(SdkFunctionProgrammer.generate(config)(importer)(route));
85
- if (i !== directory.routes.length - 1) content.push("");
95
+ statements.push(
96
+ ...SdkRouteProgrammer.generate(config)(importer)(route),
97
+ );
98
+ if (i !== directory.routes.length - 1)
99
+ statements.push(NodeUtil.enter());
86
100
  });
87
101
 
88
102
  // FINALIZE THE CONTENT
89
103
  if (directory.routes.length !== 0)
90
- content.push(
91
- importer.toScript(outDir),
92
- "",
93
- ...content.splice(0, content.length),
104
+ statements.push(
105
+ ...importer.toStatements(outDir),
106
+ ...(!importer.empty() && statements.length ? [NodeUtil.enter()] : []),
107
+ ...statements.splice(0, statements.length),
94
108
  );
95
109
 
96
110
  const script: string =
@@ -100,7 +114,22 @@ export namespace SdkFileProgrammer {
100
114
  " * @nestia Generated by Nestia - https://github.com/samchon/nestia \n" +
101
115
  " */\n" +
102
116
  "//================================================================\n" +
103
- content.join("\n");
104
- await fs.promises.writeFile(importer.file, script, "utf8");
117
+ ts
118
+ .createPrinter()
119
+ .printFile(
120
+ ts.factory.createSourceFile(
121
+ statements,
122
+ ts.factory.createToken(ts.SyntaxKind.EndOfFileToken),
123
+ ts.NodeFlags.None,
124
+ ),
125
+ );
126
+ const beautify = async () => {
127
+ try {
128
+ return await format(script, { parser: "typescript" });
129
+ } catch {
130
+ return script;
131
+ }
132
+ };
133
+ await fs.promises.writeFile(importer.file, await beautify(), "utf8");
105
134
  };
106
135
  }