file-structure

Define and manage file structures

Usage no npm install needed!

<script type="module">
  import fileStructure from 'https://cdn.skypack.dev/file-structure';
</script>

README

file-structure

NPM TypeScript Coverage Status GitHub Stars Twitter Follow

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")
  })
});

Dependenciesdependencies


Dev DependenciesDavid


License license

MIT