@nestia/sdk 2.2.4 → 2.3.0-dev.20231017

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 (45) hide show
  1. package/lib/INestiaConfig.d.ts +8 -2
  2. package/lib/NestiaSdkApplication.js +4 -4
  3. package/lib/NestiaSdkApplication.js.map +1 -1
  4. package/lib/analyses/ConfigAnalyzer.d.ts +4 -0
  5. package/lib/analyses/ConfigAnalyzer.js +74 -0
  6. package/lib/analyses/ConfigAnalyzer.js.map +1 -0
  7. package/lib/analyses/ControllerAnalyzer.js +34 -8
  8. package/lib/analyses/ControllerAnalyzer.js.map +1 -1
  9. package/lib/analyses/PathAnalyzer.d.ts +7 -1
  10. package/lib/analyses/PathAnalyzer.js +16 -2
  11. package/lib/analyses/PathAnalyzer.js.map +1 -1
  12. package/lib/analyses/ReflectAnalyzer.js +17 -4
  13. package/lib/analyses/ReflectAnalyzer.js.map +1 -1
  14. package/lib/executable/internal/NestiaConfigLoader.d.ts +2 -2
  15. package/lib/executable/internal/NestiaConfigLoader.js +9 -9
  16. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  17. package/lib/executable/internal/NestiaProjectGetter.d.ts +1 -1
  18. package/lib/executable/internal/NestiaProjectGetter.js +2 -2
  19. package/lib/executable/internal/NestiaProjectGetter.js.map +1 -1
  20. package/lib/executable/internal/NestiaSdkCommand.js +18 -2
  21. package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
  22. package/lib/executable/sdk.js +3 -3
  23. package/lib/generates/E2eGenerator.js +2 -2
  24. package/lib/generates/E2eGenerator.js.map +1 -1
  25. package/lib/structures/IController.d.ts +2 -0
  26. package/lib/utils/SourceFinder.js +7 -0
  27. package/lib/utils/SourceFinder.js.map +1 -1
  28. package/package.json +5 -4
  29. package/src/INestiaConfig.ts +38 -2
  30. package/src/NestiaSdkApplication.ts +4 -6
  31. package/src/analyses/ConfigAnalyzer.ts +73 -0
  32. package/src/analyses/ControllerAnalyzer.ts +38 -19
  33. package/src/analyses/PathAnalyzer.ts +25 -2
  34. package/src/analyses/ReflectAnalyzer.ts +25 -8
  35. package/src/executable/internal/NestiaConfigLoader.ts +7 -6
  36. package/src/executable/internal/NestiaProjectGetter.ts +2 -2
  37. package/src/executable/internal/NestiaSdkCommand.ts +18 -1
  38. package/src/executable/sdk.ts +3 -3
  39. package/src/generates/E2eGenerator.ts +2 -2
  40. package/src/structures/IController.ts +2 -0
  41. package/src/utils/SourceFinder.ts +9 -0
  42. package/lib/utils/NestiaConfigUtil.d.ts +0 -4
  43. package/lib/utils/NestiaConfigUtil.js +0 -24
  44. package/lib/utils/NestiaConfigUtil.js.map +0 -1
  45. package/src/utils/NestiaConfigUtil.ts +0 -21
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.E2eGenerator = void 0;
16
16
  const fs_1 = __importDefault(require("fs"));
17
17
  const path_1 = __importDefault(require("path"));
18
- const NestiaConfigUtil_1 = require("../utils/NestiaConfigUtil");
18
+ const ConfigAnalyzer_1 = require("../analyses/ConfigAnalyzer");
19
19
  const E2eFileProgrammer_1 = require("./internal/E2eFileProgrammer");
20
20
  var E2eGenerator;
21
21
  (function (E2eGenerator) {
@@ -41,7 +41,7 @@ var E2eGenerator;
41
41
  return;
42
42
  const location = path_1.default.join(__dirname, "..", "..", "assets", "bundle", "e2e", "index.ts");
43
43
  const content = yield fs_1.default.promises.readFile(location, "utf8");
44
- yield fs_1.default.promises.writeFile(output, content.replace("${input}", JSON.stringify(NestiaConfigUtil_1.NestiaConfigUtil.input(config.input))), "utf8");
44
+ yield fs_1.default.promises.writeFile(output, content.replace("${input}", JSON.stringify(yield ConfigAnalyzer_1.ConfigAnalyzer.input(config.input))), "utf8");
45
45
  });
