Skip to content

Commit

Permalink
feat: templateFilter option
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Nov 3, 2024
1 parent 4f80629 commit 38f8141
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ Default: `os.tmpdir()`

The directory where the fixture will be created.


##### templateFilter

Type: `(source: string, destination: string) => boolean | Promise<boolean>`

Function to filter files to copy when using a template path. Return `true` to copy the item, `false` to ignore it.

### Types
#### FileTree

Expand Down
15 changes: 12 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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 = (
Expand Down Expand Up @@ -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') {
Expand Down

0 comments on commit 38f8141

Please sign in to comment.