nestia 1.1.0 → 1.2.0

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/README.md CHANGED
@@ -152,7 +152,7 @@ export = {
152
152
  > /* input: {
153
153
  > include: ["src/controllers/*.controller.ts"],
154
154
  > exclude: ["src/controllers/fake_*.controller.ts"]
155
- > }
155
+ > },*/
156
156
  > output: "src/api"
157
157
  > }
158
158
  > ```
@@ -247,18 +247,15 @@ export function store
247
247
  connection: IConnection,
248
248
  section: string,
249
249
  saleId: number,
250
- input: store.Input
250
+ input: Primitive<store.Input>
251
251
  ): Promise<store.Output>
252
252
  {
253
253
  return Fetcher.fetch
254
254
  (
255
255
  connection,
256
- {
257
- input_encrypted: false,
258
- output_encrypted: false
259
- },
260
- "POST",
261
- `/consumers/${section}/sales/${saleId}/questions/`,
256
+ store.ENCRYPTED,
257
+ store.METHOD,
258
+ store.path(section, saleId),
262
259
  input
263
260
  );
264
261
  }
@@ -266,6 +263,18 @@ export namespace store
266
263
  {
267
264
  export type Input = Primitive<ISaleInquiry.IStore>;
268
265
  export type Output = Primitive<ISaleInquiry<ISaleArticle.IContent>>;
266
+
267
+ export const METHOD = "POST" as const;
268
+ export const PATH: string = "/consumers/:section/sales/:saleId/questions";
269
+ export const ENCRYPTED: Fetcher.IEncrypted = {
270
+ request: true,
271
+ response: true,
272
+ };
273
+
274
+ export function path(section: string, saleId: number): string
275
+ {
276
+ return `/consumers/${section}/sales/${saleId}/questions`;
277
+ }
269
278
  }
270
279
  ```
271
280
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nestia",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Automatic SDK and Document generator for the NestJS",
5
5
  "main": "src/index.ts",
6
6
  "bin": {
@@ -37,11 +37,12 @@
37
37
  "del": "^6.0.0",
38
38
  "glob": "^7.2.0",
39
39
  "ts-node": "^9.1.1",
40
- "tstl": "^2.5.0",
41
- "typescript": "^4.3.2"
40
+ "tsconfig-paths": "^3.14.1",
41
+ "tstl": "^2.5.3",
42
+ "typescript": "^4.6.3"
42
43
  },
43
44
  "devDependencies": {
44
- "nestia-helper": "^1.0.0",
45
+ "nestia-helper": "^1.2.0-dev.20220411",
45
46
  "rimraf": "^3.0.2"
46
47
  }
47
48
  }
package/src/bin/nestia.ts CHANGED
@@ -1,72 +1,82 @@
1
- #!/usr/bin/env ts-node-script
1
+ #!/usr/bin/env ts-node
2
2
 
3
- import cli from "cli";
3
+ import cp from "child_process";
4
4
  import fs from "fs";
5
- import path from "path";
6
5
  import tsc from "typescript";
7
6
 
8
- import { NestiaApplication } from "../NestiaApplication";
9
-
10
- import { Terminal } from "../utils/Terminal";
11
7
  import { stripJsonComments } from "../utils/stripJsonComments";
12
- import { IConfiguration } from "../IConfiguration";
13
8
 
14
- interface ICommand
9
+ function install(): void
15
10
  {
16
- exclude: string | null;
17
- out: string | null;
11
+ const command: string = "npm install --save nestia-fetcher";
12
+ cp.execSync(command, { stdio: "inherit" });
18
13
  }
19
14
 
