histoire
Version:
A fast story book powered by Vite
22 lines (21 loc) • 879 B
JavaScript
import { mkdirSync, writeFileSync } from 'node:fs';
import { join } from 'pathe';
/** Ignores everything in its folder, itself included. */
const GITIGNORE = '# Generated by Histoire\n*\n';
/**
* Makes a folder of generated output ignore itself with its own `.gitignore`,
* like `.pytest_cache`. Git skips it even when the project doesn't ignore
* `.histoire`, and so does Tailwind 4's source scan, which honors `.gitignore`
* files without a git repository (without it, it read `.histoire/tmp`).
* An existing `.gitignore` is kept; failures are ignored.
* @param dir Folder holding generated output only.
*/
export function markGeneratedDir(dir) {
try {
mkdirSync(dir, { recursive: true });
writeFileSync(join(dir, '.gitignore'), GITIGNORE, { flag: 'wx' });
}
catch {
// Already marked, or not writable: nothing depends on it.
}
}