完善统一构建多包发布

This commit is contained in:
aixianling
2022-02-17 16:27:59 +08:00
parent 512e30a84b
commit 89a564c2dd

View File

@@ -2,6 +2,7 @@ const fsExtra = require('fs-extra')
const path = require('path') const path = require('path')
const chalk = require('chalk') const chalk = require('chalk')
const fs = require('fs') const fs = require('fs')
const {exec} = require("child_process");
/** /**
* 将函数封装成promise * 将函数封装成promise
*/ */
@@ -112,8 +113,7 @@ const generateMain = project => {
} }
}) })
}) })
return new Promise(resolve => { return Promise.all([getCores, getApps]).then(() => new Promise(resolve => {
Promise.all([getCores, getApps]).then(() => {
chalkTag.info(project + '正在生成打包文件...') chalkTag.info(project + '正在生成打包文件...')
let bin = path.join(__dirname, project.toString(), 'index.js'), let bin = path.join(__dirname, project.toString(), 'index.js'),
coreApps = cores.map(e => `{name:'${e.name}',component:require('../../${e.component}').default}`), coreApps = cores.map(e => `{name:'${e.name}',component:require('../../${e.component}').default}`),
@@ -156,9 +156,21 @@ const generateMain = project => {
else chalkTag.done(project + '生成打包文件') else chalkTag.done(project + '生成打包文件')
resolve() resolve()
}) })
})).then(() => {
fsExtra.readJson(path.join(__dirname, project.toString(), 'package.json'), (err, json) => {
let cmd = `vue-cli-service build --target lib --dest project/${project}/dist project/${project}/index.js --name ${json.name}`
chalkTag.info(project + '正在压缩文件中...')
exec(cmd, {
cwd: path.join(__dirname, '..')
}, (err) => {
if (!err) {
chalkTag.done(project + '打包成功!')
} else {
chalkTag.error(err)
}
})
}) })
}) })
} }
const start = () => { const start = () => {
//询问打包哪个项目 //询问打包哪个项目