Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 1x 1x 1x 1x 1x 1x 1x | import { IAsyncArgdownPlugin, IAsyncRequestHandler } from "../IAsyncArgdownPlugin";
import { IFileRequest } from "../IFileRequest";
import { ArgdownPluginError } from "@argdown/core";
import { promisify } from "util";
import { readFile } from "fs";
const readFileAsync = promisify(readFile);
export class LoadFilePlugin implements IAsyncArgdownPlugin {
name = "LoadFilePlugin";
runAsync: IAsyncRequestHandler = async (request, _response, logger) => {
const fileRequest = <IFileRequest>request;
const file = fileRequest.inputPath;
if (!file) {
throw new ArgdownPluginError(this.name, "No inputPath field in request object.");
}
const input = await readFileAsync(file, "utf8");
logger.log("verbose", "[LoadFilePlugin]: Reading file completed, starting processing: " + file);
request.input = input;
};
}
|