nestia 2.0.2 → 2.0.4-dev.20220415

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.
@@ -3,7 +3,10 @@ on: [push, pull_request]
3
3
 
4
4
  jobs:
5
5
  Ubuntu:
6
- runs-on: ubuntu-latest
6
+ runs-on: ${{ matrix.os }}
7
+ strategy:
8
+ matrix:
9
+ os: [ubuntu-latest, windows-latest, macos-latest]
7
10
  steps:
8
11
  - uses: actions/checkout@v1
9
12
  - uses: actions/setup-node@v1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nestia",
3
- "version": "2.0.2",
3
+ "version": "2.0.4-dev.20220415",
4
4
  "description": "Automatic SDK and Document generator for the NestJS",
5
5
  "main": "src/index.ts",
6
6
  "bin": {
@@ -8,8 +8,7 @@
8
8
  },
9
9
  "scripts": {
10
10
  "dev": "tsc --watch",
11
- "test": "cd test && bash script.sh",
12
- "test:default": "cd test/default && rimraf -rf src/api/functional && ts-node ../../src/bin/nestia sdk src/controllers --out src/api"
11
+ "test": "ts-node test/index"
13
12
  },
14
13
  "repository": {
15
14
  "type": "git",
@@ -36,7 +35,7 @@
36
35
  "cli": "^1.0.1",
37
36
  "del": "^6.0.0",
38
37
  "glob": "^7.2.0",
39
- "ts-node": "^10.4.0",
38
+ "ts-node": "^9.1.1",
40
39
  "tstl": "^2.5.3",
41
40
  "ttypescript": "^1.5.13",
42
41
  "typescript": "^4.6.3",
@@ -1,4 +1,4 @@
1
- import type tsc from "typescript";
1
+ import * as tsc from "typescript";
2
2
 
3
3
  export interface IConfiguration
4
4
  {
@@ -1,6 +1,6 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import tsc from "typescript";
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
+ import * as tsc from "typescript";
4
4
  import { Pair } from "tstl/utility/Pair";
5
5
  import { Singleton } from "tstl/thread/Singleton";
6
6
 
@@ -1,5 +1,5 @@
1
- import NodePath from "path";
2
- import tsc from "typescript";
1
+ import * as NodePath from "path";
2
+ import * as 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 tsc from "typescript";
1
+ import * as tsc from "typescript";
2
2
 
3
3
  export namespace GenericAnalyzer
4
4
  {
@@ -1,4 +1,4 @@
1
- import tsc from "typescript";
1
+ import * as tsc from "typescript";
2
2
 
3
3
  import { HashMap } from "tstl/container/HashMap";
4
4
  import { HashSet } from "tstl/container/HashSet";
@@ -1,11 +1,11 @@
1
- import Pather from "path";
1
+ import * as NodePath from "path";
2
+ import { equal } from "tstl/ranges/module";
2
3
 
3
4
  import { ArrayUtil } from "../utils/ArrayUtil";
4
5
  import { StringUtil } from "../utils/StringUtil";
5
6
 
6
7
  import { IController } from "../structures/IController";
7
8
  import { ParamCategory } from "../structures/ParamCategory";
8
- import { equal } from "tstl/ranges/module";
9
9
 
10
10
  type IModule =
11
11
  {
@@ -128,7 +128,7 @@ export namespace ReflectAnalyzer
128
128
  }
129
129
 
130
130
  // VALIDATE PATH ARGUMENTS
131
- const funcPathArguments: string[] = StringUtil.betweens(Pather.join(controller.path, meta.path).split("\\").join("/"), ":", "/").sort();
131
+ const funcPathArguments: string[] = StringUtil.betweens(NodePath.join(controller.path, meta.path).split("\\").join("/"), ":", "/").sort();
132
132
  const paramPathArguments: string[] = meta.parameters.filter(param => param.category === "param").map(param => param.field!).sort();
133
133
 
134
134
  if (equal(funcPathArguments, paramPathArguments) === false)
@@ -1,6 +1,6 @@
1
- import fs from "fs";
1
+ import * as fs from "fs";
2
2
  import glob from "glob";
3
- import path from "path";
3
+ import * as path from "path";
4
4
 
5
5
  import { IConfiguration } from "../IConfiguration";
6
6
 
package/src/bin/nestia.ts CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  import * as cp from "child_process";
4
4
  import * as fs from "fs";
5
+ import * as path from "path";
6
+ import * as process from "process";
5
7
 
6
8
  import { CompilerOptions } from "../internal/CompilerOptions";
7
9
  import { stripJsonComments } from "../utils/stripJsonComments";
@@ -21,12 +23,12 @@ function install(): void
21
23
  }
22
24
  }
23
25
 
24
- function sdk(): void
26
+ function sdk(file: string): void
25
27
  {
26
28
  // PREPARE COMMAND
27
29
  const parameters: string[] = [
28
- "npx ts-node -C ttypescript",
29
- __dirname + "/../executable/sdk",
30
+ `npx ts-node -C ttypescript --project "${file}"`,
31
+ `"${path.relative(process.cwd(), `${__dirname}/../executable/sdk`)}"`,
30
32
  ...process.argv.slice(3)
31
33
  ];
32
34
  const command: string = parameters.join(" ");
@@ -37,7 +39,10 @@ function sdk(): void
37
39
  command,
38
40
  {
39
41
  stdio: "inherit",
40
- env: { "NODE_NO_WARNINGS": "1" }
42
+ env: {
43
+ ...process.env,
44
+ "NODE_NO_WARNINGS": "1"
45
+ }
41
46
  }
42
47
  );
43
48
  }