20
- async function sdk(include: string[], command: ICommand): Promise<void>
15
+ function sdk(alias: boolean): void
21
16
  {
22
- // CONFIGURATION
23
- let config: IConfiguration;
24
- if (fs.existsSync("nestia.config.ts") === true)
25
- config = {
26
- ...await import(path.resolve("nestia.config.ts"))
27
- };
28
- else
17
+ const parameters: string[] = [
18
+ alias ? "npx ts-node -r tsconfig-paths/register" : "npx ts-node",
19
+ __dirname + "/../executable/sdk",
20
+ ...process.argv.slice(3)
21
+ ];
22
+ const command: string = parameters.join(" ");
23
+ cp.execSync(command, { stdio: "inherit" });
24
+ }
25
+
26
+ async function tsconfig(task: (alias: boolean) => void): Promise<void>
27
+ {
28
+ // NO TSCONFIG.JSON?
29
+ if (fs.existsSync("tsconfig.json") === false)
29
30
  {
30
- if (command.out === null)
31
- throw new Error(`Output directory is not specified. Add the "--out <output_directory>" option.`);
32
- config = {
33
- input: {
34
- include,
35
- exclude: command.exclude
36
- ? [command.exclude]
37
- : undefined
38
- },
39
- output: command.out
40
- };
31
+ task(false);
32
+ return;
41
33
  }
42
-
43
- // VALIDATE OUTPUT DIRECTORY
44
- const parentPath: string = path.resolve(config.output + "/..");
45
- const parentStats: fs.Stats = await fs.promises.stat(parentPath);
46
34
 
47
- if (parentStats.isDirectory() === false)
48
- throw new Error(`Unable to find parent directory of the output path: "${parentPath}".`);
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;
49
38
 
50
- // GENERATION
51
- if (fs.existsSync("tsconfig.json") === true)
39
+ // NO ALIAS PATHS
40
+ if (!options.paths || !Object.entries(options.paths).length)
52
41
  {
53
- const content: string = await fs.promises.readFile("tsconfig.json", "utf8");
54
- const options: tsc.CompilerOptions = JSON.parse(stripJsonComments(content)).compilerOptions;
42
+ task(false);
43
+ return;
44
+ }
55
45
 
56
- config.compilerOptions = {
57
- ...options,
58
- ...(config.compilerOptions || {})
59
- };
46
+ let closer: null | (() => Promise<void>) = null;
47
+ let error: Error | null = null;
48
+
49
+ if (!options.baseUrl)
50
+ {
51
+ options.baseUrl = "./";
52
+ await fs.promises.writeFile
53
+ (
54
+ "tsconfig.json",
55
+ JSON.stringify(json, null, 2),
56
+ "utf8"
57
+ );
58
+
59
+ closer = () => fs.promises.writeFile
60
+ (
61
+ "tsconfig.json",
62
+ content,
63
+ "utf8"
64
+ );
60
65
  }
61
66
 
62
- // CALL THE APP.GENERATE()
63
- const app: NestiaApplication = new NestiaApplication(config);
64
- await app.generate();
65
- }
67
+ try
68
+ {
69
+ task(true);
70
+ }
71
+ catch (exp)
72
+ {
73
+ error = exp as Error;
74
+ }
66
75
 
67
- async function install(): Promise<void>
68
- {
69
- await Terminal.execute("npm install --save nestia-fetcher");
76
+ if (closer)
77
+ await closer();
78
+ if (error)
79
+ throw error;
70
80
  }
71
81
 
72
82
  async function main(): Promise<void>
@@ -74,33 +84,12 @@ async function main(): Promise<void>
74
84
  if (process.argv[2] === "install")
75
85
  await install();
76
86
  else if (process.argv[2] === "sdk")
77
- {
78
- const command: ICommand = cli.parse({
79
- exclude: ["e", "Something to exclude", "string", null],
80
- out: ["o", "Output path of the SDK files", "string", null],
81
- });
82
-
83
- try
84
- {
85
- const inputs: string[] = [];
86
- for (const arg of process.argv.slice(3))
87
- {
88
- if (arg[0] === "-")
89
- break;
90
- inputs.push(arg);
91
- }
92
- await sdk(inputs, command);
93
- }
94
- catch (exp)
95
- {
96
- console.log(exp);
97
- process.exit(-1);
98
- }
99
- }
87
+ await tsconfig(sdk);
100
88
  else
