very-express 0.3.6 → 0.4.0

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.
Files changed (82) hide show
  1. package/.gitattributes +2 -2
  2. package/dist/{templates/plugins → _plugins}/PassportGoogle.ts +2 -2
  3. package/dist/{templates/plugins → _plugins}/oauthVerify.ts +1 -1
  4. package/dist/{templates/services → _services}/mongoConn.ts +1 -1
  5. package/dist/_types/responseMsg.ts +13 -0
  6. package/dist/{templates/utils → _utils}/common.ts +6 -1
  7. package/dist/_utils/index.ts +11 -0
  8. package/dist/{templates/utils → _utils}/logger.ts +5 -2
  9. package/dist/_utils/response.ts +32 -0
  10. package/dist/cli.d.ts +0 -1
  11. package/dist/generators/app/openapi.generator.d.ts +3 -0
  12. package/dist/generators/{role.generator.d.ts → app/role.generator.d.ts} +2 -2
  13. package/dist/generators/app/server.generator.d.ts +2 -0
  14. package/dist/generators/{server.template.d.ts → app/server.template.d.ts} +1 -1
  15. package/dist/generators/{controller.template.d.ts → controller/controller.template.d.ts} +1 -1
  16. package/dist/generators/{controllers.generator.d.ts → controller/controllers.generator.d.ts} +2 -2
  17. package/dist/generators/index.d.ts +2 -2
  18. package/dist/generators/project/packageJson.generator.d.ts +6 -0
  19. package/dist/generators/{userSchema.generator.d.ts → project/userSchema.generator.d.ts} +2 -2
  20. package/dist/generators/routes/routes.generator.d.ts +2 -2
  21. package/dist/index.d.ts +1 -1
  22. package/dist/index.js +991 -121
  23. package/dist/preprocess/jsonschemaFormat.d.ts +1 -1
  24. package/dist/preprocess/roleSetupFile.d.ts +1 -1
  25. package/dist/templates/{plugins/PassportGoogle.gen.ts → _plugins/PassportGoogle.ts} +29 -8
  26. package/dist/templates/_plugins/oauthVerify.ts +39 -0
  27. package/dist/templates/_roles/_RoleFactory.ts +22 -0
  28. package/dist/templates/{services/mongoConn.gen.ts → _services/mongoConn.ts} +12 -1
  29. package/dist/templates/_types/responseMsg.ts +13 -0
  30. package/dist/templates/{utils/common.gen.ts → _utils/common.ts} +6 -1
  31. package/dist/templates/_utils/index.ts +11 -0
  32. package/dist/templates/{utils/logger.gen.ts → _utils/logger.ts} +5 -2
  33. package/dist/templates/_utils/response.ts +32 -0
  34. package/dist/templates/root/tsconfig.json +2 -1
  35. package/dist/types/types.d.ts +1 -0
  36. package/dist/utils/configChecker.d.ts +2 -0
  37. package/dist/utils/index.d.ts +1 -0
  38. package/package.json +12 -9
  39. package/tsconfig.json +8 -6
  40. package/vex.config.json +3 -2
  41. package/.env +0 -6
  42. package/dist/cli.js +0 -84
  43. package/dist/generators/controller.template.js +0 -204
  44. package/dist/generators/controllers.generator.js +0 -173
  45. package/dist/generators/index.js +0 -13
  46. package/dist/generators/openapi.generator.d.ts +0 -3
  47. package/dist/generators/openapi.generator.js +0 -227
  48. package/dist/generators/packageJson.generator.d.ts +0 -5
  49. package/dist/generators/packageJson.generator.js +0 -42
  50. package/dist/generators/role.generator.js +0 -112
  51. package/dist/generators/routes/oauth.generator.js +0 -66
  52. package/dist/generators/routes/routes.generator.js +0 -53
  53. package/dist/generators/routes/routes.template.js +0 -32
  54. package/dist/generators/routes/swagger.generator.js +0 -46
  55. package/dist/generators/routes.generator.d.ts +0 -11
  56. package/dist/generators/routes.generator.js +0 -53
  57. package/dist/generators/routes.template.d.ts +0 -11
  58. package/dist/generators/routes.template.js +0 -33
  59. package/dist/generators/server.generator.d.ts +0 -2
  60. package/dist/generators/server.generator.js +0 -30
  61. package/dist/generators/server.template.js +0 -149
  62. package/dist/generators/userSchema.generator.js +0 -30
  63. package/dist/preprocess/jsonschemaFormat.js +0 -107
  64. package/dist/preprocess/roleSetupFile.js +0 -60
  65. package/dist/templates/plugins/oauthVerify.gen.ts +0 -34
  66. package/dist/templates/roles/_RoleFactory.js +0 -17
  67. package/dist/templates/routes/swagger.gen.ts +0 -17
  68. package/dist/test.d.ts +0 -1
  69. package/dist/test.js +0 -10
  70. package/dist/types/controller.d.ts +0 -0
  71. package/dist/types/controller.js +0 -1
  72. package/dist/types/openapi.js +0 -2
  73. package/dist/types/types.js +0 -5
  74. package/dist/utils/common.js +0 -74
  75. package/dist/utils/generator.js +0 -74
  76. package/dist/utils/index.js +0 -20
  77. package/dist/utils/jsonSchema.js +0 -84
  78. package/dist/utils/log.d.ts +0 -13
  79. package/dist/utils/log.js +0 -31
  80. package/dist/utils/logger.js +0 -31
  81. /package/dist/{templates/roles → _roles}/_RoleFactory.ts +0 -0
  82. /package/dist/templates/{roles → _roles}/_RoleFactory.d.ts +0 -0