@@ -53,69 +58,51 @@ function configure(config: IConfig): boolean
53
58
  return CompilerOptions.emend(config.compilerOptions);
54
59
  }
55
60
 
56
- async function tsconfig(task: () => void): Promise<void>
61
+ async function tsconfig(task: (file: string) => void): Promise<void>
57
62
  {
58
63
  //----
59
64
  // PREPARE ASSETS
60
65
  //----
61
- let prepare: null | (() => Promise<void>) = null;
62
- let restore: null | (() => Promise<void>) = null;
66
+ let prepare: null | (() => Promise<[string, () => Promise<void>]>) = null;
63
67
 
68
+ // NO TSCONFIG.JSON?
64
69
  if (fs.existsSync("tsconfig.json") === false)
65
70
  {
66
- // NO TSCONFIG.JSON
67
- const config: IConfig = {
68
- compilerOptions: CompilerOptions.DEFAULT
69
- };
70
- prepare = () => fs.promises.writeFile
71
- (
72
- "tsconfig.json",
73
- JSON.stringify(config, null, 2),
74
- "utf8"
75
- );
76
- restore = () => fs.promises.unlink("tsconfig.json")
71
+ const config = { compilerOptions: CompilerOptions.DEFAULT };
72
+ prepare = CompilerOptions.temporary(config);
77
73
  }
78
74
  else
79
75
  {
80
76
  // HAS TSCONFIG.JSON
81
77
  const content: string = await fs.promises.readFile("tsconfig.json", "utf8");
82
- const config: IConfig = JSON.parse(stripJsonComments(content));
78
+ const config = JSON.parse(stripJsonComments(content));
79
+
80
+ // NEED TO ADD TRANSFORM PLUGINS
83
81
  const changed: boolean = configure(config);
84
-
85
82
  if (changed === true)
86
- {
87
- // NEED TO ADD TRANSFORM PLUGINS
88
- prepare = () => fs.promises.writeFile
89
- (
90
- "tsconfig.json",
91
- JSON.stringify(config, null, 2),
92
- "utf8"
93
- );
94
- restore = () => fs.promises.writeFile("tsconfig.json", content, "utf8");
95
- }
83
+ prepare = CompilerOptions.temporary(config);
96
84
  }
97
85
 
98
86
  //----
99
87
  // EXECUTION
100
88
  //----
101
- // PREPARE SOMETHING
102
- if (prepare !== null)
103
- await prepare();
89
+ // CREATE TEMPORARY TSCONFIG
90
+ const [file, erasure] = prepare ? await prepare() : ["tsconfig.json", null];
104
91
 
105
92
  // EXECUTE THE TASK
106
93
  let error: Error | null = null;
107
94
  try
108
95
  {
109
- task();
96
+ task(file);
110
97
  }
111
98
  catch (exp)
112
99
  {
113
100
  error = exp as Error;
114
101
  }
115
102
 
116
- // RESTORE THE TSCONFIG.JSON
117
- if (restore !== null)
118
- await restore();
103
+ // REMOVE THE TEMPORARY TSCONFIG
104
+ if (erasure)
105
+ await erasure();
119
106
 
120
107
  // THROW ERROR IF EXISTS
121
108
  if (error)
@@ -1,7 +1,7 @@
1
- import cli from "cli";
2
- import fs from "fs";
3
- import path from "path";
4
- import tsc from "typescript";
1
+ import * as cli from "cli";
2
+ import * as fs from "fs";
3
+ import * as path from "path";
4
+ import * as tsc from "typescript";
5
5
  import { Primitive } from "nestia-fetcher";
6
6
 
7
7
  import { IConfiguration } from "../IConfiguration";
@@ -1,4 +1,4 @@
1
- import fs from "fs";
1
+ import * as fs from "fs";
2
2
  import { HashMap } from "tstl/container/HashMap";
3
3
  import { IConfiguration } from "../IConfiguration";
4
4
 
@@ -1,4 +1,4 @@
1
- import type tsc from "typescript";
1
+ import * as tsc from "typescript";
2
2
  import { Pair } from "tstl/utility/Pair";
3
3
  import { Vector } from "tstl/container/Vector";
4
4
 
@@ -1,4 +1,4 @@
1
- import fs from "fs";
1
+ import * as fs from "fs";
2
2
  import { DirectoryUtil } from "../utils/DirectoryUtil";
3
3
 
4
4
  import { IRoute } from "../structures/IRoute";
@@ -36,4 +36,4 @@ export namespace SdkGenerator
36
36
  }
