@nestia/sdk 2.5.0-dev.20240130 → 2.5.0-dev.20240130-3

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.
@@ -1,96 +1,96 @@
1
- import fs from "fs";
2
- import NodePath from "path";
3
- import { IPointer } from "tstl";
4
- import ts from "typescript";
5
-
6
- import { INestiaConfig } from "../INestiaConfig";
7
- import { IRoute } from "../structures/IRoute";
8
- import { CloneGenerator } from "./CloneGenerator";
9
- import { SdkDistributionComposer } from "./internal/SdkDistributionComposer";
10
- import { SdkFileProgrammer } from "./internal/SdkFileProgrammer";
11
-
12
- export namespace SdkGenerator {
13
- export const generate =
14
- (checker: ts.TypeChecker) =>
15
- (config: INestiaConfig) =>
16
- async (routes: IRoute[]): Promise<void> => {
17
- console.log("Generating SDK Library");
18
-
19
- // PREPARE NEW DIRECTORIES
20
- try {
21
- await fs.promises.mkdir(config.output!);
22
- } catch {}
23
-
24
- // BUNDLING
25
- const bundle: string[] = await fs.promises.readdir(BUNDLE_PATH);
26
- for (const file of bundle) {
27
- const current: string = `${BUNDLE_PATH}/${file}`;
28
- const target: string = `${config.output}/${file}`;
29
- const stats: fs.Stats = await fs.promises.stat(current);
30
-
31
- if (stats.isFile() === true) {
32
- const content: string = await fs.promises.readFile(current, "utf8");
33
- if (fs.existsSync(target) === false)
34
- await fs.promises.writeFile(target, content, "utf8");
35
- else if (BUNDLE_CHANGES[file] !== undefined) {
36
- const r: IPointer<string> = {
37
- value: await fs.promises.readFile(target, "utf8"),
38
- };
39
- for (const [before, after] of BUNDLE_CHANGES[file])
40
- r.value = r.value.replace(before, after);
41
- await fs.promises.writeFile(target, r.value, "utf8");
42
- }
43
- }
44
- }
45
- if (
46
- config.simulate === true &&
47
- routes.some((r) => !!r.parameters.length)
48
- ) {
49
- try {
50
- await fs.promises.mkdir(`${config.output}/utils`);
51
- } catch {}
52
- await fs.promises.copyFile(
53
- `${BUNDLE_PATH}/utils/NestiaSimulator.ts`,
54
- `${config.output}/utils/NestiaSimulator.ts`,
55
- );
56
- }
57
-
58
- // STRUCTURES
59
- if (config.clone) await CloneGenerator.generate(checker)(config)(routes);
60
-
61
- // FUNCTIONAL
62
- await SdkFileProgrammer.generate(checker)(config)(routes);
63
-
64
- // DISTRIBUTION
65
- if (config.distribute !== undefined)
66
- await SdkDistributionComposer.compose(config);
67
- };
68
-
69
- export const BUNDLE_PATH = NodePath.join(
70
- __dirname,
71
- "..",
72
- "..",
73
- "assets",
74
- "bundle",
75
- "api",
76
- );
77
- }
78
-
79
- const BUNDLE_CHANGES: Record<string, [string, string][]> = {
80
- "IConnection.ts": [
81
- [
82
- `export { IConnection } from "@nestia/fetcher"`,
83
- `export type { IConnection } from "@nestia/fetcher"`,
84
- ],
85
- ],
86
- "module.ts": [
87
- [`export * from "./IConnection"`, `export type * from "./IConnection"`],
88
- [`export * from "./Primitive"`, `export type * from "./Primitive"`],
89
- ],
90
- "Primitive.ts": [
91
- [
92
- `export { Primitive } from "@nestia/fetcher"`,
93
- `export type { Primitive } from "@nestia/fetcher"`,
94
- ],
95
- ],
96
- };
1
+ import fs from "fs";
2
+ import NodePath from "path";
3
+ import { IPointer } from "tstl";
4
+ import ts from "typescript";
5
+
6
+ import { INestiaConfig } from "../INestiaConfig";
7
+ import { IRoute } from "../structures/IRoute";
8
+ import { CloneGenerator } from "./CloneGenerator";
9
+ import { SdkDistributionComposer } from "./internal/SdkDistributionComposer";
10
+ import { SdkFileProgrammer } from "./internal/SdkFileProgrammer";
11
+
12
+ export namespace SdkGenerator {
13
+ export const generate =
14
+ (checker: ts.TypeChecker) =>
15
+ (config: INestiaConfig) =>
16
+ async (routes: IRoute[]): Promise<void> => {
17
+ console.log("Generating SDK Library");
18
+
19
+ // PREPARE NEW DIRECTORIES
20
+ try {
21
+ await fs.promises.mkdir(config.output!);
22
+ } catch {}
23
+
24
+ // BUNDLING
25
+ const bundle: string[] = await fs.promises.readdir(BUNDLE_PATH);
26
+ for (const file of bundle) {
27
+ const current: string = `${BUNDLE_PATH}/${file}`;
28
+ const target: string = `${config.output}/${file}`;
29
+ const stats: fs.Stats = await fs.promises.stat(current);
30
+
31
+ if (stats.isFile() === true) {
32
+ const content: string = await fs.promises.readFile(current, "utf8");
33
+ if (fs.existsSync(target) === false)
34
+ await fs.promises.writeFile(target, content, "utf8");
35
+ else if (BUNDLE_CHANGES[file] !== undefined) {
36
+ const r: IPointer<string> = {
37
+ value: await fs.promises.readFile(target, "utf8"),
38
+ };
39
+ for (const [before, after] of BUNDLE_CHANGES[file])
40
+ r.value = r.value.replace(before, after);
41
+ await fs.promises.writeFile(target, r.value, "utf8");
42
+ }
43
+ }
44
+ }
45
+ if (
46
+ config.simulate === true &&
47
+ routes.some((r) => !!r.parameters.length)
48
+ ) {
49
+ try {
50
+ await fs.promises.mkdir(`${config.output}/utils`);
51
+ } catch {}
52
+ await fs.promises.copyFile(
53
+ `${BUNDLE_PATH}/utils/NestiaSimulator.ts`,
54
+ `${config.output}/utils/NestiaSimulator.ts`,
55
+ );
56
+ }
57
+
58
+ // STRUCTURES
59
+ if (config.clone) await CloneGenerator.generate(checker)(config)(routes);
60
+
61
+ // FUNCTIONAL
62
+ await SdkFileProgrammer.generate(checker)(config)(routes);
63
+
64
+ // DISTRIBUTION
65
+ if (config.distribute !== undefined)
66
+ await SdkDistributionComposer.compose(config);
67
+ };
68
+
69
+ export const BUNDLE_PATH = NodePath.join(
70
+ __dirname,
71
+ "..",
72
+ "..",
73
+ "assets",
74
+ "bundle",
75
+ "api",
76
+ );
77
+ }
78
+
79
+ const BUNDLE_CHANGES: Record<string, [string, string][]> = {
80
+ "IConnection.ts": [
81
+ [
82
+ `export { IConnection } from "@nestia/fetcher"`,
83
+ `export type { IConnection } from "@nestia/fetcher"`,
84
+ ],
85
+ ],
86
+ "module.ts": [
87
+ [`export * from "./IConnection"`, `export type * from "./IConnection"`],
88
+ [`export * from "./Primitive"`, `export type * from "./Primitive"`],
89
+ ],
90
+ "Primitive.ts": [
91
+ [
92
+ `export { Primitive } from "@nestia/fetcher"`,
93
+ `export type { Primitive } from "@nestia/fetcher"`,
94
+ ],
95
+ ],
96
+ };