fix(core): update

This commit is contained in:
2024-02-09 15:57:32 +01:00
parent 1c0b428606
commit 4f7e382bc9
5 changed files with 87 additions and 56 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/npmextra',
version: '4.0.12',
version: '4.0.13',
description: 'do more with npm'
}

View File

@ -5,6 +5,13 @@ import { KeyValueStore } from './npmextra.classes.keyvaluestore.js';
export interface IAppDataOptions {
dirPath?: string;
requiredKeys?: string[];
/**
* kvStoreKey: 'MY_ENV_VAR'
*/
envMapping?: {
[key: string]: string;
};
}
export class AppData {
@ -12,7 +19,7 @@ export class AppData {
* creates appdata. If no pathArg is given, data will be stored here:
* ${PWD}/.nogit/appdata
* @param pathArg
* @returns
* @returns
*/
public static async createAndInit(optionsArg: IAppDataOptions = {}) {
const appData = new AppData(optionsArg);
@ -51,7 +58,23 @@ export class AppData {
this.options.dirPath = nogitAppData;
}
}
this.kvStore = new KeyValueStore('custom', 'appkv', this.options.dirPath, this.options.requiredKeys);
this.kvStore = new KeyValueStore(
'custom',
'appkv',
this.options.dirPath,
this.options.requiredKeys
);
if (this.options.envMapping) {
const qenvInstance = new plugins.qenv.Qenv(process.cwd(), '~/.cloudlyrc');
for (const key in this.options.envMapping) {
const envValue = await qenvInstance.getEnvVarOnDemand(key);
if (envValue) {
await this.kvStore.writeKey(key, envValue);
}
}
}
this.readyDeferred.resolve();
}
@ -67,9 +90,13 @@ export class AppData {
const kvStore = await this.getKvStore();
const missingMandatoryKeys = kvStore.getMissingMandatoryKeys();
if (missingMandatoryKeys.length > 0) {
console.log(`The following mandatory keys are missing in the appdata:\n -> ${missingMandatoryKeys.join(',\n -> ')}`);
console.log(
`The following mandatory keys are missing in the appdata:\n -> ${missingMandatoryKeys.join(
',\n -> '
)}`
);
} else {
console.log('All mandatory keys are present in the appdata');
}
}
}
}

View File

@ -1,3 +1,4 @@
import * as qenv from '@push.rocks/qenv';
import * as smartlog from '@push.rocks/smartlog';
import * as path from 'path';
import * as smartfile from '@push.rocks/smartfile';
@ -7,4 +8,4 @@ import * as smartpromise from '@push.rocks/smartpromise';
import * as smartrx from '@push.rocks/smartrx';
import * as taskbuffer from '@push.rocks/taskbuffer';
export { smartlog, path, smartfile, smartjson, smartpath, smartpromise, smartrx, taskbuffer };
export { qenv, smartlog, path, smartfile, smartjson, smartpath, smartpromise, smartrx, taskbuffer };