very-express 0.1.0 → 0.2.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 (39) hide show
  1. package/.env +3 -4
  2. package/.eslintrc.json +37 -37
  3. package/LICENSE +1 -1
  4. package/README.md +15 -35
  5. package/dist/cli.js +41 -37
  6. package/dist/generators/controller.template.js +27 -8
  7. package/dist/generators/controllers.generator.js +17 -20
  8. package/dist/generators/openapi.generator.d.ts +1 -4
  9. package/dist/generators/openapi.generator.js +8 -8
  10. package/dist/generators/packageJson.generator.d.ts +1 -1
  11. package/dist/generators/packageJson.generator.js +10 -10
  12. package/dist/generators/routes/oauth.generator.d.ts +4 -0
  13. package/dist/generators/routes/oauth.generator.js +46 -0
  14. package/dist/generators/routes.generator.d.ts +1 -1
  15. package/dist/generators/routes.generator.js +39 -3
  16. package/dist/generators/routes.template.js +11 -32
  17. package/dist/generators/server.generator.d.ts +1 -1
  18. package/dist/generators/server.generator.js +12 -15
  19. package/dist/generators/server.template.d.ts +2 -2
  20. package/dist/generators/server.template.js +111 -15
  21. package/dist/index.d.ts +1 -1
  22. package/dist/index.js +15 -23
  23. package/dist/preprocess/jsonschemaFormat.js +10 -7
  24. package/dist/templates/jsonSchema/User.json +51 -0
  25. package/dist/templates/plugins/PassportGoogle.gen.ts +64 -0
  26. package/dist/templates/plugins/oauthVerify.gen.ts +33 -0
  27. package/dist/templates/root/.env +6 -2
  28. package/dist/templates/root/package.json +6 -5
  29. package/dist/templates/routes/swagger.gen.ts +17 -0
  30. package/dist/templates/services/mongoConn.gen.ts +25 -0
  31. package/dist/templates/utils/common.gen.ts +9 -2
  32. package/dist/templates/utils/logger.gen.ts +23 -0
  33. package/dist/types/types.d.ts +13 -4
  34. package/dist/utils/common.d.ts +3 -1
  35. package/dist/utils/common.js +26 -11
  36. package/dist/utils/logger.d.ts +13 -0
  37. package/dist/utils/logger.js +31 -0
  38. package/package.json +3 -3
  39. package/vex.config.json +10 -2
