nestia 2.0.0 → 2.0.1-dev.20220413-2

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/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "nestia",
3
- "version": "2.0.0",
3
+ "version": "2.0.1-dev.20220413-2",
4
4
  "description": "Automatic SDK and Document generator for the NestJS",
5
5
  "main": "src/index.ts",
6
6
  "bin": {
7
- "nestia": "./src/bin/nestia.ts"
7
+ "nestia": "./src/bin/nestia.js"
8
8
  },
9
9
  "scripts": {
10
+ "build": "tsc src/bin/nestia.ts",
10
11
  "dev": "tsc --watch",
11
12
  "test": "cd test && bash script.sh",
12
13
  "test:default": "cd test/default && rimraf -rf src/api/functional && ts-node ../../src/bin/nestia sdk src/controllers --out src/api"
@@ -31,15 +32,17 @@
31
32
  "dependencies": {
32
33
  "@types/cli": "^0.11.19",
33
34
  "@types/glob": "^7.2.0",
34
- "@types/node": "^14.14.22",
35
+ "@types/node": "^17.0.23",
35
36
  "@types/reflect-metadata": "^0.1.0",
36
37
  "cli": "^1.0.1",
37
38
  "del": "^6.0.0",
38
39
  "glob": "^7.2.0",
39
40
  "ts-node": "^9.1.1",
40
- "tsconfig-paths": "^3.14.1",
41
41
  "tstl": "^2.5.3",
42
- "typescript": "^4.6.3"
42
+ "ttypescript": "^1.5.13",
43
+ "typescript": "^4.5.3",
44
+ "typescript-is": "^0.19.0",
45
+ "typescript-transform-paths": "^3.3.1"
43
46
  },
44
47
  "devDependencies": {
45
48
  "nestia-helper": "^2.0.0",
@@ -5,6 +5,7 @@ export interface IConfiguration
5
5
  input: string | string[] | IConfiguration.IInput;
6
6
  output: string;
7
7
  compilerOptions?: tsc.CompilerOptions;
8
+ assert?: boolean;
8
9
  }
9
10
  export namespace IConfiguration
10
11
  {
@@ -1,6 +1,6 @@
1
- import * as fs from "fs";
2
- import * as path from "path";
3
- import * as tsc from "typescript";
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import tsc from "typescript";
4
4
  import { Pair } from "tstl/utility/Pair";
5
5
  import { Singleton } from "tstl/thread/Singleton";
6
6
 
@@ -85,7 +85,7 @@ export class NestiaApplication
85
85
  }
86
86
 
87
87
  // DO GENERATE
88
- await SdkGenerator.generate(this.config_.output, routeList);
88
+ await SdkGenerator.generate(this.config_, routeList);
89
89
  }
90
90
 
91
91
  private async is_not_excluded(file: string): Promise<boolean>
@@ -1,5 +1,5 @@
1
- import * as NodePath from "path";
2
- import * as tsc from "typescript";
1
+ import NodePath from "path";
2
+ import tsc from "typescript";
3
3
  import { HashMap } from "tstl/container/HashMap";
4
4
 
5
5
  import { IController } from "../structures/IController";
@@ -1,4 +1,4 @@
1
- import * as tsc from "typescript";
1
+ import tsc from "typescript";
2
2
 
3
3
  export namespace GenericAnalyzer
