UNPKG

aha-micro-cli

Version:

aha微前端运行脚手架

69 lines (61 loc) 1.73 kB
/* 运行打包 */ const { exec } = require('child_process') const ora = require('ora') const chalk = require('chalk') const { succeed, error, exit } = require('../utils/index') /** * @param {String} entryMsg 选择环境时提示文字 * @param {String} env.value 选择的打包环境 * @param {String} env.buildCommand 打包指令 * @param {String} entry 入口(可选) */ module.exports = async function(entryMsg, { value: env, buildCommand }, entry) { /* 获取入口配置 */ entries = await require('../utils/selectEntry')(entryMsg, entry) if (entries.length === 0) { exit('该入口不存在') } const spinner = ora('打包中...') spinner.start() try { const buildRes = await Promise.allSettled(entries.map(item => new Promise((resolve, reject) => { /* 入口参数写入 */ require('../utils/envWrite')(item) exec( buildCommand, { cwd: process.cwd(), maxBuffer: 5000 * 1024, shell: true, }, (e) => { if (e === null) { resolve(`${ chalk.green(item.name) }打包完成(${ env }环境), 路径: ${ chalk.blue(item.distPath) }`) } else { reject(e.message) } } ) }))) spinner.stop() buildRes.forEach(res => { if (res.status === 'fulfilled') { succeed(res.value) } else { error(res.reason) } }) return { env, projects: entries.map(item => { return { ...item, src: `dist/${ item.entry }` } }) } } catch (err) { error('打包失败') exit(err) } }