bingo-fs
The virtual file system used by Bingo. 🗄️
npm i bingo-fspnpm add bingo-fsyarn add bingo-fsThe separate bingo-fs package includes types and utility functions for the file system used in Concepts > Creations > files.
This file system is a simplified abstraction over the lower-level APIs in Node.js and other platforms. APIs and data are optimized for simplicity and ease of use, rather than completeness.
For example, given a structure like:
/└── README.md└── src └── index.tsbingo-fs would represent that structure with an object like:
{ "README.md": "...", "src": { "index.ts": "..." }}Directories
TypeScript type name:
CreatedDirectory
Directories in a files object are represented as objects.
Property keys are the names of children.
Values are the file or directory underneath that key.
IntakeDirectory
Directories read in from intake or intakeDirectory are represented as IntakeDirectory objects.
IntakeDirectory objects represent files as [string, CreatedFileMetadata?] tuples.
Files
TypeScript type name:
CreatedFileEntry
Each property value in a directory object may be one of the following:
falseorundefined: Ignoredobject: A directory, whose properties recursively are file creationsstring: A file to be created[string, CreatedFileMetadata?]: A file to be created with options:executable: Whether to add permissions to make the file executable
For example, this Bingo template produces an executable .husky/pre-commit file:
import { createTemplate } from "bingo";
export default createTemplate({ produce() { return { ".husky": { "pre-commit": ["npx lint-staged\n", { executable: true }], }, }; },});APIs
intake
Given a directory or file path, reads it in as a bingo-fs directory structure or file entry.
Parameters:
rootPath: string(required)settings: IntakeSettings(optional):
Returns the directory or file if it existed, or undefined if it didn’t.
For example, retrieving all files in a src/ directory:
import { intake } from "bingo-fs";
// { "index.ts": "..." }await intake("src");exclude
An optional regular expression to filter out directory children.
For example, you may want to avoid .git and node_modules directories:
import { intake } from "bingo-fs";
// Result: { README.md: "...", src: { "index.ts": "..." }, ... }await intake(".", { exclude: /node_modules|^\.git$/,});intakeDirectory
Given a directory path, reads it in as a bingo-fs directory structure.
Parameters:
directoryPath: string(required)settings: IntakeSettings(optional):
Returns the directory or file if it existed, or undefined if it didn’t.
For example, retrieving all files in a src/ directory:
import { intakeDirectory } from "bingo-fs";
// { "index.ts": "..." }await intakeDirectory("src");exclude
An optional regular expression to filter out directory children.
For example, you may want to avoid .git and node_modules directories:
import { intakeDirectory } from "bingo-fs";
// Result: { README.md: "...", src: { "index.ts": "..." }, ... }await intakeDirectory(".", { exclude: /node_modules|^\.git$/,});