Skip to content

Commit

Permalink
feat: Add file stats.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Oct 17, 2021
1 parent 33cffc7 commit f4c1c7b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ it('ignored test case', async () => {
ignored: /\/(node_modules|coverage|\.git)/
});
expect(files.length).toBe(10);
expect(Object.keys(files[0])).toEqual(['name', 'path', 'size', 'ext']);
expect(Object.keys(files[0])).toEqual(['dev', 'mode', 'nlink', 'uid', 'gid', 'rdev', 'blksize', 'ino', 'size', 'blocks', 'atimeMs', 'mtimeMs', 'ctimeMs', 'birthtimeMs', 'atime', 'mtime', 'ctime', 'birthtime', 'name', 'path', 'ext',]);
});

it('ignored/exclude/include test case', async () => {
Expand All @@ -22,7 +22,7 @@ it('ignored/exclude/include test case', async () => {
expect(arrs[0]).toEqual('package.json');
const arrs2 = files.filter(item => /renovate\.json$/.test(item.path)).map(item => item.name);
expect(arrs2.length).toEqual(0);
expect(Object.keys(files[0])).toEqual(['name', 'path', 'size', 'ext']);
expect(Object.keys(files[0])).toEqual(['dev', 'mode', 'nlink', 'uid', 'gid', 'rdev', 'blksize', 'ino', 'size', 'blocks', 'atimeMs', 'mtimeMs', 'ctimeMs', 'birthtimeMs', 'atime', 'mtime', 'ctime', 'birthtime', 'name', 'path', 'ext',]);
});

it('Recursive Readdir Files, options', async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface RecursiveReaddirFilesOptions {
filter?: (item: IFileDirStat) => boolean;
}

export interface IFileDirStat {
export interface IFileDirStat extends Partial<fs.Stats> {
/**
* @example `/a/sum.jpg` => `sum.jpg`
*/
Expand All @@ -34,7 +34,6 @@ export interface RecursiveReaddirFilesOptions {
* @example `/a/b.jpg` => `jpg`
*/
ext?: string;
size?: number;
}

export default function recursiveReaddirFiles(rootPath: string, options: RecursiveReaddirFilesOptions = {}): Promise<IFileDirStat[]> {
Expand Down Expand Up @@ -72,6 +71,7 @@ async function getFiles(rootPath: string, options: RecursiveReaddirFilesOptions
files = files.concat(arr);
} else if (stat.isFile()) {
item.ext = await getExt(item.path);
item = { ...stat, ...item }
files.push(item);
}
}),
Expand Down

0 comments on commit f4c1c7b

Please sign in to comment.