-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from nutgaard/fix/no-exit-on-fix
fix/no exit on fix
- Loading branch information
Showing
10 changed files
with
566 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { NestedDirectoryJSON } from 'memfs/lib/volume'; | ||
|
||
export function buildVolumeFromFs(directory: string): NestedDirectoryJSON { | ||
const directoryJson: NestedDirectoryJSON = {}; | ||
|
||
walkDirectory(directory, (file) => { | ||
const relativeFilePath = path.relative(directory, file); | ||
const parts = relativeFilePath.split(path.sep); | ||
|
||
let jsonObject: NestedDirectoryJSON = directoryJson; | ||
for (let i = 0; i < parts.length; i++) { | ||
const part = parts[i]; | ||
const isLast = i === parts.length - 1; | ||
|
||
if (isLast) { | ||
jsonObject[part] = fs.readFileSync(file, 'utf-8'); | ||
} else { | ||
jsonObject[part] = jsonObject[part] ?? {}; | ||
jsonObject = jsonObject[part] as NestedDirectoryJSON; | ||
} | ||
} | ||
}); | ||
|
||
return directoryJson; | ||
} | ||
|
||
function walkDirectory(directory: string, callback: (file: string) => void) { | ||
fs.readdirSync(directory).forEach((file) => { | ||
const dirPath = path.join(directory, file); | ||
const isDirectory = fs.statSync(dirPath).isDirectory(); | ||
if (isDirectory) { | ||
walkDirectory(dirPath, callback); | ||
} else { | ||
callback(dirPath); | ||
} | ||
}); | ||
} |
Oops, something went wrong.