Skip to content

Commit

Permalink
chore(no-story): add script to display commands for a given evergreen…
Browse files Browse the repository at this point in the history
… task (#3731)
  • Loading branch information
baileympearson authored Jun 22, 2023
1 parent 92c013e commit 2113226
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions etc/expand-tasks.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
}

0 comments on commit 2113226

Please sign in to comment.