完成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);
});
}
+4 -3
View File
@@ -1,17 +1,18 @@
const cpy = require('cpy');
const logger = require('./logger');
module.exports = (opts = {}) => ({
name: 'copyAfterBuild',
generateBundle(outputOptions, bundle, isWrite) {
if (!isWrite) {
throw new Error('copyAfterBuild currently only works with bundles that are written to disk');
logger.fatal('copyAfterBuild currently only works with bundles that are written to disk');
}
if (opts.from && opts.to) {
cpy(opts.from, opts.to).then(() => {
console.log('File copy succeeded!');
logger.success(`Successfully copied to: ${opts.to}`);
}).catch(() => {
throw new Error('File copy failed!');
logger.fatal('File copy failed!');
});
}
},
+1 -1
View File
@@ -69,7 +69,7 @@ module.exports = function creatRollupConfig(projectPath) {
isProd &&
copyAfterBuild({
from: path.join(projectPath, 'dist/*'),
to: path.join(process.cwd(), 'docs/compiled'),
to: path.join(process.cwd(), 'dist'),
}),
],
};
+2
View File
@@ -49,3 +49,5 @@ inquirer
.catch(err => {
logger.fatal(err);
});
module.exports = develop;