mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 05:26:47 +00:00
889afeae92
scripts/lib/ratchet.mjs carries the tree walk, the CRLF-safe reader and the baseline handling the client ratchets already use, next to a warning tally and a format comparison that take ESLint and Prettier from the calling workspace. server lint:size now runs on it with the same messages and exit codes, and the libraries have node:test suites that CI runs in the server job.
33 lines
1.0 KiB
JavaScript
33 lines
1.0 KiB
JavaScript
/*
|
|
* A throwaway tree for the tests of the libs in this directory: each key is a
|
|
* path from the tree's root, each value the file's text. The checks run
|
|
* against it with their output collected, so a test sees exactly what CI
|
|
* would print and the exit code it would end with.
|
|
*/
|
|
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { dirname, join } from 'node:path';
|
|
|
|
export function ratchetTree(files = {}) {
|
|
const root = mkdtempSync(join(tmpdir(), 'trek-ratchet-'));
|
|
const log = [];
|
|
const error = [];
|
|
const write = (more) => {
|
|
for (const [key, text] of Object.entries(more)) {
|
|
const path = join(root, key);
|
|
mkdirSync(dirname(path), { recursive: true });
|
|
writeFileSync(path, text);
|
|
}
|
|
};
|
|
write(files);
|
|
return {
|
|
root,
|
|
write,
|
|
path: (key) => join(root, key),
|
|
log,
|
|
error,
|
|
out: { log: (line) => log.push(line), error: (line) => error.push(line) },
|
|
remove: () => rmSync(root, { recursive: true, force: true }),
|
|
};
|
|
}
|