4
4
  {
@@ -1,4 +1,4 @@
1
- import * as tsc from "typescript";
1
+ import tsc from "typescript";
2
2
 
3
3
  import { HashMap } from "tstl/container/HashMap";
4
4
  import { HashSet } from "tstl/container/HashSet";
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
+ if (ar || !(i in from)) {
41
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
+ ar[i] = from[i];
43
+ }
44
+ }
45
+ return to.concat(ar || Array.prototype.slice.call(from));
46
+ };
47
+ exports.__esModule = true;
48
+ var cp = require("child_process");
49
+ var fs = require("fs");
50
+ var CompilerOptions_1 = require("../internal/CompilerOptions");
51
+ var stripJsonComments_1 = require("../utils/stripJsonComments");
52
+ function install() {
53
+ // INSTALL DEPENDENCIES
54
+ for (var _i = 0, _a = ["nestia-fetcher", "typescript-is"]; _i < _a.length; _i++) {
55
+ var lib = _a[_i];
56
+ var command = "npm install ".concat(lib);
57
+ cp.execSync(command, { stdio: "inherit" });
58
+ }
59
+ }
60
+ function sdk() {
61
+ // PREPARE COMMAND
62
+ var parameters = __spreadArray([
63
+ "npx ts-node -C ttypescript",
64
+ __dirname + "/../executable/sdk"
65
+ ], process.argv.slice(3), true);
66
+ var command = parameters.join(" ");
67
+ // EXECUTE THE COMMAND, BUT IGNORE WARNINGS
68
+ cp.execSync(command, {
69
+ stdio: "inherit",
70
+ env: { "NODE_NO_WARNINGS": "1" }
71
+ });
72
+ }
73
+ function configure(config) {
74
+ if (!config.compilerOptions) {
75
+ config.compilerOptions = CompilerOptions_1.CompilerOptions.DEFAULT;
76
+ return true;
77
+ }
78
+ else
79
+ return CompilerOptions_1.CompilerOptions.emend(config.compilerOptions);
80
+ }
81
+ function tsconfig(task) {
82
+ return __awaiter(this, void 0, void 0, function () {
83
+ var prepare, restore, config_1, content_1, config_2, changed, error;
84
+ return __generator(this, function (_a) {
85
+ switch (_a.label) {
86
+ case 0:
87
+ prepare = null;
88
+ restore = null;
89
+ if (!(fs.existsSync("tsconfig.json") === false)) return [3 /*break*/, 1];
90
+ config_1 = {
91
+ compilerOptions: CompilerOptions_1.CompilerOptions.DEFAULT
92
+ };
93
+ prepare = function () { return fs.promises.writeFile("tsconfig.json", JSON.stringify(config_1, null, 2), "utf8"); };
94
+ restore = function () { return fs.promises.unlink("tsconfig.json"); };
95
+ return [3 /*break*/, 3];
96
+ case 1: return [4 /*yield*/, fs.promises.readFile("tsconfig.json", "utf8")];
97
+ case 2:
98
+ content_1 = _a.sent();
99
+ config_2 = JSON.parse((0, stripJsonComments_1.stripJsonComments)(content_1));
100
+ changed = configure(config_2);
101
+ if (changed === true) {
102
+ // NEED TO ADD TRANSFORM PLUGINS
103
+ prepare = function () { return fs.promises.writeFile("tsconfig.json", JSON.stringify(config_2, null, 2), "utf8"); };
104
+ restore = function () { return fs.promises.writeFile("tsconfig.json", content_1, "utf8"); };
105
+ }
106
+ _a.label = 3;
107
+ case 3:
108
+ if (!(prepare !== null)) return [3 /*break*/, 5];
109
+ return [4 /*yield*/, prepare()];
110
+ case 4:
111
+ _a.sent();
112
+ _a.label = 5;
113
+ case 5:
114
+ error = null;
115
+ try {
116
+ task();
117
+ }
118
+ catch (exp) {
119
+ error = exp;
120
+ }
121
+ if (!(restore !== null)) return [3 /*break*/, 7];
122
+ return [4 /*yield*/, restore()];
123
+ case 6:
124
+ _a.sent();
125
+ _a.label = 7;
126
+ case 7:
127
+ // THROW ERROR IF EXISTS
128
+ if (error)
129
+ throw error;
130
+ return [2 /*return*/];
131
+ }
132
+ });
133
+ });
134
+ }
135
+ function main() {
136
+ return __awaiter(this, void 0, void 0, function () {
137
+ return __generator(this, function (_a) {
138
+ switch (_a.label) {
139
+ case 0:
140
+ if (!(process.argv[2] === "install")) return [3 /*break*/, 2];
141
+ return [4 /*yield*/, install()];
142
+ case 1:
143
+ _a.sent();
144
+ return [3 /*break*/, 5];
145
+ case 2:
146
+ if (!(process.argv[2] === "sdk")) return [3 /*break*/, 4];
147
+ return [4 /*yield*/, tsconfig(sdk)];
148
+ case 3:
149
+ _a.sent();
150
+ return [3 /*break*/, 5];
151
+ case 4: throw new Error("nestia supports only two commands; install and sdk, however you typed ".concat(process.argv[2]));
152
+ case 5: return [2 /*return*/];
153
+ }
154
+ });
155
+ });
156
+ }
157
+ main()["catch"](function (exp) {
158
+ console.log(exp.message);
159
+ process.exit(-1);
160
+ });
package/src/bin/nestia.ts CHANGED
@@ -1,85 +1,126 @@
1
- #!/usr/bin/env ts-node
2
-
3
- import cp from "child_process";
4
- import fs from "fs";
5
- import tsc from "typescript";
1
+ import * as cp from "child_process";
2
+ import * as fs from "fs";
6
3
 