46
46
  })(E2eGenerator || (exports.E2eGenerator = E2eGenerator = {}));
47
47
  const mkdir = (location) => __awaiter(void 0, void 0, void 0, function* () {
@@ -1 +1 @@
1
- {"version":3,"file":"E2eGener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AO,CACX,UAAU,EACV,IAAI,CAAC,SAAS,CAAC,MAAM,+BAAc,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAC3D,EACD,MAAM,CACT,CAAC;IACN,CAAC,CAAA,CAAC;AACV,CAAC,EApDgB,YAAY,4BAAZ,YAAY,QAoD5B;AAED,MAAM,KAAK,GAAG,CAAO,QAAgB,EAAiB,EAAE;IACpD,IAAI;QACA,MAAM,YAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;KACrC;IAAC,WAAM,GAAE;AACd,CAAC,CAAA,CAAC"}
@@ -3,6 +3,7 @@ export interface IController {
3
3
  file: string;
4
4
  name: string;
5
5
  paths: string[];
6
+ versions: Array<string | null>;
6
7
  functions: IController.IFunction[];
7
8
  security: Record<string, string[]>[];
8
9
  swaggerTgas: string[];
@@ -12,6 +13,7 @@ export declare namespace IController {
12
13
  name: string;
13
14
  method: string;
14
15
  paths: string[];
16
+ versions: Array<string | null>;
15
17
  encrypted: boolean;
16
18
  parameters: IParameter[];
17
19
  status?: number;
@@ -28,6 +28,10 @@ var SourceFinder;
28
28
  });
29
29
  const emplace = (filter) => (input) => (closure) => __awaiter(this, void 0, void 0, function* () {
30
30
  for (const pattern of input) {
31
+ if (_Is_file(pattern)) {
32
+ closure(path_1.default.resolve(pattern));
33
+ continue;
34
+ }
31
35
  for (const file of yield _Glob(pattern)) {
32
36
  const stats = yield fs_1.default.promises.stat(file);
33
37
  if (stats.isDirectory() === true)
@@ -56,5 +60,8 @@ var SourceFinder;
56
60
  resolve(matches.map((str) => path_1.default.resolve(str)));
57
61
  });
58
62
  });
63
+ const _Is_file = (pattern) => pattern.endsWith(".ts") &&
64
+ !pattern.endsWith(".d.ts") &&
65
+ fs_1.default.existsSync(pattern);
59
66
  })(SourceFinder || (exports.SourceFinder = SourceFinder = {}));
60
67
  //# sourceMappingURL=SourceFinder.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SourceFinder.js","source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;IACP,CAAC,CAAC,CAAC;IAEP,MAAM,QAAQ,GAAG,CAAC,OAAe,EAAW,EAAE,CAC1C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC;QACvB,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;QAC1B,YAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAC/B,CAAC,EA1DgB,YAAY,4BAAZ,YAAY,QA0D5B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestia/sdk",
3
- "version": "2.2.4",
3
+ "version": "2.3.0-dev.20231017",
4
4
  "description": "Nestia SDK and Swagger generator",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -35,8 +35,9 @@
35
35
  },
36
36
  "homepage": "https://nestia.io",
37
37
  "dependencies": {
38
- "@nestia/fetcher": "^2.2.4",
38
+ "@nestia/fetcher": "^2.3.0-dev.20231017",
39
39
  "cli": "^1.0.1",
40
+ "get-function-location": "^2.0.0",
40
41
  "glob": "^7.2.0",
41
42
  "path-to-regexp": "^6.2.1",
42
43
  "reflect-metadata": ">=0.1.12",
@@ -44,10 +45,10 @@
44
45
  "tsconfck": "^2.0.1",
45
46
  "tsconfig-paths": "^4.1.1",
46
47
  "tstl": "^2.5.13",
47
- "typia": "^5.2.2"
48
+ "typia": ">=5.2.2 <6.0.0"
48
49
  },
