flecks/build/tasks.js

24 lines
799 B
JavaScript
Raw Normal View History

2024-02-04 13:55:14 -06:00
const {join} = require('path');
const {processCode, spawnWith} = require('@flecks/core/src/server');
const {glob} = require('glob');
const {
FLECKS_CORE_ROOT = process.cwd(),
} = process.env;
2024-02-04 14:13:14 -06:00
const args = ['npm', 'run', ...process.argv.slice(2)];
2024-02-04 13:55:14 -06:00
const {workspaces} = require(join(FLECKS_CORE_ROOT, 'package.json'));
(async () => {
2024-02-04 14:13:14 -06:00
const paths = (await Promise.all(workspaces.map((path) => glob(join(FLECKS_CORE_ROOT, path)))))
2024-02-04 13:55:14 -06:00
.flat();
const cpus = new Array(require('os').cpus().length).fill(Promise.resolve(0));
2024-02-04 14:25:53 -06:00
paths.forEach((cwd, i) => {
2024-02-04 14:13:14 -06:00
// then= :)
2024-02-04 13:55:14 -06:00
cpus[i % cpus.length] = cpus[i % cpus.length]
2024-02-04 14:25:53 -06:00
.then(async (code) => (await processCode(spawnWith(args, {cwd}))) || code);
});
2024-02-04 13:55:14 -06:00
process.exitCode = (await Promise.all(cpus)).find((code) => code !== 0) || 0;
})();