4
+ import { CompilerOptions } from "../internal/CompilerOptions";
7
5
  import { stripJsonComments } from "../utils/stripJsonComments";
8
6
 
7
+ interface IConfig
8
+ {
9
+ compilerOptions?: CompilerOptions;
10
+ }
11
+
9
12
  function install(): void
10
13
  {
11
- const command: string = "npm install --save nestia-fetcher";
12
- cp.execSync(command, { stdio: "inherit" });
14
+ // INSTALL DEPENDENCIES
15
+ for (const lib of ["nestia-fetcher", "typescript-is"])
16
+ {
17
+ const command: string = `npm install ${lib}`;
18
+ cp.execSync(command, { stdio: "inherit" });
19
+ }
13
20
  }
14
21
 
15
- function sdk(alias: boolean): void
22
+ function sdk(): void
16
23
  {
24
+ // PREPARE COMMAND
17
25
  const parameters: string[] = [
18
- alias ? "npx ts-node -r tsconfig-paths/register" : "npx ts-node",
26
+ "npx ts-node -C ttypescript",
19
27
  __dirname + "/../executable/sdk",
20
28
  ...process.argv.slice(3)
21
29
  ];
22
30
  const command: string = parameters.join(" ");
23
- cp.execSync(command, { stdio: "inherit" });
31
+
32
+ // EXECUTE THE COMMAND, BUT IGNORE WARNINGS
33
+ cp.execSync
34
+ (
35
+ command,
36
+ {
37
+ stdio: "inherit",
38
+ env: { "NODE_NO_WARNINGS": "1" }
39
+ }
40
+ );
24
41
  }
25
42
 
26
- async function tsconfig(task: (alias: boolean) => void): Promise<void>
43
+ function configure(config: IConfig): boolean
27
44
  {
28
- // NO TSCONFIG.JSON?
29
- if (fs.existsSync("tsconfig.json") === false)
30
- {
31
- task(false);
32
- return;
33
- }
34
-
35
- const content: string = await fs.promises.readFile("tsconfig.json", "utf8");
36
- const json: any = JSON.parse(stripJsonComments(content));
37
- const options: tsc.CompilerOptions = json.compilerOptions;
38
-
39
- // NO ALIAS PATHS
40
- if (!options.paths || !Object.entries(options.paths).length)
45
+ if (!config.compilerOptions)
41
46
  {
42
- task(false);
43
- return;
47
+ config.compilerOptions = CompilerOptions.DEFAULT;
48
+ return true;
44
49
  }
50
+ else
51
+ return CompilerOptions.emend(config.compilerOptions);
52
+ }
45
53
 
46
- let closer: null | (() => Promise<void>) = null;
47
- let error: Error | null = null;
54
+ async function tsconfig(task: () => void): Promise<void>
55
+ {
56
+ //----
57
+ // PREPARE ASSETS
58
+ //----
59
+ let prepare: null | (() => Promise<void>) = null;
60
+ let restore: null | (() => Promise<void>) = null;
48
61
 
49
- if (!options.baseUrl)
62
+ if (fs.existsSync("tsconfig.json") === false)
50
63
  {
51
- options.baseUrl = "./";
52
- await fs.promises.writeFile
64
+ // NO TSCONFIG.JSON
65
+ const config: IConfig = {
66
+ compilerOptions: CompilerOptions.DEFAULT
67
+ };
68
+ prepare = () => fs.promises.writeFile
53
69
  (
54
- "tsconfig.json",
55
- JSON.stringify(json, null, 2),
70
+ "tsconfig.json",
71
+ JSON.stringify(config, null, 2),
56
72
  "utf8"
57
73
  );
74
+ restore = () => fs.promises.unlink("tsconfig.json")
75
+ }
76
+ else
77
+ {
78
+ // HAS TSCONFIG.JSON
79
+ const content: string = await fs.promises.readFile("tsconfig.json", "utf8");
80
+ const config: IConfig = JSON.parse(stripJsonComments(content));
81
+ const changed: boolean = configure(config);
58
82
 
59
- closer = () => fs.promises.writeFile
60
- (
61
- "tsconfig.json",
62
- content,
63
- "utf8"
64
- );
83
+ if (changed === true)
84
+ {
85
+ // NEED TO ADD TRANSFORM PLUGINS
86
+ prepare = () => fs.promises.writeFile
87
+ (
88
+ "tsconfig.json",
89
+ JSON.stringify(config, null, 2),
90
+ "utf8"
91
+ );
92
+ restore = () => fs.promises.writeFile("tsconfig.json", content, "utf8");
93
+ }
65
94
  }
66
95
 
96
+ //----
97
+ // EXECUTION
98
+ //----
99
+ // PREPARE SOMETHING
100
+ if (prepare !== null)
101
+ await prepare();
102
+
103
+ // EXECUTE THE TASK
104
+ let error: Error | null = null;
67
105
  try
68
106
  {
69
- task(true);
107
+ task();
70
108
  }
71
109
  catch (exp)
72
110
  {
73
111
  error = exp as Error;
74
112
  }
75
113
 
76
- if (closer)
77
- await closer();
114
+ // RESTORE THE TSCONFIG.JSON
115
+ if (restore !== null)
116
+ await restore();
117
+
118
+ // THROW ERROR IF EXISTS
78
119
  if (error)
79
120
  throw error;
80
121
  }
