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,112 +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.compile = void 0;
|
|
30
|
-
const fs_1 = __importDefault(require("fs"));
|
|
31
|
-
const roleBase = __importStar(require("../templates/roles/_RoleFactory"));
|
|
32
|
-
const logger_1 = __importDefault(require("../utils/logger"));
|
|
33
|
-
const utils_1 = require("../utils");
|
|
34
|
-
const roleSetupFile_1 = require("../preprocess/roleSetupFile");
|
|
35
|
-
function compile(options) {
|
|
36
|
-
var _a;
|
|
37
|
-
if (!options.compilerOptions.useRBAC) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
(0, roleSetupFile_1.roleSetupFile)({
|
|
41
|
-
collectionList: options.collectionList,
|
|
42
|
-
roleSetupDir: options.roleSourceDir,
|
|
43
|
-
compilerOptions: options.compilerOptions
|
|
44
|
-
});
|
|
45
|
-
const indexFileData = [];
|
|
46
|
-
(_a = options.compilerOptions.useRBAC) === null || _a === void 0 ? void 0 : _a.roles.forEach((role) => {
|
|
47
|
-
logger_1.default.process(`RBAC Class : ${role}`);
|
|
48
|
-
const RoleAccessAction = [];
|
|
49
|
-
const roleSrcFile = `${options.compilerOptions.rootDir}/roles/${role}.json`;
|
|
50
|
-
const roleOutFile = `${options.roleOutDir}/${role}.gen.ts`;
|
|
51
|
-
const roleContent = (0, utils_1.loadJson)(roleSrcFile);
|
|
52
|
-
Object.values(roleContent).forEach((resourceContent) => {
|
|
53
|
-
if (Array.isArray(resourceContent)) {
|
|
54
|
-
resourceContent.forEach((action) => {
|
|
55
|
-
if (!RoleAccessAction.includes(action) && !roleBase.accessActionArr.includes(action)) {
|
|
56
|
-
RoleAccessAction.push(action);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
const RoleAccessActionString = Object.keys(RoleAccessAction).map((key) => `"${key}"`);
|
|
62
|
-
RoleAccessActionString.push("roleFactory.accessAction");
|
|
63
|
-
const content = `${options.compilerOptions.headerComment}
|
|
64
|
-
import * as roleFactory from "./_RoleFactory.gen";
|
|
65
|
-
|
|
66
|
-
export type accessAction${role} = ${RoleAccessActionString.join(" | ")};
|
|
67
|
-
|
|
68
|
-
const ${role}AccessControl: roleFactory.accessControl<accessAction${role}> = ${JSON.stringify(roleContent, null, 4)};
|
|
69
|
-
|
|
70
|
-
export default class Role${role} extends roleFactory._RoleFactory<accessAction${role}> {
|
|
71
|
-
constructor() {
|
|
72
|
-
super(${role}AccessControl);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
`;
|
|
76
|
-
(0, utils_1.writeFile)("RBAC Role", roleOutFile, content);
|
|
77
|
-
indexFileData.push({
|
|
78
|
-
name: role,
|
|
79
|
-
from: roleOutFile,
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
const indexFile = `${options.roleOutDir}/index.ts`;
|
|
83
|
-
const indexFileContent = indexFileData.map((data) => `export { default as ${data.name} } from "./${data.name}.gen";`).join("\n");
|
|
84
|
-
(0, utils_1.writeFile)("RBAC Index", indexFile, `${options.compilerOptions.headerComment}\n${indexFileContent}`);
|
|
85
|
-
if (!fs_1.default.existsSync(`${options.compilerOptions.srcDir}/middlewares`)) {
|
|
86
|
-
fs_1.default.mkdirSync(`${options.compilerOptions.srcDir}/middlewares`);
|
|
87
|
-
}
|
|
88
|
-
const middlewareFile = `${options.compilerOptions.srcDir}/middlewares/RoleBaseAccessControl.gen.ts`;
|
|
89
|
-
const roleTypes = indexFileData.map((data) => `typeof roles.${data.name}`).join(" | ");
|
|
90
|
-
const middlewareContent = `${options.compilerOptions.headerComment}
|
|
91
|
-
import { Request, Response, NextFunction } from "express";
|
|
92
|
-
import * as roles from "../roles";
|
|
93
|
-
|
|
94
|
-
export { roles };
|
|
95
|
-
|
|
96
|
-
export function roleBaseAccessControl(
|
|
97
|
-
role: ${roleTypes},
|
|
98
|
-
collection: string,
|
|
99
|
-
action: string
|
|
100
|
-
) {
|
|
101
|
-
return function (req: Request, res: Response, next: NextFunction) {
|
|
102
|
-
if ( new role().checkAccess(collection, action) ) {
|
|
103
|
-
next();
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
res.status(403).send("Permission denied");
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
}`;
|
|
110
|
-
(0, utils_1.writeFile)("RBAC Middleware", middlewareFile, middlewareContent);
|
|
111
|
-
}
|
|
112
|
-
exports.compile = compile;
|
|
@@ -1,66 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.compile = void 0;
|
|
27
|
-
const utilsGenerator = __importStar(require("./../../utils/generator"));
|
|
28
|
-
function loginHtml(providers) {
|
|
29
|
-
let html = "<p> login with : </p>";
|
|
30
|
-
providers.forEach((pp) => {
|
|
31
|
-
html += `<a href="\${process.env.APP_HOST}:\${process.env.APP_PORT}/auth/${pp}">${pp}</a>`;
|
|
32
|
-
});
|
|
33
|
-
return `\`${html}\``;
|
|
34
|
-
}
|
|
35
|
-
function compile(compilerOptions) {
|
|
36
|
-
const providers = utilsGenerator.isUseOAuth(compilerOptions);
|
|
37
|
-
return `${compilerOptions.headerComment}
|
|
38
|
-
import { Router } from 'express';
|
|
39
|
-
import util from 'util';
|
|
40
|
-
|
|
41
|
-
export default class OAuthRouter{
|
|
42
|
-
|
|
43
|
-
public router: Router = Router();
|
|
44
|
-
private loginHtml = ${loginHtml(providers)};
|
|
45
|
-
|
|
46
|
-
constructor() {}
|
|
47
|
-
|
|
48
|
-
public initRoutes() {
|
|
49
|
-
|
|
50
|
-
this.router.get('/login', (req, res) => {
|
|
51
|
-
res.send(this.loginHtml);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
this.router.get('/profile', (req, res) => {
|
|
55
|
-
if (req.isAuthenticated()) {
|
|
56
|
-
res.send(\`<p>Session Data</p><pre>\${util.inspect(req.user, undefined, null)}</pre>\`);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
res.redirect('/login');
|
|
60
|
-
};
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
}`;
|
|
65
|
-
}
|
|
66
|
-
exports.compile = compile;
|
|
@@ -1,53 +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.compile = void 0;
|
|
30
|
-
const routes_template_1 = __importDefault(require("./routes.template"));
|
|
31
|
-
const routesOAuthGen = __importStar(require("./oauth.generator"));
|
|
32
|
-
const routesSwaggerGen = __importStar(require("./swagger.generator"));
|
|
33
|
-
const utilsGenerator = __importStar(require("../../utils/generator"));
|
|
34
|
-
const logger_1 = __importDefault(require("../../utils/logger"));
|
|
35
|
-
const utils_1 = require("../../utils");
|
|
36
|
-
function compile(options) {
|
|
37
|
-
logger_1.default.process("Route");
|
|
38
|
-
const routesApiOutPath = `${options.routesDir}/ApiRouter.gen.ts`;
|
|
39
|
-
const routesOAuthOutPath = `${options.routesDir}/OAuthRouter.gen.ts`;
|
|
40
|
-
const routesSwaggerOutPath = `${options.routesDir}/SwaggerRouter.gen.ts`;
|
|
41
|
-
if (utilsGenerator.isUseOAuth(options.compilerOptions).length > 0) {
|
|
42
|
-
(0, utils_1.writeFile)("Route OAuth", routesOAuthOutPath, routesOAuthGen.compile(options.compilerOptions));
|
|
43
|
-
}
|
|
44
|
-
if (options.compilerOptions.app.enableSwagger) {
|
|
45
|
-
(0, utils_1.writeFile)("Route Swagger", routesSwaggerOutPath, routesSwaggerGen.compile(options.compilerOptions));
|
|
46
|
-
}
|
|
47
|
-
(0, utils_1.writeFile)("Route API", routesApiOutPath, (0, routes_template_1.default)({
|
|
48
|
-
routes: options.routesArr,
|
|
49
|
-
openapiFile: options.openapiFile,
|
|
50
|
-
compilerOptions: options.compilerOptions,
|
|
51
|
-
}));
|
|
52
|
-
}
|
|
53
|
-
exports.compile = compile;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function routesTemplate(options) {
|
|
4
|
-
let template = options.template || `{{headerComment}}
|
|
5
|
-
import { Router } from 'express';
|
|
6
|
-
|
|
7
|
-
{{importRoutes}}
|
|
8
|
-
|
|
9
|
-
export default class ApiRouter{
|
|
10
|
-
|
|
11
|
-
public router: Router = Router();
|
|
12
|
-
|
|
13
|
-
constructor() {}
|
|
14
|
-
|
|
15
|
-
public initRoutes() {
|
|
16
|
-
|
|
17
|
-
{{useRoutes}}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
}`;
|
|
21
|
-
let importRoutes = "";
|
|
22
|
-
let useRoutes = "";
|
|
23
|
-
options.routes.forEach((obj) => {
|
|
24
|
-
importRoutes += `import ${obj.interfaceName}Controller from '${obj.controllerPath}';\n`;
|
|
25
|
-
useRoutes += ` this.router.use('${obj.route}', ${obj.interfaceName}Controller);\n`;
|
|
26
|
-
});
|
|
27
|
-
template = template.replace(/{{headerComment}}/g, options.compilerOptions.headerComment || "// generated files by very-express");
|
|
28
|
-
template = template.replace(/{{importRoutes}}/g, importRoutes);
|
|
29
|
-
template = template.replace(/{{useRoutes}}/g, useRoutes);
|
|
30
|
-
return template;
|
|
31
|
-
}
|
|
32
|
-
exports.default = routesTemplate;
|
|
@@ -1,46 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.compile = void 0;
|
|
27
|
-
const utils = __importStar(require("../../utils/common"));
|
|
28
|
-
function compile(compilerOptions) {
|
|
29
|
-
const yamlPath = utils.relativePath(compilerOptions.srcDir + "/routes", compilerOptions.openapiDir + "/openapi.gen.yaml");
|
|
30
|
-
return `${compilerOptions.headerComment}
|
|
31
|
-
import { Router } from "express";
|
|
32
|
-
import swaggerUi, { JsonObject } from "swagger-ui-express";
|
|
33
|
-
import { loadYaml } from "../utils/common.gen";
|
|
34
|
-
|
|
35
|
-
export default class SwaggerRouter{
|
|
36
|
-
|
|
37
|
-
public router: Router = Router();
|
|
38
|
-
|
|
39
|
-
constructor() {}
|
|
40
|
-
|
|
41
|
-
public initRoutes() {
|
|
42
|
-
this.router.use("/api", swaggerUi.serve, swaggerUi.setup(loadYaml(__dirname+"/${yamlPath}") as JsonObject));
|
|
43
|
-
}
|
|
44
|
-
}`;
|
|
45
|
-
}
|
|
46
|
-
exports.compile = compile;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as types from "../types/types";
|
|
2
|
-
export declare function compile(options: {
|
|
3
|
-
routesArr: {
|
|
4
|
-
route: string;
|
|
5
|
-
interfaceName: string;
|
|
6
|
-
controllerPath: string;
|
|
7
|
-
}[];
|
|
8
|
-
routesDir: string;
|
|
9
|
-
openapiFile: string;
|
|
10
|
-
compilerOptions: types.compilerOptions;
|
|
11
|
-
}): void;
|
|
@@ -1,53 +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.compile = void 0;
|
|
30
|
-
const fs_1 = __importDefault(require("fs"));
|
|
31
|
-
const routes_template_1 = __importDefault(require("./routes.template"));
|
|
32
|
-
const routesOAuthGen = __importStar(require("./routes/oauth.generator"));
|
|
33
|
-
const routesSwaggerGen = __importStar(require("./routes/swagger.generator"));
|
|
34
|
-
const utils = __importStar(require("../utils/common"));
|
|
35
|
-
const logger_1 = __importDefault(require("../utils/logger"));
|
|
36
|
-
function compile(options) {
|
|
37
|
-
const routesApiOutPath = `${options.routesDir}/ApiRouter.gen.ts`;
|
|
38
|
-
const routesOAuthOutPath = `${options.routesDir}/OAuthRouter.gen.ts`;
|
|
39
|
-
const routesSwaggerOutPath = `${options.routesDir}/SwaggerRouter.gen.ts`;
|
|
40
|
-
logger_1.default.writing(`Router : ${routesApiOutPath}`);
|
|
41
|
-
fs_1.default.writeFileSync(routesApiOutPath, (0, routes_template_1.default)({
|
|
42
|
-
routes: options.routesArr,
|
|
43
|
-
openapiFile: options.openapiFile,
|
|
44
|
-
compilerOptions: options.compilerOptions,
|
|
45
|
-
}));
|
|
46
|
-
if (utils.isUseOAuth(options.compilerOptions).length > 0) {
|
|
47
|
-
fs_1.default.writeFileSync(routesOAuthOutPath, routesOAuthGen.compile(options.compilerOptions));
|
|
48
|
-
}
|
|
49
|
-
if (options.compilerOptions.enableSwagger) {
|
|
50
|
-
fs_1.default.writeFileSync(routesSwaggerOutPath, routesSwaggerGen.compile(options.compilerOptions));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.compile = compile;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as types from "../types/types";
|
|
2
|
-
export default function routesTemplate(options: {
|
|
3
|
-
template?: string;
|
|
4
|
-
openapiFile?: string;
|
|
5
|
-
routes: {
|
|
6
|
-
route: string;
|
|
7
|
-
interfaceName: string;
|
|
8
|
-
controllerPath: string;
|
|
9
|
-
}[];
|
|
10
|
-
compilerOptions: types.compilerOptions;
|
|
11
|
-
}): string;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function routesTemplate(options) {
|
|
4
|
-
let template = options.template || `{{headerComment}}
|
|
5
|
-
import { Router } from 'express';
|
|
6
|
-
|
|
7
|
-
{{importRoutes}}
|
|
8
|
-
|
|
9
|
-
export default class ApiRouter{
|
|
10
|
-
|
|
11
|
-
public router: Router = Router();
|
|
12
|
-
|
|
13
|
-
constructor() {}
|
|
14
|
-
|
|
15
|
-
public initRoutes() {
|
|
16
|
-
|
|
17
|
-
{{useRoutes}}
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
}`;
|
|
22
|
-
let importRoutes = "";
|
|
23
|
-
let useRoutes = "";
|
|
24
|
-
options.routes.forEach((obj) => {
|
|
25
|
-
importRoutes += `import ${obj.interfaceName}Controller from '${obj.controllerPath}';\n`;
|
|
26
|
-
useRoutes += `this.router.use('${obj.route}', ${obj.interfaceName}Controller);\n`;
|
|
27
|
-
});
|
|
28
|
-
template = template.replace(/{{headerComment}}/g, options.compilerOptions.headerComment || "// generated files by very-express");
|
|
29
|
-
template = template.replace(/{{importRoutes}}/g, importRoutes);
|
|
30
|
-
template = template.replace(/{{useRoutes}}/g, useRoutes);
|
|
31
|
-
return template;
|
|
32
|
-
}
|
|
33
|
-
exports.default = routesTemplate;
|
|
@@ -1,30 +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.compile = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const server_template_1 = __importDefault(require("./server.template"));
|
|
9
|
-
const packageJson_generator_1 = __importDefault(require("./packageJson.generator"));
|
|
10
|
-
const logger_1 = __importDefault(require("../utils/logger"));
|
|
11
|
-
const utils_1 = require("../utils");
|
|
12
|
-
function compile(compilerOptions) {
|
|
13
|
-
const serverOutPath = compilerOptions.srcDir + "/server.ts";
|
|
14
|
-
const packageOutPath = compilerOptions.rootDir + "/package.json";
|
|
15
|
-
const envOutPath = compilerOptions.rootDir + "/.env";
|
|
16
|
-
const tsconfigOutPath = compilerOptions.rootDir + "/tsconfig.json";
|
|
17
|
-
(0, utils_1.writeFile)("Server", serverOutPath, (0, server_template_1.default)({
|
|
18
|
-
compilerOptions: compilerOptions,
|
|
19
|
-
}));
|
|
20
|
-
if (!fs_1.default.existsSync(envOutPath)) {
|
|
21
|
-
logger_1.default.writing(`Project : ${envOutPath}`);
|
|
22
|
-
fs_1.default.copyFileSync(__dirname + "/../templates/root/.env", envOutPath);
|
|
23
|
-
}
|
|
24
|
-
if (!fs_1.default.existsSync(tsconfigOutPath)) {
|
|
25
|
-
logger_1.default.writing(`Project : ${tsconfigOutPath}`);
|
|
26
|
-
fs_1.default.copyFileSync(__dirname + "/../templates/root/tsconfig.json", tsconfigOutPath);
|
|
27
|
-
}
|
|
28
|
-
packageJson_generator_1.default.compile(packageOutPath, compilerOptions.jsonSchemaDir, compilerOptions.rootDir);
|
|
29
|
-
}
|
|
30
|
-
exports.compile = compile;
|
|
@@ -1,149 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const utilsGenerator = __importStar(require("./../utils/generator"));
|
|
27
|
-
const importExpressSession = "import session from 'express-session';";
|
|
28
|
-
const importOAuthVerifyPlugin = "import oauthVerify from './plugins/oauthVerify.gen';";
|
|
29
|
-
const importPassportGoogle = "import PassportGoogle from './plugins/PassportGoogle.gen'";
|
|
30
|
-
const importSwaggerRouter = "import SwaggerRouter from './routes/SwaggerRouter.gen';";
|
|
31
|
-
const importOAuthRouter = "import OAuthRouter from './routes/OAuthRouter.gen';";
|
|
32
|
-
const ConfigExpressSession = `
|
|
33
|
-
const expressSessionConfig = {
|
|
34
|
-
secret: 'your session secret',
|
|
35
|
-
resave: false,
|
|
36
|
-
saveUninitialized: false
|
|
37
|
-
}`;
|
|
38
|
-
const ConfigSwaggerRouter = "const SwaggerRoute = new SwaggerRouter(); SwaggerRoute.initRoutes();";
|
|
39
|
-
const ConfigOAuthRouter = "const OAuthRoute = new OAuthRouter(); OAuthRoute.initRoutes();";
|
|
40
|
-
const ConfigPassportGoogle = `
|
|
41
|
-
const OAuthGoogle = new PassportGoogle({
|
|
42
|
-
strategyConfig: {
|
|
43
|
-
verify: oauthVerify
|
|
44
|
-
}
|
|
45
|
-
});`;
|
|
46
|
-
const UseSession = "app.use(session(expressSessionConfig));";
|
|
47
|
-
const UsePassportGoogle = `
|
|
48
|
-
await OAuthGoogle.passportSerializeUser();
|
|
49
|
-
await OAuthGoogle.passportDeserializeUser();
|
|
50
|
-
app.use(OAuthGoogle.passport.initialize());
|
|
51
|
-
app.use(OAuthGoogle.passport.session());`;
|
|
52
|
-
const UseOAuthRouter = "app.use(OAuthRoute.router);";
|
|
53
|
-
const UseSwaggerRouter = "app.use(SwaggerRoute.router);";
|
|
54
|
-
const UseOAuthGoogleRouter = "app.use(OAuthGoogle.router);";
|
|
55
|
-
function serverTemplate(options) {
|
|
56
|
-
let template = options.template || `${options.compilerOptions.headerComment || "// generated files by very-express"}
|
|
57
|
-
|
|
58
|
-
import express from 'express';
|
|
59
|
-
import dotenv from 'dotenv';
|
|
60
|
-
import helmet from 'helmet';
|
|
61
|
-
import log from './utils/logger.gen';
|
|
62
|
-
import mongoConn from './services/mongoConn.gen';
|
|
63
|
-
|
|
64
|
-
import ApiRouter from './routes/ApiRouter.gen';
|
|
65
|
-
{{Import}}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Configure
|
|
70
|
-
*/
|
|
71
|
-
dotenv.config();
|
|
72
|
-
|
|
73
|
-
const helmetConfig = {
|
|
74
|
-
xPoweredBy: false,
|
|
75
|
-
xDnsPrefetchControl: { allow: false },
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const ApiRoute = new ApiRouter(); ApiRoute.initRoutes();
|
|
79
|
-
{{Config}}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* App
|
|
84
|
-
*/
|
|
85
|
-
async function main(): Promise<void> {
|
|
86
|
-
|
|
87
|
-
const app = express();
|
|
88
|
-
app.disable("x-powered-by");
|
|
89
|
-
|
|
90
|
-
// UseMiddleware
|
|
91
|
-
app.use(express.json());
|
|
92
|
-
app.use(helmet(helmetConfig));
|
|
93
|
-
app.use(mongoConn.middleware);
|
|
94
|
-
|
|
95
|
-
// UsePlugins
|
|
96
|
-
{{AppUse}}
|
|
97
|
-
|
|
98
|
-
// Routes
|
|
99
|
-
{{AppRouter}}
|
|
100
|
-
|
|
101
|
-
app.use(ApiRoute.router);
|
|
102
|
-
|
|
103
|
-
app.get('/', (req, res) => {
|
|
104
|
-
res.send('Hello World');
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
app.listen(3000, () => {
|
|
108
|
-
if(!process.env.MONGODB_URI) throw new Error('MONGODB_URI is not defined');
|
|
109
|
-
mongoConn.connect(process.env.MONGODB_URI);
|
|
110
|
-
log.ok(\`Server is running on : \${process.env.APP_HOST}:\${process.env.APP_PORT}\`);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
main();
|
|
116
|
-
`;
|
|
117
|
-
const usedProvider = utilsGenerator.isUseOAuth(options.compilerOptions);
|
|
118
|
-
const Import = [];
|
|
119
|
-
const Config = [];
|
|
120
|
-
const AppUse = [];
|
|
121
|
-
const AppRoute = [];
|
|
122
|
-
if (usedProvider.length > 0) {
|
|
123
|
-
Import.push(importExpressSession);
|
|
124
|
-
Import.push(importOAuthVerifyPlugin);
|
|
125
|
-
Config.push(ConfigExpressSession);
|
|
126
|
-
AppUse.push(UseSession);
|
|
127
|
-
if (options.compilerOptions.app.enableSwagger) {
|
|
128
|
-
Import.push(importSwaggerRouter);
|
|
129
|
-
Config.push(ConfigSwaggerRouter);
|
|
130
|
-
AppRoute.push(UseSwaggerRouter);
|
|
131
|
-
}
|
|
132
|
-
Import.push(importOAuthRouter);
|
|
133
|
-
Config.push(ConfigOAuthRouter);
|
|
134
|
-
AppRoute.push(UseOAuthRouter);
|
|
135
|
-
if (usedProvider.includes("google")) {
|
|
136
|
-
Import.push(importPassportGoogle);
|
|
137
|
-
Config.push(ConfigPassportGoogle);
|
|
138
|
-
AppUse.push(UsePassportGoogle);
|
|
139
|
-
AppRoute.push(UseOAuthGoogleRouter);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
template = template.replace(/{{headerComment}}/g, options.compilerOptions.headerComment || "// generated files by very-express");
|
|
143
|
-
template = template.replace(/{{Import}}/g, Import.join("\n"));
|
|
144
|
-
template = template.replace(/{{Config}}/g, Config.join("\n"));
|
|
145
|
-
template = template.replace(/{{AppUse}}/g, AppUse.join("\n "));
|
|
146
|
-
template = template.replace(/{{AppRouter}}/g, AppRoute.join("\n "));
|
|
147
|
-
return template;
|
|
148
|
-
}
|
|
149
|
-
exports.default = serverTemplate;
|
|
@@ -1,30 +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.compile = void 0;
|
|
7
|
-
const logger_1 = __importDefault(require("../utils/logger"));
|
|
8
|
-
const utils_1 = require("../utils");
|
|
9
|
-
function compile(options) {
|
|
10
|
-
if (!options.compilerOptions.app.useUserSchema) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
logger_1.default.process("UserSchmea");
|
|
14
|
-
const schemaOutPath = `${options.compilerOptions.jsonSchemaDir}/User.json`;
|
|
15
|
-
const templateSchema = (0, utils_1.loadJson)(`${__dirname}/../templates/jsonSchema/User.json`);
|
|
16
|
-
const userSchema = (0, utils_1.loadJson)(schemaOutPath, () => {
|
|
17
|
-
return templateSchema;
|
|
18
|
-
});
|
|
19
|
-
Object.keys(templateSchema.properties).forEach((key) => {
|
|
20
|
-
var _a;
|
|
21
|
-
if (!userSchema.properties[key]) {
|
|
22
|
-
userSchema.properties[key] = templateSchema.properties[key];
|
|
23
|
-
if (key == "role") {
|
|
24
|
-
userSchema.properties[key].enum = ((_a = options.compilerOptions.useRBAC) === null || _a === void 0 ? void 0 : _a.roles) || ["user"];
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
(0, utils_1.writeFile)("UserSchmea", schemaOutPath, JSON.stringify(userSchema, null, 4));
|
|
29
|
-
}
|
|
30
|
-
exports.compile = compile;
|