Detalhes do pacote

file-structure

bconnorwhite145MIT1.6.2

Define and manage file structures

file, structure, fs, manage

readme (leia-me)

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

changelog (log de mudanças)

1.6.2 (2023-01-01)

Bug Fixes

1.6.1 (2023-01-01)

Bug Fixes

  • duplicate path when path is specified in root (b8026c9)

1.6.0 (2021-04-16)

Features

  • add avoid overwrite markdown write option (816793e)

1.5.1 (2021-04-16)

Bug Fixes

  • markdown write types fix (6d1e3bc)

1.5.0 (2021-04-16)

Features

1.4.0 (2021-04-16)

Features

  • directory.file, directory.subdirectory (e5c85a2)

1.3.0 (2021-04-14)

Bug Fixes

Features

1.2.0 (2021-04-13)

Features

  • add exists options, avoid overwrite option (4a0aff9)

1.1.0 (2021-04-13)

Bug Fixes

Features

  • ability to add files to any directory, not just root (af9c959)

1.0.0 (2020-10-12)