Skip to content

Commit 2113226

Browse files
chore(no-story): add script to display commands for a given evergreen task (mongodb#3731)
1 parent 92c013e commit 2113226

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

etc/expand-tasks.mjs

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

0 commit comments

Comments
 (0)