file-structure
v1.6.2
Published
Define and manage file structures
Downloads
216
Maintainers
Readme
Define and manage file structures.
Installation
yarn add file-structure
npm install file-structure
API
Use root to define a file structure:
import { root, directory, file } from "file-structure";
const structure = root("/path/to/root/", { // This path defaults to process.cwd()
source: directory("source", {
index: file("index.ts")
}),
notes: file("notes.txt")
});
From this structure, we can easily get files and their paths:
console.log(structure.files().notes.path); // /path/to/root/notes.txt
console.log(structure.files().source.relative); // source
console.log(structure.files().source.files().index.relative); // source/index.ts
Directories and files also have these additional methods:
structure.files().source.exists();
structure.files().source.read();
structure.files().source.write();
structure.files().source.remove();
structure.files().source.watch();
Files can be added later to directories:
directory.add({
myNewFile: file("test.txt")
});
Or get a file/subdirectory relative to a directory:
const subFile = directory.file("test.txt");
const subDirectory = directory.subdirectory("sub", {
myNewFile: file("test.txt");
});
Several other file types are included with specialized return types:
import {
root,
directory,
file,
jsonFile,
packageJSONFile,
tsConfigJSONFile,
markdownFile,
lcovFile
} from "file-structure";
const structure = root({
file: file("file.txt"),
json: jsonFile("file.json"),
packageJSON: packageJSONFile(), // default: "package.json"
tsConfig: tsConfigJSONFile(), // default: "tsconfig.json"
readme: markdownFile("README.md"),
coverage: directory("coverage", {
lcov: lcovFile("lcov.info")
})
});
- fs-safe: A simple fs wrapper that doesn't throw
- read-file-safe: Read files without try catch
- read-lcov-safe: Read and parse an lcov file without try catch
- read-md-safe: Read markdown files as a Marked token list or string
- types-pkg-json: Type checking for package.json
- types-tsconfig: Type checking for tsconfig.json
- write-md-safe: Write markdown files from a Marked token list or string
- @bconnorwhite/bob: undefined
- @types/object-map: undefined