files-pipeline
v0.0.4
Published
🧪 Pipeline for files.
Downloads
276
Readme
files-pipeline 🧪
Installation
First, install the files-pipeline
component like so:
npm install -D -E files-pipeline
Then, create a new pipeline from this component:
index.ts
import { files } from "files-pipeline";
await new files().in("./input");
Getting started
The pipeline will now provide you with a process method which you can use to call the callback on each file from the pipeline.
index.ts
import { files } from "files-pipeline";
await (
await (await new files().in("./input")).by("**/*.md")
).pipeline({
// Prepend some content to all of the text files
wrote: (ongoing) => (ongoing.buffer += "LICENSE [MIT]"),
});
These are the defaults for each callback.
import { files } from "files-pipeline";
await new files().pipeline({
wrote: async (ongoing) => ongoing.buffer,
read: async (ongoing) =>
await fs.promises.readFile(ongoing.inputPath, "utf-8"),
passed: async () => true,
failed: async (inputPath) => `Error: Cannot process file ${inputPath}!`,
accomplished: async (ongoing) =>
`Processed ${ongoing.inputPath} in ${ongoing.outputPath}.`,
fulfilled: async (plan) =>
`Successfully processed a total of ${plan.files} ${
plan.files === 1 ? "file" : "files"
}.`,
changed: async (plan) => plan,
});
You can add multiple paths to your pipeline by specifying an array as the path
variable.
index.ts
import { files } from "files-pipeline";
await new files().in(["./input", "./input2"]);
You can also provide a map of paths for different input output directories.
index.ts
import { files } from "files-pipeline";
new files().in([new Map([["./input", "./output"]])]);
You can provide a filter to exclude files from your pipeline. A filter can be an array of regexes or a single match. You can use functions, as well to match on file names.
index.ts
import { files } from "files-pipeline";
await new files().not([
"my-awesome.file",
(file: string) => file === "./input/this-file-will-not-be-processed.txt",
]);
Set logger
to 0
if you do not want to see debug messages. Default is 2
.
index.ts
import { files } from "files-pipeline";
new files(0);
Changelog
See CHANGELOG.md for a history of changes to this component.