@zthun/crumbtrail-fs 1.1.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ export {};
@@ -10,6 +10,32 @@ export interface IZFileSystemSearchOptions {
10
10
  */
11
11
  cwd?: string;
12
12
  }
13
+ /**
14
+ * Represents options for directory walking.
15
+ */
16
+ export interface IZFileSystemWalkOptions {
17
+ /**
18
+ * The starting directory.
19
+ *
20
+ * The default is the current working directory
21
+ *
22
+ * @see process.cwd for more information.
23
+ */
24
+ start?: string;
25
+ /**
26
+ * The directory to stop at.
27
+ *
28
+ * The default is the root of the file system.
29
+ */
30
+ stop?: string;
31
+ /**
32
+ * The type of mode that the path must support in order
33
+ * to be approved.
34
+ *
35
+ * The default is undefined and left up to the node api.
36
+ */
37
+ mode?: number;
38
+ }
13
39
  /**
14
40
  * Represents a service to enumerate the file system.
15
41
  */
@@ -36,16 +62,48 @@ export interface IZFileSystemService {
36
62
  * A list of path strings that match the given patterns.
37
63
  */
38
64
  search(pattern: string, options?: IZFileSystemSearchOptions): Promise<IZFileSystemNode[]>;
65
+ /**
66
+ * Walks up a directory tree to search for existence of a given path.
67
+ *
68
+ * @param search -
69
+ * The path to search for. This is the candidate folder path that
70
+ * may or may not exist somewhere from the start directory all the
71
+ * way up the directory tree.
72
+ * @param options -
73
+ * The given options for the search.
74
+ *
75
+ * @returns
76
+ * The fully qualified path to the first path that matches the search
77
+ * starting at the options start or the current working directory if not
78
+ * specified. Returns null if no such directory exists.
79
+ *
80
+ * @example
81
+ *
82
+ * ```ts
83
+ * import { resolve } from 'path'
84
+ *
85
+ * // Find any folder named .vscode from the current working directory all the way
86
+ * // up the directory tree. Returns null if no vscode directory can be found.
87
+ * const service = new ZFileSystemService();
88
+ * const vscode = service.walk('.vscode');
89
+ *
90
+ * // Walk the directory tree from the current script and find the .config folder.
91
+ * const config = service.walk('.config', { start: __dirname });
92
+ *
93
+ * // Walk the directory tree from the current script and stop when we reach
94
+ * // at most 2 directories up.
95
+ * const start = __dirname;
96
+ * const stop = resolve(__dirname, '../..');
97
+ * const file = service.walk('path/to/file.json', { start, stop });
98
+ * ```
99
+ */
100
+ walk(search: string, options?: IZFileSystemWalkOptions): Promise<string | null>;
39
101
  }
40
- /**
41
- * A token that you can use with a framework like nest-js to describe
42
- * a file system service implementation.
43
- */
44
- export declare const ZFileSystemToken: unique symbol;
45
102
  /**
46
103
  * Represents a node implementation of a file system service.
47
104
  */
48
105
  export declare class ZFileSystemService implements IZFileSystemService {
49
106
  info(path: string): Promise<IZFileSystemNode>;
50
107
  search(pattern: string | string[], options?: IZFileSystemSearchOptions): Promise<IZFileSystemNode[]>;
108
+ walk(search: string, options?: IZFileSystemWalkOptions): Promise<string | null>;
51
109
  }
@@ -0,0 +1 @@
1
+ export {};