add build:all

This commit is contained in:
Harvey committed 2022-04-28 13:28:51 +08:00
1 parent db66272555
commit c551231edc
3 files changed
+33 -25

No files matched your search

+31 -24
View File
@@ -3,7 +3,7 @@ import inquirer from 'inquirer';
import projects from './projects.js';
import { Parcel } from '@parcel/core';
async function develop(name) {
async function build(name) {
const { version } = JSON.parse(fs.readFileSync(`${projects[name]}/package.json`, 'utf-8'));
process.chdir(projects[name]);
@@ -36,29 +36,36 @@ async function develop(name) {
' * Released under the MIT License.\n' +
' */\n';
try {
const { bundleGraph, buildTime } = await bundler.run();
const bundles = bundleGraph.getBundles();
const filePath = `${projects[name]}/dist/index.js`;
const newFilePath = `${projects[name]}/dist/${name}.js`;
const code = banner + fs.readFileSync(filePath);
fs.writeFileSync(filePath, code);
fs.renameSync(filePath, newFilePath);
console.log(`✨ Built ${name} ${bundles.length} bundles in ${buildTime}ms!`);
} catch (err) {
console.log(err.diagnostics);
}
const { bundleGraph, buildTime } = await bundler.run();
const bundles = bundleGraph.getBundles();
const filePath = `${projects[name]}/dist/index.js`;
const newFilePath = `${projects[name]}/dist/${name}.js`;
const code = banner + fs.readFileSync(filePath);
fs.writeFileSync(filePath, code);
fs.renameSync(filePath, newFilePath);
console.log(`✨ Built ${name} ${bundles.length} bundles in ${buildTime}ms!`);
}
inquirer
.prompt([
{
type: 'list',
message: 'Which project do you want to build?',
name: 'project',
choices: Object.keys(projects),
},
])
.then((answers) => {
develop(answers.project);
function runPromisesInSeries(ps) {
return ps.reduce((p, next) => p.then(next), Promise.resolve());
}
if (process.argv.pop() === 'all') {
const bundles = Object.keys(projects).map((name) => () => build(name));
runPromisesInSeries(bundles).then(() => {
console.log(`✨ Finished building all packages!`);
});
} else {
inquirer
.prompt([
{
type: 'list',
message: 'Which project do you want to build?',
name: 'project',
choices: Object.keys(projects),
},
])
.then((answers) => {
build(answers.project);
});
}