@@ -1,2 +1,2 @@
1
- import * as types from "../types/types";
1
+ import * as types from "./../types/types";
2
2
  export declare function formatJsonSchema(jsonSchemaPath: string, compilerOptions: types.compilerOptions): types.jsonSchema;
@@ -1,4 +1,4 @@
1
- import * as types from "../types/types";
1
+ import * as types from "./../types/types";
2
2
  export declare function roleSetupFile(options: {
3
3
  collectionList: string[];
4
4
  roleSetupDir: string;
@@ -3,7 +3,8 @@
3
3
  import { Router } from "express";
4
4
  import passport, { PassportStatic, Profile } from "passport";
5
5
  import { AuthenticateOptionsGoogle, Strategy as GoogleStrategy, StrategyOptions, VerifyCallback } from "passport-google-oauth20";
6
- // import log from '../utils/logger.gen';
6
+ import log from "./../../system/_utils/logger.gen";
7
+ import { UserModel } from "./../_models/UserModel.gen";
7
8
 
8
9
  export type { Profile };
9
10
 
@@ -44,22 +45,42 @@ export default class PassportGoogle {
44
45
  this.router.get("/auth/google/callback",
45
46
  this.passport.authenticate("google", { failureRedirect: "/login" }),
46
47
  (req, res) => {
47
- // res.send(`Hello, user <pre>${req.user}</pre>`);
48
48
  res.redirect("/profile");
49
49
  }
50
50
  );
51
51
  }
52
52
 
53
- public async passportSerializeUser() {
53
+ public passportSerializeUser() {
54
+ this.passport.serializeUser(async (user, done) => {
55
+ log.info("passportGoogle().serializeUser", user);
56
+ // Here, you can choose what data to store in the session.
57
+ // This data will be used in `deserializeUser` to retrieve the full user object.
58
+ // This is typically just the user's ID.
59
+
60
+ // store role in session for access control
61
+ const DbUser = await UserModel.findById(user);
62
+ if (DbUser) {
63
+ done(null, DbUser);
64
+ } else {
65
+ done(new Error("User not found"));
66
+ }
54
67
 
55
- await this.passport.serializeUser((user, done) => {
56
- // log.info('passportGoogle().serializeUser', user)
57
68
  done(null, user);
58
69
  });
70
+ }
59
71
 
60
- await this.passport.deserializeUser((id, done) => {
61
- // log.info('passportGoogle().deserializeUser', id)
62
- done(null, { id });
72
+ public async passportDeserializeUser() {
73
+ this.passport.deserializeUser(async (id, done) => {
74
+ log.info("passportGoogle().deserializeUser", id);
75
+
76
+ const user = await UserModel.findById(id);
77
+ if (user) {
78
+ done(null, user);
79
+ }
80
+ else {
81
+ done(new Error("User not found"));
82
+ }
83
+
63
84
  });
64
85
  }
65
86
 
@@ -0,0 +1,39 @@
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 default async function oauthVerify(accessToken: string, refreshToken: string, profile: IProfile, done: (error: any, user?: any) => void) : Promise<void> {
11
+ try {
12
+
13
+ // find or create user
14
+ const existingUser = await UserModel.findOne({ email: profile.emails?.[0].value });
15
+
16
+ if( existingUser ){
17
+ // log.info('OAuthVerify ExistingUser');
18
+ return done(null, existingUser);
19
+ }
20
+ else {
21
+ // log.info('OAuthVerify NewUser');
22
+ const newUser = new UserModel({
23
+ authProvider: profile.provider,
24
+ email: profile.emails?.[0].value || "",
25
+ authId: profile.id,
26
+ name: profile.displayName,
27
+ familyName: profile.name?.familyName,
28
+ givenName: profile.name?.givenName,
29
+ isActive: true,
30
+ locale: profile._json?.locale,
31
+ });
32
+ newUser.save();
33
+ return done(null, newUser);
34
+ }
35
+ }
36
+ catch(err) {
37
+ return done(err);
38
+ }
39
+ }
@@ -0,0 +1,22 @@
1
+ export type accessAction = "create" | "read" | "update" | "delete" | "search";
2
+ export const accessActionArr: accessAction[] = ["create", "read", "update", "delete", "search"];
3
+
4
+ export interface accessControl< T = accessAction > {
5
+ [key:string]: T[]
6
+ }
7
+
8
+ export class _RoleFactory<T = accessAction> {
9
+ private accessControl: accessControl<T> = {};
10
+
11
+ constructor(accessControl: accessControl<T>) {
12
+ this.accessControl = accessControl;
13
+ }
14
+
15
+ public checkAccess(document: string, access: string): boolean {
16
+ if (this.accessControl[document]) {
17
+ return this.accessControl[document].includes(access as T);
18
+ }
19
+ return false;
20
+ }
21
+
22
+ }
@@ -1,7 +1,8 @@
1
1
  // {{headerComment}}
2
2
 
3
3
  import mongoose from "mongoose";
4
- import log from "../utils/logger.gen";
4
+ import { Request, Response, NextFunction } from "express";
5
+ import log from "./../../system/_utils/logger.gen";
5
6
 
6
7
  export function connect(mongoUrl:string): mongoose.Connection {
7
8
  mongoose.connect(mongoUrl, {
@@ -19,9 +20,19 @@ export function connect(mongoUrl:string): mongoose.Connection {
19
20
  return mongoose.connection;
20
21
  }
21
22
 
23
+ export function middleware(req: Request, res: Response, next: NextFunction) {
24
+ const db = mongoose.connection;
25
+ if (db.readyState !== 1) {
26
+ return res.status(503).json({ error: "Database connection issue" });
27
+ }
28
+ else {
29
+ next();
30
+ }
31
+ }
22
32
 
23
33
  const mongo = {
24
34
  connect,
35
+ middleware
25
36
  };
26
37
 
27
38
  export default mongo;
@@ -0,0 +1,13 @@
1
+ enum responseMessage {
2
+ permissionDeny = "Permission Denied",
3
+ ok = "OK",
4
+ notFound = "Not Found",
5
+ queryError = "Query Error",
6
+ validateError = "Validation Error",
7
+ unexpectedError = "Unexpected Error",
8
+ createFail = "Create Fail",
9
+ updateFail = "Update Fail",
10
+ deleteFail = "Delete Fail",
11
+ }
12
+
13
+ export default responseMessage;
@@ -45,4 +45,9 @@ export function parseFieldsSelect(selectString: any) : { [key: string]: number }
45
45
  }, {} as Record<string, number>);
46
46
 
47
47
  return selectFields;
48
- }
48
+ }
49
+
50
+ export default {
51
+ loadYaml,
52
+ parseFieldsSelect
53
+ };
@@ -0,0 +1,11 @@
1
+ import logger from "./logger.gen";
2
+ import response from "./response.gen";
3
+ import responseMessage from "../../system/_types/responseMsg.gen";
4
+ import common from "./common.gen";
5
+
6
+ export default {
7
+ log : logger,
8
+ response,
9
+ responseMsg : responseMessage,
10
+ common
11
+ };
@@ -1,4 +1,6 @@
1
- // {{headerComment}}
1
+ export function processing(msg: any, ...optionalParams: any[]): void {
2
+ console.log("\x1b[34m%s\x1b[0m", "[PROCESSING]", msg, optionalParams.length > 0 ? optionalParams : "");
3
+ }
2
4
 
3
5
  export function ok(msg: any, ...optionalParams: any[]): void {
4
6
  console.log("\x1b[32m%s\x1b[0m", "[OK]", msg, optionalParams.length > 0 ? optionalParams : "");
@@ -12,12 +14,13 @@ export function warn(msg: any, ...optionalParams: any[]): void {
12
14
  console.log("\x1b[33m%s\x1b[0m", "[WARN]", msg, optionalParams.length > 0 ? optionalParams : "");
13
15
  }
14
16
 
15
- export function error(msg: any, ...optionalParams: any[]): void {
17
+ export function error(msg: any, ...optionalParams: any[]): never {
16
18
  console.log("\x1b[41m%s\x1b[0m", "[ERROR]", msg, optionalParams.length > 0 ? optionalParams : "");
17
19
  process.exit(1);
18
20
  }
19
21
 
20
22
  export default {
23
+ process : processing,
21
24
  ok,
22
25
  info,
23
26
  warn,
@@ -0,0 +1,32 @@
1
+ import { Response } from "express";
2
+
3
+ export interface responseObject<T>{
4
+ ret_code : number,
5
+ ret_msg : string,
6
+ ret_time?: number,
7
+ result: T,
8
+ }
9
+
10
+ /**
11
+ * @param res express response object
12
+ * @param code http status
13
+ * @param message response data message
14
+ * @param result response data result
15
+ */
16
+ export function send<T = undefined>(
17
+ res: Response,
18
+ code: number = 200,
19
+ message: string = "OK",
20
+ result?: T,
21
+ ): Response<any, Record<string, any>> {
22
+ return res.status(code).json({
23
+ ret_code: code,
24
+ ret_msg: message,
25
+ ret_time: new Date().getTime(),
26
+ result: result,
27
+ });
28
+ }
29
+
30
+ export default {
31
+ send
32
+ };
@@ -12,7 +12,8 @@
12
12
  "outDir": "./dist", /* Specify an output folder for all emitted files. */
13
13
  "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
14
14
  "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
15
-
15
+ "allowArbitraryExtensions": true, /* Allow arbitrary file extensions. */
16
+
16
17
  /* Type Checking */
17
18
  "strict": true, /* Enable all strict type-checking options. */
18
19
  "skipLibCheck": true /* Skip type checking all .d.ts files. */
@@ -5,6 +5,7 @@ export interface compilerOptions {
5
5
  openapiDir: string;
6
6
  rootDir: string;
7
7
  srcDir: string;
8
+ sysDir: string;
8
9
  writtedDir: string[];
9
10
  app: {
10
11
  enableSwagger: boolean;
@@ -0,0 +1,2 @@
1
+ import * as types from "~/types/types";
2
+ export declare function checkConfigValid(options: types.compilerOptions): void;
@@ -2,3 +2,4 @@ export * from "./common";
2
2
  export * from "./generator";
3
3
  export * from "./jsonSchema";
4
4
  export * from "./logger";
5
+ export * from "./configChecker";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "very-express",
3
- "version": "0.3.6",
3
+ "version": "0.4.0",
4
4
  "description": "based on json schema and openapi, generate Express RestApi server with mongoDb ",
5
5
  "author": "justin26l",
6
6
  "license": "MIT",
@@ -9,12 +9,12 @@
9
9
  "vex": "./dist/cli.js"
10
10
  },
11
11
  "scripts": {
12
- "build": "npm run test && tsc -p . && node ./src/copyTsTemplates.js",
13
- "dev": "ts-node ./src/cli.ts -j ./output/jsonSchema -o ./output -s ./output/src",
14
- "prod": "node ./dist/cli.js",
15
- "test": "eslint ./src --ext .ts --fix",
16
- "vexgen": "vex -j ./output/jsonSchema -o ./output/src",
17
- "start": "node ./dist/server.js"
12
+ "build": "npm run lint && npm run compile && npm run minify",
13
+ "dev": "ts-node ./src/cli.ts",
14
+ "test": "node ./dist/index.js",
15
+ "lint": "eslint ./src --ext .ts --fix",
16
+ "compile": "ncc build ./src/cli.ts -o dist && node ./src/copyTsTemplates.js",
17
+ "minify": "uglifyjs ./dist/index.js -c -m -o ./dist/index.js"
18
18
  },
19
19
  "keywords": [
20
20
  "jsonSchema",
@@ -29,9 +29,12 @@
29
29
  "url": "git+https://github.com/Justin26l/VeryExpress.git"
30
30
  },
31
31
  "dependencies": {
32
+ "@vercel/ncc": "^0.38.1",
32
33
  "express-session": "^1.17.3",
33
34
  "js-yaml": "4.1.0",
34
35
  "json-schema-to-openapi-schema": "^0.4.0",
36
+ "json-schema-to-typescript": "^13.1.1",
37
+ "json2mongoose": "^0.3.0",
35
38
  "minimist": "^1.2.8"
36
39
  },
37
40
  "devDependencies": {
@@ -52,11 +55,11 @@
52
55
  "helmet": "^7.1.0",
53
56
  "js-yaml": "^4.1.0",
54
57
  "json-schema-to-openapi-schema": "^0.4.0",
55
- "json2mongoose": "^0.2.1",
56
58
  "passport": "^0.7.0",
57
59
  "passport-google-oauth20": "^2.0.0",
58
60
  "swagger-ui-express": "^5.0.0",
59
61
  "ts-node": "^10.9.2",
60
- "typescript": "^5.3.3"
62
+ "typescript": "^5.3.3",
63
+ "uglify-js": "^3.17.4"
61
64
  }
62
65
  }
package/tsconfig.json CHANGED
@@ -28,8 +28,10 @@
28
28
  "module": "commonjs", /* Specify what module code is generated. */
29
29
  // "rootDir": "./", /* Specify the root folder within your source files. */
30
30
  "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
31
- // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32
- // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
31
+ "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32
+ "paths": {
33
+ "~/*": ["src/*"]
34
+ }, /* Specify a set of entries that re-map imports to additional lookup locations. */
33
35
  // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
34
36
  "typeRoots": ["./node_modules/@types", "./src/types"], /* Specify multiple folders that act like './node_modules/@types'. */
35
37
  // "types": [], /* Specify type package names to be included without being referenced in a source file. */
@@ -39,7 +41,7 @@
39
41
  // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
40
42
  // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
41
43
  // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
42
- // "resolveJsonModule": true, /* Enable importing .json files. */
44
+ "resolveJsonModule": true, /* Enable importing .json files. */
43
45
  // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
44
46
  // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
45
47
 
@@ -54,8 +56,8 @@
54
56
  // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
55
57
  // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
56
58
  // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
57
- // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
58
- "outDir": "./dist", /* Specify an output folder for all emitted files. */
59
+ // "outFile": "./dist/bundle.js", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
60
+ "outDir": "./tsc_out", /* Specify an output folder for all emitted files. */
59
61
  "removeComments": true, /* Disable emitting comments. */
60
62
  // "noEmit": true, /* Disable emitting files from a compilation. */
61
63
  // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
@@ -115,5 +117,5 @@
115
117
  "src/copyTsTemplates.js",
116
118
  "src/templates/**/*.ts",
117
119
  ".env",
118
- ]
120
+ ],
119
121
  }
package/vex.config.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "jsonSchemaDir": "./output/jsonSchema",
4
4
  "rootDir": "./output",
5
5
  "srcDir": "./output/src",
6
- "openapiDir": "./output/openapi",
6
+ "openapiDir": "./output/src/openapi",
7
7
  "app": {
8
8
  "enableSwagger": true,
9
9
  "useUserSchema": true,
@@ -27,5 +27,6 @@
27
27
  "schemaIncluded": [
28
28
  "user"
29
29
  ]
30
- }
30
+ },
31
+ "sysDir": "./output/src/system"
31
32
  }
package/.env DELETED
@@ -1,6 +0,0 @@
1
- # veryExpress generated
2
- EXPRESS_PORT=3000
3
- MONGO_URL=mongodb://localhost:27017/veryExpressDB
4
-
5
- OAUTH_GOOGLE_CLIENTID=378725103786-9r1ilau6vb7rlp6gvs9pqe7d9fc3po6g.apps.googleusercontent.com
6
- OAUTH_GOOGLE_CLIENTSECRET=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
package/dist/cli.js DELETED
@@ -1,84 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- var _a;
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- const fs_1 = __importDefault(require("fs"));
9
- const child_process_1 = __importDefault(require("child_process"));
10
- const minimist_1 = __importDefault(require("minimist"));
11
- const index_1 = require("./index");
12
- const logger_1 = __importDefault(require("./utils/logger"));
13
- const utils_1 = require("./utils");
14
- console.log("\x1b[35m%s\x1b[0m", "\n========== veryExpress CLI (vex) Start ==========\n");
15
- const args = (0, minimist_1.default)(process.argv.slice(2));
16
- let config = utils_1.defaultCompilerOptions;
17
- if (fs_1.default.existsSync("vex.config.json")) {
18
- try {
19
- config = JSON.parse(fs_1.default.readFileSync("vex.config.json", "utf8"));
20
- }
21
- catch (err) {
22
- logger_1.default.error("failed to parse vex.config.json", err);
23
- process.exit(1);
24
- }
25
- }
26
- config.commitBeforeGenerate = (_a = config.commitBeforeGenerate) !== null && _a !== void 0 ? _a : false;
27
- config.jsonSchemaDir = args.j || args.jsonSchemaDir || config.jsonSchemaDir || "./jsonSchema";
28
- config.rootDir = args.o || args.rootDir || config.rootDir || ".";
29
- config.srcDir = config.srcDir || config.rootDir + "/src";
30
- config.openapiDir = config.openapiDir || config.rootDir + "./openapi";
31
- config.app = config.app || {},
32
- config.app.enableSwagger = config.app.enableSwagger || true,
33
- config.app.useUserSchema = config.app.useUserSchema || true,
34
- config.app.useObjectID = config.app.useObjectID || true,
35
- config.app.allowApiCreateUpdate_id = config.app.allowApiCreateUpdate_id || false,
36
- config.useRBAC = config.useRBAC || { roles: [], default: "", schemaIncluded: [] };
37
- config.useRBAC.roles = config.useRBAC.roles || ["user"];
38
- config.useRBAC.default = config.useRBAC.default || "user";
39
- config.useRBAC.schemaIncluded = config.useRBAC.schemaIncluded || ["user"];
40
- config.useOauth = config.useOauth || {};
41
- config.useOauth.google = config.useOauth.google || false;
42
- config.useOauth.facebook = config.useOauth.facebook || false;
43
- config.useOauth.github = config.useOauth.github || false;
44
- config.useOauth.microsoft = config.useOauth.microsoft || false;
45
- if (config.app.useObjectID && config.app.allowApiCreateUpdate_id) {
46
- logger_1.default.warn("Not recommended to use \"useObjectID\" with \"allowApiCreateUpdate_id\",\nthis may cause some logic issues");
47
- }
48
- logger_1.default.process("vex.config.json");
49
- (0, utils_1.writeFile)("vex.config", "vex.config.json", JSON.stringify(config, null, 4));
50
- if (String(args._[0]).toLowerCase() === "h" || args["h"]) {
51
- console.log(`Very Express CLI Usage :
52
- vex [flag]
53
- -h : Help
54
- -i : Create generator config etc.
55
- to generate app :
56
- vex [jsonSchemaDir] [rootDir]
57
- -j : jsonSchemaDir (configured: ${config.jsonSchemaDir})
58
- -o : rootDir (configured: ${config.rootDir})
59
- `);
60
- process.exit(0);
61
- }
62
- else if (String(args._[0]).toLowerCase() === "i" || args["i"]) {
63
- console.log("Very Express CLI : Initialization ...");
64
- process.exit(0);
65
- }
66
- else {
67
- if (!fs_1.default.existsSync(config.jsonSchemaDir)) {
68
- logger_1.default.error("Schema Dir Not Found:", config.jsonSchemaDir);
69
- process.exit(1);
70
- }
71
- if (config.commitBeforeGenerate === true) {
72
- try {
73
- logger_1.default.info("git commit \"before vex-gen\"");
74
- child_process_1.default.execSync("git add . && git commit -m \"before vex-gen\"", { stdio: "inherit" });
75
- }
76
- catch (err) {
77
- logger_1.default.error("git commit \"before vex-gen\" failed", err);
78
- }
79
- }
80
- console.log(config);
81
- (0, index_1.generate)(config);
82
- console.log("\x1b[36m%s\x1b[0m", "\nnext step:\n", `cd ${config.rootDir}\n`, "npm install\n", "npm run dev");
83
- }
84
- console.log("\x1b[35m%s\x1b[0m", "\n========== veryExpress CLI (vex) Complete ==========\n");