very-express 0.2.4 → 0.2.6
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/cli.js +10 -9
- package/dist/generators/controller.template.d.ts +0 -1
- package/dist/generators/controller.template.js +17 -26
- package/dist/generators/routes/swagger.generator.js +26 -1
- package/dist/generators/routes.template.d.ts +1 -2
- package/dist/generators/routes.template.js +4 -14
- package/dist/generators/server.template.js +2 -4
- package/dist/index.js +9 -6
- package/dist/templates/plugins/PassportGoogle.gen.ts +2 -0
- package/dist/templates/plugins/oauthVerify.gen.ts +2 -1
- package/dist/templates/services/mongoConn.gen.ts +2 -0
- package/dist/templates/utils/common.gen.ts +24 -18
- package/dist/templates/utils/logger.gen.ts +2 -0
- package/dist/types/types.d.ts +1 -3
- package/dist/utils/common.d.ts +3 -3
- package/dist/utils/common.js +26 -25
- package/package.json +2 -2
- package/tsconfig.json +2 -2
- package/vex.config.json +5 -5
package/dist/cli.js
CHANGED
|
@@ -24,18 +24,18 @@ if (fs_1.default.existsSync("vex.config.json")) {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
config.commitBeforeGenerate = (_a = config.commitBeforeGenerate) !== null && _a !== void 0 ? _a : false;
|
|
27
|
-
config.
|
|
28
|
-
config.useUserSchema = config.useUserSchema || true,
|
|
29
|
-
config.jsonSchemaDir = args.j || args.jsonSchemaDir || config.jsonSchemaDir || "./jsonSchema";
|
|
27
|
+
config.jsonSchemaDir = args.j || args.jsonSchemaDir || config.jsonSchemaDir || "./jsonSchema";
|
|
30
28
|
config.rootDir = args.o || args.rootDir || config.rootDir || ".";
|
|
31
29
|
config.srcDir = config.srcDir || config.rootDir + "/src";
|
|
32
30
|
config.openapiDir = config.openapiDir || config.rootDir + "./openapi";
|
|
33
|
-
config.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
config.enableSwagger = config.enableSwagger || true,
|
|
32
|
+
config.useUserSchema = config.useUserSchema || true,
|
|
33
|
+
config.useOauth = config.useOauth || {
|
|
34
|
+
google: false,
|
|
35
|
+
microsoft: false,
|
|
36
|
+
apple: false,
|
|
37
|
+
github: false
|
|
38
|
+
};
|
|
39
39
|
logger_1.default.process("vex.config.json");
|
|
40
40
|
fs_1.default.writeFileSync("vex.config.json", JSON.stringify(config, null, 4));
|
|
41
41
|
if (String(args._[0]).toLowerCase() === "h" || args["h"]) {
|
|
@@ -68,6 +68,7 @@ else {
|
|
|
68
68
|
logger_1.default.error("git commit \"before vex-gen\" failed", err);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
+
console.log(config);
|
|
71
72
|
(0, index_1.generate)(config);
|
|
72
73
|
console.log("\x1b[36m%s\x1b[0m", "\nnext step:\n", `cd ${config.rootDir}\n`, "npm install\n", "npm run dev");
|
|
73
74
|
}
|
|
@@ -5,10 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const util_1 = __importDefault(require("util"));
|
|
7
7
|
function controllerTemplate(templateOptions) {
|
|
8
|
-
var _a;
|
|
9
|
-
if (!templateOptions.headerComment) {
|
|
10
|
-
templateOptions.headerComment = ((_a = templateOptions.compilerOptions) === null || _a === void 0 ? void 0 : _a.headerComment) || "// generated files by very-express";
|
|
11
|
-
}
|
|
12
8
|
let template = templateOptions.template || `{{headerComment}}
|
|
13
9
|
import { Router, Request, Response } from 'express';
|
|
14
10
|
import { checkSchema, validationResult } from 'express-validator';
|
|
@@ -67,19 +63,14 @@ class {{interfaceName}}Controller {
|
|
|
67
63
|
return res.status(400).json(validationError.array());
|
|
68
64
|
};
|
|
69
65
|
|
|
70
|
-
// Get mongoose filter query
|
|
71
66
|
const searchFilter = new MongoQS().parse(req.query);
|
|
67
|
+
let selectedFields : {[key: string]: number} | undefined = undefined;
|
|
72
68
|
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
try { selectedFields = parseFieldsSelect(req.query.select || '');}
|
|
70
|
+
catch (err:any) { return res.status(400).json({ error: err.message });};
|
|
75
71
|
|
|
76
72
|
const result = await {{interfaceName}}Model.find(searchFilter, selectedFields);
|
|
77
|
-
|
|
78
|
-
return res.status(404).json({ error: "no data found" });
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
return res.status(200).json(result);
|
|
82
|
-
};
|
|
73
|
+
return res.status(200).json(result);
|
|
83
74
|
} catch (err:any) {
|
|
84
75
|
return res.status(500).json({ error: err.message });
|
|
85
76
|
}
|
|
@@ -162,41 +153,41 @@ class {{interfaceName}}Controller {
|
|
|
162
153
|
export default new {{interfaceName}}Controller().router;
|
|
163
154
|
`;
|
|
164
155
|
const indent3 = " ";
|
|
165
|
-
template = template.replace(/{{headerComment}}/g, templateOptions.headerComment);
|
|
156
|
+
template = template.replace(/{{headerComment}}/g, templateOptions.compilerOptions.headerComment || "// generated files by very-express");
|
|
166
157
|
template = template.replace(/{{interfaceName}}/g, templateOptions.interfaceName);
|
|
167
158
|
template = template.replace(/{{modelPath}}/g, templateOptions.modelPath);
|
|
168
|
-
template = template.replace(/{{getListRoute}}/g, !templateOptions.validators[templateOptions.endpoint].get ?
|
|
169
|
-
|
|
159
|
+
template = template.replace(/{{getListRoute}}/g, !templateOptions.validators[templateOptions.endpoint].get ? `
|
|
160
|
+
// getListRoute disabled` : `
|
|
170
161
|
this.router.get('/',
|
|
171
162
|
checkSchema(${util_1.default.inspect(templateOptions.validators[templateOptions.endpoint].get, { depth: null }).replace(/^/gm, indent3)}),
|
|
172
163
|
this.getList${templateOptions.interfaceName}.bind(this)
|
|
173
164
|
);`);
|
|
174
|
-
template = template.replace(/{{getRoute}}/g, !templateOptions.validators[templateOptions.endpoint + "/{id}"].get ?
|
|
175
|
-
|
|
165
|
+
template = template.replace(/{{getRoute}}/g, !templateOptions.validators[templateOptions.endpoint + "/{id}"].get ? `
|
|
166
|
+
// getRoute disabled` : `
|
|
176
167
|
this.router.get('/:id',
|
|
177
168
|
checkSchema(${util_1.default.inspect(templateOptions.validators[templateOptions.endpoint + "/{id}"].get, { depth: null }).replace(/^/gm, indent3)}),
|
|
178
169
|
this.get${templateOptions.interfaceName}.bind(this)
|
|
179
170
|
);`);
|
|
180
|
-
template = template.replace(/{{postRoute}}/g, !templateOptions.validators[templateOptions.endpoint].post ?
|
|
181
|
-
|
|
171
|
+
template = template.replace(/{{postRoute}}/g, !templateOptions.validators[templateOptions.endpoint].post ? `
|
|
172
|
+
// postRoute disabled` : `
|
|
182
173
|
this.router.post('/',
|
|
183
174
|
checkSchema(${util_1.default.inspect(templateOptions.validators[templateOptions.endpoint].post, { depth: null }).replace(/^/gm, indent3)}),
|
|
184
175
|
this.create${templateOptions.interfaceName}.bind(this)
|
|
185
176
|
);`);
|
|
186
|
-
template = template.replace(/{{putRoute}}/g, !templateOptions.validators[templateOptions.endpoint + "/{id}"].put ?
|
|
187
|
-
|
|
177
|
+
template = template.replace(/{{putRoute}}/g, !templateOptions.validators[templateOptions.endpoint + "/{id}"].put ? `
|
|
178
|
+
// putRoute disabled` : `
|
|
188
179
|
this.router.put('/:id',
|
|
189
180
|
checkSchema(${util_1.default.inspect(templateOptions.validators[templateOptions.endpoint + "/{id}"].put, { depth: null }).replace(/^/gm, indent3)}),
|
|
190
181
|
this.replace${templateOptions.interfaceName}.bind(this)
|
|
191
182
|
);`);
|
|
192
|
-
template = template.replace(/{{patchRoute}}/g, !templateOptions.validators[templateOptions.endpoint + "/{id}"].patch ?
|
|
193
|
-
|
|
183
|
+
template = template.replace(/{{patchRoute}}/g, !templateOptions.validators[templateOptions.endpoint + "/{id}"].patch ? `
|
|
184
|
+
// patchRoute disabled` : `
|
|
194
185
|
this.router.patch('/:id',
|
|
195
186
|
checkSchema(${util_1.default.inspect(templateOptions.validators[templateOptions.endpoint + "/{id}"].patch, { depth: null }).replace(/^/gm, indent3)}),
|
|
196
187
|
this.update${templateOptions.interfaceName}.bind(this)
|
|
197
188
|
);`);
|
|
198
|
-
template = template.replace(/{{deleteRoute}}/g, !templateOptions.validators[templateOptions.endpoint + "/{id}"].delete ?
|
|
199
|
-
|
|
189
|
+
template = template.replace(/{{deleteRoute}}/g, !templateOptions.validators[templateOptions.endpoint + "/{id}"].delete ? `
|
|
190
|
+
// deleteRoute disabled` : `
|
|
200
191
|
this.router.delete('/:id',
|
|
201
192
|
checkSchema(${util_1.default.inspect(templateOptions.validators[templateOptions.endpoint + "/{id}"].delete, { depth: null }).replace(/^/gm, indent3)}),
|
|
202
193
|
this.delete${templateOptions.interfaceName}.bind(this)
|
|
@@ -1,7 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.compile = void 0;
|
|
27
|
+
const utils = __importStar(require("../../utils/common"));
|
|
4
28
|
function compile(compilerOptions) {
|
|
29
|
+
const yamlPath = utils.relativePath(compilerOptions.srcDir + "/routes", compilerOptions.openapiDir + "/openapi.gen.yaml");
|
|
5
30
|
return `${compilerOptions.headerComment}
|
|
6
31
|
import { Router } from "express";
|
|
7
32
|
import swaggerUi, { JsonObject } from "swagger-ui-express";
|
|
@@ -14,7 +39,7 @@ export default class SwaggerRouter{
|
|
|
14
39
|
constructor() {}
|
|
15
40
|
|
|
16
41
|
public initRoutes() {
|
|
17
|
-
this.router.use("/api", swaggerUi.serve, swaggerUi.setup(loadYaml("
|
|
42
|
+
this.router.use("/api", swaggerUi.serve, swaggerUi.setup(loadYaml(__dirname+"/${yamlPath}") as JsonObject));
|
|
18
43
|
}
|
|
19
44
|
}`;
|
|
20
45
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import * as types from "../types/types";
|
|
2
|
-
export default function routesTemplate(
|
|
2
|
+
export default function routesTemplate(options: {
|
|
3
3
|
template?: string;
|
|
4
4
|
openapiFile?: string;
|
|
5
|
-
enableOpenApi?: boolean;
|
|
6
5
|
routes: {
|
|
7
6
|
route: string;
|
|
8
7
|
interfaceName: string;
|
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function routesTemplate(
|
|
4
|
-
|
|
5
|
-
if (!templateOptions.compilerOptions.headerComment) {
|
|
6
|
-
templateOptions.compilerOptions.headerComment = templateOptions.compilerOptions.headerComment || "// generated files by very-express";
|
|
7
|
-
}
|
|
8
|
-
const enableOpenApi = templateOptions.enableOpenApi || true;
|
|
9
|
-
if (enableOpenApi && !templateOptions.compilerOptions.openapiDir) {
|
|
10
|
-
console.log("\x1b[31m%s\x1b[0m", "[Error]", "OpenApi : routers.generator > compile() : Args \"openapiPath\" is required while enableOpenApi is true.");
|
|
11
|
-
throw new Error("OpenApi : routers.generator > compile() : Args \"openapiPath\" is required while enableOpenApi is true.");
|
|
12
|
-
}
|
|
13
|
-
const headerComment = ((_a = templateOptions.compilerOptions) === null || _a === void 0 ? void 0 : _a.headerComment) || "// generated files by very-express";
|
|
14
|
-
let template = templateOptions.template || `{{headerComment}}
|
|
3
|
+
function routesTemplate(options) {
|
|
4
|
+
let template = options.template || `{{headerComment}}
|
|
15
5
|
import { Router } from 'express';
|
|
16
6
|
|
|
17
7
|
{{importRoutes}}
|
|
@@ -31,11 +21,11 @@ export default class ApiRouter{
|
|
|
31
21
|
}`;
|
|
32
22
|
let importRoutes = "";
|
|
33
23
|
let useRoutes = "";
|
|
34
|
-
|
|
24
|
+
options.routes.forEach((obj) => {
|
|
35
25
|
importRoutes += `import ${obj.interfaceName}Controller from '${obj.controllerPath}';\n`;
|
|
36
26
|
useRoutes += `this.router.use('${obj.route}', ${obj.interfaceName}Controller);\n`;
|
|
37
27
|
});
|
|
38
|
-
template = template.replace(/{{headerComment}}/g, headerComment);
|
|
28
|
+
template = template.replace(/{{headerComment}}/g, options.compilerOptions.headerComment || "// generated files by very-express");
|
|
39
29
|
template = template.replace(/{{importRoutes}}/g, importRoutes);
|
|
40
30
|
template = template.replace(/{{useRoutes}}/g, useRoutes);
|
|
41
31
|
return template;
|
|
@@ -34,9 +34,7 @@ const UseOAuthRouter = "app.use(OAuthRoute.router);";
|
|
|
34
34
|
const UseSwaggerRouter = "app.use(SwaggerRoute.router);";
|
|
35
35
|
const UseOAuthGoogleRouter = "app.use(OAuthGoogle.router);";
|
|
36
36
|
function serverTemplate(options) {
|
|
37
|
-
|
|
38
|
-
const headerComment = ((_a = options.compilerOptions) === null || _a === void 0 ? void 0 : _a.headerComment) || "// generated files by very-express";
|
|
39
|
-
let template = options.template || `{{headerComment}}
|
|
37
|
+
let template = options.template || `${options.compilerOptions.headerComment || "// generated files by very-express"}
|
|
40
38
|
|
|
41
39
|
import express from 'express';
|
|
42
40
|
import dotenv from 'dotenv';
|
|
@@ -119,7 +117,7 @@ main();
|
|
|
119
117
|
AppRoute.push(UseOAuthGoogleRouter);
|
|
120
118
|
}
|
|
121
119
|
}
|
|
122
|
-
template = template.replace(/{{headerComment}}/g, headerComment);
|
|
120
|
+
template = template.replace(/{{headerComment}}/g, options.compilerOptions.headerComment || "// generated files by very-express");
|
|
123
121
|
template = template.replace(/{{Import}}/g, Import.join("\n"));
|
|
124
122
|
template = template.replace(/{{Config}}/g, Config.join("\n"));
|
|
125
123
|
template = template.replace(/{{AppUse}}/g, AppUse.join("\n "));
|
package/dist/index.js
CHANGED
|
@@ -37,6 +37,7 @@ const routeGen = __importStar(require("./generators/routes.generator"));
|
|
|
37
37
|
const serverGen = __importStar(require("./generators/server.generator"));
|
|
38
38
|
const jsonschemaFormat_1 = require("./preprocess/jsonschemaFormat");
|
|
39
39
|
function generate(options) {
|
|
40
|
+
const openapiFile = "/openapi.gen.yaml";
|
|
40
41
|
const dir = {
|
|
41
42
|
routeDir: `${options.srcDir}/routes`,
|
|
42
43
|
middlewareDir: `${options.srcDir}/middlewares`,
|
|
@@ -47,7 +48,10 @@ function generate(options) {
|
|
|
47
48
|
pluginDir: `${options.srcDir}/plugins`,
|
|
48
49
|
utilsDir: `${options.srcDir}/utils`,
|
|
49
50
|
};
|
|
50
|
-
const
|
|
51
|
+
const routeData = [];
|
|
52
|
+
if (!options.headerComment) {
|
|
53
|
+
options.headerComment = common_1.default.getGenaratorHeaderComment();
|
|
54
|
+
}
|
|
51
55
|
if (!fs_1.default.existsSync(options.rootDir)) {
|
|
52
56
|
fs_1.default.mkdirSync(options.rootDir);
|
|
53
57
|
}
|
|
@@ -62,11 +66,10 @@ function generate(options) {
|
|
|
62
66
|
fs_1.default.mkdirSync(path);
|
|
63
67
|
}
|
|
64
68
|
});
|
|
69
|
+
common_1.default.copyDir(`${__dirname}/templates/utils`, dir.utilsDir, options, true);
|
|
70
|
+
common_1.default.copyDir(`${__dirname}/templates/services`, dir.serviceDir, options, true);
|
|
71
|
+
common_1.default.copyDir(`${__dirname}/templates/plugins`, dir.pluginDir, options, true);
|
|
65
72
|
openapiGen.compile(openapiFile, options);
|
|
66
|
-
common_1.default.copyDir(`${__dirname}/templates/utils`, dir.utilsDir, true);
|
|
67
|
-
common_1.default.copyDir(`${__dirname}/templates/services`, dir.serviceDir, true);
|
|
68
|
-
common_1.default.copyDir(`${__dirname}/templates/plugins`, dir.pluginDir, true);
|
|
69
|
-
const routeData = [];
|
|
70
73
|
const files = fs_1.default.readdirSync(options.jsonSchemaDir);
|
|
71
74
|
files.forEach((schemaFileName) => {
|
|
72
75
|
const schemaPath = `${options.jsonSchemaDir}/${schemaFileName}`;
|
|
@@ -90,7 +93,7 @@ function generate(options) {
|
|
|
90
93
|
}
|
|
91
94
|
});
|
|
92
95
|
openapiGen.compile(openapiFile, options || common_1.default.defaultCompilerOptions);
|
|
93
|
-
common_1.default.copyDir(`${options.openapiDir}`, options.rootDir + "/openapi", true);
|
|
96
|
+
common_1.default.copyDir(`${options.openapiDir}`, options.rootDir + "/openapi", options, true);
|
|
94
97
|
controllerGen.compile({
|
|
95
98
|
openapiFile: openapiFile,
|
|
96
99
|
controllerOutDir: dir.controllerDir,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// {{headerComment}}
|
|
2
|
+
|
|
1
3
|
import jsYaml from "js-yaml";
|
|
2
4
|
import fs from "fs";
|
|
3
5
|
|
|
@@ -15,28 +17,32 @@ export function loadYaml(yamlFilePath: string) {
|
|
|
15
17
|
* @param fieldsString json stringified array of string
|
|
16
18
|
* @error may throw an error if the fieldsString is not a valid JSON
|
|
17
19
|
*/
|
|
18
|
-
export function parseFieldsSelect(
|
|
20
|
+
export function parseFieldsSelect(selectString: any) : { [key: string]: number } | undefined {
|
|
21
|
+
const ErrorArrStrMsg = "Invalid select string, only array of string accepted";
|
|
19
22
|
|
|
20
|
-
|
|
23
|
+
if (typeof selectString === "undefined" || selectString === "") {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
else if (typeof selectString !== "string") {
|
|
27
|
+
throw new Error(ErrorArrStrMsg);
|
|
28
|
+
}
|
|
21
29
|
|
|
22
|
-
|
|
23
|
-
return reject("Invalid fields string : "+typeof fieldsString,);
|
|
24
|
-
}
|
|
30
|
+
const fieldArr: string[] = JSON.parse(selectString);
|
|
25
31
|
|
|
26
|
-
|
|
32
|
+
if (!Array.isArray(fieldArr)) {
|
|
33
|
+
throw new Error(ErrorArrStrMsg);
|
|
34
|
+
}
|
|
27
35
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return reject("Invalid fields string");
|
|
36
|
+
for (let i = 0; i < fieldArr.length; i++) {
|
|
37
|
+
if (typeof fieldArr[i] !== "string") {
|
|
38
|
+
throw new Error(ErrorArrStrMsg);
|
|
32
39
|
}
|
|
40
|
+
}
|
|
41
|
+
// Convert the fieldArr to an object that can be used in the select method
|
|
42
|
+
const selectFields = fieldArr.reduce((obj: any, field: string) => {
|
|
43
|
+
obj[field] = 1;
|
|
44
|
+
return obj;
|
|
45
|
+
}, {} as Record<string, number>);
|
|
33
46
|
|
|
34
|
-
|
|
35
|
-
const selectFields = fieldArr.reduce((obj:any, field:string) => {
|
|
36
|
-
obj[field] = 1;
|
|
37
|
-
return obj;
|
|
38
|
-
}, {} as Record<string, number>);
|
|
39
|
-
|
|
40
|
-
resolve(selectFields);
|
|
41
|
-
});
|
|
47
|
+
return selectFields;
|
|
42
48
|
}
|
package/dist/types/types.d.ts
CHANGED
package/dist/utils/common.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import * as types from "../types/types";
|
|
2
|
+
export declare function getGenaratorHeaderComment(): string;
|
|
3
|
+
export declare function getSimpleHeaderComment(): string;
|
|
2
4
|
export declare const relativePath: (fromPath: string, toPath: string) => string;
|
|
3
5
|
export declare function loadJsonSchema(jsonSchemaPath: string): types.jsonSchema | never;
|
|
4
|
-
export declare function getGenaratorHeaderComment(comment?: string): string;
|
|
5
|
-
export declare function getSimpleHeaderComment(): string;
|
|
6
6
|
export declare function cleanXcustomValue(schemaObj: {
|
|
7
7
|
[key: string]: any;
|
|
8
8
|
}, additionalKeyArr?: string[] | types.additionalKeyObj): {
|
|
9
9
|
[key: string]: any;
|
|
10
10
|
};
|
|
11
11
|
export declare function httpMethod(jsonSchemaMethod: string, documentName: string): types.httpMethod;
|
|
12
|
-
export declare function copyDir(source: string, destination: string, overwrite?: boolean): void;
|
|
12
|
+
export declare function copyDir(source: string, destination: string, compilerOptions: types.compilerOptions, overwrite?: boolean): void;
|
|
13
13
|
export declare function isUseOAuth(compilerOptions: types.compilerOptions): string[];
|
|
14
14
|
export declare const defaultCompilerOptions: types.compilerOptions;
|
|
15
15
|
declare const _default: {
|
package/dist/utils/common.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.defaultCompilerOptions = exports.isUseOAuth = exports.copyDir = exports.httpMethod = exports.cleanXcustomValue = exports.
|
|
29
|
+
exports.defaultCompilerOptions = exports.isUseOAuth = exports.copyDir = exports.httpMethod = exports.cleanXcustomValue = exports.loadJsonSchema = exports.relativePath = exports.getSimpleHeaderComment = exports.getGenaratorHeaderComment = void 0;
|
|
30
30
|
const fs_1 = __importDefault(require("fs"));
|
|
31
31
|
const path_1 = __importDefault(require("path"));
|
|
32
32
|
const child_process_1 = __importDefault(require("child_process"));
|
|
@@ -38,13 +38,31 @@ function getPackageInfo() {
|
|
|
38
38
|
globalPackages = JSON.parse(child_process_1.default.execSync("npm -g list --json").toString());
|
|
39
39
|
}
|
|
40
40
|
catch (error) {
|
|
41
|
-
logger_1.default.error("Failed to execute command: npm -g list --json", error);
|
|
41
|
+
logger_1.default.error("Failed to read version number, on execute command: npm -g list --json", error);
|
|
42
42
|
}
|
|
43
43
|
return {
|
|
44
44
|
version: globalPackages.dependencies["very-express"].version || "[unknown version]",
|
|
45
45
|
author: globalPackages.author || "justin26l",
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
+
function getGenaratorHeaderComment() {
|
|
49
|
+
const packageInfo = getPackageInfo();
|
|
50
|
+
return `/* eslint-disable */
|
|
51
|
+
/**
|
|
52
|
+
* Generated by veryExpress@${packageInfo.version}
|
|
53
|
+
* https://www.npmjs.com/package/very-express
|
|
54
|
+
* author: ${packageInfo.author}
|
|
55
|
+
*
|
|
56
|
+
* Not recommended to modify it manually because it will be overwritten while re-generate.
|
|
57
|
+
*/
|
|
58
|
+
`;
|
|
59
|
+
}
|
|
60
|
+
exports.getGenaratorHeaderComment = getGenaratorHeaderComment;
|
|
61
|
+
function getSimpleHeaderComment() {
|
|
62
|
+
const packageInfo = getPackageInfo();
|
|
63
|
+
return `// Generated by veryExpress@${packageInfo.version}`;
|
|
64
|
+
}
|
|
65
|
+
exports.getSimpleHeaderComment = getSimpleHeaderComment;
|
|
48
66
|
const relativePath = (fromPath, toPath) => {
|
|
49
67
|
return path_1.default.relative(fromPath, toPath).replace(/\\/g, "/");
|
|
50
68
|
};
|
|
@@ -61,25 +79,6 @@ function loadJsonSchema(jsonSchemaPath) {
|
|
|
61
79
|
}
|
|
62
80
|
}
|
|
63
81
|
exports.loadJsonSchema = loadJsonSchema;
|
|
64
|
-
function getGenaratorHeaderComment(comment) {
|
|
65
|
-
const packageInfo = getPackageInfo();
|
|
66
|
-
return `/* eslint-disable */
|
|
67
|
-
/**
|
|
68
|
-
* Generated by veryExpress@${packageInfo.version}
|
|
69
|
-
* We recommend not to modified it manually because it will be overwrite.
|
|
70
|
-
* we suggest to modified the jsonSchema then regenerate the project .
|
|
71
|
-
*
|
|
72
|
-
* author: ${packageInfo.author}
|
|
73
|
-
* version: ${packageInfo.version}${comment ? `\n * comment: ${comment}` : ""}
|
|
74
|
-
*/
|
|
75
|
-
`;
|
|
76
|
-
}
|
|
77
|
-
exports.getGenaratorHeaderComment = getGenaratorHeaderComment;
|
|
78
|
-
function getSimpleHeaderComment() {
|
|
79
|
-
const packageInfo = getPackageInfo();
|
|
80
|
-
return `// Generated by veryExpress@${packageInfo.version}`;
|
|
81
|
-
}
|
|
82
|
-
exports.getSimpleHeaderComment = getSimpleHeaderComment;
|
|
83
82
|
function cleanXcustomValue(schemaObj, additionalKeyArr) {
|
|
84
83
|
const obj = JSON.parse(JSON.stringify(schemaObj));
|
|
85
84
|
const isAddiArrStr = Array.isArray(additionalKeyArr);
|
|
@@ -115,7 +114,7 @@ function httpMethod(jsonSchemaMethod, documentName) {
|
|
|
115
114
|
}
|
|
116
115
|
}
|
|
117
116
|
exports.httpMethod = httpMethod;
|
|
118
|
-
function copyDir(source, destination, overwrite) {
|
|
117
|
+
function copyDir(source, destination, compilerOptions, overwrite) {
|
|
119
118
|
if (!fs_1.default.existsSync(destination)) {
|
|
120
119
|
fs_1.default.mkdirSync(destination);
|
|
121
120
|
}
|
|
@@ -123,7 +122,7 @@ function copyDir(source, destination, overwrite) {
|
|
|
123
122
|
for (let i = 0; i < files.length; i++) {
|
|
124
123
|
const current = fs_1.default.lstatSync(source + "/" + files[i]);
|
|
125
124
|
if (current.isDirectory()) {
|
|
126
|
-
copyDir(source + "/" + files[i], destination + "/" + files[i]);
|
|
125
|
+
copyDir(source + "/" + files[i], destination + "/" + files[i], compilerOptions, overwrite);
|
|
127
126
|
}
|
|
128
127
|
else if (!overwrite && fs_1.default.existsSync(destination + "/" + files[i])) {
|
|
129
128
|
logger_1.default.info(`FILE : existed, skip file ${destination + "/" + files[i]} exist, skip`);
|
|
@@ -131,7 +130,9 @@ function copyDir(source, destination, overwrite) {
|
|
|
131
130
|
else {
|
|
132
131
|
const outPath = destination + "/" + files[i];
|
|
133
132
|
logger_1.default.writing(`FILE : ${outPath}`);
|
|
134
|
-
fs_1.default.
|
|
133
|
+
let content = fs_1.default.readFileSync(source + "/" + files[i], "utf8");
|
|
134
|
+
content = content.replace(/{{headerComment}}/g, compilerOptions.headerComment);
|
|
135
|
+
fs_1.default.writeFileSync(outPath, content);
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
138
|
}
|
|
@@ -143,7 +144,7 @@ function isUseOAuth(compilerOptions) {
|
|
|
143
144
|
}
|
|
144
145
|
exports.isUseOAuth = isUseOAuth;
|
|
145
146
|
exports.defaultCompilerOptions = {
|
|
146
|
-
headerComment:
|
|
147
|
+
headerComment: "// generated files by very-express",
|
|
147
148
|
commitBeforeGenerate: false,
|
|
148
149
|
rootDir: ".",
|
|
149
150
|
srcDir: "./src",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "very-express",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "based on json schema and openapi, generate Express RestApi server with mongoDb ",
|
|
5
5
|
"author": "justin26l",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"vex": "./dist/cli.js"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
|
-
"build": "npm run test && tsc -p . && node ./src/
|
|
12
|
+
"build": "npm run test && tsc -p . && node ./src/copyTsTemplates.js",
|
|
13
13
|
"dev": "ts-node ./src/cli.ts -j ./output/jsonSchema -o ./output -s ./output/src",
|
|
14
14
|
"prod": "node ./dist/cli.js",
|
|
15
15
|
"test": "eslint ./src --ext .ts --fix",
|
package/tsconfig.json
CHANGED
|
@@ -108,11 +108,11 @@
|
|
|
108
108
|
},
|
|
109
109
|
"include": [
|
|
110
110
|
"src/**/*.ts",
|
|
111
|
-
"src/generators/routes.generator.ts", "src/test.js", "src/
|
|
111
|
+
"src/generators/routes.generator.ts", "src/test.js", "src/copyTsTemplates.js" ],
|
|
112
112
|
"exclude": [
|
|
113
113
|
"node_modules",
|
|
114
114
|
"output",
|
|
115
|
-
"src/
|
|
115
|
+
"src/copyTsTemplates.js",
|
|
116
116
|
"src/templates/**/*.gen.ts",
|
|
117
117
|
".env",
|
|
118
118
|
]
|
package/vex.config.json
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"commitBeforeGenerate": false,
|
|
3
|
+
"jsonSchemaDir": "./output/jsonSchema",
|
|
4
|
+
"rootDir": "./output",
|
|
5
|
+
"srcDir": "./output/src",
|
|
6
|
+
"openapiDir": "./output/openapi",
|
|
3
7
|
"enableSwagger": true,
|
|
4
8
|
"useUserSchema": true,
|
|
5
9
|
"useOauth": {
|
|
@@ -7,9 +11,5 @@
|
|
|
7
11
|
"microsoft": false,
|
|
8
12
|
"apple": false,
|
|
9
13
|
"github": false
|
|
10
|
-
}
|
|
11
|
-
"jsonSchemaDir": "./output/jsonSchema",
|
|
12
|
-
"rootDir": "./output",
|
|
13
|
-
"srcDir": "./output/src",
|
|
14
|
-
"openapiDir": "./output/openapi"
|
|
14
|
+
}
|
|
15
15
|
}
|