@nestia/sdk 0.2.0 → 1.0.1
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/assets/config/nestia.config.ts +79 -70
- package/lib/INestiaConfig.d.ts +18 -14
- package/lib/executable/sdk.js +16 -16
- package/lib/generates/FunctionGenerator.js +9 -9
- package/lib/generates/FunctionGenerator.js.map +1 -1
- package/lib/generates/SwaggerGenerator.js +9 -9
- package/package.json +3 -3
- package/src/INestiaConfig.ts +124 -120
- package/src/NestiaSdkApplication.ts +183 -183
- package/src/analyses/ControllerAnalyzer.ts +203 -203
- package/src/analyses/GenericAnalyzer.ts +53 -53
- package/src/analyses/ImportAnalyzer.ts +143 -143
- package/src/analyses/PathAnalyzer.ts +58 -58
- package/src/analyses/ReflectAnalyzer.ts +279 -279
- package/src/analyses/SourceFinder.ts +59 -59
- package/src/executable/internal/CommandParser.ts +15 -15
- package/src/executable/internal/NestiaConfigCompilerOptions.ts +18 -18
- package/src/executable/internal/NestiaSdkCommand.ts +174 -174
- package/src/executable/internal/NestiaSdkConfig.ts +35 -35
- package/src/executable/internal/nestia.config.getter.ts +12 -12
- package/src/executable/sdk.ts +74 -74
- package/src/generates/FileGenerator.ts +156 -156
- package/src/generates/FunctionGenerator.ts +284 -287
- package/src/generates/SdkGenerator.ts +50 -50
- package/src/generates/SwaggerGenerator.ts +393 -393
- package/src/index.ts +3 -3
- package/src/module.ts +2 -2
- package/src/structures/IController.ts +27 -27
- package/src/structures/IRoute.ts +29 -29
- package/src/structures/ISwagger.ts +55 -55
- package/src/structures/ITypeTuple.ts +6 -6
- package/src/structures/MethodType.ts +11 -11
- package/src/structures/ParamCategory.ts +1 -1
- package/src/structures/TypeEntry.ts +22 -22
- package/src/utils/ArrayUtil.ts +26 -26
- package/src/utils/ImportDictionary.ts +56 -56
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/StripEnums.ts +10 -10
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export namespace CommandParser {
|
|
2
|
-
export function parse(argList: string[]): Record<string, string> {
|
|
3
|
-
const output: Record<string, string> = {};
|
|
4
|
-
argList.forEach((arg, i) => {
|
|
5
|
-
if (arg.startsWith("--") === false) return;
|
|
6
|
-
|
|
7
|
-
const key = arg.slice(2);
|
|
8
|
-
const value: string | undefined = argList[i + 1];
|
|
9
|
-
if (value === undefined || value.startsWith("--")) return;
|
|
10
|
-
|
|
11
|
-
output[key] = value;
|
|
12
|
-
});
|
|
13
|
-
return output;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
export namespace CommandParser {
|
|
2
|
+
export function parse(argList: string[]): Record<string, string> {
|
|
3
|
+
const output: Record<string, string> = {};
|
|
4
|
+
argList.forEach((arg, i) => {
|
|
5
|
+
if (arg.startsWith("--") === false) return;
|
|
6
|
+
|
|
7
|
+
const key = arg.slice(2);
|
|
8
|
+
const value: string | undefined = argList[i + 1];
|
|
9
|
+
if (value === undefined || value.startsWith("--")) return;
|
|
10
|
+
|
|
11
|
+
output[key] = value;
|
|
12
|
+
});
|
|
13
|
+
return output;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export namespace NestiaConfigCompilerOptions {
|
|
2
|
-
/* -----------------------------------------------------------
|
|
3
|
-
DEFAULT VALUES
|
|
4
|
-
----------------------------------------------------------- */
|
|
5
|
-
const ESSENTIAL_OPTIONS = {
|
|
6
|
-
types: ["node", "reflect-metadata"],
|
|
7
|
-
noEmit: true,
|
|
8
|
-
esModuleInterop: true,
|
|
9
|
-
experimentalDecorators: true,
|
|
10
|
-
emitDecoratorMetadata: true,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const DEFAULT_OPTIONS = {
|
|
14
|
-
...ESSENTIAL_OPTIONS,
|
|
15
|
-
target: "es5",
|
|
16
|
-
module: "commonjs",
|
|
17
|
-
};
|
|
18
|
-
}
|
|
1
|
+
export namespace NestiaConfigCompilerOptions {
|
|
2
|
+
/* -----------------------------------------------------------
|
|
3
|
+
DEFAULT VALUES
|
|
4
|
+
----------------------------------------------------------- */
|
|
5
|
+
const ESSENTIAL_OPTIONS = {
|
|
6
|
+
types: ["node", "reflect-metadata"],
|
|
7
|
+
noEmit: true,
|
|
8
|
+
esModuleInterop: true,
|
|
9
|
+
experimentalDecorators: true,
|
|
10
|
+
emitDecoratorMetadata: true,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const DEFAULT_OPTIONS = {
|
|
14
|
+
...ESSENTIAL_OPTIONS,
|
|
15
|
+
target: "es5",
|
|
16
|
+
module: "commonjs",
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -1,174 +1,174 @@
|
|
|
1
|
-
import cli from "cli";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { WorkerConnector } from "tgrid/protocols/workers/WorkerConnector";
|
|
4
|
-
import { parseNative } from "tsconfck";
|
|
5
|
-
import ts from "typescript";
|
|
6
|
-
|
|
7
|
-
import { INestiaConfig } from "../../INestiaConfig";
|
|
8
|
-
import { NestiaSdkApplication } from "../../NestiaSdkApplication";
|
|
9
|
-
import { NestiaSdkConfig } from "./NestiaSdkConfig";
|
|
10
|
-
|
|
11
|
-
interface ICommand {
|
|
12
|
-
exclude: string | null;
|
|
13
|
-
out: string | null;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface IOutput {
|
|
17
|
-
assign: (config: INestiaConfig, output: string) => void;
|
|
18
|
-
validate: (config: INestiaConfig) => boolean;
|
|
19
|
-
location: (config: INestiaConfig) => string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export namespace NestiaSdkCommand {
|
|
23
|
-
export function sdk(
|
|
24
|
-
elements: string[],
|
|
25
|
-
pure: boolean = true,
|
|
26
|
-
): Promise<void> {
|
|
27
|
-
return main(
|
|
28
|
-
(app) => app.sdk(),
|
|
29
|
-
{
|
|
30
|
-
assign: (config, output) => (config.output = output),
|
|
31
|
-
validate: (config) => !!config.output,
|
|
32
|
-
location: (config) => config.output!,
|
|
33
|
-
},
|
|
34
|
-
elements,
|
|
35
|
-
pure,
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function swagger(
|
|
40
|
-
elements: string[],
|
|
41
|
-
pure: boolean = true,
|
|
42
|
-
): Promise<void> {
|
|
43
|
-
return main(
|
|
44
|
-
(app) => app.swagger(),
|
|
45
|
-
{
|
|
46
|
-
assign: (config, output) => {
|
|
47
|
-
if (!config.swagger) config.swagger = { output };
|
|
48
|
-
else config.swagger.output = output;
|
|
49
|
-
},
|
|
50
|
-
validate: (config) =>
|
|
51
|
-
!!config.swagger && !!config.swagger.output,
|
|
52
|
-
location: (config) => config.swagger!.output!,
|
|
53
|
-
},
|
|
54
|
-
elements,
|
|
55
|
-
pure,
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async function main(
|
|
60
|
-
task: (app: NestiaSdkApplication) => Promise<void>,
|
|
61
|
-
output: IOutput,
|
|
62
|
-
elements: string[],
|
|
63
|
-
pure: boolean,
|
|
64
|
-
): Promise<void> {
|
|
65
|
-
if (pure === false)
|
|
66
|
-
cli.setArgv([
|
|
67
|
-
process.argv[0],
|
|
68
|
-
process.argv[1],
|
|
69
|
-
"nestia",
|
|
70
|
-
...elements,
|
|
71
|
-
]);
|
|
72
|
-
const command: ICommand = cli.parse({
|
|
73
|
-
exclude: ["e", "Something to exclude", "string", null],
|
|
74
|
-
out: ["o", "Output path of the SDK files", "string", null],
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
const inputs: string[] = [];
|
|
78
|
-
for (const arg of elements) {
|
|
79
|
-
if (arg[0] === "-") break;
|
|
80
|
-
inputs.push(arg);
|
|
81
|
-
}
|
|
82
|
-
await generate(task, inputs, command, output);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async function generate(
|
|
86
|
-
task: (app: NestiaSdkApplication) => Promise<void>,
|
|
87
|
-
include: string[],
|
|
88
|
-
command: ICommand,
|
|
89
|
-
output: IOutput,
|
|
90
|
-
): Promise<void> {
|
|
91
|
-
// CONFIGURATION
|
|
92
|
-
const config: INestiaConfig =
|
|
93
|
-
(await get_nestia_config(output.validate)) ??
|
|
94
|
-
parse_cli(include, command, output);
|
|
95
|
-
|
|
96
|
-
const options = await get_typescript_options();
|
|
97
|
-
|
|
98
|
-
config.compilerOptions = {
|
|
99
|
-
...options,
|
|
100
|
-
...(config.compilerOptions || {}),
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
// CALL THE APP.GENERATE()
|
|
104
|
-
const app: NestiaSdkApplication = new NestiaSdkApplication(config);
|
|
105
|
-
await task(app);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
async function get_typescript_options(): Promise<ts.CompilerOptions | null> {
|
|
109
|
-
const configFileName = ts.findConfigFile(
|
|
110
|
-
process.cwd(),
|
|
111
|
-
ts.sys.fileExists,
|
|
112
|
-
"tsconfig.json",
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
if (!configFileName) return null;
|
|
116
|
-
|
|
117
|
-
const { tsconfig } = await parseNative(configFileName);
|
|
118
|
-
|
|
119
|
-
const configFileText = JSON.stringify(tsconfig);
|
|
120
|
-
|
|
121
|
-
const { config } = ts.parseConfigFileTextToJson(
|
|
122
|
-
configFileName,
|
|
123
|
-
configFileText,
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
const configParseResult = ts.parseJsonConfigFileContent(
|
|
127
|
-
config,
|
|
128
|
-
ts.sys,
|
|
129
|
-
path.dirname(configFileName),
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
const { moduleResolution, ...result } =
|
|
133
|
-
configParseResult.raw.compilerOptions;
|
|
134
|
-
return result;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
async function get_nestia_config(
|
|
138
|
-
validate: (config: INestiaConfig) => boolean,
|
|
139
|
-
): Promise<INestiaConfig | null> {
|
|
140
|
-
const connector = new WorkerConnector(null, null, "process");
|
|
141
|
-
await connector.connect(`${__dirname}/nestia.config.getter.js`);
|
|
142
|
-
|
|
143
|
-
const driver = await connector.getDriver<typeof NestiaSdkConfig>();
|
|
144
|
-
const config: INestiaConfig | null = await driver.get();
|
|
145
|
-
await connector.close();
|
|
146
|
-
|
|
147
|
-
if (config !== null && validate(config) === false)
|
|
148
|
-
throw new Error(
|
|
149
|
-
`Error on NestiaCommand.main(): output path is not specified in the "nestia.config.ts".`,
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
return config;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function parse_cli(
|
|
156
|
-
include: string[],
|
|
157
|
-
command: ICommand,
|
|
158
|
-
output: IOutput,
|
|
159
|
-
): INestiaConfig {
|
|
160
|
-
if (command.out === null)
|
|
161
|
-
throw new Error(
|
|
162
|
-
`Error on NestiaCommand.main(): output directory is not specified. Add the "--out <output_directory>" option.`,
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
const config: INestiaConfig = {
|
|
166
|
-
input: {
|
|
167
|
-
include,
|
|
168
|
-
exclude: command.exclude ? [command.exclude] : undefined,
|
|
169
|
-
},
|
|
170
|
-
};
|
|
171
|
-
output.assign(config, command.out);
|
|
172
|
-
return config;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
1
|
+
import cli from "cli";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { WorkerConnector } from "tgrid/protocols/workers/WorkerConnector";
|
|
4
|
+
import { parseNative } from "tsconfck";
|
|
5
|
+
import ts from "typescript";
|
|
6
|
+
|
|
7
|
+
import { INestiaConfig } from "../../INestiaConfig";
|
|
8
|
+
import { NestiaSdkApplication } from "../../NestiaSdkApplication";
|
|
9
|
+
import { NestiaSdkConfig } from "./NestiaSdkConfig";
|
|
10
|
+
|
|
11
|
+
interface ICommand {
|
|
12
|
+
exclude: string | null;
|
|
13
|
+
out: string | null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface IOutput {
|
|
17
|
+
assign: (config: INestiaConfig, output: string) => void;
|
|
18
|
+
validate: (config: INestiaConfig) => boolean;
|
|
19
|
+
location: (config: INestiaConfig) => string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export namespace NestiaSdkCommand {
|
|
23
|
+
export function sdk(
|
|
24
|
+
elements: string[],
|
|
25
|
+
pure: boolean = true,
|
|
26
|
+
): Promise<void> {
|
|
27
|
+
return main(
|
|
28
|
+
(app) => app.sdk(),
|
|
29
|
+
{
|
|
30
|
+
assign: (config, output) => (config.output = output),
|
|
31
|
+
validate: (config) => !!config.output,
|
|
32
|
+
location: (config) => config.output!,
|
|
33
|
+
},
|
|
34
|
+
elements,
|
|
35
|
+
pure,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function swagger(
|
|
40
|
+
elements: string[],
|
|
41
|
+
pure: boolean = true,
|
|
42
|
+
): Promise<void> {
|
|
43
|
+
return main(
|
|
44
|
+
(app) => app.swagger(),
|
|
45
|
+
{
|
|
46
|
+
assign: (config, output) => {
|
|
47
|
+
if (!config.swagger) config.swagger = { output };
|
|
48
|
+
else config.swagger.output = output;
|
|
49
|
+
},
|
|
50
|
+
validate: (config) =>
|
|
51
|
+
!!config.swagger && !!config.swagger.output,
|
|
52
|
+
location: (config) => config.swagger!.output!,
|
|
53
|
+
},
|
|
54
|
+
elements,
|
|
55
|
+
pure,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function main(
|
|
60
|
+
task: (app: NestiaSdkApplication) => Promise<void>,
|
|
61
|
+
output: IOutput,
|
|
62
|
+
elements: string[],
|
|
63
|
+
pure: boolean,
|
|
64
|
+
): Promise<void> {
|
|
65
|
+
if (pure === false)
|
|
66
|
+
cli.setArgv([
|
|
67
|
+
process.argv[0],
|
|
68
|
+
process.argv[1],
|
|
69
|
+
"nestia",
|
|
70
|
+
...elements,
|
|
71
|
+
]);
|
|
72
|
+
const command: ICommand = cli.parse({
|
|
73
|
+
exclude: ["e", "Something to exclude", "string", null],
|
|
74
|
+
out: ["o", "Output path of the SDK files", "string", null],
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const inputs: string[] = [];
|
|
78
|
+
for (const arg of elements) {
|
|
79
|
+
if (arg[0] === "-") break;
|
|
80
|
+
inputs.push(arg);
|
|
81
|
+
}
|
|
82
|
+
await generate(task, inputs, command, output);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function generate(
|
|
86
|
+
task: (app: NestiaSdkApplication) => Promise<void>,
|
|
87
|
+
include: string[],
|
|
88
|
+
command: ICommand,
|
|
89
|
+
output: IOutput,
|
|
90
|
+
): Promise<void> {
|
|
91
|
+
// CONFIGURATION
|
|
92
|
+
const config: INestiaConfig =
|
|
93
|
+
(await get_nestia_config(output.validate)) ??
|
|
94
|
+
parse_cli(include, command, output);
|
|
95
|
+
|
|
96
|
+
const options = await get_typescript_options();
|
|
97
|
+
|
|
98
|
+
config.compilerOptions = {
|
|
99
|
+
...options,
|
|
100
|
+
...(config.compilerOptions || {}),
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// CALL THE APP.GENERATE()
|
|
104
|
+
const app: NestiaSdkApplication = new NestiaSdkApplication(config);
|
|
105
|
+
await task(app);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function get_typescript_options(): Promise<ts.CompilerOptions | null> {
|
|
109
|
+
const configFileName = ts.findConfigFile(
|
|
110
|
+
process.cwd(),
|
|
111
|
+
ts.sys.fileExists,
|
|
112
|
+
"tsconfig.json",
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
if (!configFileName) return null;
|
|
116
|
+
|
|
117
|
+
const { tsconfig } = await parseNative(configFileName);
|
|
118
|
+
|
|
119
|
+
const configFileText = JSON.stringify(tsconfig);
|
|
120
|
+
|
|
121
|
+
const { config } = ts.parseConfigFileTextToJson(
|
|
122
|
+
configFileName,
|
|
123
|
+
configFileText,
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
const configParseResult = ts.parseJsonConfigFileContent(
|
|
127
|
+
config,
|
|
128
|
+
ts.sys,
|
|
129
|
+
path.dirname(configFileName),
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
const { moduleResolution, ...result } =
|
|
133
|
+
configParseResult.raw.compilerOptions;
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function get_nestia_config(
|
|
138
|
+
validate: (config: INestiaConfig) => boolean,
|
|
139
|
+
): Promise<INestiaConfig | null> {
|
|
140
|
+
const connector = new WorkerConnector(null, null, "process");
|
|
141
|
+
await connector.connect(`${__dirname}/nestia.config.getter.js`);
|
|
142
|
+
|
|
143
|
+
const driver = await connector.getDriver<typeof NestiaSdkConfig>();
|
|
144
|
+
const config: INestiaConfig | null = await driver.get();
|
|
145
|
+
await connector.close();
|
|
146
|
+
|
|
147
|
+
if (config !== null && validate(config) === false)
|
|
148
|
+
throw new Error(
|
|
149
|
+
`Error on NestiaCommand.main(): output path is not specified in the "nestia.config.ts".`,
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
return config;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function parse_cli(
|
|
156
|
+
include: string[],
|
|
157
|
+
command: ICommand,
|
|
158
|
+
output: IOutput,
|
|
159
|
+
): INestiaConfig {
|
|
160
|
+
if (command.out === null)
|
|
161
|
+
throw new Error(
|
|
162
|
+
`Error on NestiaCommand.main(): output directory is not specified. Add the "--out <output_directory>" option.`,
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
const config: INestiaConfig = {
|
|
166
|
+
input: {
|
|
167
|
+
include,
|
|
168
|
+
exclude: command.exclude ? [command.exclude] : undefined,
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
output.assign(config, command.out);
|
|
172
|
+
return config;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import * as runner from "ts-node";
|
|
4
|
-
import { Singleton } from "tstl/thread/Singleton";
|
|
5
|
-
import { assert } from "typia";
|
|
6
|
-
|
|
7
|
-
import { INestiaConfig } from "../../INestiaConfig";
|
|
8
|
-
|
|
9
|
-
export namespace NestiaSdkConfig {
|
|
10
|
-
export function get(): Promise<INestiaConfig | null> {
|
|
11
|
-
return singleton.get();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const singleton = new Singleton(async () => {
|
|
15
|
-
if (fs.existsSync("nestia.config.ts") === false) return null;
|
|
16
|
-
|
|
17
|
-
runner.register({
|
|
18
|
-
emit: false,
|
|
19
|
-
compilerOptions: {
|
|
20
|
-
module: "CommonJS",
|
|
21
|
-
noEmit: true,
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const loaded: INestiaConfig & { default?: INestiaConfig } =
|
|
26
|
-
await import(path.resolve("nestia.config.ts"));
|
|
27
|
-
if (typeof loaded !== "object")
|
|
28
|
-
throw new Error("Error on NestiaConfig.get(): failed to load data");
|
|
29
|
-
|
|
30
|
-
const config: INestiaConfig =
|
|
31
|
-
typeof loaded.default === "object" ? loaded.default : loaded;
|
|
32
|
-
const cloned: INestiaConfig = JSON.parse(JSON.stringify(config));
|
|
33
|
-
return assert(cloned);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import * as runner from "ts-node";
|
|
4
|
+
import { Singleton } from "tstl/thread/Singleton";
|
|
5
|
+
import { assert } from "typia";
|
|
6
|
+
|
|
7
|
+
import { INestiaConfig } from "../../INestiaConfig";
|
|
8
|
+
|
|
9
|
+
export namespace NestiaSdkConfig {
|
|
10
|
+
export function get(): Promise<INestiaConfig | null> {
|
|
11
|
+
return singleton.get();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const singleton = new Singleton(async () => {
|
|
15
|
+
if (fs.existsSync("nestia.config.ts") === false) return null;
|
|
16
|
+
|
|
17
|
+
runner.register({
|
|
18
|
+
emit: false,
|
|
19
|
+
compilerOptions: {
|
|
20
|
+
module: "CommonJS",
|
|
21
|
+
noEmit: true,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const loaded: INestiaConfig & { default?: INestiaConfig } =
|
|
26
|
+
await import(path.resolve("nestia.config.ts"));
|
|
27
|
+
if (typeof loaded !== "object")
|
|
28
|
+
throw new Error("Error on NestiaConfig.get(): failed to load data");
|
|
29
|
+
|
|
30
|
+
const config: INestiaConfig =
|
|
31
|
+
typeof loaded.default === "object" ? loaded.default : loaded;
|
|
32
|
+
const cloned: INestiaConfig = JSON.parse(JSON.stringify(config));
|
|
33
|
+
return assert(cloned);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { WorkerServer } from "tgrid/protocols/workers/WorkerServer";
|
|
2
|
-
|
|
3
|
-
import { NestiaSdkConfig } from "./NestiaSdkConfig";
|
|
4
|
-
|
|
5
|
-
async function main(): Promise<void> {
|
|
6
|
-
const worker = new WorkerServer();
|
|
7
|
-
await worker.open(NestiaSdkConfig);
|
|
8
|
-
}
|
|
9
|
-
main().catch((exp) => {
|
|
10
|
-
console.log(exp);
|
|
11
|
-
process.exit(-1);
|
|
12
|
-
});
|
|
1
|
+
import { WorkerServer } from "tgrid/protocols/workers/WorkerServer";
|
|
2
|
+
|
|
3
|
+
import { NestiaSdkConfig } from "./NestiaSdkConfig";
|
|
4
|
+
|
|
5
|
+
async function main(): Promise<void> {
|
|
6
|
+
const worker = new WorkerServer();
|
|
7
|
+
await worker.open(NestiaSdkConfig);
|
|
8
|
+
}
|
|
9
|
+
main().catch((exp) => {
|
|
10
|
+
console.log(exp);
|
|
11
|
+
process.exit(-1);
|
|
12
|
+
});
|
package/src/executable/sdk.ts
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import cp from "child_process";
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import process from "process";
|
|
5
|
-
|
|
6
|
-
import { CommandParser } from "./internal/CommandParser";
|
|
7
|
-
import type { NestiaSdkCommand } from "./internal/NestiaSdkCommand";
|
|
8
|
-
|
|
9
|
-
const USAGE = `Wrong command has been detected. Use like below:
|
|
10
|
-
|
|
11
|
-
npx @nestia/sdk [command] [options?]
|
|
12
|
-
|
|
13
|
-
1. npx @nestia/sdk dependencies --manager (npm|pnpm|yarn)
|
|
14
|
-
- npx @nestia/sdk dependencies
|
|
15
|
-
- npx @nestia/sdk dependencies --manager pnpm
|
|
16
|
-
2. npx @nestia/sdk init
|
|
17
|
-
3. npx @nestia/sdk sdk <input> --out <output>
|
|
18
|
-
- npx @nestia/sdk sdk # when "nestia.config.ts" be configured
|
|
19
|
-
- npx @nestia/sdk sdk src/controllers --out src/api
|
|
20
|
-
- npx @nestia/sdk sdk src/**/*.controller.ts --out src/api
|
|
21
|
-
4. npx @nestia/sdk swagger <input> --out <output>
|
|
22
|
-
- npx @nestia/sdk swagger # when "nestia.config.ts" be configured
|
|
23
|
-
- npx @nestia/sdk swagger src/controllers --out src/api
|
|
24
|
-
- npx @nestia/sdk swagger src/**/*.controller.ts --out src/api
|
|
25
|
-
`;
|
|
26
|
-
|
|
27
|
-
function halt(desc: string): never {
|
|
28
|
-
console.error(desc);
|
|
29
|
-
process.exit(-1);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function dependencies(argv: string[]): void {
|
|
33
|
-
// INSTALL DEPENDENCIES
|
|
34
|
-
const module = CommandParser.parse(argv).module ?? "npm";
|
|
35
|
-
const prefix: string = module === "yarn" ? "yarn add" : `${module} install`;
|
|
36
|
-
|
|
37
|
-
for (const lib of ["@nestia/fetcher", "typia"]) {
|
|
38
|
-
const command: string = `${prefix} ${lib}`;
|
|
39
|
-
cp.execSync(command, { stdio: "inherit" });
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async function initialize(): Promise<void> {
|
|
44
|
-
if (fs.existsSync("nestia.config.ts") === true)
|
|
45
|
-
halt(
|
|
46
|
-
`Error on nestia.sdk.initialize(): "nestia.config.ts" file already has been configured.`,
|
|
47
|
-
);
|
|
48
|
-
await fs.promises.copyFile(
|
|
49
|
-
`${__dirname}/../../assets/config/nestia.config.ts`,
|
|
50
|
-
"nestia.config.ts",
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async function execute(
|
|
55
|
-
closure: (commander: typeof NestiaSdkCommand) => Promise<void>,
|
|
56
|
-
): Promise<void> {
|
|
57
|
-
const module = await import("./internal/NestiaSdkCommand");
|
|
58
|
-
await closure(module.NestiaSdkCommand);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async function main() {
|
|
62
|
-
const type: string | undefined = process.argv[2];
|
|
63
|
-
const argv: string[] = process.argv.slice(3);
|
|
64
|
-
|
|
65
|
-
if (type === "dependencies") dependencies(argv);
|
|
66
|
-
else if (type === "init") await initialize();
|
|
67
|
-
else if (type === "sdk") await execute((c) => c.sdk(argv));
|
|
68
|
-
else if (type === "swagger") await execute((c) => c.swagger(argv));
|
|
69
|
-
else halt(USAGE);
|
|
70
|
-
}
|
|
71
|
-
main().catch((exp) => {
|
|
72
|
-
console.log(exp.message);
|
|
73
|
-
process.exit(-1);
|
|
74
|
-
});
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import cp from "child_process";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import process from "process";
|
|
5
|
+
|
|
6
|
+
import { CommandParser } from "./internal/CommandParser";
|
|
7
|
+
import type { NestiaSdkCommand } from "./internal/NestiaSdkCommand";
|
|
8
|
+
|
|
9
|
+
const USAGE = `Wrong command has been detected. Use like below:
|
|
10
|
+
|
|
11
|
+
npx @nestia/sdk [command] [options?]
|
|
12
|
+
|
|
13
|
+
1. npx @nestia/sdk dependencies --manager (npm|pnpm|yarn)
|
|
14
|
+
- npx @nestia/sdk dependencies
|
|
15
|
+
- npx @nestia/sdk dependencies --manager pnpm
|
|
16
|
+
2. npx @nestia/sdk init
|
|
17
|
+
3. npx @nestia/sdk sdk <input> --out <output>
|
|
18
|
+
- npx @nestia/sdk sdk # when "nestia.config.ts" be configured
|
|
19
|
+
- npx @nestia/sdk sdk src/controllers --out src/api
|
|
20
|
+
- npx @nestia/sdk sdk src/**/*.controller.ts --out src/api
|
|
21
|
+
4. npx @nestia/sdk swagger <input> --out <output>
|
|
22
|
+
- npx @nestia/sdk swagger # when "nestia.config.ts" be configured
|
|
23
|
+
- npx @nestia/sdk swagger src/controllers --out src/api
|
|
24
|
+
- npx @nestia/sdk swagger src/**/*.controller.ts --out src/api
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
function halt(desc: string): never {
|
|
28
|
+
console.error(desc);
|
|
29
|
+
process.exit(-1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function dependencies(argv: string[]): void {
|
|
33
|
+
// INSTALL DEPENDENCIES
|
|
34
|
+
const module = CommandParser.parse(argv).module ?? "npm";
|
|
35
|
+
const prefix: string = module === "yarn" ? "yarn add" : `${module} install`;
|
|
36
|
+
|
|
37
|
+
for (const lib of ["@nestia/fetcher", "typia"]) {
|
|
38
|
+
const command: string = `${prefix} ${lib}`;
|
|
39
|
+
cp.execSync(command, { stdio: "inherit" });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function initialize(): Promise<void> {
|
|
44
|
+
if (fs.existsSync("nestia.config.ts") === true)
|
|
45
|
+
halt(
|
|
46
|
+
`Error on nestia.sdk.initialize(): "nestia.config.ts" file already has been configured.`,
|
|
47
|
+
);
|
|
48
|
+
await fs.promises.copyFile(
|
|
49
|
+
`${__dirname}/../../assets/config/nestia.config.ts`,
|
|
50
|
+
"nestia.config.ts",
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function execute(
|
|
55
|
+
closure: (commander: typeof NestiaSdkCommand) => Promise<void>,
|
|
56
|
+
): Promise<void> {
|
|
57
|
+
const module = await import("./internal/NestiaSdkCommand");
|
|
58
|
+
await closure(module.NestiaSdkCommand);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function main() {
|
|
62
|
+
const type: string | undefined = process.argv[2];
|
|
63
|
+
const argv: string[] = process.argv.slice(3);
|
|
64
|
+
|
|
65
|
+
if (type === "dependencies") dependencies(argv);
|
|
66
|
+
else if (type === "init") await initialize();
|
|
67
|
+
else if (type === "sdk") await execute((c) => c.sdk(argv));
|
|
68
|
+
else if (type === "swagger") await execute((c) => c.swagger(argv));
|
|
69
|
+
else halt(USAGE);
|
|
70
|
+
}
|
|
71
|
+
main().catch((exp) => {
|
|
72
|
+
console.log(exp.message);
|
|
73
|
+
process.exit(-1);
|
|
74
|
+
});
|