@willsoto/node-konfig-file
Version:
Node Konfig integration for Files
31 lines • 908 B
JavaScript
import { Loader, } from "@willsoto/node-konfig-core";
import fs from "node:fs";
export class FileLoader extends Loader {
options;
name = "file";
constructor(options) {
super(options);
this.options = options;
}
load(store) {
if (this.maxRetries > 0) {
return this.retryPolicy.execute(() => this.processFiles(store));
}
return this.processFiles(store);
}
async processFiles(store) {
for (const file of this.options.files) {
try {
const contents = await fs.promises.readFile(file.path, "utf-8");
const result = file.parser.parse(contents);
store.assign(result);
}
catch (error) {
if (this.stopOnFailure) {
throw error;
}
}
}
}
}
//# sourceMappingURL=loader.js.map