plugins: expose persistant data dir

Plugins need to be able to store persistant files, say settings or
databases or similar things.
Expose a standard location that gets created when the path is
accessed.
This commit is contained in:
Reto Brunner 2021-10-12 22:48:47 +02:00
parent bb4ab4f168
commit 02ccbc1f69

View file

@ -46,6 +46,7 @@ const packageApis = function (packageInfo) {
}, },
Config: { Config: {
getConfig: () => Helper.config, getConfig: () => Helper.config,
getPersistentStorageDir: getPersistentStorageDir.bind(this, packageInfo.packageName),
}, },
Logger: { Logger: {
error: (...args) => log.error(...args), error: (...args) => log.error(...args),
@ -87,6 +88,12 @@ function getEnabledPackages(packageJson) {
return []; return [];
} }
function getPersistentStorageDir(packageName) {
const dir = path.join(Helper.getPackagesPath(), packageName);
fs.mkdirSync(dir, {recursive: true}); // we don't care if it already exists or not
return dir;
}
function loadPackage(packageName) { function loadPackage(packageName) {
let packageInfo; let packageInfo;
let packageFile; let packageFile;