flecks/build/tasks.js

53 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2024-02-11 22:37:25 -06:00
const {join, relative} = require('path');
2024-02-11 22:53:52 -06:00
const {PassThrough} = require('stream');
2024-02-04 13:55:14 -06:00
2024-02-11 22:53:52 -06:00
const {pipesink, processCode, spawnWith} = require('@flecks/core/src/server');
const chalk = require('chalk');
2024-02-04 13:55:14 -06:00
const {glob} = require('glob');
2024-02-09 01:11:27 -06:00
const concurrent = require('./concurrent');
2024-02-04 13:55:14 -06:00
const {
FLECKS_CORE_ROOT = process.cwd(),
2024-02-15 22:44:33 -06:00
FLECKS_CI_SHOW_SUCCESS,
2024-02-04 13:55:14 -06:00
} = process.env;
2024-02-09 01:11:27 -06:00
const args = process.argv.slice(2);
2024-02-04 13:55:14 -06:00
const {workspaces} = require(join(FLECKS_CORE_ROOT, 'package.json'));
2024-02-15 22:44:33 -06:00
const showSuccess = !!FLECKS_CI_SHOW_SUCCESS;
2024-02-04 13:55:14 -06:00
(async () => {
2024-02-09 01:11:27 -06:00
process.exitCode = await concurrent(
(await Promise.all(workspaces.map((path) => glob(join(FLECKS_CORE_ROOT, path))))).flat(),
2024-02-11 22:37:25 -06:00
async (cwd) => {
2024-02-11 22:53:52 -06:00
const child = spawnWith(
args,
{
cwd,
stdio: 'pipe',
},
);
const stdio = new PassThrough();
const buffer = pipesink(child.stderr.pipe(child.stdout.pipe(stdio)));
const code = await processCode(child);
2024-02-15 22:44:33 -06:00
if (!showSuccess && 0 === code) {
console.log(`@flecks/${
chalk.blue(relative(join(FLECKS_CORE_ROOT, 'packages'), cwd))
2024-02-15 22:44:33 -06:00
} ${chalk.green('passed')}\n`);
}
else {
console.log(
`::group::@flecks/${
chalk.blue(relative(join(FLECKS_CORE_ROOT, 'packages'), cwd))
} ${0 === code ? chalk.green('passed') : chalk.red('failed')}`,
);
process.stdout.write(await buffer);
console.log('::endgroup::\n');
}
2024-02-11 22:37:25 -06:00
return code;
},
2024-02-09 01:11:27 -06:00
);
console.log(0 === process.exitCode ? chalk.green('success') : chalk.red('failure'), '\n');
2024-02-04 13:55:14 -06:00
})();