very-express 0.0.1 → 0.0.3

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/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,21 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const index_1 = __importDefault(require("./index"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const schemaDir = process.argv[2] || './jsonSchema';
10
+ const openapi = process.argv[3] || './openapi';
11
+ const outputDir = process.argv[4] || './output';
12
+ if (!fs_1.default.existsSync(schemaDir)) {
13
+ console.log('\x1b[31m%s\x1b[0m', 'Schema Dir Not Found:', schemaDir);
14
+ process.exit(1);
15
+ }
16
+ ;
17
+ if (!fs_1.default.existsSync(outputDir)) {
18
+ fs_1.default.mkdirSync(outputDir);
19
+ }
20
+ ;
21
+ (0, index_1.default)(schemaDir, openapi, outputDir);
@@ -0,0 +1,2 @@
1
+ import * as types from "../types/types";
2
+ export declare function compile(openapiPath: string, controllerToModelDir: string, outDir: string, options?: types.compilerOptions): void;
@@ -0,0 +1,151 @@
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 js_yaml_1 = __importDefault(require("js-yaml"));
32
+ const templates_1 = __importDefault(require("../templates"));
33
+ const types = __importStar(require("../types/types"));
34
+ function compile(openapiPath, controllerToModelDir, outDir, options) {
35
+ const file = fs_1.default.readFileSync(openapiPath, 'utf8');
36
+ const openApi = js_yaml_1.default.load(file);
37
+ const endpointsValidator = {};
38
+ Object.keys(openApi.paths).forEach((endpoint) => {
39
+ const interfaceName = openApi.paths[endpoint].summary;
40
+ endpointsValidator[endpoint] = {};
41
+ console.log('\x1b[36m%s\x1b[0m', '[Processing]', `Controller : ${endpoint} -> ${interfaceName}Controller`);
42
+ Object.keys(openApi.paths[endpoint]).forEach((method) => {
43
+ if (!Object.values(types.method).includes(method))
44
+ return;
45
+ let methodEnum = method;
46
+ let validators = [];
47
+ validators = buildParamValidator(endpoint, methodEnum, openApi);
48
+ validators = validators.concat(buildRequestBodyValidator(endpoint, methodEnum, openApi));
49
+ endpointsValidator[endpoint][method] = validators;
50
+ });
51
+ });
52
+ let writtedEndpoint = [];
53
+ Object.keys(openApi.paths).forEach((endpoint) => {
54
+ const interfaceName = openApi.paths[endpoint].summary;
55
+ const endpointFormatted = endpoint.replace('/{id}', '').toLowerCase();
56
+ if (writtedEndpoint.includes(endpointFormatted)) {
57
+ return;
58
+ }
59
+ else {
60
+ writtedEndpoint.push(endpointFormatted);
61
+ }
62
+ ;
63
+ const outPath = `${outDir}/${interfaceName}Controller.gen.ts`;
64
+ const controllerToModelPath = `${controllerToModelDir}/${interfaceName}Model.gen`;
65
+ console.log('\x1b[32m%s\x1b[0m', '[Writing]', `Controller : ${outPath}`);
66
+ fs_1.default.writeFileSync(outPath, templates_1.default.controllerTemplate({
67
+ endpoint: endpoint,
68
+ modelPath: controllerToModelPath,
69
+ interfaceName: interfaceName,
70
+ validator: endpointsValidator,
71
+ options: options,
72
+ }));
73
+ });
74
+ }
75
+ exports.compile = compile;
76
+ ;
77
+ function buildParamValidator(endpoint, method, openapi) {
78
+ let validators = [];
79
+ openapi.paths[endpoint][method].parameters.forEach((parameter) => {
80
+ validators = validators.concat(processSchema(parameter.name, parameter, undefined));
81
+ });
82
+ return validators;
83
+ }
84
+ ;
85
+ function buildRequestBodyValidator(endpoint, method, openapi) {
86
+ var _a, _b, _c;
87
+ let validators = [];
88
+ const referencePath = (_c = (_b = (_a = openapi.paths[endpoint][method]) === null || _a === void 0 ? void 0 : _a.requestBody) === null || _b === void 0 ? void 0 : _b.content) === null || _c === void 0 ? void 0 : _c['application/json'].schema.$ref;
89
+ const reference = referencePath ? referencePath.split('/').pop() : undefined;
90
+ const components = reference ? openapi.components.schemas[reference] : undefined;
91
+ if (components !== undefined) {
92
+ for (let key in components.properties) {
93
+ validators = validators.concat(processSchema(key, undefined, components.properties[key]));
94
+ }
95
+ ;
96
+ }
97
+ return validators;
98
+ }
99
+ function processSchema(fieldName, paramFields, bodyFields) {
100
+ var _a, _b, _c, _d;
101
+ let validators = [];
102
+ const useBody = bodyFields !== undefined && paramFields == undefined;
103
+ const checkOn = useBody ? 'body' : 'check';
104
+ const type = useBody ? bodyFields === null || bodyFields === void 0 ? void 0 : bodyFields.type : paramFields === null || paramFields === void 0 ? void 0 : paramFields.schema.type;
105
+ const required = (paramFields === null || paramFields === void 0 ? void 0 : paramFields.required) ? '.exists()' : '.optional()';
106
+ const enumValidator = useBody && (bodyFields === null || bodyFields === void 0 ? void 0 : bodyFields.enum) ? `.isIn(${JSON.stringify(bodyFields.enum)})` :
107
+ !useBody && (paramFields === null || paramFields === void 0 ? void 0 : paramFields.schema.enum) ? `.isIn(${JSON.stringify(paramFields.schema.enum)})` :
108
+ '';
109
+ const typeValidatorOption = JSON.stringify(useBody && bodyFields ? {
110
+ min: bodyFields.minLength || bodyFields.minimum,
111
+ max: bodyFields.maxLength || bodyFields.maximum,
112
+ } :
113
+ !useBody && paramFields ? {
114
+ min: ((_a = paramFields.schema) === null || _a === void 0 ? void 0 : _a.minLength) || ((_b = paramFields.schema) === null || _b === void 0 ? void 0 : _b.minimum),
115
+ max: ((_c = paramFields.schema) === null || _c === void 0 ? void 0 : _c.maxLength) || ((_d = paramFields.schema) === null || _d === void 0 ? void 0 : _d.maximum),
116
+ } :
117
+ undefined);
118
+ const typeValidator = typeValidatorOption !== '{}' ? typeValidatorOption : undefined;
119
+ switch (type) {
120
+ case "string":
121
+ validators.push(`${checkOn}("${fieldName}")${required}.isString()${typeValidator !== undefined ? `.isLength(${typeValidator})` : ''}${enumValidator}`);
122
+ break;
123
+ case "integer":
124
+ validators.push(`${checkOn}("${fieldName}")${required}.isInt(${typeValidator})`);
125
+ break;
126
+ case "float":
127
+ validators.push(`${checkOn}("${fieldName}")${required}.isFloat(${typeValidator})`);
128
+ break;
129
+ case "number":
130
+ validators.push(`${checkOn}("${fieldName}")${required}.isNumeric()`);
131
+ break;
132
+ case "boolean":
133
+ validators.push(`${checkOn}("${fieldName}")${required}.isBoolean()`);
134
+ break;
135
+ case "array":
136
+ validators.push(`${checkOn}("${fieldName}")${required}.isArray(${typeValidator})`);
137
+ break;
138
+ case "object":
139
+ if (useBody) {
140
+ for (let key in bodyFields === null || bodyFields === void 0 ? void 0 : bodyFields.properties) {
141
+ validators = validators.concat(processSchema(fieldName + '.' + key, undefined, bodyFields.properties[key]));
142
+ }
143
+ ;
144
+ }
145
+ ;
146
+ break;
147
+ }
148
+ ;
149
+ return validators;
150
+ }
151
+ ;
@@ -0,0 +1,2 @@
1
+ export declare function compile(schemaDir: string, outPath: string): void;
2
+ export default compile;
@@ -0,0 +1,214 @@
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 json_schema_to_openapi_schema_1 = __importDefault(require("json-schema-to-openapi-schema"));
31
+ const js_yaml_1 = __importDefault(require("js-yaml"));
32
+ const fs_1 = __importDefault(require("fs"));
33
+ const types = __importStar(require("../types/types"));
34
+ const utils_1 = __importDefault(require("../utils"));
35
+ function compile(schemaDir, outPath) {
36
+ let openapiJson = {
37
+ openapi: "3.0.0",
38
+ info: {
39
+ title: "veryExpress generated api server",
40
+ description: "OpenApi Spec generated by veryExpress",
41
+ version: "1.0.0"
42
+ },
43
+ paths: {},
44
+ components: {
45
+ schemas: {},
46
+ },
47
+ };
48
+ const files = fs_1.default.readdirSync(schemaDir);
49
+ files.forEach((file) => {
50
+ if (!file.endsWith('.json'))
51
+ return;
52
+ console.log('\x1b[36m%s\x1b[0m', '[Processing]', `OpenApi : ${schemaDir + '/' + file}`);
53
+ const jsonSchemaBuffer = fs_1.default.readFileSync(`${schemaDir}/${file}`);
54
+ const jsonSchema = JSON.parse(jsonSchemaBuffer.toString());
55
+ openapiJson = jsonToOpenapiPath(openapiJson, jsonSchema);
56
+ openapiJson = jsonToOpenapiComponentSchema(openapiJson, jsonSchema);
57
+ });
58
+ const validOpenApi = (0, json_schema_to_openapi_schema_1.default)(openapiJson, { version: 3.0 });
59
+ const openapiYaml = js_yaml_1.default.dump(validOpenApi);
60
+ console.log('\x1b[32m%s\x1b[0m', '[Writing]', `OpenApi : ${outPath}`);
61
+ fs_1.default.writeFileSync(outPath, openapiYaml);
62
+ }
63
+ exports.compile = compile;
64
+ ;
65
+ function jsonToOpenapiPath(openapiJson, jsonSchema) {
66
+ const documentConfig = jsonSchema["x-documentConfig"];
67
+ const lowerDocName = documentConfig.documentName.toLowerCase();
68
+ const interfaceName = documentConfig.interfaceName;
69
+ const properties = jsonSchema.properties;
70
+ const methods = documentConfig.method;
71
+ let routes = {
72
+ ['/' + lowerDocName]: {
73
+ summary: interfaceName,
74
+ },
75
+ ['/' + lowerDocName + '/{id}']: {
76
+ summary: interfaceName,
77
+ },
78
+ };
79
+ methods.forEach((method) => {
80
+ const useId = [types.method.put, types.method.patch, types.method.delete].includes(method);
81
+ const useBody = [types.method.post, types.method.put, types.method.patch].includes(method);
82
+ const route = '/' + lowerDocName + (useId ? '/{id}' : '');
83
+ routes[route][method] = {
84
+ summary: interfaceName,
85
+ operationId: method + interfaceName,
86
+ tags: [lowerDocName],
87
+ parameters: [],
88
+ requestBody: undefined,
89
+ responses: {
90
+ 200: {
91
+ description: 'OK',
92
+ content: {
93
+ 'application/json': { schema: { $ref: `#/components/schemas/${method}${interfaceName}Response` } },
94
+ },
95
+ },
96
+ 400: { description: 'Bad Request', },
97
+ 401: { description: 'Unauthorized', },
98
+ 403: { description: 'Forbidden', },
99
+ 404: { description: 'Not Found', },
100
+ 405: { description: 'Method Not Allowed', },
101
+ 413: { description: 'Payload Too Large', },
102
+ 429: { description: 'Too Many Requests', },
103
+ 500: { description: 'Internal Server Error', },
104
+ 502: { description: 'Bad Gateway', },
105
+ 503: { description: 'Service Unavailable', },
106
+ },
107
+ };
108
+ if ((useId || method == types.method.get) && properties['_id']) {
109
+ const idParameter = {
110
+ name: 'id',
111
+ in: 'path',
112
+ description: properties['_id'].description,
113
+ required: true,
114
+ schema: {
115
+ type: properties['_id'].type,
116
+ format: properties['_id'].format,
117
+ },
118
+ };
119
+ routes[route][method].parameters = [idParameter];
120
+ if (method == types.method.get) {
121
+ routes[route + '/{id}'][method] = routes[route][method];
122
+ routes[route + '/{id}'][method].responses[200].content["application/json"].schema.$ref = `#/components/schemas/${method}${interfaceName}Response`;
123
+ routes[route + '/{id}'][method].parameters = [idParameter];
124
+ }
125
+ ;
126
+ }
127
+ ;
128
+ if (useBody) {
129
+ routes[route][method].requestBody = {
130
+ description: `${method} ${documentConfig.documentName}`,
131
+ required: false,
132
+ content: {
133
+ 'application/json': { schema: { $ref: `#/components/schemas/${method}${interfaceName}Body` } },
134
+ },
135
+ };
136
+ }
137
+ ;
138
+ if (method == types.method.post) {
139
+ routes[route][method].responses[201] = routes[route][method].responses[200];
140
+ routes[route][method].responses[201].description = 'Crerated';
141
+ delete routes[route][method].responses[200];
142
+ }
143
+ else if (method == types.method.delete) {
144
+ delete routes[route][method].responses[200].content;
145
+ }
146
+ ;
147
+ });
148
+ openapiJson.paths = Object.assign(openapiJson.paths, routes);
149
+ return openapiJson;
150
+ }
151
+ ;
152
+ function jsonToOpenapiComponentSchema(openapiJson, jsonSchema) {
153
+ let parameters = [];
154
+ let componentSchemaPath = {};
155
+ const documentConfig = jsonSchema["x-documentConfig"];
156
+ const lowerDocName = documentConfig.documentName.toLowerCase();
157
+ const interfaceName = documentConfig.interfaceName;
158
+ const methods = documentConfig.method;
159
+ const componentSchemaResponse = {
160
+ type: 'object',
161
+ properties: (0, json_schema_to_openapi_schema_1.default)(utils_1.default.cleanXcustomValue(jsonSchema.properties, ['index', 'unique', 'required']), { version: 3.0 }),
162
+ };
163
+ const componentSchemaBody = {
164
+ type: 'object',
165
+ properties: (0, json_schema_to_openapi_schema_1.default)(utils_1.default.cleanXcustomValue(jsonSchema.properties, ['_id', 'index', 'unique', 'required']), { version: 3.0 }),
166
+ };
167
+ methods.forEach((method) => {
168
+ switch (method) {
169
+ case types.method.delete:
170
+ break;
171
+ case types.method.get:
172
+ let parameters = [];
173
+ Object.keys(jsonSchema.properties).forEach((key) => {
174
+ const props = jsonSchema.properties[key];
175
+ if (props.type == 'object')
176
+ return;
177
+ let parameter = {
178
+ name: key,
179
+ in: "query",
180
+ required: props.required,
181
+ schema: {
182
+ type: props.type,
183
+ format: props.format,
184
+ minLength: props.minLength,
185
+ maxLength: props.maxLength,
186
+ minimum: props.minimum,
187
+ maximum: props.maximum,
188
+ enum: props.enum,
189
+ }
190
+ };
191
+ parameters.push(parameter);
192
+ });
193
+ openapiJson.paths['/' + lowerDocName][method].parameters = parameters;
194
+ componentSchemaPath[method + interfaceName + 'Response'] = componentSchemaResponse;
195
+ componentSchemaPath[method + interfaceName + 'ResponseList'] = {
196
+ type: 'array',
197
+ items: componentSchemaResponse,
198
+ };
199
+ break;
200
+ case types.method.post:
201
+ case types.method.put:
202
+ case types.method.patch:
203
+ componentSchemaPath[method + interfaceName + 'Body'] = componentSchemaBody;
204
+ componentSchemaPath[method + interfaceName + 'Response'] = componentSchemaResponse;
205
+ break;
206
+ default:
207
+ break;
208
+ }
209
+ ;
210
+ });
211
+ openapiJson.components.schemas = Object.assign(openapiJson.components.schemas, componentSchemaPath);
212
+ return openapiJson;
213
+ }
214
+ exports.default = compile;
@@ -0,0 +1,6 @@
1
+ import * as types from "../types/types";
2
+ export declare function compile(routesArr: {
3
+ route: string;
4
+ controllerClassName: string;
5
+ controllerPath: string;
6
+ }[], openapiPath: string, outPath: string, options?: types.compilerOptions): void;
@@ -0,0 +1,18 @@
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 templates_1 = __importDefault(require("../templates"));
9
+ function compile(routesArr, openapiPath, outPath, options) {
10
+ console.log('\x1b[32m%s\x1b[0m', '[Writing]', `Router : ${outPath}`);
11
+ fs_1.default.writeFileSync(outPath, templates_1.default.routesTemplate({
12
+ routes: routesArr,
13
+ openapiPath: openapiPath,
14
+ options: options,
15
+ }));
16
+ }
17
+ exports.compile = compile;
18
+ ;
@@ -0,0 +1,2 @@
1
+ import * as types from "../types/types";
2
+ export declare function compile(outDir: string, options?: types.compilerOptions): void;
@@ -0,0 +1,29 @@
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 templates_1 = __importDefault(require("../templates"));
9
+ function compile(outDir, options) {
10
+ const serverOutPath = `${outDir}/server.ts`;
11
+ const envOutPath = `${outDir}/.env`;
12
+ const gitignoreOutPath = `${outDir}/.gitignore`;
13
+ console.log('\x1b[32m%s\x1b[0m', '[Writing]', `Server : ${serverOutPath}`);
14
+ fs_1.default.writeFileSync(outDir + '/server.ts', templates_1.default.serverTemplate({
15
+ options: options,
16
+ }));
17
+ console.log('\x1b[32m%s\x1b[0m', '[Writing]', `Server : ${envOutPath}`);
18
+ fs_1.default.writeFileSync(`${outDir}/.env`, `# veryExpress generated
19
+ VERYEXPRESS_PORT=3000
20
+ `);
21
+ console.log('\x1b[32m%s\x1b[0m', '[Writing]', `Server : ${gitignoreOutPath}`);
22
+ fs_1.default.writeFileSync(`${outDir}/.env`, `# veryExpress generated
23
+ node_modules
24
+ dist
25
+ *.gen.ts
26
+ `);
27
+ }
28
+ exports.compile = compile;
29
+ ;
@@ -0,0 +1,2 @@
1
+ import { compilerOptions } from './types/types';
2
+ export default function generate(schemaDir: string, openapiDir: string, outDir: string, options?: compilerOptions): void;
package/dist/index.js ADDED
@@ -0,0 +1,87 @@
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
+ const fs_1 = __importDefault(require("fs"));
30
+ const json2mongoose_1 = __importDefault(require("json2mongoose"));
31
+ const openapiGen = __importStar(require("./generators/openapi.generator"));
32
+ const utils_1 = __importDefault(require("./utils"));
33
+ const controllerGen = __importStar(require("./generators/controllers.generator"));
34
+ const routeGen = __importStar(require("./generators/routes.generator"));
35
+ const serverGen = __importStar(require("./generators/server.generator"));
36
+ function generate(schemaDir, openapiDir, outDir, options) {
37
+ const dir = {
38
+ routeDir: `${outDir}/routes`,
39
+ middlewareDir: `${outDir}/middlewares`,
40
+ controllerDir: `${outDir}/controllers`,
41
+ modelDir: `${outDir}/models`,
42
+ typeDir: `${outDir}/types`,
43
+ serviceDir: `${outDir}/services`,
44
+ utilsDir: `${outDir}/utils`,
45
+ };
46
+ if (!fs_1.default.existsSync(outDir)) {
47
+ fs_1.default.mkdirSync(outDir);
48
+ }
49
+ ;
50
+ if (!fs_1.default.existsSync(openapiDir)) {
51
+ fs_1.default.mkdirSync(openapiDir);
52
+ }
53
+ Object.values(dir).forEach((path) => {
54
+ if (!fs_1.default.existsSync(path)) {
55
+ fs_1.default.mkdirSync(path);
56
+ }
57
+ });
58
+ openapiGen.compile(schemaDir, openapiDir + '/openapi.gen.yaml');
59
+ utils_1.default.copyDir(`${openapiDir}`, outDir + '/openapi');
60
+ utils_1.default.copyDir(`${__dirname}/templates/utils`, dir.utilsDir);
61
+ let routeData = [];
62
+ const files = fs_1.default.readdirSync(schemaDir);
63
+ files.forEach((schemaFileName) => {
64
+ try {
65
+ if (!schemaFileName.endsWith('.json'))
66
+ return;
67
+ const fileName = schemaFileName.replace('.json', '');
68
+ json2mongoose_1.default.typesGen.compileFromFile(`${schemaDir}/${schemaFileName}`, `${dir.typeDir}/${fileName}.gen.ts`, options || utils_1.default.defaultCompilerOptions);
69
+ json2mongoose_1.default.modelsGen.compileFromFile(`${schemaDir}/${schemaFileName}`, `${utils_1.default.relativePath(dir.modelDir, dir.typeDir)}/${fileName}.gen`, `${dir.modelDir}/${fileName}Model.gen.ts`, options || utils_1.default.defaultCompilerOptions);
70
+ const schema = JSON.parse(fs_1.default.readFileSync(`${schemaDir}/${schemaFileName}`, 'utf-8'));
71
+ routeData.push({
72
+ route: `/${schema['x-documentConfig'].documentName}`,
73
+ controllerClassName: schema['x-documentConfig'].interfaceName,
74
+ controllerPath: utils_1.default.relativePath(dir.routeDir, dir.controllerDir) + '/' + schema['x-documentConfig'].interfaceName + 'Controller.gen',
75
+ });
76
+ }
77
+ catch (err) {
78
+ console.error('\x1b[31m%s\x1b[0m', `Processing File : ${schemaDir}/${schemaFileName}\n`, err);
79
+ }
80
+ ;
81
+ });
82
+ controllerGen.compile(openapiDir + '/openapi.gen.yaml', `${utils_1.default.relativePath(dir.controllerDir, dir.modelDir)}`, dir.controllerDir, options || utils_1.default.defaultCompilerOptions);
83
+ routeGen.compile(routeData, openapiDir + '/openapi.gen.yaml', `${dir.routeDir}/routes.gen.ts`, options || utils_1.default.defaultCompilerOptions);
84
+ serverGen.compile(outDir, options || { headerComment: utils_1.default.getSimpleHeaderComment() });
85
+ }
86
+ exports.default = generate;
87
+ ;
@@ -0,0 +1,14 @@
1
+ import * as types from '../types/types';
2
+ export default function controllerTemplate(templateOptions: {
3
+ headerComment?: string;
4
+ template?: string;
5
+ endpoint: string;
6
+ modelPath: string;
7
+ interfaceName: string;
8
+ validator: {
9
+ [key: string]: {
10
+ [key: string]: string[];
11
+ };
12
+ };
13
+ options?: types.compilerOptions;
14
+ }): string;