@argdown/node
Version:
Async Argdown application for node.js
29 lines • 1.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LoadFilePlugin = void 0;
const core_1 = require("@argdown/core");
const util_1 = require("util");
const fs_1 = require("fs");
const readFileAsync = (0, util_1.promisify)(fs_1.readFile);
class LoadFilePlugin {
constructor() {
this.name = "LoadFilePlugin";
this.runAsync = async (request, _response, logger) => {
const file = request.inputPath;
if (!file) {
throw new core_1.ArgdownPluginError(this.name, "missing-inputPath-request-field", "No inputPath field in request object.");
}
let input;
try {
input = await readFileAsync(file, "utf8");
}
catch (e) {
throw new core_1.ArgdownPluginError(this.name, "file-not-found", `'${file}' not found.`);
}
logger.log("verbose", "[LoadFilePlugin]: Reading file completed, starting processing: " + file);
request.input = input;
};
}
}
exports.LoadFilePlugin = LoadFilePlugin;
//# sourceMappingURL=LoadFilePlugin.js.map