gg-express 1.0.7 → 1.0.9
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/dist/GGExpress.d.ts +4 -2
- package/dist/GGExpress.js +80 -4
- package/package.json +1 -1
- package/src/GGExpress.ts +81 -3
package/dist/GGExpress.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { NextFunction, Request, Response } from "express";
|
|
2
2
|
import Express from "express-serve-static-core";
|
|
3
|
-
export { GGApi } from "./GGApi";
|
|
4
3
|
type Unarray<T> = T extends (infer U)[] ? U : T;
|
|
5
4
|
type AsConstArray<T extends readonly any[]> = [...T];
|
|
6
5
|
type paramType = "number" | "string" | AsConstArray<Array<string>> | AsConstArray<Array<number>>;
|
|
@@ -57,5 +56,8 @@ export default class GGExpress {
|
|
|
57
56
|
requireParams: M;
|
|
58
57
|
responseStructure: R;
|
|
59
58
|
}, ...middlewares: Array<(req: MyRequest<M["dataType"], T, K>, res: MyResponse<R["dataType"], RS, KR>, next: NextFunction) => any>): Express.Express;
|
|
60
|
-
|
|
59
|
+
generateAPIFiles(): void;
|
|
60
|
+
private generateStaticRouteFile;
|
|
61
|
+
private generateGGApi;
|
|
61
62
|
}
|
|
63
|
+
export {};
|
package/dist/GGExpress.js
CHANGED
|
@@ -3,10 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.GGApi = void 0;
|
|
7
6
|
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
|
|
9
|
-
Object.defineProperty(exports, "GGApi", { enumerable: true, get: function () { return GGApi_1.GGApi; } });
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
10
8
|
const myExpressRouteList = [];
|
|
11
9
|
class GGExpress {
|
|
12
10
|
constructor(app, outputPath) {
|
|
@@ -36,6 +34,9 @@ class GGExpress {
|
|
|
36
34
|
delete(url, options, ...middlewares) {
|
|
37
35
|
return this.rootMethod("delete", url, options, ...middlewares);
|
|
38
36
|
}
|
|
37
|
+
generateAPIFiles() {
|
|
38
|
+
this.generateStaticRouteFile();
|
|
39
|
+
}
|
|
39
40
|
generateStaticRouteFile() {
|
|
40
41
|
const genRequireParamCode = (data) => {
|
|
41
42
|
let result;
|
|
@@ -97,7 +98,8 @@ class GGExpress {
|
|
|
97
98
|
delete : { ${genInterfaceString(deleteDelete)} },
|
|
98
99
|
}`;
|
|
99
100
|
for (let row of this.outputPath) {
|
|
100
|
-
fs_1.default.writeFileSync(row, content);
|
|
101
|
+
fs_1.default.writeFileSync(path_1.default.join(row, 'staticRouteInterface.ts'), content);
|
|
102
|
+
this.generateGGApi(path_1.default.join(row, 'apiConnector.ts'));
|
|
101
103
|
}
|
|
102
104
|
// const serverFilePath = path.join(
|
|
103
105
|
// appRootPath.toString(),
|
|
@@ -116,5 +118,79 @@ class GGExpress {
|
|
|
116
118
|
// fs.writeFileSync(serverFilePath, content)
|
|
117
119
|
// fs.writeFileSync(myAppFilePath, content)
|
|
118
120
|
}
|
|
121
|
+
generateGGApi(filePathWithFileName) {
|
|
122
|
+
let code = `
|
|
123
|
+
import { staticRouteInterface } from "./staticRouteInterface"
|
|
124
|
+
import axios from "axios"
|
|
125
|
+
|
|
126
|
+
export class GGApi {
|
|
127
|
+
constructor() {}
|
|
128
|
+
|
|
129
|
+
get<T extends keyof staticRouteInterface["get"]>(
|
|
130
|
+
url: T,
|
|
131
|
+
requireParams: staticRouteInterface["get"][T]["requireParams"]
|
|
132
|
+
): Promise<staticRouteInterface["get"][T]["responseStructure"]> {
|
|
133
|
+
return new Promise((resolve, reject) => {
|
|
134
|
+
axios
|
|
135
|
+
.get(url, { params: requireParams })
|
|
136
|
+
.then((response) => {
|
|
137
|
+
resolve(response.data)
|
|
138
|
+
})
|
|
139
|
+
.catch((error) => {
|
|
140
|
+
reject(error)
|
|
141
|
+
})
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
post<T extends keyof staticRouteInterface["post"]>(
|
|
146
|
+
url: T,
|
|
147
|
+
requireParams: staticRouteInterface["post"][T]["requireParams"]
|
|
148
|
+
): Promise<staticRouteInterface["post"][T]["responseStructure"]> {
|
|
149
|
+
return new Promise((resolve, reject) => {
|
|
150
|
+
axios
|
|
151
|
+
.post(url, requireParams)
|
|
152
|
+
.then((response) => {
|
|
153
|
+
resolve(response.data)
|
|
154
|
+
})
|
|
155
|
+
.catch((error) => {
|
|
156
|
+
reject(error)
|
|
157
|
+
})
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
put<T extends keyof staticRouteInterface["put"]>(
|
|
161
|
+
url: T,
|
|
162
|
+
requireParams: staticRouteInterface["put"][T]["requireParams"]
|
|
163
|
+
): Promise<staticRouteInterface["put"][T]["responseStructure"]> {
|
|
164
|
+
return new Promise((resolve, reject) => {
|
|
165
|
+
axios
|
|
166
|
+
.put(url, requireParams)
|
|
167
|
+
.then((response) => {
|
|
168
|
+
resolve(response.data)
|
|
169
|
+
})
|
|
170
|
+
.catch((error) => {
|
|
171
|
+
reject(error)
|
|
172
|
+
})
|
|
173
|
+
})
|
|
174
|
+
}
|
|
175
|
+
delete<T extends keyof staticRouteInterface["delete"]>(
|
|
176
|
+
url: T,
|
|
177
|
+
requireParams: staticRouteInterface["delete"][T]["requireParams"]
|
|
178
|
+
): Promise<staticRouteInterface["delete"][T]["responseStructure"]> {
|
|
179
|
+
return new Promise((resolve, reject) => {
|
|
180
|
+
axios
|
|
181
|
+
.delete(url, requireParams)
|
|
182
|
+
.then((response) => {
|
|
183
|
+
resolve(response.data)
|
|
184
|
+
})
|
|
185
|
+
.catch((error) => {
|
|
186
|
+
reject(error)
|
|
187
|
+
})
|
|
188
|
+
})
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
`;
|
|
193
|
+
fs_1.default.writeFileSync(filePathWithFileName, code);
|
|
194
|
+
}
|
|
119
195
|
}
|
|
120
196
|
exports.default = GGExpress;
|
package/package.json
CHANGED
package/src/GGExpress.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { NextFunction, Request, Response } from "express"
|
|
|
3
3
|
import Express from "express-serve-static-core"
|
|
4
4
|
import fs from "fs"
|
|
5
5
|
import path from "path"
|
|
6
|
-
export { GGApi } from "./GGApi"
|
|
6
|
+
// export { GGApi } from "./GGApi"
|
|
7
7
|
type Unarray<T> = T extends (infer U)[] ? U : T;
|
|
8
8
|
type AsConstArray<T extends readonly any[]> = [...T]
|
|
9
9
|
type paramType =
|
|
@@ -215,7 +215,10 @@ export default class GGExpress {
|
|
|
215
215
|
) {
|
|
216
216
|
return this.rootMethod("delete", url, options, ...middlewares)
|
|
217
217
|
}
|
|
218
|
-
|
|
218
|
+
public generateAPIFiles() {
|
|
219
|
+
this.generateStaticRouteFile()
|
|
220
|
+
}
|
|
221
|
+
private generateStaticRouteFile() {
|
|
219
222
|
const genRequireParamCode = (data: requireParamsStructure) => {
|
|
220
223
|
let result: string
|
|
221
224
|
const resultArray = Object.entries(data["structure"]).map(
|
|
@@ -279,7 +282,8 @@ export default class GGExpress {
|
|
|
279
282
|
}`
|
|
280
283
|
|
|
281
284
|
for (let row of this.outputPath) {
|
|
282
|
-
fs.writeFileSync(row, content)
|
|
285
|
+
fs.writeFileSync(path.join(row,'staticRouteInterface.ts'), content)
|
|
286
|
+
this.generateGGApi(path.join(row,'apiConnector.ts'))
|
|
283
287
|
}
|
|
284
288
|
|
|
285
289
|
// const serverFilePath = path.join(
|
|
@@ -300,4 +304,78 @@ export default class GGExpress {
|
|
|
300
304
|
// fs.writeFileSync(serverFilePath, content)
|
|
301
305
|
// fs.writeFileSync(myAppFilePath, content)
|
|
302
306
|
}
|
|
307
|
+
private generateGGApi(filePathWithFileName : string) {
|
|
308
|
+
let code = `
|
|
309
|
+
import { staticRouteInterface } from "./staticRouteInterface"
|
|
310
|
+
import axios from "axios"
|
|
311
|
+
|
|
312
|
+
export class GGApi {
|
|
313
|
+
constructor() {}
|
|
314
|
+
|
|
315
|
+
get<T extends keyof staticRouteInterface["get"]>(
|
|
316
|
+
url: T,
|
|
317
|
+
requireParams: staticRouteInterface["get"][T]["requireParams"]
|
|
318
|
+
): Promise<staticRouteInterface["get"][T]["responseStructure"]> {
|
|
319
|
+
return new Promise((resolve, reject) => {
|
|
320
|
+
axios
|
|
321
|
+
.get(url, { params: requireParams })
|
|
322
|
+
.then((response) => {
|
|
323
|
+
resolve(response.data)
|
|
324
|
+
})
|
|
325
|
+
.catch((error) => {
|
|
326
|
+
reject(error)
|
|
327
|
+
})
|
|
328
|
+
})
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
post<T extends keyof staticRouteInterface["post"]>(
|
|
332
|
+
url: T,
|
|
333
|
+
requireParams: staticRouteInterface["post"][T]["requireParams"]
|
|
334
|
+
): Promise<staticRouteInterface["post"][T]["responseStructure"]> {
|
|
335
|
+
return new Promise((resolve, reject) => {
|
|
336
|
+
axios
|
|
337
|
+
.post(url, requireParams)
|
|
338
|
+
.then((response) => {
|
|
339
|
+
resolve(response.data)
|
|
340
|
+
})
|
|
341
|
+
.catch((error) => {
|
|
342
|
+
reject(error)
|
|
343
|
+
})
|
|
344
|
+
})
|
|
345
|
+
}
|
|
346
|
+
put<T extends keyof staticRouteInterface["put"]>(
|
|
347
|
+
url: T,
|
|
348
|
+
requireParams: staticRouteInterface["put"][T]["requireParams"]
|
|
349
|
+
): Promise<staticRouteInterface["put"][T]["responseStructure"]> {
|
|
350
|
+
return new Promise((resolve, reject) => {
|
|
351
|
+
axios
|
|
352
|
+
.put(url, requireParams)
|
|
353
|
+
.then((response) => {
|
|
354
|
+
resolve(response.data)
|
|
355
|
+
})
|
|
356
|
+
.catch((error) => {
|
|
357
|
+
reject(error)
|
|
358
|
+
})
|
|
359
|
+
})
|
|
360
|
+
}
|
|
361
|
+
delete<T extends keyof staticRouteInterface["delete"]>(
|
|
362
|
+
url: T,
|
|
363
|
+
requireParams: staticRouteInterface["delete"][T]["requireParams"]
|
|
364
|
+
): Promise<staticRouteInterface["delete"][T]["responseStructure"]> {
|
|
365
|
+
return new Promise((resolve, reject) => {
|
|
366
|
+
axios
|
|
367
|
+
.delete(url, requireParams)
|
|
368
|
+
.then((response) => {
|
|
369
|
+
resolve(response.data)
|
|
370
|
+
})
|
|
371
|
+
.catch((error) => {
|
|
372
|
+
reject(error)
|
|
373
|
+
})
|
|
374
|
+
})
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
`
|
|
379
|
+
fs.writeFileSync(filePathWithFileName,code)
|
|
380
|
+
}
|
|
303
381
|
}
|