UNPKG

@backstage-community/plugin-rbac-backend

Version:
47 lines (41 loc) 1.42 kB
'use strict'; var chokidar = require('chokidar'); var fs = require('fs'); function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; } var chokidar__default = /*#__PURE__*/_interopDefaultCompat(chokidar); var fs__default = /*#__PURE__*/_interopDefaultCompat(fs); class AbstractFileWatcher { constructor(filePath, allowReload, logger) { this.filePath = filePath; this.allowReload = allowReload; this.logger = logger; } /** * watchFile initializes the file watcher and sets it to begin watching for changes. */ watchFile() { if (!this.filePath) { throw new Error("File path is not specified"); } const watcher = chokidar__default.default.watch(this.filePath); watcher.on("change", async (path) => { this.logger.info(`file ${path} has changed`); await this.onChange(); }); watcher.on("error", (error) => { this.logger.error(`error watching file ${this.filePath}: ${error}`); }); } /** * getCurrentContents reads the current contents of the CSV file. * @returns The current contents of the file. */ getCurrentContents() { if (!this.filePath) { throw new Error("File path is not specified"); } return fs__default.default.readFileSync(this.filePath, "utf-8"); } } exports.AbstractFileWatcher = AbstractFileWatcher; //# sourceMappingURL=file-watcher.cjs.js.map