完成build脚本

This commit is contained in:
Harvey Zack committed 2018-12-03 12:46:52 +08:00
1 parent cc2027832e
commit 00b51c32ba
18 files changed
+84 -123

No files matched your search

+53
View File
@@ -0,0 +1,53 @@
const inquirer = require('inquirer');
const rollup = require('rollup');
const logger = require('./logger');
const projects = require('./getProjects')();
const creatRollupConfig = require('./creatRollupConfig');
const isBuildAll = process.argv.pop() === 'all';
function build(projectPath) {
const { input, output, plugins } = creatRollupConfig(projectPath);
logger.log(`bundling ${output.file}...`);
return rollup
.rollup({
input,
plugins,
})
.then(bundle => {
bundle.write(output);
logger.success('finished building all bundles');
});
}
if (isBuildAll) {
const bundles = [];
Object.keys(projects).forEach(item => {
const projectPath = projects[item];
bundles.push(build(projectPath));
});
Promise.all(bundles)
.then(() => {
logger.success('----finished building all packages----');
})
.catch(err => {
logger.fatal(err);
});
} else {
inquirer
.prompt([
{
type: 'list',
message: 'Which project do you want to build?',
name: 'project',
choices: Object.keys(projects),
},
])
.then(answers => {
build(projects[answers.project]);
})
.catch(err => {
logger.fatal(err);
});
}