101
- {
102
- console.log(`nestia supports only two commands; install and sdk, however you typed ${process.argv[2]}`);
103
- process.exit(-1);
104
- }
89
+ throw new Error(`nestia supports only two commands; install and sdk, however you typed ${process.argv[2]}`);
105
90
  }
106
- main();
91
+ main().catch(exp =>
92
+ {
93
+ console.log(exp.message);
94
+ process.exit(-1);
95
+ });
@@ -0,0 +1,89 @@
1
+ import cli from "cli";
2
+ import fs from "fs";
3
+ import path from "path";
4
+ import tsc from "typescript";
5
+ import { Primitive } from "nestia-fetcher";
6
+
7
+ import { IConfiguration } from "../IConfiguration";
8
+ import { NestiaApplication } from "../NestiaApplication";
9
+ import { stripJsonComments } from "../utils/stripJsonComments";
10
+
11
+ interface ICommand
12
+ {
13
+ exclude: string | null;
14
+ out: string | null;
15
+ }
16
+
17
+ async function sdk(include: string[], command: ICommand): Promise<void>
18
+ {
19
+ // CONFIGURATION
20
+ let config: IConfiguration;
21
+ if (fs.existsSync("nestia.config.ts") === true)
22
+ config = Primitive.clone
23
+ (
24
+ await import(path.resolve("nestia.config.ts"))
25
+ );
26
+ else
27
+ {
28
+ if (command.out === null)
29
+ throw new Error(`Output directory is not specified. Add the "--out <output_directory>" option.`);
30
+ config = {
31
+ input: {
32
+ include,
33
+ exclude: command.exclude
34
+ ? [command.exclude]
35
+ : undefined
36
+ },
37
+ output: command.out
38
+ };
39
+ }
40
+
41
+ // VALIDATE OUTPUT DIRECTORY
42
+ const parentPath: string = path.resolve(config.output + "/..");
43
+ const parentStats: fs.Stats = await fs.promises.stat(parentPath);
44
+
45
+ if (parentStats.isDirectory() === false)
46
+ throw new Error(`Unable to find parent directory of the output path: "${parentPath}".`);
47
+
48
+ // GENERATION
49
+ if (fs.existsSync("tsconfig.json") === true)
50
+ {
51
+ const content: string = await fs.promises.readFile("tsconfig.json", "utf8");
52
+ const options: tsc.CompilerOptions = JSON.parse(stripJsonComments(content)).compilerOptions;
53
+
54
+ config.compilerOptions = {
55
+ ...options,
56
+ ...(config.compilerOptions || {})
57
+ };
58
+ }
59
+
60
+ // CALL THE APP.GENERATE()
61
+ const app: NestiaApplication = new NestiaApplication(config);
62
+ await app.generate();
63
+ }
64
+
65
+ async function main(): Promise<void>
66
+ {
67
+ const command: ICommand = cli.parse({
68
+ exclude: ["e", "Something to exclude", "string", null],
69
+ out: ["o", "Output path of the SDK files", "string", null],
70
+ });
71
+
72
+ try
73
+ {
74
+ const inputs: string[] = [];
75
+ for (const arg of process.argv.slice(2))
76
+ {
77
+ if (arg[0] === "-")
78
+ break;
79
+ inputs.push(arg);
80
+ }
81
+ await sdk(inputs, command);
82
+ }
83
+ catch (exp)
84
+ {
85
+ console.log(exp);
86
+ process.exit(-1);
87
+ }
88
+ }
89
+ main();
@@ -1,19 +0,0 @@
1
- import * as cp from "child_process";
2
- import { Pair } from "tstl/utility/Pair";
3
-
4
- export namespace Terminal
5
- {
6
- export function execute(...commands: string[]): Promise<Pair<string, string>>
7
- {
8
- return new Promise((resolve, reject) =>
9
- {
10
- cp.exec(commands.join(" && "), (error: Error | null, stdout: string, stderr: string) =>
11
- {
12
- if (error)
13
- reject(error);
14
- else
15
- resolve(new Pair(stdout, stderr));
16
- });
17
- });
18
- }
19
- }