nestia 2.0.4-dev.20220413 → 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.
- package/package.json +2 -3
- package/src/bin/nestia.ts +23 -38
- package/src/internal/CompilerOptions.ts +30 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nestia",
|
|
3
|
-
"version": "2.0.4-dev.
|
|
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": "
|
|
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",
|
package/src/bin/nestia.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import * as cp from "child_process";
|
|
4
4
|
import * as fs from "fs";
|
|
5
5
|
import * as path from "path";
|
|
6
|
-
import * as
|
|
6
|
+
import * as process from "process";
|
|
7
7
|
|
|
8
8
|
import { CompilerOptions } from "../internal/CompilerOptions";
|
|
9
9
|
import { stripJsonComments } from "../utils/stripJsonComments";
|
|
@@ -23,12 +23,12 @@ function install(): void
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
function sdk(): void
|
|
26
|
+
function sdk(file: string): void
|
|
27
27
|
{
|
|
28
28
|
// PREPARE COMMAND
|
|
29
29
|
const parameters: string[] = [
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
`npx ts-node -C ttypescript --project "${file}"`,
|
|
31
|
+
`"${path.relative(process.cwd(), `${__dirname}/../executable/sdk`)}"`,
|
|
32
32
|
...process.argv.slice(3)
|
|
33
33
|
];
|
|
34
34
|
const command: string = parameters.join(" ");
|
|
@@ -39,7 +39,10 @@ function sdk(): void
|
|
|
39
39
|
command,
|
|
40
40
|
{
|
|
41
41
|
stdio: "inherit",
|
|
42
|
-
env: {
|
|
42
|
+
env: {
|
|
43
|
+
...process.env,
|
|
44
|
+
"NODE_NO_WARNINGS": "1"
|
|
45
|
+
}
|
|
43
46
|
}
|
|
44
47
|
);
|
|
45
48
|
}
|
|
@@ -55,69 +58,51 @@ function configure(config: IConfig): boolean
|
|
|
55
58
|
return CompilerOptions.emend(config.compilerOptions);
|
|
56
59
|
}
|
|
57
60
|
|
|
58
|
-
async function tsconfig(task: () => void): Promise<void>
|
|
61
|
+
async function tsconfig(task: (file: string) => void): Promise<void>
|
|
59
62
|
{
|
|
60
63
|
//----
|
|
61
64
|
// PREPARE ASSETS
|
|
62
65
|
//----
|
|
63
|
-
let prepare: null | (() => Promise<void>) = null;
|
|
64
|
-
let restore: null | (() => Promise<void>) = null;
|
|
66
|
+
let prepare: null | (() => Promise<[string, () => Promise<void>]>) = null;
|
|
65
67
|
|
|
68
|
+
// NO TSCONFIG.JSON?
|
|
66
69
|
if (fs.existsSync("tsconfig.json") === false)
|
|
67
70
|
{
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
compilerOptions: CompilerOptions.DEFAULT
|
|
71
|
-
};
|
|
72
|
-
prepare = () => fs.promises.writeFile
|
|
73
|
-
(
|
|
74
|
-
"tsconfig.json",
|
|
75
|
-
JSON.stringify(config, null, 2),
|
|
76
|
-
"utf8"
|
|
77
|
-
);
|
|
78
|
-
restore = () => fs.promises.unlink("tsconfig.json")
|
|
71
|
+
const config = { compilerOptions: CompilerOptions.DEFAULT };
|
|
72
|
+
prepare = CompilerOptions.temporary(config);
|
|
79
73
|
}
|
|
80
74
|
else
|
|
81
75
|
{
|
|
82
76
|
// HAS TSCONFIG.JSON
|
|
83
77
|
const content: string = await fs.promises.readFile("tsconfig.json", "utf8");
|
|
84
|
-
const config
|
|
78
|
+
const config = JSON.parse(stripJsonComments(content));
|
|
79
|
+
|
|
80
|
+
// NEED TO ADD TRANSFORM PLUGINS
|
|
85
81
|
const changed: boolean = configure(config);
|
|
86
|
-
|
|
87
82
|
if (changed === true)
|
|
88
|
-
|
|
89
|
-
// NEED TO ADD TRANSFORM PLUGINS
|
|
90
|
-
prepare = () => fs.promises.writeFile
|
|
91
|
-
(
|
|
92
|
-
"tsconfig.json",
|
|
93
|
-
JSON.stringify(config, null, 2),
|
|
94
|
-
"utf8"
|
|
95
|
-
);
|
|
96
|
-
restore = () => fs.promises.writeFile("tsconfig.json", content, "utf8");
|
|
97
|
-
}
|
|
83
|
+
prepare = CompilerOptions.temporary(config);
|
|
98
84
|
}
|
|
99
85
|
|
|
100
86
|
//----
|
|
101
87
|
// EXECUTION
|
|
102
88
|
//----
|
|
103
|
-
//
|
|
104
|
-
|
|
105
|
-
await prepare();
|
|
89
|
+
// CREATE TEMPORARY TSCONFIG
|
|
90
|
+
const [file, erasure] = prepare ? await prepare() : ["tsconfig.json", null];
|
|
106
91
|
|
|
107
92
|
// EXECUTE THE TASK
|
|
108
93
|
let error: Error | null = null;
|
|
109
94
|
try
|
|
110
95
|
{
|
|
111
|
-
task();
|
|
96
|
+
task(file);
|
|
112
97
|
}
|
|
113
98
|
catch (exp)
|
|
114
99
|
{
|
|
115
100
|
error = exp as Error;
|
|
116
101
|
}
|
|
117
102
|
|
|
118
|
-
//
|
|
119
|
-
if (
|
|
120
|
-
await
|
|
103
|
+
// REMOVE THE TEMPORARY TSCONFIG
|
|
104
|
+
if (erasure)
|
|
105
|
+
await erasure();
|
|
121
106
|
|
|
122
107
|
// THROW ERROR IF EXISTS
|
|
123
108
|
if (error)
|
|
@@ -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
|
}
|