37
37
  }
38
38
 
39
- const BUNDLE = __dirname + "/../bundle"
39
+ const BUNDLE = __dirname + "/../bundle";
@@ -1,3 +1,5 @@
1
+ import * as fs from "fs";
2
+
1
3
  export interface CompilerOptions
2
4
  {
3
5
  target: string;
@@ -14,7 +16,10 @@ export interface CompilerOptions
14
16
  emitDecoratorMetadata?: boolean;
15
17
  }
16
18
  export namespace CompilerOptions
17
- {
19
+ {
20
+ /* -----------------------------------------------------------
21
+ DEFAULT VALUES
22
+ ----------------------------------------------------------- */
18
23
  export const DEPENDENCIES: string[] = [
19
24
  "nestia-fetcher",
20
25
  "typescript-is"
@@ -110,4 +115,28 @@ export namespace CompilerOptions
110
115
  const checks: boolean[] = checkers.map(func => func());
111
116
  return checks.some(flag => flag);
112
117
  }
118
+
119
+ /* -----------------------------------------------------------
120
+ PROCEDURES
121
+ ----------------------------------------------------------- */
122
+ export function temporary(config: IConfig): () => Promise<[string, () => Promise<void>]>
123
+ {
124
+ return async () =>
125
+ {
126
+ const file: string = `nestia.temporary.tsconfig.${Math.random().toString().substr(2)}.json`;
127
+
128
+ await fs.promises.writeFile
129
+ (
130
+ file,
131
+ JSON.stringify(config, null, 2),
132
+ "utf8"
133
+ );
134
+ return [file, () => fs.promises.unlink(file)];
135
+ };
136
+ }
137
+ }
138
+
139
+ interface IConfig
140
+ {
141
+ compilerOptions?: CompilerOptions;
113
142
  }
@@ -1,4 +1,4 @@
1
- import type tsc from "typescript";
1
+ import * as 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 fs from "fs";
2
+ import * as fs from "fs";
3
3
 
4
4
  export namespace DirectoryUtil
5
5
  {
@@ -1,4 +1,4 @@
1
- import path from "path";
1
+ import * as path from "path";
2
2
 
3
3
  import { HashMap } from "tstl/container/HashMap";
4
4
  import { HashSet } from "tstl/container/HashSet";