完善统一构建多包发布
This commit is contained in:
@@ -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,14 +113,13 @@ 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}`),
|
bizApps = apps.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],
|
||||||
comps = [...coreApps, ...bizApps],
|
content = `
|
||||||
content = `
|
|
||||||
const apps = [${comps.toString()}]
|
const apps = [${comps.toString()}]
|
||||||
const install = function (Vue) {
|
const install = function (Vue) {
|
||||||
if (install.installed) return Promise.resolve()
|
if (install.installed) return Promise.resolve()
|
||||||
@@ -151,14 +151,26 @@ const generateMain = project => {
|
|||||||
install
|
install
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
fsExtra.outputFile(bin, content, err => {
|
fsExtra.outputFile(bin, content, err => {
|
||||||
if (err) chalkTag.error(err)
|
if (err) chalkTag.error(err)
|
||||||
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 = () => {
|
||||||
//询问打包哪个项目
|
//询问打包哪个项目
|
||||||
|
|||||||
Reference in New Issue
Block a user