@@ -12,12 +12,19 @@ export function loadYaml(yamlFilePath: string) {
12
12
 
13
13
  /**
14
14
  * build mongoose select object
15
- * @param fieldsString stringified array of FieldPath
15
+ * @param fieldsString json stringified array of string
16
16
  * @error may throw an error if the fieldsString is not a valid JSON
17
17
  */
18
- export function parseFieldsSelect(fieldsString:string): Promise<{[key:string]:number}> {
18
+ export function parseFieldsSelect(fieldsString: any ): Promise<{[key:string]:number}> {
19
+
19
20
  return new Promise((resolve, reject) => {
21
+
22
+ if ( !fieldsString || typeof fieldsString !== "string"){
23
+ return reject("Invalid fields string : "+typeof fieldsString,);
24
+ }
25
+
20
26
  let fieldArr: string[] = [];
27
+
21
28
  try {
22
29
  fieldArr = JSON.parse(fieldsString);
23
30
  } catch (err) {
@@ -0,0 +1,23 @@
1
+ export function ok(msg: any, ...optionalParams: any[]): void {
2
+ console.log("\x1b[32m%s\x1b[0m", "[OK]", msg, optionalParams.length > 0 ? optionalParams : "");
3
+ }
4
+
5
+ export function info(msg: any, ...optionalParams: any[]): void {
6
+ console.log("\x1b[36m%s\x1b[0m", "[INFO]", msg, optionalParams.length > 0 ? optionalParams : "");
7
+ }
8
+
9
+ export function warn(msg: any, ...optionalParams: any[]): void {
10
+ console.log("\x1b[33m%s\x1b[0m", "[WARN]", msg, optionalParams.length > 0 ? optionalParams : "");
11
+ }
12
+
13
+ export function error(msg: any, ...optionalParams: any[]): void {
14
+ console.log("\x1b[41m%s\x1b[0m", "[ERROR]", msg, optionalParams.length > 0 ? optionalParams : "");
15
+ process.exit(1);
16
+ }
17
+
18
+ export default {
19
+ ok,
20
+ info,
21
+ warn,
22
+ error,
23
+ };
@@ -1,12 +1,21 @@
1
1
  export interface compilerOptions {
2
+ commitBeforeGenerate: boolean;
3
+ headerComment?: string;
4
+ modelsTemplate?: string;
5
+ controllersTemplate?: string;
2
6
  jsonSchemaDir: string;
3
7
  openapiDir: string;
4
8
  rootDir: string;
5
9
  srcDir: string;
6
- headerComment?: string;
7
- modelsTemplate?: string;
8
- controllersTemplate?: string;
9
- use_id?: boolean;
10
+ enableSwagger: true;
11
+ useUserSchema: true;
12
+ useOauth: {
13
+ google?: boolean;
14
+ microsoft?: boolean;
15
+ apple?: boolean;
16
+ github?: boolean;
17
+ [key: string]: boolean | undefined;
18
+ };
10
19
  }
11
20
  export interface jsonSchema {
12
21
  type: string;
@@ -9,7 +9,8 @@ export declare function cleanXcustomValue(schemaObj: {
9
9
  [key: string]: any;
10
10
  };
11
11
  export declare function httpMethod(jsonSchemaMethod: string, documentName: string): types.httpMethod;
12
- export declare function copyDir(source: string, destination: string): void;
12
+ export declare function copyDir(source: string, destination: string, overwrite?: boolean): void;
13
+ export declare function isUseOAuth(compilerOptions: types.compilerOptions): string[];
13
14
  export declare const defaultCompilerOptions: types.compilerOptions;
14
15
  declare const _default: {
15
16
  defaultCompilerOptions: types.compilerOptions;
@@ -20,5 +21,6 @@ declare const _default: {
20
21
  httpMethod: typeof httpMethod;
21
22
  loadJsonSchema: typeof loadJsonSchema;
22
23
  copyDir: typeof copyDir;
24
+ isUseOAuth: typeof isUseOAuth;
23
25
  };
24
26
  export default _default;
@@ -26,19 +26,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.defaultCompilerOptions = exports.copyDir = exports.httpMethod = exports.cleanXcustomValue = exports.getSimpleHeaderComment = exports.getGenaratorHeaderComment = exports.loadJsonSchema = exports.relativePath = void 0;
29
+ exports.defaultCompilerOptions = exports.isUseOAuth = exports.copyDir = exports.httpMethod = exports.cleanXcustomValue = exports.getSimpleHeaderComment = exports.getGenaratorHeaderComment = exports.loadJsonSchema = exports.relativePath = void 0;
30
30
  const fs_1 = __importDefault(require("fs"));
31
31
  const path_1 = __importDefault(require("path"));
32
32
  const child_process_1 = __importDefault(require("child_process"));
33
33
  const types = __importStar(require("../types/types"));
34
- const log_1 = __importDefault(require("./log"));
34
+ const logger_1 = __importDefault(require("./logger"));
35
35
  function getPackageInfo() {
36
36
  let globalPackages = {};
37
37
  try {
38
38
  globalPackages = JSON.parse(child_process_1.default.execSync("npm -g list --json").toString());
39
39
  }
40
40
  catch (error) {
41
- log_1.default.error("Failed to execute command: npm -g list --json", error);
41
+ logger_1.default.error("Failed to execute command: npm -g list --json", error);
42
42
  }
43
43
  return {
44
44
  version: globalPackages.dependencies["very-express"].version || "[unknown version]",
@@ -51,13 +51,13 @@ const relativePath = (fromPath, toPath) => {
51
51
  exports.relativePath = relativePath;
52
52
  function loadJsonSchema(jsonSchemaPath) {
53
53
  if (!fs_1.default.existsSync(jsonSchemaPath)) {
54
- return log_1.default.error(`loadJsonSchema : File Not Found ${jsonSchemaPath}`);
54
+ return logger_1.default.error(`loadJsonSchema : File Not Found ${jsonSchemaPath}`);
55
55
  }
56
56
  try {
57
57
  return JSON.parse(fs_1.default.readFileSync(jsonSchemaPath, "utf8"));
58
58
  }
59
59
  catch (e) {
60
- return log_1.default.error("Error Load JsonSchema File :\n", e.message || e, jsonSchemaPath);
60
+ return logger_1.default.error("Error Load JsonSchema File :\n", e.message || e, jsonSchemaPath);
61
61
  }
62
62
  }
63
63
  exports.loadJsonSchema = loadJsonSchema;
@@ -110,12 +110,12 @@ function httpMethod(jsonSchemaMethod, documentName) {
110
110
  return jsonSchemaMethod;
111
111
  }
112
112
  else {
113
- log_1.default.error(`httpMethod : invalid method "${jsonSchemaMethod}" in "${documentName}".`);
113
+ logger_1.default.error(`httpMethod : invalid method "${jsonSchemaMethod}" in "${documentName}".`);
114
114
  process.exit(1);
115
115
  }
116
116
  }
117
117
  exports.httpMethod = httpMethod;
118
- function copyDir(source, destination) {
118
+ function copyDir(source, destination, overwrite) {
119
119
  if (!fs_1.default.existsSync(destination)) {
120
120
  fs_1.default.mkdirSync(destination);
121
121
  }
@@ -125,24 +125,38 @@ function copyDir(source, destination) {
125
125
  if (current.isDirectory()) {
126
126
  copyDir(source + "/" + files[i], destination + "/" + files[i]);
127
127
  }
128
- else if (current.isSymbolicLink()) {
129
- const symlink = fs_1.default.readlinkSync(source + "/" + files[i]);
130
- fs_1.default.symlinkSync(symlink, destination + "/" + files[i]);
128
+ else if (!overwrite && fs_1.default.existsSync(destination + "/" + files[i])) {
129
+ logger_1.default.info(`FILE : existed, skip file ${destination + "/" + files[i]} exist, skip`);
131
130
  }
132
131
  else {
133
132
  const outPath = destination + "/" + files[i];
134
- log_1.default.writing(outPath);
133
+ logger_1.default.writing(`FILE : ${outPath}`);
135
134
  fs_1.default.copyFileSync(source + "/" + files[i], outPath);
136
135
  }
137
136
  }
138
137
  }
139
138
  exports.copyDir = copyDir;
139
+ function isUseOAuth(compilerOptions) {
140
+ return Object.keys(compilerOptions.useOauth).filter((key) => {
141
+ return compilerOptions.useOauth[key] === true;
142
+ });
143
+ }
144
+ exports.isUseOAuth = isUseOAuth;
140
145
  exports.defaultCompilerOptions = {
141
146
  headerComment: getGenaratorHeaderComment(),
147
+ commitBeforeGenerate: false,
142
148
  rootDir: ".",
143
149
  srcDir: "./src",
144
150
  jsonSchemaDir: "./jsonSchema",
145
151
  openapiDir: "./openapi",
152
+ enableSwagger: true,
153
+ useUserSchema: true,
154
+ useOauth: {
155
+ google: false,
156
+ microsoft: false,
157
+ apple: false,
158
+ github: false,
159
+ },
146
160
  };
147
161
  exports.default = {
148
162
  defaultCompilerOptions: exports.defaultCompilerOptions,
@@ -153,4 +167,5 @@ exports.default = {
153
167
  httpMethod,
154
168
  loadJsonSchema,
155
169
  copyDir,
170
+ isUseOAuth,
156
171
  };
@@ -0,0 +1,13 @@
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;
@@ -0,0 +1,31 @@
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "very-express",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "based on json schema and openapi, generate Express RestApi server with mongoDb ",
5
5
  "author": "justin26l",
6
6
  "license": "MIT",
@@ -10,10 +10,10 @@
10
10
  },
11
11
  "scripts": {
12
12
  "build": "npm run test && tsc -p . && node ./src/copyDir.js",
13
- "dev": "ts-node ./src/cli.ts -j ./output/jsonSchema -a ./output/openapi -o ./output -s ./output/src",
13
+ "dev": "ts-node ./src/cli.ts -j ./output/jsonSchema -o ./output -s ./output/src",
14
14
  "prod": "node ./dist/cli.js",
15
15
  "test": "eslint ./src --ext .ts --fix",
16
- "vexgen": "vex -j ./output/jsonSchema -a ./output/openapi -o ./output/src",
16
+ "vexgen": "vex -j ./output/jsonSchema -o ./output/src",
17
17
  "start": "node ./dist/server.js"
18
18
  },
19
19
  "keywords": [
package/vex.config.json CHANGED
@@ -1,7 +1,15 @@
1
1
  {
2
2
  "commitBeforeGenerate": false,
3
+ "enableSwagger": true,
4
+ "useUserSchema": true,
5
+ "useOauth": {
6
+ "google": true,
7
+ "microsoft": false,
8
+ "apple": false,
9
+ "github": false
10
+ },
3
11
  "jsonSchemaDir": "./output/jsonSchema",
4
- "openapiDir": "./output/openapi",
5
12
  "rootDir": "./output",
6
- "srcDir": "./output/src"
13
+ "srcDir": "./output/src",
14
+ "openapiDir": "./output/openapi"
7
15
  }