重构打包脚本

This commit is contained in:
aixianling
2022-04-20 11:35:08 +08:00
parent c239698292
commit c04c89507c
2 changed files with 19 additions and 16 deletions

View File

@@ -87,27 +87,29 @@ const init = () => {
const generateMain = project => { const generateMain = project => {
const getApps = new Promise(resolve => { const getApps = new Promise(resolve => {
const appLib = path.join(__dirname, project.toString(), 'apps.import.json') const appLib = path.join(__dirname, project.toString(), 'apps.import.json')
fsExtra.readJson(appLib, (err, data) => { fsExtra.readJson(appLib, (err, data) => {
chalkTag.info(project + '加载业务应用配置...') fsExtra.emptyDirSync(`project/${project}/apps`)
let apps = [] let apps = []
if (data) { if (data) {
fsExtra.emptyDirSync(`project/${project}/apps`) chalkTag.info(project + '加载业务应用配置...')
Promise.all([ Promise.all([
findApp(`src/project/${project}`, f => apps.push(f)), findApp(`project/${project}`, file => {
findApp('src/mods', file => apps.push(file)) let reg = new RegExp(/.+(App[^\\\/]+)$/)
]).then(() => { if (reg.test(file)) {
Promise.all(Object.keys(data).map(e => { data[file.replace(reg, '$1')] = file.replace(reg, '$1')
let app = [...new Set(apps)].find(s => s.indexOf(e) > -1)
if (app) {
return copyFiles(`project/${project}/apps/${e}`, app)
} }
})).then(() => { return apps.push(file)
chalkTag.done(project + '业务应用加载完成') }),
resolve() findApp('src/mods', file => apps.push(file))
}) ]).then(() => Promise.all(Object.keys(data).map(e => {
let app = [...new Set(apps)].find(s => s.indexOf(e) > -1)
if (app) {
return copyFiles(`project/${project}/apps/${e}`, app)
}
}))).then(() => {
chalkTag.done(project + '业务应用加载完成')
resolve()
}) })
} else { } else {
chalkTag.done(project + '业务应用无打包') chalkTag.done(project + '业务应用无打包')
resolve() resolve()

View File

@@ -2,7 +2,8 @@
"name": "@dvcp-wechat-apps/sanjianxi", "name": "@dvcp-wechat-apps/sanjianxi",
"version": "1.0.0", "version": "1.0.0",
"files": [ "files": [
"apps" "apps",
"static"
], ],
"dependencies": { "dependencies": {
} }