完善统一构建多包发布

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 chalk = require('chalk')
const fs = require('fs')
const {exec} = require("child_process");
/**
* 将函数封装成promise
*/
@@ -112,14 +113,13 @@ const generateMain = project => {
}
})
})
return new Promise(resolve => {
Promise.all([getCores, getApps]).then(() => {
chalkTag.info(project + '正在生成打包文件...')
let bin = path.join(__dirname, project.toString(), 'index.js'),
coreApps = cores.map(e => `{name:'${e.name}',component:require('../../${e.component}').default}`),
bizApps = apps.map(e => `{name:'${e.name}',component:require('../../${e.component}').default}`),
comps = [...coreApps, ...bizApps],
content = `
return Promise.all([getCores, getApps]).then(() => new Promise(resolve => {
chalkTag.info(project + '正在生成打包文件...')
let bin = path.join(__dirname, project.toString(), 'index.js'),
coreApps = cores.map(e => `{name:'${e.name}',component:require('../../${e.component}').default}`),
bizApps = apps.map(e => `{name:'${e.name}',component:require('../../${e.component}').default}`),
comps = [...coreApps, ...bizApps],
content = `
const apps = [${comps.toString()}]
const install = function (Vue) {
if (install.installed) return Promise.resolve()
@@ -151,14 +151,26 @@ const generateMain = project => {
install
}
`
fsExtra.outputFile(bin, content, err => {
if (err) chalkTag.error(err)
else chalkTag.done(project + '生成打包文件')
resolve()
fsExtra.outputFile(bin, content, err => {
if (err) chalkTag.error(err)
else chalkTag.done(project + '生成打包文件')
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 = () => {
//询问打包哪个项目