Installation
First, install the files-pipe
component like so:
npm install -D -E files-pipe
Then, create a new pipe from this component:
Index.ts
import { Files } from "files-pipe";
await new Files().In("./input");
Getting started
The files-pipe
will now provide you with a pipe
method which you can use to
execute the callback on each file from the pipe.
Index.ts
import { Files } from "files-pipe";
await (
await (await new Files().In("./Input")).By("**/*.md")
).Pipe({
Wrote: (On) => (On.Buffer += "LICENSE [MIT]"),
});
These are the defaults for each callback.
import { Files } from "files-pipe";
await new Files().Pipe({
Wrote: async (On) => On.Buffer,
Read: async (On) => await fs.promises.readFile(On.Input, "utf-8"),
Passed: async (On) => On && true,
Failed: async (Input) => `Error: Cannot process file ${Input}!`,
Accomplished: async (On) => `Processed ${On.Input} in ${On.Output}.`,
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 pipe by specifying an array as the path
variable.
Index.ts
import { Files } from "files-pipe";
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-pipe";
await new Files().In(new Map([["./Input", "./Output"]]));
You can provide a filter to exclude files from your pipe. 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-pipe";
await new Files().Not([
"File.txt",
(File: string) => File === "./Input/File.txt",
]);
Set logger
to 0
if you do not want to see debug messages. Default is 2
.
Index.ts
import { Files } from "files-pipe";
new Files(0);
Changelog
See CHANGELOG.md for a history of changes to this component.