diff --git a/README.md b/README.md index 6f14146..f74e26f 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,13 @@ Default: `os.tmpdir()` The directory where the fixture will be created. + +##### templateFilter + +Type: `(source: string, destination: string) => boolean | Promise` + +Function to filter files to copy when using a template path. Return `true` to copy the item, `false` to ignore it. + ### Types #### FileTree diff --git a/src/index.ts b/src/index.ts index ee19bdc..3704b16 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ -import fs from 'fs/promises'; -import path from 'path'; +import fs from 'node:fs/promises'; +import type { CopyOptions } from 'node:fs'; +import path from 'node:path'; import { FsFixture } from './fs-fixture.js'; import { osTemporaryDirectory, @@ -9,6 +10,8 @@ import { export { type FsFixtureType as FsFixture } from './fs-fixture.js'; +type FilterFunction = CopyOptions['filter']; + type SymlinkType = 'file' | 'dir' | 'junction'; class Symlink { @@ -60,6 +63,12 @@ export type CreateFixtureOptions = { * Defaults to `os.tmpdir()`. */ tempDir?: string; + + /** + * Function to filter files to copy when using a template path. + * Return `true` to copy the item, `false` to ignore it. + */ + templateFilter?: FilterFunction; }; const flattenFileTree = ( @@ -129,7 +138,7 @@ export const createFixture = async ( fixturePath, { recursive: true, - // filter: source => !path.basename(source).startsWith('.'), + filter: options?.templateFilter, }, ); } else if (typeof source === 'object') {