very-express 0.2.8 → 0.3.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/.env +3 -0
- package/dist/cli.js +18 -14
- package/dist/generators/controller.template.js +1 -1
- package/dist/generators/controllers.generator.js +6 -7
- package/dist/generators/index.d.ts +1 -1
- package/dist/generators/index.js +1 -1
- package/dist/generators/openapi.generator.js +10 -10
- package/dist/generators/packageJson.generator.js +6 -16
- package/dist/generators/role.generator.d.ts +7 -0
- package/dist/generators/role.generator.js +109 -0
- package/dist/generators/routes/oauth.generator.js +24 -4
- package/dist/generators/routes/routes.generator.d.ts +11 -0
- package/dist/generators/routes/routes.generator.js +53 -0
- package/dist/generators/routes/routes.template.d.ts +11 -0
- package/dist/generators/routes/routes.template.js +32 -0
- package/dist/generators/server.generator.js +2 -1
- package/dist/generators/server.template.js +62 -40
- package/dist/generators/userSchema.generator.d.ts +4 -0
- package/dist/generators/userSchema.generator.js +27 -0
- package/dist/index.js +41 -18
- package/dist/preprocess/jsonschemaFormat.js +5 -8
- package/dist/preprocess/roleSetupFile.d.ts +6 -0
- package/dist/preprocess/roleSetupFile.js +28 -0
- package/dist/templates/jsonSchema/User.json +12 -11
- package/dist/templates/plugins/PassportGoogle.ts +87 -0
- package/dist/templates/plugins/oauthVerify.ts +39 -0
- package/dist/templates/roles/_RoleFactory.d.ts +10 -0
- package/dist/templates/roles/_RoleFactory.js +17 -0
- package/dist/templates/roles/_RoleFactory.ts +22 -0
- package/dist/templates/services/mongoConn.ts +38 -0
- package/dist/templates/utils/common.ts +48 -0
- package/dist/templates/utils/logger.ts +25 -0
- package/dist/types/types.d.ts +14 -6
- package/dist/utils/common.d.ts +3 -18
- package/dist/utils/common.js +27 -127
- package/dist/utils/generator.d.ts +12 -0
- package/dist/utils/generator.js +72 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/jsonSchema.d.ts +14 -0
- package/dist/utils/jsonSchema.js +84 -0
- package/package.json +1 -1
- package/tsconfig.json +2 -2
- package/vex.config.json +15 -4
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// {{headerComment}}
|
|
2
|
+
|
|
3
|
+
import jsYaml from "js-yaml";
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
|
|
6
|
+
export function loadYaml(yamlFilePath: string) {
|
|
7
|
+
try {
|
|
8
|
+
return jsYaml.load(fs.readFileSync(yamlFilePath, "utf8"));
|
|
9
|
+
} catch (e: any) {
|
|
10
|
+
console.log("\x1b[41m%s\x1b[0m", "[ERROR]", "Error Load OpenApi File :\n", e);
|
|
11
|
+
process.exit(0);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* build mongoose select object
|
|
17
|
+
* @param fieldsString json stringified array of string
|
|
18
|
+
* @error may throw an error if the fieldsString is not a valid JSON
|
|
19
|
+
*/
|
|
20
|
+
export function parseFieldsSelect(selectString: any) : { [key: string]: number } | undefined {
|
|
21
|
+
const ErrorArrStrMsg = "Invalid select string, only array of string accepted";
|
|
22
|
+
|
|
23
|
+
if (typeof selectString === "undefined" || selectString === "") {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
else if (typeof selectString !== "string") {
|
|
27
|
+
throw new Error(ErrorArrStrMsg);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const fieldArr: string[] = JSON.parse(selectString);
|
|
31
|
+
|
|
32
|
+
if (!Array.isArray(fieldArr)) {
|
|
33
|
+
throw new Error(ErrorArrStrMsg);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
for (let i = 0; i < fieldArr.length; i++) {
|
|
37
|
+
if (typeof fieldArr[i] !== "string") {
|
|
38
|
+
throw new Error(ErrorArrStrMsg);
|
|
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>);
|
|
46
|
+
|
|
47
|
+
return selectFields;
|
|
48
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// {{headerComment}}
|
|
2
|
+
|
|
3
|
+
export function ok(msg: any, ...optionalParams: any[]): void {
|
|
4
|
+
console.log("\x1b[32m%s\x1b[0m", "[OK]", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function info(msg: any, ...optionalParams: any[]): void {
|
|
8
|
+
console.log("\x1b[36m%s\x1b[0m", "[INFO]", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function warn(msg: any, ...optionalParams: any[]): void {
|
|
12
|
+
console.log("\x1b[33m%s\x1b[0m", "[WARN]", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function error(msg: any, ...optionalParams: any[]): void {
|
|
16
|
+
console.log("\x1b[41m%s\x1b[0m", "[ERROR]", msg, optionalParams.length > 0 ? optionalParams : "");
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default {
|
|
21
|
+
ok,
|
|
22
|
+
info,
|
|
23
|
+
warn,
|
|
24
|
+
error,
|
|
25
|
+
};
|
package/dist/types/types.d.ts
CHANGED
|
@@ -5,11 +5,17 @@ export interface compilerOptions {
|
|
|
5
5
|
openapiDir: string;
|
|
6
6
|
rootDir: string;
|
|
7
7
|
srcDir: string;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
writtedDir: string[];
|
|
9
|
+
app: {
|
|
10
|
+
enableSwagger: boolean;
|
|
11
|
+
useUserSchema: boolean;
|
|
12
|
+
useObjectID: boolean;
|
|
13
|
+
allowApiCreateUpdate_id: boolean;
|
|
14
|
+
};
|
|
15
|
+
useRBAC?: {
|
|
16
|
+
roles: string[];
|
|
17
|
+
};
|
|
18
|
+
useOauth?: {
|
|
13
19
|
google?: boolean;
|
|
14
20
|
microsoft?: boolean;
|
|
15
21
|
apple?: boolean;
|
|
@@ -17,6 +23,9 @@ export interface compilerOptions {
|
|
|
17
23
|
[key: string]: boolean | undefined;
|
|
18
24
|
};
|
|
19
25
|
}
|
|
26
|
+
export interface roleJson {
|
|
27
|
+
[key: string]: string[];
|
|
28
|
+
}
|
|
20
29
|
export interface jsonSchema {
|
|
21
30
|
type: string;
|
|
22
31
|
"x-documentConfig": documentConfig;
|
|
@@ -50,7 +59,6 @@ export interface jsonSchemaPropsItem {
|
|
|
50
59
|
}
|
|
51
60
|
export interface documentConfig {
|
|
52
61
|
documentName: string;
|
|
53
|
-
documentType?: "primary" | "secondary";
|
|
54
62
|
interfaceName: string;
|
|
55
63
|
keyPrefix?: string;
|
|
56
64
|
methods: schemaMethod[];
|
package/dist/utils/common.d.ts
CHANGED
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
import * as types from "../types/types";
|
|
2
|
-
export declare
|
|
3
|
-
export declare function getSimpleHeaderComment(): string;
|
|
2
|
+
export declare const writtedFiles: string[];
|
|
4
3
|
export declare const relativePath: (fromPath: string, toPath: string) => string;
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
7
|
-
[key: string]: any;
|
|
8
|
-
}, additionalKeyArr?: string[] | types.additionalKeyObj): {
|
|
9
|
-
[key: string]: any;
|
|
10
|
-
};
|
|
11
|
-
export declare function httpMethod(jsonSchemaMethod: string, documentName: string): types.httpMethod;
|
|
4
|
+
export declare function loadJson<T = any>(filePath: string, fileNotExistHandler?: () => T): T;
|
|
5
|
+
export declare function writeFile(title: string, destination: string, newContent: string): boolean;
|
|
12
6
|
export declare function copyDir(source: string, destination: string, compilerOptions: types.compilerOptions, overwrite?: boolean): void;
|
|
13
|
-
export declare function isUseOAuth(compilerOptions: types.compilerOptions): string[];
|
|
14
|
-
export declare const defaultCompilerOptions: types.compilerOptions;
|
|
15
7
|
declare const _default: {
|
|
16
|
-
defaultCompilerOptions: types.compilerOptions;
|
|
17
|
-
getGenaratorHeaderComment: typeof getGenaratorHeaderComment;
|
|
18
|
-
getSimpleHeaderComment: typeof getSimpleHeaderComment;
|
|
19
8
|
relativePath: (fromPath: string, toPath: string) => string;
|
|
20
|
-
cleanXcustomValue: typeof cleanXcustomValue;
|
|
21
|
-
httpMethod: typeof httpMethod;
|
|
22
|
-
loadJsonSchema: typeof loadJsonSchema;
|
|
23
9
|
copyDir: typeof copyDir;
|
|
24
|
-
isUseOAuth: typeof isUseOAuth;
|
|
25
10
|
};
|
|
26
11
|
export default _default;
|
package/dist/utils/common.js
CHANGED
|
@@ -1,119 +1,49 @@
|
|
|
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
|
-
};
|
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
28
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
6
|
+
exports.copyDir = exports.writeFile = exports.loadJson = exports.relativePath = exports.writtedFiles = void 0;
|
|
30
7
|
const fs_1 = __importDefault(require("fs"));
|
|
31
8
|
const path_1 = __importDefault(require("path"));
|
|
32
|
-
const child_process_1 = __importDefault(require("child_process"));
|
|
33
|
-
const types = __importStar(require("../types/types"));
|
|
34
9
|
const logger_1 = __importDefault(require("./logger"));
|
|
35
|
-
|
|
36
|
-
let globalPackages = {};
|
|
37
|
-
try {
|
|
38
|
-
globalPackages = JSON.parse(child_process_1.default.execSync("npm -g list --json").toString());
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
logger_1.default.error("Failed to read version number, on execute command: npm -g list --json", error);
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
version: globalPackages.dependencies["very-express"].version || "[unknown version]",
|
|
45
|
-
author: globalPackages.author || "justin26l",
|
|
46
|
-
};
|
|
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;
|
|
10
|
+
exports.writtedFiles = [];
|
|
66
11
|
const relativePath = (fromPath, toPath) => {
|
|
67
12
|
return path_1.default.relative(fromPath, toPath).replace(/\\/g, "/");
|
|
68
13
|
};
|
|
69
14
|
exports.relativePath = relativePath;
|
|
70
|
-
function
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
return JSON.parse(fs_1.default.readFileSync(jsonSchemaPath, "utf8"));
|
|
15
|
+
function loadJson(filePath, fileNotExistHandler) {
|
|
16
|
+
const fileExist = fs_1.default.existsSync(filePath);
|
|
17
|
+
if (!fileExist && fileNotExistHandler) {
|
|
18
|
+
return fileNotExistHandler();
|
|
76
19
|
}
|
|
77
|
-
|
|
78
|
-
return logger_1.default.error(
|
|
20
|
+
else if (!fileExist) {
|
|
21
|
+
return logger_1.default.error(`FILE : ${filePath} not found`);
|
|
79
22
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const isAddiArrStr = Array.isArray(additionalKeyArr);
|
|
85
|
-
const addiArrStr = isAddiArrStr ? additionalKeyArr : [];
|
|
86
|
-
const addiArrObj = !isAddiArrStr ? additionalKeyArr : {};
|
|
87
|
-
for (const key in obj) {
|
|
88
|
-
if (key.startsWith("x-")) {
|
|
89
|
-
delete obj[key];
|
|
90
|
-
}
|
|
91
|
-
else if (isAddiArrStr && addiArrStr.includes(key)) {
|
|
92
|
-
delete obj[key];
|
|
93
|
-
}
|
|
94
|
-
else if (!isAddiArrStr && typeof addiArrObj[key] !== "undefined" && addiArrObj[key] == typeof obj[key]) {
|
|
95
|
-
delete obj[key];
|
|
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}`);
|
|
96
27
|
}
|
|
97
|
-
|
|
98
|
-
|
|
28
|
+
catch (err) {
|
|
29
|
+
return logger_1.default.error(`FILE : ${filePath}\n`, err.message);
|
|
99
30
|
}
|
|
100
31
|
}
|
|
101
|
-
return obj;
|
|
102
32
|
}
|
|
103
|
-
exports.
|
|
104
|
-
function
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return jsonSchemaMethod;
|
|
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;
|
|
110
39
|
}
|
|
111
40
|
else {
|
|
112
|
-
logger_1.default.
|
|
113
|
-
|
|
41
|
+
logger_1.default.writing(`${title} : "${destination}"`);
|
|
42
|
+
fs_1.default.writeFileSync(destination, newContent);
|
|
43
|
+
return true;
|
|
114
44
|
}
|
|
115
45
|
}
|
|
116
|
-
exports.
|
|
46
|
+
exports.writeFile = writeFile;
|
|
117
47
|
function copyDir(source, destination, compilerOptions, overwrite) {
|
|
118
48
|
if (!fs_1.default.existsSync(destination)) {
|
|
119
49
|
fs_1.default.mkdirSync(destination);
|
|
@@ -128,47 +58,17 @@ function copyDir(source, destination, compilerOptions, overwrite) {
|
|
|
128
58
|
logger_1.default.info(`FILE : existed, skip file ${destination + "/" + files[i]} exist, skip`);
|
|
129
59
|
}
|
|
130
60
|
else {
|
|
131
|
-
const
|
|
61
|
+
const fileNameGen = files[i].replace(".ts", ".gen.ts");
|
|
62
|
+
const outPath = destination + "/" + fileNameGen;
|
|
132
63
|
logger_1.default.writing(`FILE : ${outPath}`);
|
|
133
64
|
let content = fs_1.default.readFileSync(source + "/" + files[i], "utf8");
|
|
134
|
-
content = content.replace(
|
|
65
|
+
content = content.replace(/\/\/ {{headerComment}}/g, compilerOptions.headerComment);
|
|
135
66
|
fs_1.default.writeFileSync(outPath, content);
|
|
136
67
|
}
|
|
137
68
|
}
|
|
138
69
|
}
|
|
139
70
|
exports.copyDir = copyDir;
|
|
140
|
-
function isUseOAuth(compilerOptions) {
|
|
141
|
-
return Object.keys(compilerOptions.useOauth).filter((key) => {
|
|
142
|
-
return compilerOptions.useOauth[key] === true;
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
exports.isUseOAuth = isUseOAuth;
|
|
146
|
-
exports.defaultCompilerOptions = {
|
|
147
|
-
headerComment: "// generated files by very-express",
|
|
148
|
-
commitBeforeGenerate: false,
|
|
149
|
-
rootDir: ".",
|
|
150
|
-
srcDir: "./src",
|
|
151
|
-
jsonSchemaDir: "./jsonSchema",
|
|
152
|
-
openapiDir: "./openapi",
|
|
153
|
-
enableSwagger: true,
|
|
154
|
-
useUserSchema: true,
|
|
155
|
-
useObjectID: true,
|
|
156
|
-
allowApiCreateUpdate_id: false,
|
|
157
|
-
useOauth: {
|
|
158
|
-
google: false,
|
|
159
|
-
microsoft: false,
|
|
160
|
-
apple: false,
|
|
161
|
-
github: false,
|
|
162
|
-
},
|
|
163
|
-
};
|
|
164
71
|
exports.default = {
|
|
165
|
-
defaultCompilerOptions: exports.defaultCompilerOptions,
|
|
166
|
-
getGenaratorHeaderComment,
|
|
167
|
-
getSimpleHeaderComment,
|
|
168
72
|
relativePath: exports.relativePath,
|
|
169
|
-
cleanXcustomValue,
|
|
170
|
-
httpMethod,
|
|
171
|
-
loadJsonSchema,
|
|
172
73
|
copyDir,
|
|
173
|
-
isUseOAuth,
|
|
174
74
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as types from "../types/types";
|
|
2
|
+
export declare function getGenaratorHeaderComment(): string;
|
|
3
|
+
export declare function getSimpleHeaderComment(): string;
|
|
4
|
+
export declare function isUseOAuth(compilerOptions: types.compilerOptions): string[];
|
|
5
|
+
export declare const defaultCompilerOptions: types.compilerOptions;
|
|
6
|
+
declare const _default: {
|
|
7
|
+
defaultCompilerOptions: types.compilerOptions;
|
|
8
|
+
getGenaratorHeaderComment: typeof getGenaratorHeaderComment;
|
|
9
|
+
getSimpleHeaderComment: typeof getSimpleHeaderComment;
|
|
10
|
+
isUseOAuth: typeof isUseOAuth;
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
},
|
|
60
|
+
useOauth: {
|
|
61
|
+
google: false,
|
|
62
|
+
microsoft: false,
|
|
63
|
+
apple: false,
|
|
64
|
+
github: false,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
exports.default = {
|
|
68
|
+
defaultCompilerOptions: exports.defaultCompilerOptions,
|
|
69
|
+
getGenaratorHeaderComment,
|
|
70
|
+
getSimpleHeaderComment,
|
|
71
|
+
isUseOAuth,
|
|
72
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
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);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as types from "../types/types";
|
|
2
|
+
export declare function loadJsonSchema(jsonSchemaPath: string): types.jsonSchema | never;
|
|
3
|
+
export declare function cleanXcustomValue(schemaObj: {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}, additionalKeyArr?: string[] | types.additionalKeyObj): {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
};
|
|
8
|
+
export declare function httpMethod(jsonSchemaMethod: string, documentName: string): types.httpMethod;
|
|
9
|
+
declare const _default: {
|
|
10
|
+
cleanXcustomValue: typeof cleanXcustomValue;
|
|
11
|
+
httpMethod: typeof httpMethod;
|
|
12
|
+
loadJsonSchema: typeof loadJsonSchema;
|
|
13
|
+
};
|
|
14
|
+
export default _default;
|
|
@@ -0,0 +1,84 @@
|
|
|
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/package.json
CHANGED
package/tsconfig.json
CHANGED
|
@@ -108,12 +108,12 @@
|
|
|
108
108
|
},
|
|
109
109
|
"include": [
|
|
110
110
|
"src/**/*.ts",
|
|
111
|
-
|
|
111
|
+
],
|
|
112
112
|
"exclude": [
|
|
113
113
|
"node_modules",
|
|
114
114
|
"output",
|
|
115
115
|
"src/copyTsTemplates.js",
|
|
116
|
-
"src/templates/**/*.
|
|
116
|
+
"src/templates/**/*.ts",
|
|
117
117
|
".env",
|
|
118
118
|
]
|
|
119
119
|
}
|
package/vex.config.json
CHANGED
|
@@ -4,14 +4,25 @@
|
|
|
4
4
|
"rootDir": "./output",
|
|
5
5
|
"srcDir": "./output/src",
|
|
6
6
|
"openapiDir": "./output/openapi",
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
"app": {
|
|
8
|
+
"roles": [
|
|
9
|
+
"admin",
|
|
10
|
+
"user"
|
|
11
|
+
],
|
|
12
|
+
"enableSwagger": true,
|
|
13
|
+
"useUserSchema": true,
|
|
14
|
+
"useObjectID": true,
|
|
15
|
+
"allowApiCreateUpdate_id": false
|
|
16
|
+
},
|
|
11
17
|
"useOauth": {
|
|
12
18
|
"google": true,
|
|
13
19
|
"microsoft": false,
|
|
14
20
|
"apple": false,
|
|
15
21
|
"github": false
|
|
22
|
+
},
|
|
23
|
+
"useRBAC": {
|
|
24
|
+
"roles": [
|
|
25
|
+
"user"
|
|
26
|
+
]
|
|
16
27
|
}
|
|
17
28
|
}
|