@ayanaware/bento
Version:
Modular runtime framework designed to solve complex tasks
71 lines (70 loc) • 2.29 kB
TypeScript
/// <reference types="node" />
import { PluginAPI } from '../../entities/api/PluginAPI';
import { VariableLoader } from './VariableLoader';
/**
* Allows you to load Bento Variables and set their defaults from files
* If you have a custom file format or prefer to use something other than JSON
* You can provide a custom `parseFileContents` function. Just return Key/Value pairs
* derived from the file Buffer.
*
* Keep in mind that if you have key `HELLO_WORLD` in a file or defaults file and `HELLO_WORLD` in the enviorment
* the value from the enviorment will take priority
*/
export declare class VariableFileLoader extends VariableLoader {
name: string;
api: PluginAPI;
/**
* Registered files and Variables they loaded
*/
readonly files: Map<string, Set<string>>;
private readonly watching;
/**
* Registered fs Watchers
*/
private readonly watchers;
/**
* @param watching Enable file watching? (Automatic hot-loading of variables in files)
*/
constructor(watching?: boolean);
/**
* Add Multiple Variable Files
* @param files Array of File Locations
* @param defaults Defaults Mode
*
* @returns Array<Path>
*/
addFiles(files: Array<Array<string>>, defaults: boolean): Promise<Array<string>>;
/**
* Add Variables File
* @param location File Location
* @param defaults Defaults Mode
*
* @throws ProcessingError If `fs.access` check fails and `defaults` is true
* @returns Path
*/
addFile(location: Array<string>, defaults?: boolean): Promise<string>;
/**
* Remove Variables file
* @param location File Location
* @param purge Purge Variables that this file Added
*/
removeFile(location: Array<string>, purge: boolean): void;
private addWatcher;
/**
* Read and return file contents
* @param location File Location
*
* @returns File Buffer
*/
private getFileContents;
/**
* Convert File Buffer into Key/Value pairings
* @param data File Buffer
*
* @returns Key/Value Pairings Object
*/
parseFileContents(data: Buffer): {
[key: string]: unknown;
};
protected processFile(location: string, defaults: boolean): Promise<void>;
}