@joshski/dust 0.1.72 → 0.1.73
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.
- package/dist/dust.js +1 -1
- package/dist/filesystem/emulator.d.ts +10 -2
- package/dist/filesystem-emulator.js +10 -1
- package/package.json +1 -1
package/dist/dust.js
CHANGED
|
@@ -25,10 +25,12 @@ export interface FileSystemEmulator extends FileSystem, GlobScanner {
|
|
|
25
25
|
* Implements both FileSystem and GlobScanner interfaces - the scan() method
|
|
26
26
|
* iterates over the files the emulator knows about.
|
|
27
27
|
*
|
|
28
|
-
* @param tree - Nested object representing file system hierarchy
|
|
28
|
+
* @param tree - Nested object representing file system hierarchy (paths get '/' prefix)
|
|
29
|
+
* @param flatFiles - Optional record of path→content entries added as-is (no prefix)
|
|
29
30
|
* @returns FileSystemEmulator with tracking for created directories and written files
|
|
30
31
|
*
|
|
31
32
|
* @example
|
|
33
|
+
* // Nested tree (paths become /project/.dust/...)
|
|
32
34
|
* createFileSystemEmulator({
|
|
33
35
|
* project: {
|
|
34
36
|
* '.dust': {
|
|
@@ -37,5 +39,11 @@ export interface FileSystemEmulator extends FileSystem, GlobScanner {
|
|
|
37
39
|
* }
|
|
38
40
|
* }
|
|
39
41
|
* })
|
|
42
|
+
*
|
|
43
|
+
* // Flat files (paths used as-is)
|
|
44
|
+
* createFileSystemEmulator({}, {
|
|
45
|
+
* '.dust/config/audits/security.md': '# Security Audit\n...',
|
|
46
|
+
* '.dust/tasks/audit-security.md': '# Run security audit\n...',
|
|
47
|
+
* })
|
|
40
48
|
*/
|
|
41
|
-
export declare function createFileSystemEmulator(tree?: FileSystemTree): FileSystemEmulator;
|
|
49
|
+
export declare function createFileSystemEmulator(tree?: FileSystemTree, flatFiles?: Record<string, string>): FileSystemEmulator;
|
|
@@ -28,8 +28,17 @@ function flattenFileSystemTree(tree, basePath = "") {
|
|
|
28
28
|
}
|
|
29
29
|
return { files, paths };
|
|
30
30
|
}
|
|
31
|
-
function createFileSystemEmulator(tree = {}) {
|
|
31
|
+
function createFileSystemEmulator(tree = {}, flatFiles) {
|
|
32
32
|
const { files, paths } = flattenFileSystemTree(tree);
|
|
33
|
+
if (flatFiles) {
|
|
34
|
+
for (const [filePath, content] of Object.entries(flatFiles)) {
|
|
35
|
+
files.set(filePath, content);
|
|
36
|
+
paths.add(filePath);
|
|
37
|
+
for (let dir = filePath.substring(0, filePath.lastIndexOf("/"));dir; dir = dir.substring(0, dir.lastIndexOf("/"))) {
|
|
38
|
+
paths.add(dir);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
33
42
|
const createdDirs = [];
|
|
34
43
|
const writtenFiles = new Map;
|
|
35
44
|
const permissions = new Map;
|