From 8452180cfb02ad806738b8241f79b21f1d47c3f5 Mon Sep 17 00:00:00 2001 From: aixianling Date: Wed, 22 Jun 2022 17:15:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BD=8E=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tools/generate.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/tools/generate.js b/src/tools/generate.js index f0b92df..d351158 100644 --- a/src/tools/generate.js +++ b/src/tools/generate.js @@ -4,7 +4,7 @@ const {checkJson} = require("./index"); /** * 生成入口页 */ -const genHome = app => { +const genHome = (app, dest) => { return readFile('./tpl/AppEntry.vue').then(data => { let file = data.toString(), content = file.replace(/@appName/g, app.appName) @@ -15,13 +15,13 @@ const genHome = app => { props.length > 0 && (dicts = props.map(e => `'${e}'`).toString()) } content = content.replace(/@dicts/g, dicts) - return fse.outputFileSync(`./zips/${app.id}/${app.appName}.vue`, content) + return fse.outputFileSync(`${dest}/${app.appName}.vue`, content) }) } /** * 生成列表页 */ -const genList = app => { +const genList = (app, dest) => { return readFile('./tpl/list.vue').then(data => { let file = data.toString(), content = file.replace(/@rightCode/g, app.rightCode) @@ -65,13 +65,13 @@ const genList = app => { .replace(/@searchProps/g, searchProps) .replace(/@btns/g, btns) .replace(/@tableBtns/g, tableBtns) - return fse.outputFileSync(`./zips/${app.id}/list.vue`, content) + return fse.outputFileSync(`${dest}/list.vue`, content) }) } /** * 生成新增/编辑页 */ -const genAdd = app => { +const genAdd = (app, dest) => { return readFile('./tpl/add.vue').then(data => { let file = data.toString(), content = file.replace(/@rightCode/g, app.rightCode) @@ -92,7 +92,7 @@ const genAdd = app => { } content = content.replace(/@content/g, domain) .replace(/@rules/g, rules) - return fse.outputFileSync(`./zips/${app.id}/add.vue`, content) + return fse.outputFileSync(`${dest}/add.vue`, content) }) } const getComp = e => { @@ -149,9 +149,8 @@ const getComp = e => { } const generate = (app, dest) => { fse.emptydirSync(dest) - fse.emptydirSync(`./zips/${app.id}`) - let tasks = [genHome(app), genList(app)] - app.detailType == 0 && tasks.push(genAdd(app)) + let tasks = [genHome(app, dest), genList(app, dest)] + app.detailType == 0 && tasks.push(genAdd(app, dest)) return Promise.all(tasks) } module.exports = generate