49
50
  "peerDependencies": {
50
- "@nestia/fetcher": ">=2.2.4",
51
+ "@nestia/fetcher": ">=2.3.0-dev.20231017",
51
52
  "@nestjs/common": ">=7.0.1",
52
53
  "@nestjs/core": ">=7.0.1",
53
54
  "reflect-metadata": ">=0.1.12",
@@ -1,3 +1,6 @@
1
+ import type { INestApplication } from "@nestjs/common";
2
+ import type { VersionValue } from "@nestjs/common/interfaces";
3
+
1
4
  import type { ISwagger } from "./structures/ISwagger";
2
5
  import type { ISwaggerInfo } from "./structures/ISwaggerInfo";
3
6
  import type { ISwaggerSecurityScheme } from "./structures/ISwaggerSecurityScheme";
@@ -16,9 +19,18 @@ export interface INestiaConfig {
16
19
  swagger?: INestiaConfig.ISwaggerConfig;
17
20
 
18
21
  /**
19
- * List of files or directories containing the NestJS controller classes.
22
+ * Accessor of controller classes.
23
+ *
24
+ * You can specify it within two ways
25
+ *
26
+ * - Assign `INestApplication` instance or its factory function
27
+ * - Specify the path or directory of controller class files
20
28
  */
21
- input: string | string[] | INestiaConfig.IInput;
29
+ input:
30
+ | string
31
+ | string[]
32
+ | INestiaConfig.IInput
33
+ | (() => Promise<INestApplication>);
22
34
 
23
35
  /**
24
36
  * Output directory that SDK would be placed in.
@@ -159,6 +171,22 @@ export namespace INestiaConfig {
159
171
  * List of files or directories to be excluded.
160
172
  */
161
173
  exclude?: string[];
174
+
175
+ /**
176
+ * @internal
177
+ */
178
+ globalPrefix?: {
179
+ prefix: string;
180
+ exclude?: Array<string | RouteInfo>;
181
+ };
182
+
183
+ /**
184
+ * @internal
185
+ */
186
+ versioning?: {
187
+ prefix: string;
188
+ defaultVersion?: VersionValue;
189
+ };
162
190
  }
163
191
 
164
192
  /**
@@ -213,3 +241,11 @@ export namespace INestiaConfig {
213
241
  }): string;
214
242
  }
215
243
  }
244
+
245
+ /**
246
+ * @internal
247
+ */
248
+ interface RouteInfo {
249
+ path: string;
250
+ method: string;
251
+ }
@@ -5,6 +5,7 @@ import ts from "typescript";
5
5
 
6
6
  import { INestiaConfig } from "./INestiaConfig";
7
7
  import { AccessorAnalyzer } from "./analyses/AccessorAnalyzer";
8
+ import { ConfigAnalyzer } from "./analyses/ConfigAnalyzer";
8
9
  import { ControllerAnalyzer } from "./analyses/ControllerAnalyzer";
9
10
  import { ReflectAnalyzer } from "./analyses/ReflectAnalyzer";
10
11
  import { E2eGenerator } from "./generates/E2eGenerator";
@@ -13,7 +14,6 @@ import { SwaggerGenerator } from "./generates/SwaggerGenerator";
13
14
  import { IController } from "./structures/IController";
14
15
  import { IRoute } from "./structures/IRoute";
15
16
  import { ArrayUtil } from "./utils/ArrayUtil";
16
- import { NestiaConfigUtil } from "./utils/NestiaConfigUtil";
17
17
  import { SourceFinder } from "./utils/SourceFinder";
18
18
 
19
19
  export class NestiaSdkApplication {
@@ -153,13 +153,11 @@ export class NestiaSdkApplication {
153
153
  ) => (config: Config) => (routes: IRoute[]) => Promise<void>,
154
154
  ): Promise<void> {
155
155
  // LOAD CONTROLLER FILES
156
- const input: INestiaConfig.IInput = NestiaConfigUtil.input(
157
- this.config.input,
158
- );
156
+ this.config.input = await ConfigAnalyzer.input(this.config.input);
159
157
  const fileList: string[] = await ArrayUtil.asyncFilter(
160
158
  await SourceFinder.find({
161
- include: input.include,
162
- exclude: input.exclude,
159
+ include: this.config.input.include,
160
+ exclude: this.config.input.exclude,
163
161
  filter: (file) =>
164
162
  file.substring(file.length - 3) === ".ts" &&
165
163
  file.substring(file.length - 5) !== ".d.ts",
@@ -0,0 +1,73 @@
1
+ import { INestApplication, VersioningType } from "@nestjs/common";
2
+
3
+ import { INestiaConfig } from "../INestiaConfig";
4
+
5
+ export namespace ConfigAnalyzer {
6
+ export const input = async (
7
+ config: INestiaConfig["input"],
8
+ ): Promise<INestiaConfig.IInput> => {
9
+ if (Array.isArray(config))
10
+ return {
11
+ include: config,
12
+ exclude: [],
13
+ };
14
+ else if (typeof config === "function")
15
+ return application(await config());
16
+ else if (typeof config === "object")
17
+ if (config === null) throw new Error("Invalid input config.");
18
+ else return config as INestiaConfig.IInput;
19
+ else if (typeof config === "string")
20
+ return {
21
+ include: [config],
22
+ exclude: [],
23
+ };
24
+ else throw new Error("Invalid input config.");
25
+ };
26
+
27
+ const application = async (
28
+ app: INestApplication,
29
+ ): Promise<INestiaConfig.IInput> => {
30
+ const files: string[] = await (async () => {
31
+ const functions = new Set<Function>();
32
+ for (const module of (app as any).container.modules.values())
33
+ for (const controller of module._controllers.keys())
34
+ functions.add(controller);
35
+ const files: Set<string> = new Set();
36
+ for (const f of functions)
37
+ files.add(
38
+ (await require("get-function-location")(f))?.source ?? "",
39
+ );
40
+ return [...files]
41
+ .filter((str) => str.startsWith("file://"))
42
+ .map((str) =>
43
+ str.substring(str.startsWith("file:///") ? 8 : 7),
44
+ );
45
+ })();
46
+ const versioning = (app as any).config?.versioningOptions;
47
+
48
+ return {
49
+ include: files,
50
+ exclude: [],
51
+ globalPrefix:
52
+ typeof (app as any).config?.globalPrefix === "string"
53
+ ? {
54
+ prefix: (app as any).config.globalPrefix,
55
+ exclude:
56
+ (app as any).config.globalPrefixOptions
57
+ ?.exclude ?? {},
58
+ }
59
+ : undefined,
60
+ versioning:
61
+ versioning === undefined ||
62
+ versioning.type !== VersioningType.URI
63
+ ? undefined
64
+ : {
65
+ prefix:
66
+ versioning.prefix === undefined ||
67
+ versioning.prefix === false
68
+ ? "v"
69
+ : versioning.prefix,
70
+ },
71
+ };
72
+ };
73
+ }
@@ -231,27 +231,46 @@ export namespace ControllerAnalyzer {
231
231
  };
232
232
 
233
233
  // CONFIGURE PATHS
234
- const pathList: string[] = [];
235
- for (const controllerPath of controller.paths)
236
- for (const filePath of func.paths) {
237
- const path: string = PathAnalyzer.join(
238
- controllerPath,
239
- filePath,
240
- );
241
- pathList.push(
242
- PathAnalyzer.espace(
243
- path,
244
- () => "ControllerAnalyzer.analyze()",
245
- ),
246
- );
234
+ const input: INestiaConfig.IInput =
235
+ config.input as INestiaConfig.IInput;
236
+ const pathList: Set<string> = new Set();
237
+ const versions: Set<string | null> = new Set();
238
+
239
+ for (const cPath of controller.paths)
240
+ for (const filePath of func.paths)
241
+ pathList.add(PathAnalyzer.join(cPath, filePath));
242
+ if (input.versioning?.prefix.length) {
243
+ if (input.versioning.defaultVersion !== undefined) {
244
+ if (typeof input.versioning.defaultVersion === "symbol")
245
+ versions.add(null);
246
+ else if (Array.isArray(input.versioning.defaultVersion))
247
+ for (const v of input.versioning.defaultVersion)
248
+ if (typeof v === "symbol") versions.add(null);
249
+ else versions.add(String(v));
250
+ else versions.add(String(input.versioning.defaultVersion));
247
251
  }
252
+ for (const cv of input.versioning.prefix) {
253
+ versions.add(cv);
254
+ for (const fv of func.versions) versions.add(fv);
255
+ }
256
+ } else versions.add(null);
248
257
 
249
- // RETURNS
250
- return pathList.map((path) => ({
251
- ...common,
252
- path,
253
- accessors: [...PathUtil.accessors(path), func.name],
254
- }));
258
+ return [...pathList]
259
+ .map((individual) =>
260
+ PathAnalyzer.combinate(input.globalPrefix)([...versions])({
261
+ method: func.method,
262
+ path: individual,
263
+ }),
264
+ )
265
+ .flat()
266
+ .map((path) => ({
267
+ ...common,
268
+ path: PathAnalyzer.escape(
269
+ path,
270
+ () => "ControllerAnalyzer.analyze()",
271
+ ),
272
+ accessors: [...PathUtil.accessors(path), func.name],
273
+ }));
255
274
  }
256
275
 
257
276
  function _Analyze_parameter(
@@ -1,17 +1,40 @@
1
1
  import path from "path";
2
2
  import { Token, parse } from "path-to-regexp";
3
3
 
4
+ import { INestiaConfig } from "../INestiaConfig";
5
+
4
6
  export namespace PathAnalyzer {
7
+ export const combinate =
8
+ (globalPrefix: INestiaConfig.IInput["globalPrefix"]) =>
9
+ (versions: Array<string | null>) =>
10
+ (props: { path: string; method: string }): string[] => {
11
+ const out = (str: string) =>
12
+ versions.map((v) => (v === null ? str : join(v, str)));
13
+ if (!globalPrefix?.prefix.length) return out(props.path);
14
+ else if (!globalPrefix.exclude?.length)
15
+ return out(props.path).map((str) =>
16
+ join(globalPrefix.prefix, str),
17
+ );
18
+ return globalPrefix.exclude.some((exclude) =>
19
+ typeof exclude === "string"
20
+ ? RegExp(exclude).test(props.path)
21
+ : (exclude.method as string) === props.method &&
22
+ RegExp(exclude.path).test(props.path),
23
+ )
24
+ ? out(props.path)
25
+ : out(props.path).map((str) => join(globalPrefix.prefix, str));
26
+ };
27
+
5
28
  export const join = (...args: string[]) =>
6
29
  "/" +
7
30
  _Trim(
8
31
  path
9
- .join(...args)
32
+ .join(...args.filter((s) => !!s.length))
10
33
  .split("\\")
11
34
  .join("/"),
12
35
  );
13
36
 
14
- export const espace = (str: string, method: () => string) =>
37
+ export const escape = (str: string, method: () => string) =>
15
38
  "/" +
16
39
  _Parse(str, method)
17
40
  .map((arg) => (arg.type === "param" ? `:${arg.value}` : arg.value))
@@ -1,4 +1,5 @@
1
1
  import * as Constants from "@nestjs/common/constants";
2
+ import { VersionValue } from "@nestjs/common/interfaces";
2
3
  import "reflect-metadata";
3
4
  import { equal } from "tstl/ranges/module";
4
5
 
@@ -82,14 +83,12 @@ export namespace ReflectAnalyzer {
82
83
  // CONSTRUCTION
83
84
  //----
84
85
  // BASIC INFO
85
- const paths: string[] = _Get_paths(
86
- Reflect.getMetadata(Constants.PATH_METADATA, creator),
87
- );
88
86
  const meta: IController = {
89
87
  file,
90
88
  name,
91
- paths,
92
89
  functions: [],
90
+ paths: _Get_paths(creator),
91
+ versions: _Get_versions(creator),
93
92
  security: _Get_securities(creator),
94
93
  swaggerTgas:
95
94
  Reflect.getMetadata("swagger/apiUseTags", creator) ?? [],
@@ -123,12 +122,31 @@ export namespace ReflectAnalyzer {
123
122
  return entries;
124
123
  }
125
124
 
126
- function _Get_paths(value: string | string[]): string[] {
125
+ function _Get_paths(target: any): string[] {
126
+ const value: string | string[] = Reflect.getMetadata(
127
+ Constants.PATH_METADATA,
128
+ target,
129
+ );
127
130
  if (typeof value === "string") return [value];
128
131
  else if (value.length === 0) return [""];
129
132
  else return value;
130
133
  }
131
134
 
135
+ function _Get_versions(target: any): Array<string | null> {
136
+ const value: VersionValue | undefined = Reflect.getMetadata(
137
+ Constants.VERSION_METADATA,
138
+ target,
139
+ );
140
+ if (value === undefined || typeof value === "symbol") return [null];
141
+ else if (Array.isArray(value))
142
+ if (value.length === 0) return [null];
143
+ else
144
+ return value.map((v) =>
145
+ typeof value === "symbol" ? null : v,
146
+ ) as Array<string | null>;
147
+ return [String(value)];
148
+ }
149
+
132
150
  function _Get_securities(value: any): Record<string, string[]>[] {
133
151
  const entire: Record<string, string[]>[] | undefined =
134
152
  Reflect.getMetadata("swagger/apiSecurity", value);
@@ -218,9 +236,8 @@ export namespace ReflectAnalyzer {
218
236
  const meta: IController.IFunction = {
219
237
  name,
220
238
  method: method === "ALL" ? "POST" : method,
221
- paths: _Get_paths(
222
- Reflect.getMetadata(Constants.PATH_METADATA, proto),
223
- ),
239
+ paths: _Get_paths(proto),
240
+ versions: _Get_versions(proto),
224
241
  parameters,
225
242
  status: Reflect.getMetadata(Constants.HTTP_CODE_METADATA, proto),
226
243
  encrypted,
@@ -40,10 +40,11 @@ export namespace NestiaConfigLoader {
40
40
  };
41
41
 
42
42
  export const config = async (
43
+ file: string,
43
44
  options: ts.CompilerOptions,
44
45
  ): Promise<INestiaConfig> => {
45
- if (fs.existsSync(path.resolve("nestia.config.ts")) === false)
46
- throw new Error(`unable to find "nestia.config.ts" file.`);
46
+ if (fs.existsSync(path.resolve(file)) === false)
47
+ throw new Error(`Unable to find "${file}" file.`);
47
48
 
48
49
  register({
49
50
  emit: false,
@@ -52,7 +53,7 @@ export namespace NestiaConfigLoader {
52
53
  });
53
54
 
54
55
  const loaded: INestiaConfig & { default?: INestiaConfig } =
55
- await import(path.resolve("nestia.config.ts"));
56
+ await import(path.resolve(file));
56
57
  const config: INestiaConfig =
57
58
  typeof loaded?.default === "object" && loaded.default !== null
58
59
  ? loaded.default
@@ -62,19 +63,19 @@ export namespace NestiaConfigLoader {
62
63
  return typia.assert(config);
63
64
  } catch (exp) {
64
65
  if (typia.is<typia.TypeGuardError>(exp))
65
- exp.message = `invalid "nestia.config.ts" data.`;
66
+ exp.message = `invalid "${file}" data.`;
66
67
  throw exp;
67
68
  }
68
69
  };
69
70
 
70
- export const project = async (): Promise<string> => {
71
+ export const project = async (file: string): Promise<string> => {
71
72
  const connector = new WorkerConnector(null, null, "process");
72
73
  await connector.connect(
73
74
  `${__dirname}/nestia.project.getter.${__filename.substr(-2)}`,
74
75
  );
75
76
 
76
77
  const driver = await connector.getDriver<typeof NestiaProjectGetter>();
77
- const project: string = await driver.get();
78
+ const project: string = await driver.get(file);
78
79
  await connector.close();
79
80
 
80
81
  return project;
@@ -1,8 +1,8 @@
1
1
  import { NestiaConfigLoader } from "./NestiaConfigLoader";
2
2
 
3
3
  export namespace NestiaProjectGetter {
4
- export async function get(): Promise<string> {
5
- const config = await NestiaConfigLoader.config({
4
+ export async function get(file: string): Promise<string> {
5
+ const config = await NestiaConfigLoader.config(file, {
6
6
  module: "CommonJS" as any,
7
7
  noEmit: true,
8
8
  });
@@ -17,10 +17,12 @@ export namespace NestiaSdkCommand {
17
17
  task: (app: NestiaSdkApplication) => Promise<void>,
18
18
  ) => {
19
19
  // LOAD CONFIG INFO
20
- const project: string = await NestiaConfigLoader.project();
20
+ const file: string = getConfigFile() ?? "nestia.config.ts";
21
+ const project: string = await NestiaConfigLoader.project(file);
21
22
  const compilerOptions: ts.CompilerOptions =
22
23
  await NestiaConfigLoader.compilerOptions(project);
23
24
  const config: INestiaConfig = await NestiaConfigLoader.config(
25
+ file,
24
26
  compilerOptions,
25
27
  );
26
28
 
@@ -31,4 +33,19 @@ export namespace NestiaSdkCommand {
31
33
  );
32
34
  await task(app);
33
35
  };
36
+
37
+ const getConfigFile = (): string | null => {
38
+ const argv: string[] = process.argv.slice(3);
39
+ if (argv.length < 1) return null;
40
+
41
+ const index: number = argv.findIndex((str) => str === "--config");
42
+ if (index === -1) return null;
43
+ else if (argv.length === 1)
44
+ throw new Error("Config file must be provided");
45
+
46
+ const file: string = argv[index + 1];
47
+ if (file.endsWith(".ts") === false)
48
+ throw new Error("Config file must be TypeScript file");
49
+ return file;
50
+ };
34
51
  }
@@ -14,9 +14,9 @@ npx @nestia/sdk [command] [options?]
14
14
  - npx @nestia/sdk dependencies
15
15
  - npx @nestia/sdk dependencies --manager pnpm
16
16
  2. npx @nestia/sdk init
17
- 3. npx @nestia/sdk sdk
18
- 4. npx @nestia/sdk swagger
19
- 5. npx @nestia/sdk e2e
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
20
  `;
21
21
 
22
22
  function halt(desc: string): never {
@@ -2,8 +2,8 @@ import fs from "fs";
2
2
  import path from "path";
3
3
 
4
4
  import { INestiaConfig } from "../INestiaConfig";
5
+ import { ConfigAnalyzer } from "../analyses/ConfigAnalyzer";
5
6
  import { IRoute } from "../structures/IRoute";
6
- import { NestiaConfigUtil } from "../utils/NestiaConfigUtil";
7
7
  import { E2eFileProgrammer } from "./internal/E2eFileProgrammer";
8
8
 
9
9
  export namespace E2eGenerator {
@@ -53,7 +53,7 @@ export namespace E2eGenerator {
53
53
  output,
54
54
  content.replace(
55
55
  "${input}",
56
- JSON.stringify(NestiaConfigUtil.input(config.input)),
56
+ JSON.stringify(await ConfigAnalyzer.input(config.input)),
57
57
  ),
58
58
  "utf8",
59
59
  );
@@ -4,6 +4,7 @@ export interface IController {
4
4
  file: string;
5
5
  name: string;
6
6
  paths: string[];
7
+ versions: Array<string | null>;
7
8
  functions: IController.IFunction[];
8
9
  security: Record<string, string[]>[];
9
10
  swaggerTgas: string[];
@@ -14,6 +15,7 @@ export namespace IController {
14
15
  name: string;
15
16
  method: string;
16
17
  paths: string[];
18
+ versions: Array<string | null>;
17
19
  encrypted: boolean;
18
20
  parameters: IParameter[];
19
21
  status?: number;
@@ -20,6 +20,10 @@ export namespace SourceFinder {
20
20
  (input: string[]) =>
21
21
  async (closure: (location: string) => void): Promise<void> => {
22
22
  for (const pattern of input) {
23
+ if (_Is_file(pattern)) {
24
+ closure(path.resolve(pattern));
25
+ continue;
26
+ }
23
27
  for (const file of await _Glob(pattern)) {
24
28
  const stats: fs.Stats = await fs.promises.stat(file);
25
29
  if (stats.isDirectory() === true)
@@ -51,6 +55,11 @@ export namespace SourceFinder {
51
55
  else resolve(matches.map((str) => path.resolve(str)));
52
56
  });
53
57
  });
58
+
59
+ const _Is_file = (pattern: string): boolean =>
60
+ pattern.endsWith(".ts") &&
61
+ !pattern.endsWith(".d.ts") &&
62
+ fs.existsSync(pattern);
54
63
  }
55
64
 
56
65
  interface IProps {
@@ -1,4 +0,0 @@
1
- import { INestiaConfig } from "../INestiaConfig";
2
- export declare namespace NestiaConfigUtil {
3
- const input: (config: INestiaConfig["input"]) => INestiaConfig.IInput;
4
- }
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NestiaConfigUtil = void 0;
4
- var NestiaConfigUtil;
5
- (function (NestiaConfigUtil) {
6
- NestiaConfigUtil.input = (config) => {
7
- var _a;
8
- return Array.isArray(config)
9
- ? {
10
- include: config,
11
- exclude: [],
12
- }
13
- : typeof config === "object"
14
- ? {
15
- include: config.include,
16
- exclude: (_a = config.exclude) !== null && _a !== void 0 ? _a : [],
17
- }
18
- : {
19
- include: [config],
20
- exclude: [],
21
- };
22
- };
23
- })(NestiaConfigUtil || (exports.NestiaConfigUtil = NestiaConfigUtil = {}));
24
- //# sourceMappingURL=NestiaConfigUtil.js.map