Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
runAsync: IAsyncRequestHandler = async request => {
if (!request.input) {
throw new ArgdownPluginError(
this.name,
"missing-input-request-field",
"Missing input."
);
}
if (!request.inputPath) {
throw new ArgdownPluginError(
this.name,
"missing-inputPath-request-field",
"Missing input path."
);
}
const settings = this.getSettings(request);
settings.regEx!.lastIndex = 0;
request.input = await this.replaceIncludesAsync(
request.inputPath!,
runAsync: IAsyncRequestHandler = async request => {
if (!request.input) {
throw new ArgdownPluginError(
this.name,
"missing-input-request-field",
"Missing input."
);
}
if (!request.inputPath) {
throw new ArgdownPluginError(
this.name,
"missing-inputPath-request-field",
"Missing input path."
);
}
const settings = this.getSettings(request);
settings.regEx!.lastIndex = 0;
request.input = await this.replaceIncludesAsync(
request.inputPath!,
request.input!,
settings.regEx!,
[]
);
};
async replaceIncludesAsync(
runAsync: IAsyncRequestHandler = async (request, _response, logger) => {
const file = request.inputPath;
if (!file) {
throw new ArgdownPluginError(
this.name,
"missing-inputPath-request-field",
"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;
};
}