-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathexpand-tasks.mjs
34 lines (27 loc) · 935 Bytes
/
expand-tasks.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// usage: node expand-task.js <task name>
// must be run from root of the Node driver
//
// The output is pipeable: `node expand-task.js <task name> | jq '.'`
import { readFileSync } from 'fs';
import { load } from 'js-yaml';
import { gte } from 'semver';
import { Readable } from 'stream';
import { inspect } from 'util';
if (!gte(process.version, '16.0.0')) {
console.error('expand-tasks.mjs requires Node16+');
process.exit(1);
}
const config = load(readFileSync('.evergreen/config.yml'));
const taskName = (process.argv[2] ?? '').trim();
const task = config.tasks.find(({ name }) => name === taskName);
if (!task) {
process.exit();
}
const commands = task.commands.flatMap(({ func }) => config.functions[func]);
if (process.stdout.isTTY) {
console.log(inspect(commands, { depth: Infinity, colors: true }));
} else {
Readable.from(commands)
.map(command => JSON.stringify(command))
.pipe(process.stdout);
}