very-express 0.0.6 → 0.0.8

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 ADDED
@@ -0,0 +1,3 @@
1
+
2
+ G_OAUTH_CLIENTID=997485928958-ep5gd9gf25rs5lkpnau5r5q50729utrf.apps.googleusercontent.com
3
+ G_OAUTH_CLIENTSECRET=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
package/README.md CHANGED
@@ -1,24 +1,84 @@
1
1
  # VeryExpress
2
2
  an generator that generate [Express](https://github.com/expressjs/express) rest-api app based on [jsonSchema](https://github.com/json-schema-org) and [openApi](https://github.com/OAI)
3
3
 
4
- ## tech stack
5
- - TypeScript
6
- - ExpressJs
7
- - mongoDb
4
+ ## Idea
5
+ doing same things once is good,
6
+ twice is okay, third times is wasting life.
8
7
 
9
- ## TO DO
10
- - [x] genarate express server from template
8
+ all you need is define the `JsonSchema` and `openApi` spec.
11
9
 
12
- - [x] generate openapi
13
- - [x] path
14
- - [x] param
15
- - [x] response
10
+ ## JsonSchmea Setup
11
+ at the root of schema :
16
12
 
17
- - [x] generate mongoose & collection interface
18
- - [ ] generate sql interface
13
+ | Fields | Description |
14
+ | - | - |
15
+ | documentName | name of **collection** or **table**, also used at `Model`. |
16
+ | interfaceName | used at endpoint and naming `Class`, `Interface`, `Files`. |
17
+ | methods | available method of rest api. |
19
18
 
20
- - [x] genarate controllers from template
21
- - [x] based on openapi spec
22
19
 
23
- - [x] genarate routes from template
24
- - [x] based on controller
20
+ "x-documentConfig": {
21
+ "documentName": "user",
22
+ "interfaceName": "User",
23
+ "methods": [
24
+ "get",
25
+ "post",
26
+ "put",
27
+ "patch",
28
+ "delete"
29
+ ]
30
+ }
31
+
32
+ at the properites :
33
+
34
+ "userContact":{
35
+ "type": "string",
36
+ "format": "uuid",
37
+ "required": false,
38
+ "x-foreignKey": "usercontact"
39
+ }
40
+
41
+
42
+
43
+ ## Road Map
44
+ - [ ] dockernize
45
+ - [x] generate express server
46
+ - [x] gen. routes
47
+ - [x] gen. controllers based on openapi spec
48
+ - [ ] define fields searching method
49
+ - [x] gen. openapi based on json schema
50
+ - [x] gen. mongoose model
51
+ - [ ] gen. sql model
52
+ - [ ] database connection
53
+ - [ ] implement sensitive data encryption & hash (PDPA)
54
+ - [x] TS interface based on json schema
55
+
56
+ ## Enhancement To Do
57
+ - avoid mongo `_id` , instead using custom index `id` for db compatibilities,
58
+ - at JsonSchmea.x-documentConfig, add fields
59
+ `index: string` point to index fields,
60
+ `indexPrefix: string` for easier to identify if its is a foreignKey value.
61
+
62
+ - Implement data encryption & hash (PDPA)
63
+ - at JsonSchmea.Properties, add attribute
64
+ `x-dataSecure: sting` while accessing data, perform hash or encryption.
65
+
66
+ - `* TBC *` Controller > define fields searching method
67
+ - at JsonSchmea.x-Properties, add attribute
68
+ `x-filterType: obejct` method will be array of [ "equal", "like", "between", "gratherThan", "smallerThen" ] default "equal" :
69
+
70
+ "date":{
71
+ "type": "string",
72
+ "format": "date-time",
73
+
74
+ "x-filterType": {
75
+ method : "between",
76
+ from : 'startDate', // additinal fields at openapi /get
77
+ to : 'endDate', // additinal fields at openapi /get
78
+ },
79
+
80
+ "x-filterType": {
81
+ method : "like",
82
+ },
83
+ }
84
+
package/dist/cli.js CHANGED
@@ -7,15 +7,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const index_1 = __importDefault(require("./index"));
8
8
  const fs_1 = __importDefault(require("fs"));
9
9
  const minimist_1 = __importDefault(require("minimist"));
10
+ const log_1 = __importDefault(require("./utils/log"));
10
11
  var args = (0, minimist_1.default)(process.argv.slice(2));
11
12
  console.log('\x1b[35m%s\x1b[0m', '\n========== veryExpress CLI (vex) ==========\n');
12
13
  if ('h' in args) {
13
14
  console.log(`
14
15
  Usage: vex [jsonSchemaDir] [openapiDir] [outputDir]
15
16
  -h : Help
16
- -j : jsonSchemaDir
17
- -a : openApiDir
18
- -o : outputDir
17
+ -j : jsonSchemaDir (default: ./jsonSchema)
18
+ -a : openApiDir (default: ./openapi)
19
+ -o : outputDir (default: ./src)
19
20
  `);
20
21
  process.exit(0);
21
22
  }
@@ -23,7 +24,7 @@ const schemaDir = args.j || args.jsonSchemaDir || process.argv[2] || './jsonSche
23
24
  const openapiDir = args.a || args.openApiDir || process.argv[3] || './openapi';
24
25
  const outputDir = args.o || args.outputDir || process.argv[4] || './output';
25
26
  if (!fs_1.default.existsSync(schemaDir)) {
26
- console.log('\x1b[31m%s\x1b[0m', 'Schema Dir Not Found:', schemaDir);
27
+ log_1.default.error('Schema Dir Not Found:', schemaDir);
27
28
  process.exit(1);
28
29
  }
29
30
  ;
@@ -114,36 +114,30 @@ class {{interfaceName}}Controller {
114
114
 
115
115
  export default new {{interfaceName}}Controller().router;
116
116
  `;
117
- template = template.replace(/{{headerComment}}/g, templateOptions.headerComment);
118
- template = template.replace(/{{interfaceName}}/g, templateOptions.interfaceName);
119
- template = template.replace(/{{modelPath}}/g, templateOptions.modelPath);
120
117
  const indent2 = '\n ';
121
118
  const indent3 = '\n ';
122
119
  const indent4 = '\n ';
123
- if (templateOptions.validator[templateOptions.endpoint].get) {
124
- template = template.replace(/{{getListRoute}}/g, `this.router.get('/', ${indent3}[${indent4 + templateOptions.validator[templateOptions.endpoint].get.join(',' + indent4) + indent3}],${indent3}this.getList${templateOptions.interfaceName}.bind(this)${indent2});`);
125
- }
126
- ;
127
- if (templateOptions.validator[templateOptions.endpoint + '/{id}'].get) {
128
- template = template.replace(/{{getOneRoute}}/g, `this.router.get('/:id', ${indent3}[${indent4 + templateOptions.validator[templateOptions.endpoint + '/{id}'].get.join(',' + indent4) + indent3}],${indent3}this.get${templateOptions.interfaceName}.bind(this)${indent2});`);
129
- }
130
- ;
131
- if (templateOptions.validator[templateOptions.endpoint].post) {
132
- template = template.replace(/{{postRoute}}/g, `this.router.post('/', ${indent3}[${indent4 + templateOptions.validator[templateOptions.endpoint].post.join(',' + indent4) + indent3}],${indent3}this.create${templateOptions.interfaceName}.bind(this)${indent2});`);
133
- }
134
- ;
135
- if (templateOptions.validator[templateOptions.endpoint + '/{id}'].put) {
136
- template = template.replace(/{{putRoute}}/g, `this.router.put('/:id', ${indent3}[${indent4 + templateOptions.validator[templateOptions.endpoint + '/{id}'].put.join(',' + indent4) + indent3}],${indent3}this.update${templateOptions.interfaceName}.bind(this)${indent2});`);
137
- }
138
- ;
139
- if (templateOptions.validator[templateOptions.endpoint + '/{id}'].patch) {
140
- template = template.replace(/{{patchRoute}}/g, `this.router.patch('/:id', ${indent3}[${indent4 + templateOptions.validator[templateOptions.endpoint + '/{id}'].patch.join(',' + indent4) + indent3}],${indent3}this.update${templateOptions.interfaceName}.bind(this)${indent2});`);
141
- }
142
- ;
143
- if (templateOptions.validator[templateOptions.endpoint + '/{id}'].delete) {
144
- template = template.replace(/{{deleteRoute}}/g, `this.router.delete('/:id', ${indent3}[${indent4 + templateOptions.validator[templateOptions.endpoint + '/{id}'].delete.join(',' + indent4) + indent3}],${indent3}this.delete${templateOptions.interfaceName}.bind(this)${indent2});`);
145
- }
146
- ;
120
+ template = template.replace(/{{headerComment}}/g, templateOptions.headerComment);
121
+ template = template.replace(/{{interfaceName}}/g, templateOptions.interfaceName);
122
+ template = template.replace(/{{modelPath}}/g, templateOptions.modelPath);
123
+ template = template.replace(/{{getListRoute}}/g, !templateOptions.validator[templateOptions.endpoint].get ?
124
+ '' :
125
+ `this.router.get('/', ${indent3}[${indent4 + templateOptions.validator[templateOptions.endpoint].get.join(',' + indent4) + indent3}],${indent3}this.getList${templateOptions.interfaceName}.bind(this)${indent2});`);
126
+ template = template.replace(/{{getOneRoute}}/g, !templateOptions.validator[templateOptions.endpoint + '/{id}'].get ?
127
+ '' :
128
+ `this.router.get('/:id', ${indent3}[${indent4 + templateOptions.validator[templateOptions.endpoint + '/{id}'].get.join(',' + indent4) + indent3}],${indent3}this.get${templateOptions.interfaceName}.bind(this)${indent2});`);
129
+ template = template.replace(/{{postRoute}}/g, !templateOptions.validator[templateOptions.endpoint].post ?
130
+ '' :
131
+ `this.router.post('/', ${indent3}[${indent4 + templateOptions.validator[templateOptions.endpoint].post.join(',' + indent4) + indent3}],${indent3}this.create${templateOptions.interfaceName}.bind(this)${indent2});`);
132
+ template = template.replace(/{{putRoute}}/g, !templateOptions.validator[templateOptions.endpoint + '/{id}'].put ?
133
+ '' :
134
+ `this.router.put('/:id', ${indent3}[${indent4 + templateOptions.validator[templateOptions.endpoint + '/{id}'].put.join(',' + indent4) + indent3}],${indent3}this.update${templateOptions.interfaceName}.bind(this)${indent2});`);
135
+ template = template.replace(/{{patchRoute}}/g, !templateOptions.validator[templateOptions.endpoint + '/{id}'].patch ?
136
+ '' :
137
+ `this.router.patch('/:id', ${indent3}[${indent4 + templateOptions.validator[templateOptions.endpoint + '/{id}'].patch.join(',' + indent4) + indent3}],${indent3}this.update${templateOptions.interfaceName}.bind(this)${indent2});`);
138
+ template = template.replace(/{{deleteRoute}}/g, !templateOptions.validator[templateOptions.endpoint + '/{id}'].delete ?
139
+ '' :
140
+ `this.router.delete('/:id', ${indent3}[${indent4 + templateOptions.validator[templateOptions.endpoint + '/{id}'].delete.join(',' + indent4) + indent3}],${indent3}this.delete${templateOptions.interfaceName}.bind(this)${indent2});`);
147
141
  return template;
148
142
  }
149
143
  exports.default = controllerTemplate;
@@ -29,15 +29,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.compile = void 0;
30
30
  const fs_1 = __importDefault(require("fs"));
31
31
  const js_yaml_1 = __importDefault(require("js-yaml"));
32
- const templates_1 = __importDefault(require("../templates"));
32
+ const controller_template_1 = __importDefault(require("./controller.template"));
33
33
  const types = __importStar(require("../types/types"));
34
34
  const log_1 = __importDefault(require("../utils/log"));
35
35
  function compile(openapiPath, controllerToModelDir, outDir, options) {
36
36
  const file = fs_1.default.readFileSync(openapiPath, 'utf8');
37
37
  const openApi = js_yaml_1.default.load(file);
38
38
  const endpointsValidator = {};
39
+ let writtedEndpoint = [];
39
40
  Object.keys(openApi.paths).forEach((endpoint) => {
40
- const interfaceName = openApi.paths[endpoint].summary;
41
41
  endpointsValidator[endpoint] = {};
42
42
  log_1.default.process(`Controller : ${openapiPath} > ${endpoint}`);
43
43
  Object.keys(openApi.paths[endpoint]).forEach((method) => {
@@ -50,7 +50,6 @@ function compile(openapiPath, controllerToModelDir, outDir, options) {
50
50
  endpointsValidator[endpoint][method] = validators;
51
51
  });
52
52
  });
53
- let writtedEndpoint = [];
54
53
  Object.keys(openApi.paths).forEach((endpoint) => {
55
54
  const interfaceName = openApi.paths[endpoint].summary;
56
55
  const endpointFormatted = endpoint.replace('/{id}', '').toLowerCase();
@@ -62,15 +61,19 @@ function compile(openapiPath, controllerToModelDir, outDir, options) {
62
61
  }
63
62
  ;
64
63
  const outPath = `${outDir}/${interfaceName}Controller.gen.ts`;
64
+ const outPathNoGen = `${outDir}/${interfaceName}Controller.nogen.ts`;
65
65
  const controllerToModelPath = `${controllerToModelDir}/${interfaceName}Model.gen`;
66
66
  log_1.default.writing(`Controller : ${outPath}`);
67
- fs_1.default.writeFileSync(outPath, templates_1.default.controllerTemplate({
68
- endpoint: endpoint,
69
- modelPath: controllerToModelPath,
70
- interfaceName: interfaceName,
71
- validator: endpointsValidator,
72
- options: options,
73
- }));
67
+ if (!fs_1.default.existsSync(outPathNoGen)) {
68
+ fs_1.default.writeFileSync(outPath, (0, controller_template_1.default)({
69
+ endpoint: endpoint,
70
+ modelPath: controllerToModelPath,
71
+ interfaceName: interfaceName,
72
+ validator: endpointsValidator,
73
+ options: options,
74
+ }));
75
+ }
76
+ ;
74
77
  });
75
78
  }
76
79
  exports.compile = compile;
@@ -5,11 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.compile = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
- const templates_1 = __importDefault(require("../templates"));
8
+ const routes_template_1 = __importDefault(require("./routes.template"));
9
9
  const log_1 = __importDefault(require("../utils/log"));
10
10
  function compile(routesArr, openapiPath, outPath, options) {
11
11
  log_1.default.writing(`Router : ${outPath}`);
12
- fs_1.default.writeFileSync(outPath, templates_1.default.routesTemplate({
12
+ fs_1.default.writeFileSync(outPath, (0, routes_template_1.default)({
13
13
  routes: routesArr,
14
14
  openapiPath: openapiPath,
15
15
  options: options,
@@ -1,2 +1,2 @@
1
1
  import * as types from "../types/types";
2
- export declare function compile(outDir: string, options?: types.compilerOptions): void;
2
+ export declare function compile(schemaDir: string, openapiDir: string, outDir: string, options?: types.compilerOptions): void;
@@ -5,26 +5,50 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.compile = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
- const templates_1 = __importDefault(require("../templates"));
8
+ const child_process_1 = __importDefault(require("child_process"));
9
+ const server_template_1 = __importDefault(require("./server.template"));
9
10
  const log_1 = __importDefault(require("../utils/log"));
10
- function compile(outDir, options) {
11
+ function compile(schemaDir, openapiDir, outDir, options) {
11
12
  const serverOutPath = `${outDir}/server.ts`;
13
+ const packageOutPath = `${outDir}/package.json`;
12
14
  const envOutPath = `${outDir}/.env`;
15
+ const tsconfigOutPath = `${outDir}/tsconfig.json`;
13
16
  const gitignoreOutPath = `${outDir}/.gitignore`;
14
17
  log_1.default.writing(`Server : ${serverOutPath}`);
15
- fs_1.default.writeFileSync(outDir + '/server.ts', templates_1.default.serverTemplate({
18
+ fs_1.default.writeFileSync(outDir + '/server.ts', (0, server_template_1.default)({
16
19
  options: options,
17
20
  }));
18
- log_1.default.writing(`Server : ${envOutPath}`);
19
- fs_1.default.writeFileSync(`${outDir}/.env`, `# veryExpress generated
20
- VERYEXPRESS_PORT=3000
21
- `);
22
- log_1.default.writing(`Server : ${gitignoreOutPath}`);
23
- fs_1.default.writeFileSync(`${outDir}/.env`, `# veryExpress generated
24
- node_modules
25
- dist
26
- *.gen.ts
27
- `);
21
+ log_1.default.writing(`Project : ${packageOutPath}`);
22
+ let packjson = '';
23
+ if (!fs_1.default.existsSync(packageOutPath)) {
24
+ packjson = fs_1.default.readFileSync(__dirname + '/../templates/root/package.json').toString();
25
+ }
26
+ else {
27
+ packjson = fs_1.default.readFileSync(packageOutPath).toString();
28
+ }
29
+ const packageJson = JSON.parse(packjson);
30
+ packageJson['scripts'] = {
31
+ "vex-gen": `vex -j ${schemaDir} -a ${openapiDir} -o ${outDir}`,
32
+ "build": "tsc -p .",
33
+ "dev": `nodemon --watch src --exec ts-node ${outDir}/server.ts`,
34
+ "start": "node ./dist/server.js",
35
+ };
36
+ fs_1.default.writeFileSync(packageOutPath, JSON.stringify(packageJson, null, 4));
37
+ if (!fs_1.default.existsSync(tsconfigOutPath)) {
38
+ try {
39
+ log_1.default.writing(`Project : ${tsconfigOutPath}`);
40
+ child_process_1.default.execSync('tsc --init', { cwd: outDir, stdio: 'inherit' });
41
+ }
42
+ catch (error) {
43
+ log_1.default.error('Error on command: tsc --init');
44
+ }
45
+ }
46
+ ;
47
+ if (!fs_1.default.existsSync(envOutPath)) {
48
+ log_1.default.writing(`Project : ${envOutPath}`);
49
+ fs_1.default.copyFileSync(__dirname + '/../templates/root/.env', envOutPath);
50
+ }
51
+ ;
28
52
  }
29
53
  exports.compile = compile;
30
54
  ;
package/dist/index.js CHANGED
@@ -27,6 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const fs_1 = __importDefault(require("fs"));
30
+ const child_process_1 = __importDefault(require("child_process"));
30
31
  const json2mongoose_1 = __importDefault(require("json2mongoose"));
31
32
  const openapiGen = __importStar(require("./generators/openapi.generator"));
32
33
  const log_1 = __importDefault(require("./utils/log"));
@@ -35,6 +36,13 @@ const controllerGen = __importStar(require("./generators/controllers.generator")
35
36
  const routeGen = __importStar(require("./generators/routes.generator"));
36
37
  const serverGen = __importStar(require("./generators/server.generator"));
37
38
  function generate(schemaDir, openapiDir, outDir, options) {
39
+ try {
40
+ child_process_1.default.execSync('git add . && git commit -m "before vex-gen"', { stdio: 'inherit' });
41
+ }
42
+ catch (err) {
43
+ log_1.default.error('git commit "before vex-gen" failed', err);
44
+ }
45
+ ;
38
46
  const dir = {
39
47
  routeDir: `${outDir}/routes`,
40
48
  middlewareDir: `${outDir}/middlewares`,
@@ -79,8 +87,13 @@ function generate(schemaDir, openapiDir, outDir, options) {
79
87
  log_1.default.error(`x-documentConfig.methods is invalid in ${schemaDir}/${schemaFileName}`);
80
88
  if (typeof jsonSchema.properties !== 'object')
81
89
  log_1.default.error(`properties is invalid in ${schemaDir}/${schemaFileName}`);
82
- json2mongoose_1.default.typesGen.compileFromFile(`${schemaDir}/${schemaFileName}`, `${dir.typeDir}/${documentConfig.interfaceName}.gen.ts`, options || common_1.default.defaultCompilerOptions);
83
- json2mongoose_1.default.modelsGen.compileFromFile(`${schemaDir}/${schemaFileName}`, `${common_1.default.relativePath(dir.modelDir, dir.typeDir)}/${documentConfig.interfaceName}.gen`, `${dir.modelDir}/${documentConfig.interfaceName}Model.gen.ts`, options || common_1.default.defaultCompilerOptions);
90
+ if (!fs_1.default.existsSync(`${schemaDir}/${schemaFileName}.nogen.ts`)) {
91
+ json2mongoose_1.default.typesGen.compileFromFile(`${schemaDir}/${schemaFileName}`, `${dir.typeDir}/${documentConfig.interfaceName}.gen.ts`, options || common_1.default.defaultCompilerOptions);
92
+ }
93
+ if (!fs_1.default.existsSync(`${schemaDir}/${schemaFileName}Model.nogen.ts`)) {
94
+ json2mongoose_1.default.modelsGen.compileFromFile(`${schemaDir}/${schemaFileName}`, `${common_1.default.relativePath(dir.modelDir, dir.typeDir)}/${documentConfig.interfaceName}.gen`, `${dir.modelDir}/${documentConfig.interfaceName}Model.gen.ts`, options || common_1.default.defaultCompilerOptions);
95
+ }
96
+ ;
84
97
  routeData.push({
85
98
  route: `/${documentConfig.documentName}`,
86
99
  controllerClassName: documentConfig.interfaceName,
@@ -92,12 +105,15 @@ function generate(schemaDir, openapiDir, outDir, options) {
92
105
  }
93
106
  ;
94
107
  });
95
- openapiGen.compile(schemaDir, openapiDir + '/openapi.gen.yaml');
108
+ if (!fs_1.default.existsSync(openapiDir + '/openapi.nogen.yaml')) {
109
+ openapiGen.compile(schemaDir, openapiDir + '/openapi.gen.yaml');
110
+ }
111
+ ;
96
112
  common_1.default.copyDir(`${openapiDir}`, outDir + '/openapi');
97
113
  common_1.default.copyDir(`${__dirname}/templates/utils`, dir.utilsDir);
98
114
  controllerGen.compile(openapiDir + '/openapi.gen.yaml', `${common_1.default.relativePath(dir.controllerDir, dir.modelDir)}`, dir.controllerDir, options || common_1.default.defaultCompilerOptions);
99
115
  routeGen.compile(routeData, openapiDir + '/openapi.gen.yaml', `${dir.routeDir}/routes.gen.ts`, options || common_1.default.defaultCompilerOptions);
100
- serverGen.compile(outDir, options || { headerComment: common_1.default.getSimpleHeaderComment() });
116
+ serverGen.compile(schemaDir, openapiDir, outDir, options || { headerComment: common_1.default.getSimpleHeaderComment() });
101
117
  }
102
118
  exports.default = generate;
103
119
  ;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "very-express",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "based on json schema and openapi, generate Express RestApi server with mongoDb ",
5
5
  "author": "justin26l",
6
6
  "license": "MIT",
@@ -9,8 +9,8 @@
9
9
  "vex": "./dist/cli.js"
10
10
  },
11
11
  "scripts": {
12
- "build": "tsc -p .",
13
- "dev": "ts-node ./src/cli.ts",
12
+ "build": "tsc -p . && node ./src/copyDir.js",
13
+ "dev": "ts-node ./src/cli.ts -j ./jsonSchema -a ./openapi -o ./output",
14
14
  "prod": "node ./dist/cli.js",
15
15
  "test": "echo \"Error: no test specified\" && exit 1"
16
16
  },
@@ -27,6 +27,8 @@
27
27
  "url": "git+https://github.com/Justin26l/VeryExpress.git"
28
28
  },
29
29
  "dependencies": {
30
+ "@types/express-session": "^1.17.10",
31
+ "express-session": "^1.17.3",
30
32
  "js-yaml": "4.1.0",
31
33
  "json-schema-to-openapi-schema": "^0.4.0",
32
34
  "json2mongoose": "^0.1.5",
@@ -36,7 +38,9 @@
36
38
  "@types/express": "^4.17.21",
37
39
  "@types/js-yaml": "^4.0.9",
38
40
  "@types/minimist": "^1.2.5",
39
- "@types/node": "^20.10.4",
41
+ "@types/node": "^20.10.5",
42
+ "@types/passport": "^1.0.16",
43
+ "@types/passport-google-oauth20": "^2.0.14",
40
44
  "@types/swagger-ui-express": "^4.1.6",
41
45
  "dotenv": "^16.3.1",
42
46
  "express": "^4.18.2",
@@ -45,8 +49,11 @@
45
49
  "js-yaml": "^4.1.0",
46
50
  "json-schema-to-openapi-schema": "^0.4.0",
47
51
  "json2mongoose": "^0.1.5",
52
+ "ncp": "^2.0.0",
53
+ "passport": "^0.7.0",
54
+ "passport-google-oauth20": "^2.0.0",
48
55
  "swagger-ui-express": "^5.0.0",
49
- "ts-node": "^10.9.1",
50
- "typescript": "^5.3.2"
56
+ "ts-node": "^10.9.2",
57
+ "typescript": "^5.3.3"
51
58
  }
52
59
  }
package/tsconfig.json CHANGED
@@ -107,10 +107,13 @@
107
107
  "skipLibCheck": true /* Skip type checking all .d.ts files. */
108
108
  },
109
109
  "include": [
110
- "src/**/*.ts"
111
- , "src/generators/routes.generator.ts" ],
110
+ "src/**/*.ts",
111
+ "src/generators/routes.generator.ts", "src/test.js", "src/copyDir.js" ],
112
112
  "exclude": [
113
113
  "node_modules",
114
- "output"
114
+ "output",
115
+ "src/copyDir.js",
116
+ "src/templates/**/*.gen.ts",
117
+ ".env",
115
118
  ]
116
119
  }
@@ -1 +0,0 @@
1
- export declare function loadYaml(yamlFilePath: string): unknown;
@@ -1,19 +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.loadYaml = void 0;
7
- const js_yaml_1 = __importDefault(require("js-yaml"));
8
- const fs_1 = __importDefault(require("fs"));
9
- const log_1 = __importDefault(require("../../utils/log"));
10
- function loadYaml(yamlFilePath) {
11
- try {
12
- return js_yaml_1.default.load(fs_1.default.readFileSync(yamlFilePath, 'utf8'));
13
- }
14
- catch (e) {
15
- log_1.default.error('Error Load OpenApi File :\n', e.message || e);
16
- }
17
- }
18
- exports.loadYaml = loadYaml;
19
- ;
package/dist/utils.d.ts DELETED
@@ -1,22 +0,0 @@
1
- import { compilerOptions } from "./types/types";
2
- export declare const relativePath: (fromPath: string, toPath: string) => string;
3
- export declare function loadYaml(yamlFilePath: string): void;
4
- export declare function getGenaratorHeaderComment(comment?: string): string;
5
- export declare function getSimpleHeaderComment(): string;
6
- export declare function cleanXcustomValue(schemaObj: {
7
- [key: string]: any;
8
- }, additionalKeyArr?: string[]): {
9
- [key: string]: any;
10
- };
11
- export declare function copyDir(source: string, destination: string): void;
12
- export declare const defaultCompilerOptions: compilerOptions;
13
- declare const _default: {
14
- getGenaratorHeaderComment: typeof getGenaratorHeaderComment;
15
- getSimpleHeaderComment: typeof getSimpleHeaderComment;
16
- defaultCompilerOptions: compilerOptions;
17
- relativePath: (fromPath: string, toPath: string) => string;
18
- cleanXcustomValue: typeof cleanXcustomValue;
19
- loadYaml: typeof loadYaml;
20
- copyDir: typeof copyDir;
21
- };
22
- export default _default;
package/dist/utils.js DELETED
@@ -1,104 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.defaultCompilerOptions = exports.copyDir = exports.cleanXcustomValue = exports.getSimpleHeaderComment = exports.getGenaratorHeaderComment = exports.loadYaml = exports.relativePath = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- const js_yaml_1 = __importDefault(require("js-yaml"));
10
- function getPackageInfo() {
11
- var _a;
12
- const packageJson = fs_1.default.readFileSync("./package.json", "utf8");
13
- const packageJsonObject = JSON.parse(packageJson);
14
- return {
15
- version: ((_a = packageJsonObject.dependencies['very-express']) === null || _a === void 0 ? void 0 : _a.replace('^', '')) || "[unknown version]",
16
- author: packageJsonObject.author || "justin26l",
17
- };
18
- }
19
- const relativePath = (fromPath, toPath) => {
20
- return path_1.default.relative(fromPath, toPath).replace(/\\/g, '/');
21
- };
22
- exports.relativePath = relativePath;
23
- function loadYaml(yamlFilePath) {
24
- try {
25
- const doc = js_yaml_1.default.load(fs_1.default.readFileSync(yamlFilePath, 'utf8'));
26
- }
27
- catch (e) {
28
- console.error(e);
29
- }
30
- }
31
- exports.loadYaml = loadYaml;
32
- ;
33
- function getGenaratorHeaderComment(comment) {
34
- const packageInfo = getPackageInfo();
35
- return `/* eslint-disable */
36
- /**
37
- * Generated by veryExpress@${packageInfo.version}
38
- * DO NOT MODIFY MANUALLY. Instead, modify the JsonSchema file,
39
- * then run veryExpress to regenerate this file.
40
- *
41
- * author: ${packageInfo.author}
42
- * version: ${packageInfo.version}${comment ? `\n * comment: ${comment}` : ''}
43
- */
44
- `;
45
- }
46
- exports.getGenaratorHeaderComment = getGenaratorHeaderComment;
47
- ;
48
- function getSimpleHeaderComment() {
49
- const packageInfo = getPackageInfo();
50
- return `// Generated by veryExpress@${packageInfo.version}`;
51
- }
52
- exports.getSimpleHeaderComment = getSimpleHeaderComment;
53
- ;
54
- function cleanXcustomValue(schemaObj, additionalKeyArr) {
55
- let obj = Object.assign(schemaObj);
56
- for (const key in obj) {
57
- if (key.startsWith("x-")) {
58
- delete obj[key];
59
- }
60
- else if (additionalKeyArr && additionalKeyArr.includes(key)) {
61
- delete obj[key];
62
- }
63
- else if (typeof obj[key] === "object") {
64
- cleanXcustomValue(obj[key], additionalKeyArr);
65
- }
66
- }
67
- return obj;
68
- }
69
- exports.cleanXcustomValue = cleanXcustomValue;
70
- ;
71
- function copyDir(source, destination) {
72
- if (!fs_1.default.existsSync(destination)) {
73
- fs_1.default.mkdirSync(destination);
74
- }
75
- const files = fs_1.default.readdirSync(source);
76
- for (let i = 0; i < files.length; i++) {
77
- const current = fs_1.default.lstatSync(source + '/' + files[i]);
78
- if (current.isDirectory()) {
79
- copyDir(source + '/' + files[i], destination + '/' + files[i]);
80
- }
81
- else if (current.isSymbolicLink()) {
82
- const symlink = fs_1.default.readlinkSync(source + '/' + files[i]);
83
- fs_1.default.symlinkSync(symlink, destination + '/' + files[i]);
84
- }
85
- else {
86
- const outPath = destination + '/' + files[i];
87
- console.log('\x1b[32m%s\x1b[0m', '[Writing]', `Utils : ${outPath}`);
88
- fs_1.default.copyFileSync(source + '/' + files[i], outPath);
89
- }
90
- }
91
- }
92
- exports.copyDir = copyDir;
93
- exports.defaultCompilerOptions = {
94
- headerComment: getGenaratorHeaderComment(),
95
- };
96
- exports.default = {
97
- getGenaratorHeaderComment,
98
- getSimpleHeaderComment,
99
- defaultCompilerOptions: exports.defaultCompilerOptions,
100
- relativePath: exports.relativePath,
101
- cleanXcustomValue,
102
- loadYaml,
103
- copyDir,
104
- };
File without changes
File without changes