81
122
 
82
- async function main(): Promise<void>
123
+ async function main()
83
124
  {
84
125
  if (process.argv[2] === "install")
85
126
  await install();
@@ -1,5 +1,6 @@
1
- import * as fs from "fs";
1
+ import fs from "fs";
2
2
  import { HashMap } from "tstl/container/HashMap";
3
+ import { IConfiguration } from "../IConfiguration";
3
4
 
4
5
  import { IRoute } from "../structures/IRoute";
5
6
  import { ImportDictionary } from "../utils/ImportDictionary";
@@ -10,7 +11,7 @@ export namespace FileGenerator
10
11
  /* ---------------------------------------------------------
11
12
  CONSTRUCTOR
12
13
  --------------------------------------------------------- */
13
- export async function generate(outDir: string, routeList: IRoute[]): Promise<void>
14
+ export async function generate(config: IConfiguration, routeList: IRoute[]): Promise<void>
14
15
  {
15
16
  // CONSTRUCT FOLDER TREE
16
17
  const root: Directory = new Directory(null, "functional");
@@ -21,7 +22,7 @@ export namespace FileGenerator
21
22
  relocate(root);
22
23
 
23
24
  // ITERATE FILES
24
- await iterate(outDir + "/functional", root);
25
+ await iterate(!!config.assert, config.output + "/functional", root);
25
26
  }
26
27
 
27
28
  function emplace(directory: Directory, route: IRoute): void
@@ -63,7 +64,12 @@ export namespace FileGenerator
63
64
  /* ---------------------------------------------------------
64
65
  FILE ITERATOR
65
66
  --------------------------------------------------------- */
66
- async function iterate(outDir: string, directory: Directory): Promise<void>
67
+ async function iterate
68
+ (
69
+ assert: boolean,
70
+ outDir: string,
71
+ directory: Directory
72
+ ): Promise<void>
67
73
  {
68
74
  // CREATE A NEW DIRECTORY
69
75
  try
@@ -76,7 +82,7 @@ export namespace FileGenerator
76
82
  let content: string = "";
77
83
  for (const it of directory.directories)
78
84
  {
79
- await iterate(`${outDir}/${it.first}`, it.second);
85
+ await iterate(assert, `${outDir}/${it.first}`, it.second);
80
86
  content += `export * as ${it.first} from "./${it.first}";\n`;
81
87
  }
82
88
  content += "\n";
@@ -88,27 +94,34 @@ export namespace FileGenerator
88
94
  for (const tuple of route.imports)
89
95
  for (const instance of tuple[1])
90
96
  importDict.emplace(tuple[0], false, instance);
91
- content += FunctionGenerator.generate(route) + "\n\n";
97
+ content += FunctionGenerator.generate(assert, route) + "\n\n";
92
98
  }
93
99
 
94
100
  // FINALIZE THE CONTENT
95
101
  if (directory.routes.length !== 0)
102
+ {
103
+ const primitived: boolean = directory.routes.some(route => route.output !== "void"
104
+ || route.parameters.some(param => param.category !== "param")
105
+ );
106
+ const asserted: boolean = assert
107
+ && directory.routes.some(route => route.parameters.length !== 0);
108
+
109
+ const fetcher: string[] = ["Fetcher"];
110
+ if (primitived)
111
+ fetcher.push("Primitive");
112
+
96
113
  content = ""
97
- + `import { AesPkcs5, Fetcher, Primitive } from "nestia-fetcher";\n`
114
+ + `import { ${fetcher.join(", ")} } from "nestia-fetcher";\n`
98
115
  + `import type { IConnection } from "nestia-fetcher";\n`
116
+ + (asserted ? `import { assertType } from "typescript-is";\n` : "")
99
117
  +
100
118
  (
101
119
  importDict.empty()
102
120
  ? ""
103
121
  : "\n" + importDict.toScript(outDir) + "\n"
104
122
  )
105
- + content + "\n\n"
106
- + "//---------------------------------------------------------\n"
107
- + "// TO PREVENT THE UNUSED VARIABLE ERROR\n"
108
- + "//---------------------------------------------------------\n"
109
- + "AesPkcs5;\n"
110
- + "Fetcher;\n"
111
- + "Primitive;";
123
+ + content;
124
+ }
112
125
 
113
126
  content = "/**\n"
114
127
  + " * @packageDocumentation\n"
@@ -1,4 +1,4 @@
1
- import type * as tsc from "typescript";
1
+ import type tsc from "typescript";
2
2
  import { Pair } from "tstl/utility/Pair";
3
3
  import { Vector } from "tstl/container/Vector";
4
4
 
@@ -6,13 +6,13 @@ import { IRoute } from "../structures/IRoute";
6
6
 
7
7
  export namespace FunctionGenerator
8
8
  {
9
- export function generate(route: IRoute): string
9
+ export function generate(assert: boolean, route: IRoute): string
10
10
  {
11
11
  const query: IRoute.IParameter | undefined = route.parameters.find(param => param.category === "query");
12
12
  const input: IRoute.IParameter | undefined = route.parameters.find(param => param.category === "body");
13
13
 
14
14
  return [head, body, tail]
15
- .map(closure => closure(route, query, input))
15
+ .map(closure => closure(route, query, input, assert))
16
16
  .filter(str => !!str)
17
17
  .join("\n");
18
18
  }
@@ -20,7 +20,13 @@ export namespace FunctionGenerator
20
20
  /* ---------------------------------------------------------
21
21
  BODY
22
22
  --------------------------------------------------------- */
23
- function body(route: IRoute, query: IRoute.IParameter | undefined, input: IRoute.IParameter | undefined): string
23
+ function body
24
+ (
25
+ route: IRoute,
26
+ query: IRoute.IParameter | undefined,
27
+ input: IRoute.IParameter | undefined,
28
+ assert: boolean
29
+ ): string
24
30
  {
25
31
  // FETCH ARGUMENTS WITH REQUST BODY
26
32
  const parameters = filter_parameters(route, query);
@@ -34,8 +40,15 @@ export namespace FunctionGenerator
34
40
  if (input !== undefined)
35
41
  fetchArguments.push(input.name);
36
42
 
43
+ const assertions: string = assert === true && route.parameters.length !== 0
44
+ ? route.parameters
45
+ .map(param => ` assertType<typeof ${param.name}>(${param.name});`)
46
+ .join("\n") + "\n\n"
47
+ : "";
48
+
37
49
  // RETURNS WITH FINALIZATION
38
50
  return "{\n"
51
+ + assertions
39
52
  + " return Fetcher.fetch\n"
40
53
  + " (\n"
41
54
  + fetchArguments.map(param => ` ${param}`).join(",\n") + "\n"
@@ -54,7 +67,12 @@ export namespace FunctionGenerator
54
67
  /* ---------------------------------------------------------
55
68
  HEAD & TAIL
56
69
  --------------------------------------------------------- */
57
- function head(route: IRoute, query: IRoute.IParameter | undefined, input: IRoute.IParameter | undefined): string
70
+ function head
71
+ (
72
+ route: IRoute,
73
+ query: IRoute.IParameter | undefined,
74
+ input: IRoute.IParameter | undefined
75
+ ): string
58
76
  {
59
77
  //----
60
78
  // CONSTRUCT COMMENT
@@ -132,7 +150,12 @@ export namespace FunctionGenerator
132
150
  + ` ): Promise<${output}>`;
133
151
  }
134
152
 
135
- function tail(route: IRoute, query: IRoute.IParameter | undefined, input: IRoute.IParameter | undefined): string | null
153
+ function tail
154
+ (
155
+ route: IRoute,
156
+ query: IRoute.IParameter | undefined,
157
+ input: IRoute.IParameter | undefined
158
+ ): string | null
136
159
  {
137
160
  // LIST UP TYPES
138
161
  const types: Pair<string, string>[] = [];
@@ -1,15 +1,20 @@
1
- import * as fs from "fs";
1
+ import fs from "fs";
2
2
  import { DirectoryUtil } from "../utils/DirectoryUtil";
3
3
 
4
4
  import { IRoute } from "../structures/IRoute";
5
5
  import { FileGenerator } from "./FileGenerator";
6
+ import { IConfiguration } from "../IConfiguration";
6
7
 
7
8
  export namespace SdkGenerator
8
9
  {
9
- export async function generate(outDir: string, routeList: IRoute[]): Promise<void>
10
+ export async function generate
11
+ (
12
+ config: IConfiguration,
13
+ routeList: IRoute[],
14
+ ): Promise<void>
10
15
  {
11
16
  // PREPARE NEW DIRECTORIES
12
- try { await fs.promises.mkdir(outDir); } catch {}
17
+ try { await fs.promises.mkdir(config.output); } catch {}
13
18
 
14
19
  // BUNDLING
15
20
  const bundle: string[] = await fs.promises.readdir(BUNDLE);
@@ -21,13 +26,13 @@ export namespace SdkGenerator
21
26
  if (stats.isFile() === true)
22
27
  {
23
28
  const content: string = await fs.promises.readFile(current, "utf8");
24
- await fs.promises.writeFile(`${outDir}/${file}`, content, "utf8");
29
+ await fs.promises.writeFile(`${config.output}/${file}`, content, "utf8");
25
30
  }
26
31
  }
27
- await DirectoryUtil.copy(BUNDLE + "/__internal", outDir + "/__internal");
32
+ await DirectoryUtil.copy(BUNDLE + "/__internal", config.output + "/__internal");
28
33
 
29
34
  // FUNCTIONAL
30
- await FileGenerator.generate(outDir, routeList);
35
+ await FileGenerator.generate(config, routeList);
31
36
  }
32
37
  }
33
38
 
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.CompilerOptions = void 0;
4
+ var CompilerOptions;
5
+ (function (CompilerOptions) {
6
+ CompilerOptions.DEPENDENCIES = [
7
+ "nestia-fetcher",
8
+ "typescript-is"
9
+ ];
10
+ CompilerOptions.TRANSFORMERS = [
11
+ "typescript-is/lib/transform-inline/transformer",
12
+ "typescript-transform-paths"
13
+ ];
14
+ CompilerOptions.TYPES = [];
15
+ CompilerOptions.DEFAULT = {
16
+ target: "es5",
17
+ module: "commonjs",
18
+ lib: [
19
+ "DOM",
20
+ "ES2015"
21
+ ],
22
+ strict: true,
23
+ downlevelIteration: true,
24
+ esModuleInterop: true,
25
+ plugins: CompilerOptions.TRANSFORMERS.map(function (transform) { return ({ transform: transform }); }),
26
+ types: [
27
+ "node",
28
+ "reflect-metadata"
29
+ ],
30
+ experimentalDecorators: true,
31
+ emitDecoratorMetadata: true
32
+ };
33
+ function emend(options) {
34
+ // FILL ARRAY DATA
35
+ if (!options.plugins)
36
+ options.plugins = [];
37
+ if (!options.types)
38
+ options.types = [];
39
+ // CONSTRUCT CHECKERS
40
+ var emended = options;
41
+ var checkers = [
42
+ function () {
43
+ var changed = false;
44
+ var _loop_1 = function (transform) {
45
+ if (emended.plugins.find(function (elem) { return elem.transform === transform; }) !== undefined)
46
+ return "continue";
47
+ changed = true;
48
+ emended.plugins.push({ transform: transform });
49
+ };
50
+ for (var _i = 0, _a = CompilerOptions.TRANSFORMERS; _i < _a.length; _i++) {
51
+ var transform = _a[_i];
52
+ _loop_1(transform);
53
+ }
54
+ return changed;
55
+ },
56
+ function () {
57
+ var changed = false;
58
+ var _loop_2 = function (type) {
59
+ if (emended.types.find(function (elem) { return elem === type; }) !== undefined)
60
+ return "continue";
61
+ changed = true;
62
+ emended.types.push(type);
63
+ };
64
+ for (var _i = 0, _a = CompilerOptions.TYPES; _i < _a.length; _i++) {
65
+ var type = _a[_i];
66
+ _loop_2(type);
67
+ }
68
+ return changed;
69
+ },
70
+ function () {
71
+ var changed = emended.experimentalDecorators !== true;
72
+ if (changed)
73
+ emended.experimentalDecorators = true;
74
+ return changed;
75
+ },
76
+ function () {
77
+ var changed = emended.emitDecoratorMetadata !== true;
78
+ if (changed)
79
+ emended.emitDecoratorMetadata = true;
80
+ return changed;
81
+ },
82
+ function () {
83
+ var changed = emended.esModuleInterop !== true;
84
+ if (changed)
85
+ emended.esModuleInterop = true;
86
+ return changed;
87
+ }
88
+ ];
89
+ // DO CHECK IT
90
+ var checks = checkers.map(function (func) { return func(); });
91
+ return checks.some(function (flag) { return flag; });
92
+ }
93
+ CompilerOptions.emend = emend;
94
+ })(CompilerOptions = exports.CompilerOptions || (exports.CompilerOptions = {}));
@@ -0,0 +1,113 @@
1
+ export interface CompilerOptions
2
+ {
3
+ target: string;
4
+ module: string;
5
+ lib: string[];
6
+ strict: boolean;
7
+ downlevelIteration: boolean;
8
+ esModuleInterop?: boolean;
9
+ plugins?: Array<{
10
+ transform?: string
11
+ }>;
12
+ types?: string[];
13
+ experimentalDecorators?: boolean;
14
+ emitDecoratorMetadata?: boolean;
15
+ }
16
+ export namespace CompilerOptions
17
+ {
18
+ export const DEPENDENCIES: string[] = [
19
+ "nestia-fetcher",
20
+ "typescript-is"
21
+ ];
22
+
23
+ export const TRANSFORMERS: string[] = [
24
+ "typescript-is/lib/transform-inline/transformer",
25
+ "typescript-transform-paths"
26
+ ];
27
+
28
+ export const TYPES: string[] = []
29
+
30
+ export const DEFAULT = {
31
+ target: "es5",
32
+ module: "commonjs",
33
+ lib: [
34
+ "DOM",
35
+ "ES2015"
36
+ ],
37
+ strict: true,
38
+ downlevelIteration: true,
39
+ esModuleInterop: true,
40
+ plugins: TRANSFORMERS.map(transform => ({ transform })),
41
+ types: [
42
+ "node",
43
+ "reflect-metadata"
44
+ ],
45
+ experimentalDecorators: true,
46
+ emitDecoratorMetadata: true,
47
+ };
48
+
49
+ export function emend(options: CompilerOptions): boolean
50
+ {
51
+ // FILL ARRAY DATA
52
+ if (!options.plugins)
53
+ options.plugins = [];
54
+ if (!options.types)
55
+ options.types = [];
56
+
57
+ // CONSTRUCT CHECKERS
58
+ const emended: Required<CompilerOptions> = options as Required<CompilerOptions>;
59
+ const checkers: Array<() => boolean> = [
60
+ () =>
61
+ {
62
+ let changed: boolean = false;
63
+ for (const transform of CompilerOptions.TRANSFORMERS)
64
+ {
65
+ if (emended.plugins.find(elem => elem.transform === transform) !== undefined)
66
+ continue;
67
+
68
+ changed = true;
69
+ emended.plugins.push({ transform });
70
+ }
71
+ return changed;
72
+ },
73
+ () =>
74
+ {
75
+ let changed: boolean = false;
76
+ for (const type of CompilerOptions.TYPES)
77
+ {
78
+ if (emended.types.find(elem => elem === type) !== undefined)
79
+ continue;
80
+
81
+ changed = true;
82
+ emended.types.push(type);
83
+ }
84
+ return changed;
85
+ },
86
+ () =>
87
+ {
88
+ const changed: boolean = emended.experimentalDecorators !== true;
89
+ if (changed)
90
+ emended.experimentalDecorators = true;
91
+ return changed;
92
+ },
93
+ () =>
94
+ {
95
+ const changed: boolean = emended.emitDecoratorMetadata !== true;
96
+ if (changed)
97
+ emended.emitDecoratorMetadata = true;
98
+ return changed;
99
+ },
100
+ () =>
101
+ {
102
+ const changed: boolean = emended.esModuleInterop !== true;
103
+ if (changed)
104
+ emended.esModuleInterop = true;
105
+ return changed;
106
+ }
107
+ ];
108
+
109
+ // DO CHECK IT
110
+ const checks: boolean[] = checkers.map(func => func());
111
+ return checks.some(flag => flag);
112
+ }
113
+ }
@@ -1,4 +1,4 @@
1
- import type * as tsc from "typescript";
1
+ import type tsc from "typescript";
2
2
  import { ParamCategory } from "./ParamCategory";
3
3
 
4
4
  export interface IRoute
@@ -1,5 +1,5 @@
1
1
  import del from "del";
2
- import * as fs from "fs";
2
+ import fs from "fs";
3
3
 
4
4
  export namespace DirectoryUtil
5
5
  {
@@ -1,4 +1,4 @@
1
- import * as path from "path";
1
+ import path from "path";
2
2
 
3
3
  import { HashMap } from "tstl/container/HashMap";
4
4
  import { HashSet } from "tstl/container/HashSet";
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ // https://github.com/sindresorhus/strip-json-comments
3
+ exports.__esModule = true;
4
+ exports.stripJsonComments = void 0;
5
+ var singleComment = Symbol('singleComment');
6
+ var multiComment = Symbol('multiComment');
7
+ var stripWithoutWhitespace = function () { return ''; };
8
+ var stripWithWhitespace = function (string, start, end) { return string.slice(start, end).replace(/\S/g, ' '); };
9
+ var isEscaped = function (jsonString, quotePosition) {
10
+ var index = quotePosition - 1;
11
+ var backslashCount = 0;
12
+ while (jsonString[index] === '\\') {
13
+ index -= 1;
14
+ backslashCount += 1;
15
+ }
16
+ return Boolean(backslashCount % 2);
17
+ };
18
+ function stripJsonComments(jsonString, _a) {
19
+ var _b = _a === void 0 ? {} : _a, _c = _b.whitespace, whitespace = _c === void 0 ? true : _c;
20
+ if (typeof jsonString !== 'string') {
21
+ throw new TypeError("Expected argument `jsonString` to be a `string`, got `".concat(typeof jsonString, "`"));
22
+ }
23
+ var strip = whitespace ? stripWithWhitespace : stripWithoutWhitespace;
24
+ var isInsideString = false;
25
+ var isInsideComment = false;
26
+ var offset = 0;
27
+ var result = '';
28
+ for (var index = 0; index < jsonString.length; index++) {
29
+ var currentCharacter = jsonString[index];
30
+ var nextCharacter = jsonString[index + 1];
31
+ if (!isInsideComment && currentCharacter === '"') {
32
+ var escaped = isEscaped(jsonString, index);
33
+ if (!escaped) {
34
+ isInsideString = !isInsideString;
35
+ }
36
+ }
37
+ if (isInsideString) {
38
+ continue;
39
+ }
40
+ if (!isInsideComment && currentCharacter + nextCharacter === '//') {
41
+ result += jsonString.slice(offset, index);
42
+ offset = index;
43
+ isInsideComment = singleComment;
44
+ index++;
45
+ }
46
+ else if (isInsideComment === singleComment && currentCharacter + nextCharacter === '\r\n') {
47
+ index++;
48
+ isInsideComment = false;
49
+ result += strip(jsonString, offset, index);
50
+ offset = index;
51
+ continue;
52
+ }
53
+ else if (isInsideComment === singleComment && currentCharacter === '\n') {
54
+ isInsideComment = false;
55
+ result += strip(jsonString, offset, index);
56
+ offset = index;
57
+ }
58
+ else if (!isInsideComment && currentCharacter + nextCharacter === '/*') {
59
+ result += jsonString.slice(offset, index);
60
+ offset = index;
61
+ isInsideComment = multiComment;
62
+ index++;
63
+ continue;
64
+ }
65
+ else if (isInsideComment === multiComment && currentCharacter + nextCharacter === '*/') {
66
+ index++;
67
+ isInsideComment = false;
68
+ result += strip(jsonString, offset, index + 1);
69
+ offset = index + 1;
70
+ continue;
71
+ }
72
+ }
73
+ return result + (isInsideComment ? strip(jsonString.slice(offset)) : jsonString.slice(offset));
74
+ }
75
+ exports.stripJsonComments = stripJsonComments;
package/tsconfig.json CHANGED
@@ -17,7 +17,7 @@
17
17
  // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
18
18
  // "sourceMap": true, /* Generates corresponding '.map' file. */
19
19
  // "outFile": "./", /* Concatenate and emit output to single file. */
20
- // "outDir": "./lib", /* Redirect output structure to the directory. */
20
+ "outDir": "./lib", /* Redirect output structure to the directory. */
21
21
  // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
22
22
  // "composite": true, /* Enable project compilation */
23
23
  // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
@@ -72,7 +72,11 @@
72
72
 
73
73
  /* Advanced Options */
74
74
  "skipLibCheck": true, /* Skip type checking of declaration files. */
75
- "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
75
+ "forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
76
+ "plugins": [
77
+ { "transform": "typescript-is/lib/transform-inline/transformer" },
78
+ { "transform": "typescript-transform-paths" }
79
+ ]
76
80
  },
77
81
  "include": ["src"]
78
82
  }