From 17264e0456977fbd79e47b116a329da7aefae747 Mon Sep 17 00:00:00 2001 From: Tim Perry Date: Fri, 6 Jan 2017 16:04:10 +0100 Subject: [PATCH] Add missing walk() method to fs-extra (#13070) * Add walk() to fs-extra * Fix some indentation in fs-extra --- fs-extra/fs-extra-tests.ts | 9 +++++++++ fs-extra/index.d.ts | 28 +++++++++++++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/fs-extra/fs-extra-tests.ts b/fs-extra/fs-extra-tests.ts index c6b95c0100..0954fcaf47 100644 --- a/fs-extra/fs-extra-tests.ts +++ b/fs-extra/fs-extra-tests.ts @@ -101,3 +101,12 @@ fs.ensureSymlink(path, errorCallback); fs.ensureSymlinkSync(path); fs.emptyDir(path, errorCallback); fs.emptyDirSync(path); + +var items: string[]; +fs.walk("my-path") + .on('data', function (item) { + items.push(item.path); + }) + .on('end', function () { + console.dir(items); + }); diff --git a/fs-extra/index.d.ts b/fs-extra/index.d.ts index c24ee5a49d..ffc2ec434b 100644 --- a/fs-extra/index.d.ts +++ b/fs-extra/index.d.ts @@ -8,6 +8,7 @@ /// import * as stream from 'stream'; +import { Stats } from "fs"; export * from "fs"; export declare function copy(src: string, dest: string, callback?: (err: Error) => void): void; @@ -72,8 +73,21 @@ export declare function ensureSymlinkSync(path: string): void; export declare function emptyDir(path: string, callback?: (err: Error) => void): void; export declare function emptyDirSync(path: string): boolean; - - export interface CopyFilterFunction { + +export interface WalkEventEmitter { + on(event: 'data', callback: (file: WalkEventFile) => void): WalkEventEmitter; + on(event: 'end', callback: () => void): WalkEventEmitter; + on(event: string, callback: Function): WalkEventEmitter; +} + +export interface WalkEventFile { + path: string; + stats: Stats; +} + +export function walk(path: string, options?: {}): WalkEventEmitter; + +export interface CopyFilterFunction { (src: string): boolean } @@ -86,11 +100,11 @@ export interface CopyOptions { filter?: CopyFilter recursive?: boolean } - - export interface MoveOptions { - clobber? : boolean; - limit?: number; - } + +export interface MoveOptions { + clobber? : boolean; + limit?: number; +} export interface MoveOptions { clobber? : boolean;