very-express 0.3.6 → 0.4.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/.gitattributes +2 -2
- package/dist/{templates/plugins → _plugins}/PassportGoogle.ts +2 -2
- package/dist/{templates/plugins → _plugins}/oauthVerify.ts +1 -1
- package/dist/{templates/services → _services}/mongoConn.ts +1 -1
- package/dist/{templates/utils → _utils}/common.ts +6 -1
- package/dist/_utils/index.ts +11 -0
- package/dist/{templates/utils → _utils}/logger.ts +5 -2
- package/dist/_utils/response.ts +32 -0
- package/dist/cli.d.ts +0 -1
- package/dist/generators/app/openapi.generator.d.ts +3 -0
- package/dist/generators/{role.generator.d.ts → app/role.generator.d.ts} +2 -2
- package/dist/generators/app/server.generator.d.ts +2 -0
- package/dist/generators/{server.template.d.ts → app/server.template.d.ts} +1 -1
- package/dist/generators/{controller.template.d.ts → controller/controller.template.d.ts} +1 -1
- package/dist/generators/{controllers.generator.d.ts → controller/controllers.generator.d.ts} +2 -2
- package/dist/generators/index.d.ts +2 -2
- package/dist/generators/project/packageJson.generator.d.ts +6 -0
- package/dist/generators/{userSchema.generator.d.ts → project/userSchema.generator.d.ts} +2 -2
- package/dist/generators/routes/routes.generator.d.ts +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +991 -121
- package/dist/preprocess/jsonschemaFormat.d.ts +1 -1
- package/dist/preprocess/roleSetupFile.d.ts +1 -1
- package/dist/templates/{plugins/PassportGoogle.gen.ts → _plugins/PassportGoogle.ts} +29 -8
- package/dist/templates/_plugins/oauthVerify.ts +39 -0
- package/dist/templates/_roles/_RoleFactory.ts +22 -0
- package/dist/templates/{services/mongoConn.gen.ts → _services/mongoConn.ts} +12 -1
- package/dist/templates/_types/responseMsg.ts +13 -0
- package/dist/templates/{utils/common.gen.ts → _utils/common.ts} +6 -1
- package/dist/templates/_utils/index.ts +11 -0
- package/dist/templates/{utils/logger.gen.ts → _utils/logger.ts} +5 -2
- package/dist/templates/_utils/response.ts +32 -0
- package/dist/templates/root/tsconfig.json +2 -1
- package/dist/types/types.d.ts +1 -0
- package/dist/utils/configChecker.d.ts +2 -0
- package/dist/utils/index.d.ts +1 -0
- package/package.json +13 -10
- package/tsconfig.json +8 -6
- package/vex.config.json +3 -2
- package/.env +0 -6
- package/dist/cli.js +0 -84
- package/dist/generators/controller.template.js +0 -204
- package/dist/generators/controllers.generator.js +0 -173
- package/dist/generators/index.js +0 -13
- package/dist/generators/openapi.generator.d.ts +0 -3
- package/dist/generators/openapi.generator.js +0 -227
- package/dist/generators/packageJson.generator.d.ts +0 -5
- package/dist/generators/packageJson.generator.js +0 -42
- package/dist/generators/role.generator.js +0 -112
- package/dist/generators/routes/oauth.generator.js +0 -66
- package/dist/generators/routes/routes.generator.js +0 -53
- package/dist/generators/routes/routes.template.js +0 -32
- package/dist/generators/routes/swagger.generator.js +0 -46
- package/dist/generators/routes.generator.d.ts +0 -11
- package/dist/generators/routes.generator.js +0 -53
- package/dist/generators/routes.template.d.ts +0 -11
- package/dist/generators/routes.template.js +0 -33
- package/dist/generators/server.generator.d.ts +0 -2
- package/dist/generators/server.generator.js +0 -30
- package/dist/generators/server.template.js +0 -149
- package/dist/generators/userSchema.generator.js +0 -30
- package/dist/preprocess/jsonschemaFormat.js +0 -107
- package/dist/preprocess/roleSetupFile.js +0 -60
- package/dist/templates/plugins/oauthVerify.gen.ts +0 -34
- package/dist/templates/roles/_RoleFactory.js +0 -17
- package/dist/templates/routes/swagger.gen.ts +0 -17
- package/dist/test.d.ts +0 -1
- package/dist/test.js +0 -10
- package/dist/types/controller.d.ts +0 -0
- package/dist/types/controller.js +0 -1
- package/dist/types/openapi.js +0 -2
- package/dist/types/types.js +0 -5
- package/dist/utils/common.js +0 -74
- package/dist/utils/generator.js +0 -74
- package/dist/utils/index.js +0 -20
- package/dist/utils/jsonSchema.js +0 -84
- package/dist/utils/log.d.ts +0 -13
- package/dist/utils/log.js +0 -31
- package/dist/utils/logger.js +0 -31
- /package/dist/{templates/roles → _roles}/_RoleFactory.ts +0 -0
- /package/dist/templates/{roles → _roles}/_RoleFactory.d.ts +0 -0
|
@@ -1,107 +0,0 @@
|
|
|
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
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.formatJsonSchema = void 0;
|
|
30
|
-
const types = __importStar(require("../types/types"));
|
|
31
|
-
const utilsJsonSchema = __importStar(require("../utils/jsonSchema"));
|
|
32
|
-
const logger_1 = __importDefault(require("../utils/logger"));
|
|
33
|
-
const utils_1 = require("../utils");
|
|
34
|
-
function formatJsonSchema(jsonSchemaPath, compilerOptions) {
|
|
35
|
-
const jsonSchema = utilsJsonSchema.loadJsonSchema(jsonSchemaPath);
|
|
36
|
-
if (!jsonSchema["x-documentConfig"]) {
|
|
37
|
-
logger_1.default.error(`formatJsonSchema : x-documentConfig not found in ${jsonSchemaPath}`);
|
|
38
|
-
}
|
|
39
|
-
else if (!jsonSchema["x-documentConfig"].documentName) {
|
|
40
|
-
logger_1.default.error(`formatJsonSchema : x-documentConfig.documentName not found in ${jsonSchemaPath}`);
|
|
41
|
-
}
|
|
42
|
-
else if (!jsonSchema["x-documentConfig"].interfaceName) {
|
|
43
|
-
logger_1.default.error(`formatJsonSchema : x-documentConfig.interfaceName not found in ${jsonSchemaPath}`);
|
|
44
|
-
}
|
|
45
|
-
else if (!jsonSchema["x-documentConfig"].methods) {
|
|
46
|
-
logger_1.default.warn(`formatJsonSchema : x-documentConfig.methods is not found in ${jsonSchemaPath}, supported methods added.`);
|
|
47
|
-
jsonSchema["x-documentConfig"].methods = Object.assign([], types.schemaMethodArr);
|
|
48
|
-
}
|
|
49
|
-
if (typeof jsonSchema.properties !== "object") {
|
|
50
|
-
logger_1.default.error(`properties is invalid in ${jsonSchemaPath}`);
|
|
51
|
-
}
|
|
52
|
-
if (compilerOptions.app.useObjectID) {
|
|
53
|
-
checkField_id(jsonSchema, jsonSchemaPath);
|
|
54
|
-
}
|
|
55
|
-
jsonSchema.required = getRequiredArrStr(jsonSchema, jsonSchemaPath);
|
|
56
|
-
(0, utils_1.writeFile)("Format JsonSchema", jsonSchemaPath, JSON.stringify(jsonSchema, null, 4));
|
|
57
|
-
return jsonSchema;
|
|
58
|
-
}
|
|
59
|
-
exports.formatJsonSchema = formatJsonSchema;
|
|
60
|
-
function getRequiredArrStr(schema, jsonSchemaPath) {
|
|
61
|
-
let properties;
|
|
62
|
-
let requiredArr = [];
|
|
63
|
-
const isArrObj = (props) => Boolean(props.type == "array" && props.items && props.items.type == "object");
|
|
64
|
-
if (isArrObj(schema)) {
|
|
65
|
-
properties = schema.items.properties;
|
|
66
|
-
requiredArr = typeof schema.items.required == "object" ? schema.items.required : [];
|
|
67
|
-
}
|
|
68
|
-
else if (schema.type == "object") {
|
|
69
|
-
properties = schema.properties;
|
|
70
|
-
requiredArr = typeof schema.required == "object" ? schema.required : [];
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
if (properties == undefined) {
|
|
76
|
-
logger_1.default.error(`formatJsonSchema > formatRequired : invalid "schema.properties" in ${jsonSchemaPath}`, schema);
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
Object.keys(properties).forEach((propKey) => {
|
|
80
|
-
const prop = properties === null || properties === void 0 ? void 0 : properties[propKey];
|
|
81
|
-
const keyNotInRequiredArr = !requiredArr.includes(propKey);
|
|
82
|
-
if (prop && prop.type !== "object" && prop.required === true && keyNotInRequiredArr) {
|
|
83
|
-
requiredArr.push(propKey);
|
|
84
|
-
}
|
|
85
|
-
else if (prop && prop.items && isArrObj(prop)) {
|
|
86
|
-
prop.items.required = getRequiredArrStr(prop.items, jsonSchemaPath);
|
|
87
|
-
}
|
|
88
|
-
else if (prop && prop.type == "object") {
|
|
89
|
-
prop.required = getRequiredArrStr(prop, jsonSchemaPath);
|
|
90
|
-
if (prop.required && prop.required.length > 0 && keyNotInRequiredArr) {
|
|
91
|
-
requiredArr.push(propKey);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
return requiredArr;
|
|
97
|
-
}
|
|
98
|
-
function checkField_id(schema, jsonSchemaPath) {
|
|
99
|
-
if (schema.properties && !schema.properties._id) {
|
|
100
|
-
schema.properties._id = {
|
|
101
|
-
type: "string",
|
|
102
|
-
description: "Unique Identifier",
|
|
103
|
-
example: "60c8c9d2b2b4f2c3e8d6f3e1",
|
|
104
|
-
};
|
|
105
|
-
logger_1.default.info(`formatJsonSchema : "_id" field added to ${jsonSchemaPath}`);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.roleSchemaFormat = exports.roleSetupFile = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const utils_1 = require("../utils");
|
|
9
|
-
const logger_1 = __importDefault(require("../utils/logger"));
|
|
10
|
-
function roleSetupFile(options) {
|
|
11
|
-
var _a;
|
|
12
|
-
if (!options.compilerOptions.useRBAC) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
const actionArray = ["create", "search", "read", "update", "delete"];
|
|
16
|
-
(_a = options.compilerOptions.useRBAC) === null || _a === void 0 ? void 0 : _a.roles.forEach((role) => {
|
|
17
|
-
logger_1.default.process(`Role Setting File : ${role}`);
|
|
18
|
-
const roleFilePath = `${options.roleSetupDir}/${role}.json`;
|
|
19
|
-
const content = {};
|
|
20
|
-
if (fs_1.default.existsSync(roleFilePath)) {
|
|
21
|
-
Object.assign(content, (0, utils_1.loadJson)(roleFilePath));
|
|
22
|
-
}
|
|
23
|
-
options.collectionList.forEach(collectionName => {
|
|
24
|
-
if (!content[collectionName]) {
|
|
25
|
-
content[collectionName] = actionArray;
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
(0, utils_1.writeFile)(`Role Setting File : ${roleFilePath}`, roleFilePath, JSON.stringify(content, null, 4));
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
exports.roleSetupFile = roleSetupFile;
|
|
32
|
-
function roleSchemaFormat(options) {
|
|
33
|
-
var _a;
|
|
34
|
-
if (!options.compilerOptions.useRBAC) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
(_a = options.compilerOptions.useRBAC) === null || _a === void 0 ? void 0 : _a.schemaIncluded.forEach((file) => {
|
|
38
|
-
var _a, _b;
|
|
39
|
-
logger_1.default.process(`Schema Role Format : ${file}.json`);
|
|
40
|
-
const roleSchemaPath = `${options.compilerOptions.jsonSchemaDir}/${file}.json`;
|
|
41
|
-
const schema = (0, utils_1.loadJson)(roleSchemaPath);
|
|
42
|
-
for (const key in schema.properties) {
|
|
43
|
-
const prop = schema.properties[key];
|
|
44
|
-
if (prop["x-vexData"] === "role") {
|
|
45
|
-
prop.type = "array";
|
|
46
|
-
prop.required = true;
|
|
47
|
-
prop.default = [(_a = options.compilerOptions.useRBAC) === null || _a === void 0 ? void 0 : _a.default];
|
|
48
|
-
if (!prop.items) {
|
|
49
|
-
prop.items = { type: "" };
|
|
50
|
-
}
|
|
51
|
-
prop.items.type = "string";
|
|
52
|
-
prop.items.required = true;
|
|
53
|
-
prop.items.enum = (_b = options.compilerOptions.useRBAC) === null || _b === void 0 ? void 0 : _b.roles;
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
(0, utils_1.writeFile)("Schema Role Format", roleSchemaPath, JSON.stringify(schema, null, 4));
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
exports.roleSchemaFormat = roleSchemaFormat;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// {{headerComment}}
|
|
2
|
-
|
|
3
|
-
import { Profile } from "passport";
|
|
4
|
-
import { UserModel } from "../models/UserModel.gen";
|
|
5
|
-
|
|
6
|
-
interface IProfile extends Profile {
|
|
7
|
-
[key: string]: any;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export async function oauthVerify(accessToken: string, refreshToken: string, profile: IProfile, done: (error: any, user?: any) => void) : Promise<void> {
|
|
11
|
-
|
|
12
|
-
// find or create user
|
|
13
|
-
const existingUser = await UserModel.findOne({ email: profile.emails?.[0].value });
|
|
14
|
-
|
|
15
|
-
if( existingUser ){
|
|
16
|
-
// log.info('OAuthVerify ExistingUser');
|
|
17
|
-
return done(null, profile);
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
// log.info('OAuthVerify NewUser');
|
|
21
|
-
const newUser = new UserModel({
|
|
22
|
-
authProvider: profile.provider,
|
|
23
|
-
email: profile.emails?.[0].value || "",
|
|
24
|
-
authId: profile.id,
|
|
25
|
-
name: profile.displayName,
|
|
26
|
-
familyName: profile.name?.familyName,
|
|
27
|
-
givenName: profile.name?.givenName,
|
|
28
|
-
isActive: true,
|
|
29
|
-
locale: profile._json?.locale,
|
|
30
|
-
});
|
|
31
|
-
newUser.save();
|
|
32
|
-
return done(null, profile);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._RoleFactory = exports.accessActionArr = void 0;
|
|
4
|
-
exports.accessActionArr = ["create", "read", "update", "delete", "search"];
|
|
5
|
-
class _RoleFactory {
|
|
6
|
-
constructor(accessControl) {
|
|
7
|
-
this.accessControl = {};
|
|
8
|
-
this.accessControl = accessControl;
|
|
9
|
-
}
|
|
10
|
-
checkAccess(document, access) {
|
|
11
|
-
if (this.accessControl[document]) {
|
|
12
|
-
return this.accessControl[document].includes(access);
|
|
13
|
-
}
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports._RoleFactory = _RoleFactory;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Router } from "express";
|
|
2
|
-
import swaggerUi, { JsonObject } from "swagger-ui-express";
|
|
3
|
-
import { loadYaml } from "../utils/common.gen";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export default class SwaggerRouter{
|
|
7
|
-
|
|
8
|
-
public router: Router = Router();
|
|
9
|
-
|
|
10
|
-
constructor() {}
|
|
11
|
-
|
|
12
|
-
public initRoutes() {
|
|
13
|
-
this.router.use("/api", swaggerUi.serve, swaggerUi.setup(loadYaml("./openapi/openapi.gen.yaml") as JsonObject));
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
}
|
package/dist/test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/test.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const common_1 = __importDefault(require("./utils/common"));
|
|
7
|
-
const util_1 = __importDefault(require("util"));
|
|
8
|
-
const jsonSchema = common_1.default.loadJsonSchema("./output/jsonSchema/User.json");
|
|
9
|
-
const formattedSchema = common_1.default.cleanXcustomValue(jsonSchema.properties, { _id: "string", index: "boolean", unique: "boolean", required: "boolean" });
|
|
10
|
-
console.log(util_1.default.inspect(formattedSchema, { depth: null, colors: true }));
|
|
File without changes
|
package/dist/types/controller.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/dist/types/openapi.js
DELETED
package/dist/types/types.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.httpMethodArr = exports.schemaMethodArr = void 0;
|
|
4
|
-
exports.schemaMethodArr = ["get", "getList", "post", "put", "patch", "delete", "options", "head", "trace"];
|
|
5
|
-
exports.httpMethodArr = ["get", "post", "put", "patch", "delete", "options", "head", "trace"];
|
package/dist/utils/common.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.copyDir = exports.writeFile = exports.loadJson = exports.relativePath = exports.writtedFiles = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const logger_1 = __importDefault(require("./logger"));
|
|
10
|
-
exports.writtedFiles = [];
|
|
11
|
-
const relativePath = (fromPath, toPath) => {
|
|
12
|
-
return path_1.default.relative(fromPath, toPath).replace(/\\/g, "/");
|
|
13
|
-
};
|
|
14
|
-
exports.relativePath = relativePath;
|
|
15
|
-
function loadJson(filePath, fileNotExistHandler) {
|
|
16
|
-
const fileExist = fs_1.default.existsSync(filePath);
|
|
17
|
-
if (!fileExist && fileNotExistHandler) {
|
|
18
|
-
return fileNotExistHandler();
|
|
19
|
-
}
|
|
20
|
-
else if (!fileExist) {
|
|
21
|
-
return logger_1.default.error(`FILE : ${filePath} not found`);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
try {
|
|
25
|
-
const content = JSON.parse(fs_1.default.readFileSync(filePath, "utf8"));
|
|
26
|
-
return content ? content : logger_1.default.error(`FILE JSON : Read Error ${filePath}`);
|
|
27
|
-
}
|
|
28
|
-
catch (err) {
|
|
29
|
-
return logger_1.default.error(`FILE : ${filePath}\n`, err.message);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.loadJson = loadJson;
|
|
34
|
-
function writeFile(title, destination, newContent) {
|
|
35
|
-
const oldContent = fs_1.default.existsSync(destination) ? fs_1.default.readFileSync(destination, "utf8") : "";
|
|
36
|
-
if (oldContent === newContent) {
|
|
37
|
-
logger_1.default.info(`${title} : "${destination}" No changes`);
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
logger_1.default.writing(`${title} : "${destination}"`);
|
|
42
|
-
fs_1.default.writeFileSync(destination, newContent);
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
exports.writeFile = writeFile;
|
|
47
|
-
function copyDir(source, destination, compilerOptions, overwrite) {
|
|
48
|
-
if (!fs_1.default.existsSync(destination)) {
|
|
49
|
-
fs_1.default.mkdirSync(destination);
|
|
50
|
-
}
|
|
51
|
-
const files = fs_1.default.readdirSync(source);
|
|
52
|
-
for (let i = 0; i < files.length; i++) {
|
|
53
|
-
const current = fs_1.default.lstatSync(source + "/" + files[i]);
|
|
54
|
-
if (current.isDirectory()) {
|
|
55
|
-
copyDir(source + "/" + files[i], destination + "/" + files[i], compilerOptions, overwrite);
|
|
56
|
-
}
|
|
57
|
-
else if (!overwrite && fs_1.default.existsSync(destination + "/" + files[i])) {
|
|
58
|
-
logger_1.default.info(`FILE : existed, skip file ${destination + "/" + files[i]} exist, skip`);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
const fileNameGen = files[i].replace(".ts", ".gen.ts");
|
|
62
|
-
const outPath = destination + "/" + fileNameGen;
|
|
63
|
-
logger_1.default.writing(`FILE : ${outPath}`);
|
|
64
|
-
let content = fs_1.default.readFileSync(source + "/" + files[i], "utf8");
|
|
65
|
-
content = content.replace(/\/\/ {{headerComment}}/g, compilerOptions.headerComment);
|
|
66
|
-
fs_1.default.writeFileSync(outPath, content);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.copyDir = copyDir;
|
|
71
|
-
exports.default = {
|
|
72
|
-
relativePath: exports.relativePath,
|
|
73
|
-
copyDir,
|
|
74
|
-
};
|
package/dist/utils/generator.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.defaultCompilerOptions = exports.isUseOAuth = exports.getSimpleHeaderComment = exports.getGenaratorHeaderComment = void 0;
|
|
7
|
-
const child_process_1 = __importDefault(require("child_process"));
|
|
8
|
-
const logger_1 = __importDefault(require("./logger"));
|
|
9
|
-
function getPackageInfo() {
|
|
10
|
-
let globalPackages = {};
|
|
11
|
-
try {
|
|
12
|
-
globalPackages = JSON.parse(child_process_1.default.execSync("npm -g list --json").toString());
|
|
13
|
-
}
|
|
14
|
-
catch (error) {
|
|
15
|
-
logger_1.default.error("Failed to read version number, on execute command: npm -g list --json", error);
|
|
16
|
-
}
|
|
17
|
-
return {
|
|
18
|
-
version: globalPackages.dependencies["very-express"].version || "[unknown version]",
|
|
19
|
-
author: globalPackages.author || "justin26l",
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function getGenaratorHeaderComment() {
|
|
23
|
-
const packageInfo = getPackageInfo();
|
|
24
|
-
return `/**
|
|
25
|
-
* Generated by veryExpress@${packageInfo.version}
|
|
26
|
-
* https://www.npmjs.com/package/very-express
|
|
27
|
-
* author: ${packageInfo.author}
|
|
28
|
-
*/
|
|
29
|
-
`;
|
|
30
|
-
}
|
|
31
|
-
exports.getGenaratorHeaderComment = getGenaratorHeaderComment;
|
|
32
|
-
function getSimpleHeaderComment() {
|
|
33
|
-
const packageInfo = getPackageInfo();
|
|
34
|
-
return `// Generated by veryExpress@${packageInfo.version}`;
|
|
35
|
-
}
|
|
36
|
-
exports.getSimpleHeaderComment = getSimpleHeaderComment;
|
|
37
|
-
function isUseOAuth(compilerOptions) {
|
|
38
|
-
return Object.keys(compilerOptions.useOauth).filter((key) => {
|
|
39
|
-
return compilerOptions.useOauth[key] === true;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
exports.isUseOAuth = isUseOAuth;
|
|
43
|
-
exports.defaultCompilerOptions = {
|
|
44
|
-
headerComment: "// generated files by very-express",
|
|
45
|
-
commitBeforeGenerate: false,
|
|
46
|
-
rootDir: ".",
|
|
47
|
-
srcDir: "./src",
|
|
48
|
-
jsonSchemaDir: "./jsonSchema",
|
|
49
|
-
openapiDir: "./openapi",
|
|
50
|
-
writtedDir: [],
|
|
51
|
-
app: {
|
|
52
|
-
enableSwagger: true,
|
|
53
|
-
useUserSchema: true,
|
|
54
|
-
useObjectID: true,
|
|
55
|
-
allowApiCreateUpdate_id: false,
|
|
56
|
-
},
|
|
57
|
-
useRBAC: {
|
|
58
|
-
roles: ["user"],
|
|
59
|
-
default: "user",
|
|
60
|
-
schemaIncluded: ["user"],
|
|
61
|
-
},
|
|
62
|
-
useOauth: {
|
|
63
|
-
google: false,
|
|
64
|
-
microsoft: false,
|
|
65
|
-
apple: false,
|
|
66
|
-
github: false,
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
exports.default = {
|
|
70
|
-
defaultCompilerOptions: exports.defaultCompilerOptions,
|
|
71
|
-
getGenaratorHeaderComment,
|
|
72
|
-
getSimpleHeaderComment,
|
|
73
|
-
isUseOAuth,
|
|
74
|
-
};
|
package/dist/utils/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./common"), exports);
|
|
18
|
-
__exportStar(require("./generator"), exports);
|
|
19
|
-
__exportStar(require("./jsonSchema"), exports);
|
|
20
|
-
__exportStar(require("./logger"), exports);
|
package/dist/utils/jsonSchema.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
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
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.httpMethod = exports.cleanXcustomValue = exports.loadJsonSchema = void 0;
|
|
30
|
-
const fs_1 = __importDefault(require("fs"));
|
|
31
|
-
const types = __importStar(require("../types/types"));
|
|
32
|
-
const logger_1 = __importDefault(require("./logger"));
|
|
33
|
-
function loadJsonSchema(jsonSchemaPath) {
|
|
34
|
-
if (!fs_1.default.existsSync(jsonSchemaPath)) {
|
|
35
|
-
return logger_1.default.error(`loadJsonSchema : File Not Found ${jsonSchemaPath}`);
|
|
36
|
-
}
|
|
37
|
-
try {
|
|
38
|
-
return JSON.parse(fs_1.default.readFileSync(jsonSchemaPath, "utf8"));
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
return logger_1.default.error("Error Load JsonSchema :\n", e.message || e, jsonSchemaPath);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.loadJsonSchema = loadJsonSchema;
|
|
45
|
-
function cleanXcustomValue(schemaObj, additionalKeyArr) {
|
|
46
|
-
const obj = JSON.parse(JSON.stringify(schemaObj));
|
|
47
|
-
const isAddiArrStr = Array.isArray(additionalKeyArr);
|
|
48
|
-
const addiArrStr = isAddiArrStr ? additionalKeyArr : [];
|
|
49
|
-
const addiArrObj = !isAddiArrStr ? additionalKeyArr : {};
|
|
50
|
-
for (const key in obj) {
|
|
51
|
-
if (key.startsWith("x-")) {
|
|
52
|
-
delete obj[key];
|
|
53
|
-
}
|
|
54
|
-
else if (isAddiArrStr && addiArrStr.includes(key)) {
|
|
55
|
-
delete obj[key];
|
|
56
|
-
}
|
|
57
|
-
else if (!isAddiArrStr && typeof addiArrObj[key] !== "undefined" && addiArrObj[key] == typeof obj[key]) {
|
|
58
|
-
delete obj[key];
|
|
59
|
-
}
|
|
60
|
-
else if (typeof obj[key] === "object") {
|
|
61
|
-
obj[key] = cleanXcustomValue(obj[key], additionalKeyArr);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return obj;
|
|
65
|
-
}
|
|
66
|
-
exports.cleanXcustomValue = cleanXcustomValue;
|
|
67
|
-
function httpMethod(jsonSchemaMethod, documentName) {
|
|
68
|
-
if (jsonSchemaMethod == "getList") {
|
|
69
|
-
return "get";
|
|
70
|
-
}
|
|
71
|
-
else if (types.httpMethodArr.includes(jsonSchemaMethod)) {
|
|
72
|
-
return jsonSchemaMethod;
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
logger_1.default.error(`httpMethod : invalid method "${jsonSchemaMethod}" in "${documentName}".`);
|
|
76
|
-
process.exit(1);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
exports.httpMethod = httpMethod;
|
|
80
|
-
exports.default = {
|
|
81
|
-
cleanXcustomValue,
|
|
82
|
-
httpMethod,
|
|
83
|
-
loadJsonSchema,
|
|
84
|
-
};
|
package/dist/utils/log.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare function processing(msg: any, ...optionalParams: any[]): void;
|
|
2
|
-
export declare function writing(msg: any, ...optionalParams: any[]): void;
|
|
3
|
-
export declare function info(msg: any, ...optionalParams: any[]): void;
|
|
4
|
-
export declare function warn(msg: any, ...optionalParams: any[]): void;
|
|
5
|
-
export declare function error(msg: any, ...optionalParams: any[]): never;
|
|
6
|
-
declare const _default: {
|
|
7
|
-
process: typeof processing;
|
|
8
|
-
writing: typeof writing;
|
|
9
|
-
info: typeof info;
|
|
10
|
-
warn: typeof warn;
|
|
11
|
-
error: typeof error;
|
|
12
|
-
};
|
|
13
|
-
export default _default;
|
package/dist/utils/log.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.error = exports.warn = exports.info = exports.writing = exports.processing = void 0;
|
|
4
|
-
function processing(msg, ...optionalParams) {
|
|
5
|
-
console.log("\x1b[34m%s\x1b[0m", "[PROCESSING]", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
6
|
-
}
|
|
7
|
-
exports.processing = processing;
|
|
8
|
-
function writing(msg, ...optionalParams) {
|
|
9
|
-
console.log("\x1b[32m%s\x1b[0m", "[WRITING]", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
10
|
-
}
|
|
11
|
-
exports.writing = writing;
|
|
12
|
-
function info(msg, ...optionalParams) {
|
|
13
|
-
console.log("\x1b[36m%s\x1b[0m", "[INFO]", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
14
|
-
}
|
|
15
|
-
exports.info = info;
|
|
16
|
-
function warn(msg, ...optionalParams) {
|
|
17
|
-
console.log("\x1b[33m%s\x1b[0m", "[WARN]", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
18
|
-
}
|
|
19
|
-
exports.warn = warn;
|
|
20
|
-
function error(msg, ...optionalParams) {
|
|
21
|
-
console.log("\x1b[41m%s\x1b[0m", "[ERROR]", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
22
|
-
process.exit(1);
|
|
23
|
-
}
|
|
24
|
-
exports.error = error;
|
|
25
|
-
exports.default = {
|
|
26
|
-
process: processing,
|
|
27
|
-
writing,
|
|
28
|
-
info,
|
|
29
|
-
warn,
|
|
30
|
-
error,
|
|
31
|
-
};
|
package/dist/utils/logger.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.error = exports.warn = exports.info = exports.writing = exports.processing = void 0;
|
|
4
|
-
function processing(msg, ...optionalParams) {
|
|
5
|
-
console.log("\x1b[34m%s\x1b[0m", "[PROCESSING]", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
6
|
-
}
|
|
7
|
-
exports.processing = processing;
|
|
8
|
-
function writing(msg, ...optionalParams) {
|
|
9
|
-
console.log("\x1b[32m%s\x1b[0m", "[WRITING]", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
10
|
-
}
|
|
11
|
-
exports.writing = writing;
|
|
12
|
-
function info(msg, ...optionalParams) {
|
|
13
|
-
console.log("\x1b[36m%s\x1b[0m", "[INFO]", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
14
|
-
}
|
|
15
|
-
exports.info = info;
|
|
16
|
-
function warn(msg, ...optionalParams) {
|
|
17
|
-
console.log("\x1b[33m%s\x1b[0m", "[WARN]", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
18
|
-
}
|
|
19
|
-
exports.warn = warn;
|
|
20
|
-
function error(msg, ...optionalParams) {
|
|
21
|
-
console.log("\x1b[41m%s\x1b[0m", "[ERROR]", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
22
|
-
process.exit(1);
|
|
23
|
-
}
|
|
24
|
-
exports.error = error;
|
|
25
|
-
exports.default = {
|
|
26
|
-
process: processing,
|
|
27
|
-
writing,
|
|
28
|
-
info,
|
|
29
|
-
warn,
|
|
30
|
-
error,
|
|
31
|
-
};
|
|
File without changes
|
|
File without changes
|