nestia 2.0.5 → 2.0.6-dev.20220414
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 +1 -1
- package/src/bin/nestia.ts +1 -1
- package/src/executable/sdk.ts +3 -8
- package/src/internal/NestiaConfig.ts +36 -0
- package/src/internal/TsConfig.ts +48 -40
package/package.json
CHANGED
package/src/bin/nestia.ts
CHANGED
|
@@ -50,7 +50,7 @@ async function main()
|
|
|
50
50
|
else if (process.argv[2] === "sdk")
|
|
51
51
|
await sdk();
|
|
52
52
|
else
|
|
53
|
-
throw new Error(`nestia supports only two commands; install and sdk, however you typed ${process.argv[2]}`);
|
|
53
|
+
throw new Error(`nestia supports only two commands; install and sdk, however you've typed the "${process.argv[2]}"`);
|
|
54
54
|
}
|
|
55
55
|
main().catch(exp =>
|
|
56
56
|
{
|
package/src/executable/sdk.ts
CHANGED
|
@@ -2,11 +2,11 @@ import * as cli from "cli";
|
|
|
2
2
|
import * as fs from "fs";
|
|
3
3
|
import * as path from "path";
|
|
4
4
|
import * as tsc from "typescript";
|
|
5
|
-
import { Primitive } from "nestia-fetcher";
|
|
6
5
|
|
|
7
6
|
import { IConfiguration } from "../IConfiguration";
|
|
8
7
|
import { NestiaApplication } from "../NestiaApplication";
|
|
9
8
|
import { stripJsonComments } from "../utils/stripJsonComments";
|
|
9
|
+
import { NestiaConfig } from "../internal/NestiaConfig";
|
|
10
10
|
|
|
11
11
|
interface ICommand
|
|
12
12
|
{
|
|
@@ -17,13 +17,8 @@ interface ICommand
|
|
|
17
17
|
async function sdk(include: string[], command: ICommand): Promise<void>
|
|
18
18
|
{
|
|
19
19
|
// CONFIGURATION
|
|
20
|
-
let config: IConfiguration;
|
|
21
|
-
if (
|
|
22
|
-
config = Primitive.clone
|
|
23
|
-
(
|
|
24
|
-
await import(path.resolve("nestia.config.ts"))
|
|
25
|
-
);
|
|
26
|
-
else
|
|
20
|
+
let config: IConfiguration | null = await NestiaConfig.get();
|
|
21
|
+
if (config === null)
|
|
27
22
|
{
|
|
28
23
|
if (command.out === null)
|
|
29
24
|
throw new Error(`Output directory is not specified. Add the "--out <output_directory>" option.`);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { InvalidArgument } from "tstl/exception/InvalidArgument";
|
|
4
|
+
import { Primitive } from "nestia-fetcher";
|
|
5
|
+
import { Singleton } from "tstl/thread/Singleton";
|
|
6
|
+
import { assertType, is } from "typescript-is";
|
|
7
|
+
|
|
8
|
+
import { IConfiguration } from "../IConfiguration";
|
|
9
|
+
|
|
10
|
+
export namespace NestiaConfig
|
|
11
|
+
{
|
|
12
|
+
export function get(): Promise<IConfiguration | null>
|
|
13
|
+
{
|
|
14
|
+
return singleton.get();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function assert(config: IConfiguration): IConfiguration
|
|
18
|
+
{
|
|
19
|
+
assertType<Omit<typeof config, "input"|"compilerOptions">>(config);
|
|
20
|
+
if (is<string>(config.input) === false
|
|
21
|
+
&& is<string[]>(config.input) === false
|
|
22
|
+
&& is<IConfiguration.IInput>(config.input) === false)
|
|
23
|
+
throw new InvalidArgument("Error on NestiaConfig.get(): invalid input type.");
|
|
24
|
+
|
|
25
|
+
return config;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const singleton = new Singleton(async () =>
|
|
29
|
+
{
|
|
30
|
+
if (fs.existsSync("nestia.config.ts") === false)
|
|
31
|
+
return null;
|
|
32
|
+
|
|
33
|
+
const config: IConfiguration = await import(path.resolve("nestia.config.ts"));
|
|
34
|
+
return assert(Primitive.clone(config));
|
|
35
|
+
});
|
|
36
|
+
}
|
package/src/internal/TsConfig.ts
CHANGED
|
@@ -25,7 +25,7 @@ export namespace TsConfig
|
|
|
25
25
|
emitDecoratorMetadata: true,
|
|
26
26
|
plugins: [
|
|
27
27
|
{ transform: "typescript-is/lib/transform-inline/transformer" },
|
|
28
|
-
{ transform: "typescript-transform-paths" }
|
|
28
|
+
// { transform: "typescript-transform-paths" }
|
|
29
29
|
]
|
|
30
30
|
};
|
|
31
31
|
|
|
@@ -65,51 +65,59 @@ export namespace TsConfig
|
|
|
65
65
|
"utf8"
|
|
66
66
|
);
|
|
67
67
|
}
|
|
68
|
-
else
|
|
68
|
+
else if (emend(config.compilerOptions as CSON.CommentObject) === true)
|
|
69
69
|
{
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
// OVERWRITE THE CONTENT
|
|
71
|
+
await fs.promises.writeFile
|
|
72
|
+
(
|
|
73
|
+
"tsconfig.json",
|
|
74
|
+
CSON.stringify(config, null, 2),
|
|
75
|
+
"utf8"
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function emend(options: CSON.CommentObject): boolean
|
|
81
|
+
{
|
|
82
|
+
if (options.paths && Object.entries(options.paths).length !== 0)
|
|
83
|
+
DEFAULT_OPTIONS.plugins.push({ transform: "typescript-transform-paths" });
|
|
84
|
+
|
|
85
|
+
let changed: boolean = false;
|
|
86
|
+
for (const [key, value] of Object.entries(DEFAULT_OPTIONS))
|
|
87
|
+
if (options[key] instanceof Array && value instanceof Array)
|
|
73
88
|
{
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
{
|
|
81
|
-
[key]:
|
|
82
|
-
[
|
|
83
|
-
...new Set
|
|
84
|
-
([
|
|
85
|
-
...value,
|
|
86
|
-
...options[key] as string[]
|
|
87
|
-
])
|
|
88
|
-
]
|
|
89
|
-
}
|
|
90
|
-
);
|
|
89
|
+
merge<any>(options[key] as Array<any>, value,
|
|
90
|
+
key !== "plugins"
|
|
91
|
+
? (x, y) => x === y
|
|
92
|
+
: (x, y) => x.transform === y.transform
|
|
93
|
+
);
|
|
94
|
+
changed ||= true;
|
|
91
95
|
}
|
|
92
|
-
|
|
93
|
-
if (!options.plugins)
|
|
94
|
-
CSON.assign(options.plugins, { plugins: DEFAULT_OPTIONS.plugins });
|
|
95
|
-
else
|
|
96
|
+
else if (options[key] !== value)
|
|
96
97
|
{
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
{
|
|
100
|
-
const found = optionPlugins.find(elem => elem.transform === plugin.transform);
|
|
101
|
-
if (!found)
|
|
102
|
-
optionPlugins.push(plugin);
|
|
103
|
-
}
|
|
98
|
+
CSON.assign(options, { [key]: value });
|
|
99
|
+
changed ||= true;
|
|
104
100
|
}
|
|
105
|
-
|
|
101
|
+
return changed;
|
|
102
|
+
}
|
|
106
103
|
|
|
107
|
-
|
|
108
|
-
await fs.promises.writeFile
|
|
104
|
+
function merge<T>
|
|
109
105
|
(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
)
|
|
106
|
+
origin: T[],
|
|
107
|
+
must: T[],
|
|
108
|
+
pred: (a: T, b: T) => boolean
|
|
109
|
+
): boolean
|
|
110
|
+
{
|
|
111
|
+
let changed: boolean = false;
|
|
112
|
+
for (const m of must)
|
|
113
|
+
{
|
|
114
|
+
const found: T | undefined = origin.find(elem => pred(elem, m));
|
|
115
|
+
if (found !== undefined)
|
|
116
|
+
continue;
|
|
117
|
+
|
|
118
|
+
origin.push(m);
|
|
119
|
+
changed ||= true;
|
|
120
|
+
}
|
|
121
|
+
return changed;
|
|
114
122
|
}
|
|
115
123
|
}
|