UNPKG

youzanyun-devtool-worker

Version:

81 lines (80 loc) 3.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const path_1 = tslib_1.__importDefault(require("path")); const lodash_1 = require("lodash"); const fs_extra_1 = tslib_1.__importDefault(require("fs-extra")); const spring4js_nodejs_1 = require("spring4js-nodejs"); const nunjucks_1 = tslib_1.__importDefault(require("nunjucks")); let NodeJsProjectService = class NodeJsProjectService { constructor() { } async start() { } async generateBepFile(projectId, extId) { let projectInfo = await this.projectService.getProjectById(projectId); let projectDir = projectInfo.proPath; let bepDetail = await this.documentCenterApiService.getBepDetail(extId); let { interfaceDto, inParam, outParam, desc } = bepDetail; let serviceFullName = interfaceDto.fullyQualifiedClassName; let serviceShortName = serviceFullName.replace(/.*\./, ""); let filePath = path_1.default.resolve(projectDir, `app/bep/${serviceShortName}.js`); let inExample = this.bepService.generateBepDataExample(inParam); outParam.name = 'return'; let outExample = this.bepService.generateBepDataExample(outParam); let tpl = await fs_extra_1.default.readFile(path_1.default.resolve(this.configService.getWorkerDir(), 'code-tpl/bep.njk.js'), 'utf8'); let code = await this.render(tpl, { serviceFullName, serviceShortName, inputName: inParam.name, desc, methodName: interfaceDto.methodName, inExampleLines: JSON.stringify(inExample[inParam.name], null, 2).split('\n'), outExampleLines: JSON.stringify(outExample.return, null, 2).split('\n') }); await fs_extra_1.default.writeFile(filePath, code); } async generateMepFile(projectId, bizType) { let projectInfo = await this.projectService.getProjectById(projectId); let projectDir = projectInfo.proPath; let paramType = await this.documentCenterApiService.getMepParamType(bizType); let { generateCondition, name, remarks } = paramType; let paramExample = this.mepService.generateMepCallExample(paramType); let mepName = (0, lodash_1.upperFirst)((0, lodash_1.camelCase)(bizType)); let filePath = path_1.default.resolve(projectDir, `app/mep/${mepName}.js`); let tpl = await fs_extra_1.default.readFile(path_1.default.resolve(this.configService.getWorkerDir(), 'code-tpl/mep.njk.js'), 'utf8'); let code = await this.render(tpl, { topic: bizType, generateCondition, name, remarks, paramExampleLines: JSON.stringify(paramExample[paramType.name], null, 2).split('\n'), mepName, }); await fs_extra_1.default.writeFile(filePath, code); } async render(tpl, context) { let env = new nunjucks_1.default.Environment(null, { autoescape: false }); let fun = nunjucks_1.default.compile(tpl, env); let res = fun.render(context); return res; } }; tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], NodeJsProjectService.prototype, "projectService", void 0); tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], NodeJsProjectService.prototype, "documentCenterApiService", void 0); tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], NodeJsProjectService.prototype, "configService", void 0); tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], NodeJsProjectService.prototype, "bepService", void 0); tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], NodeJsProjectService.prototype, "mepService", void 0); NodeJsProjectService = tslib_1.__decorate([ (0, spring4js_nodejs_1.Service)() ], NodeJsProjectService); exports.default = NodeJsProjectService;