Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
1c0b428606 | |||
90e8625771 | |||
abbce0d4a1 | |||
93c65acc95 | |||
a68d59a4d2 | |||
0133dca698 | |||
6174490e8e | |||
d952a761b2 | |||
05909f776e | |||
779883fbab |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/npmextra",
|
"name": "@push.rocks/npmextra",
|
||||||
"version": "4.0.7",
|
"version": "4.0.12",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "do more with npm",
|
"description": "do more with npm",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
|
12
pnpm-lock.yaml
generated
12
pnpm-lock.yaml
generated
@ -12,13 +12,13 @@ dependencies:
|
|||||||
specifier: ^5.0.10
|
specifier: ^5.0.10
|
||||||
version: 5.0.10
|
version: 5.0.10
|
||||||
'@push.rocks/smartlog':
|
'@push.rocks/smartlog':
|
||||||
specifier: ^3.0.3
|
specifier: ^3.0.2
|
||||||
version: 3.0.3
|
version: 3.0.3
|
||||||
'@push.rocks/smartpath':
|
'@push.rocks/smartpath':
|
||||||
specifier: ^5.0.11
|
specifier: ^5.0.11
|
||||||
version: 5.0.11
|
version: 5.0.11
|
||||||
'@push.rocks/smartpromise':
|
'@push.rocks/smartpromise':
|
||||||
specifier: ^4.0.3
|
specifier: ^4.0.2
|
||||||
version: 4.0.3
|
version: 4.0.3
|
||||||
'@push.rocks/smartrx':
|
'@push.rocks/smartrx':
|
||||||
specifier: ^3.0.7
|
specifier: ^3.0.7
|
||||||
@ -29,19 +29,19 @@ dependencies:
|
|||||||
|
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@git.zone/tsbuild':
|
'@git.zone/tsbuild':
|
||||||
specifier: ^2.1.72
|
specifier: ^2.1.66
|
||||||
version: 2.1.72
|
version: 2.1.72
|
||||||
'@git.zone/tsrun':
|
'@git.zone/tsrun':
|
||||||
specifier: ^1.2.46
|
specifier: ^1.2.44
|
||||||
version: 1.2.46(@types/node@20.11.16)
|
version: 1.2.46(@types/node@20.11.16)
|
||||||
'@git.zone/tstest':
|
'@git.zone/tstest':
|
||||||
specifier: ^1.0.86
|
specifier: ^1.0.77
|
||||||
version: 1.0.86(@types/node@20.11.16)(sinon@17.0.1)
|
version: 1.0.86(@types/node@20.11.16)(sinon@17.0.1)
|
||||||
'@push.rocks/tapbundle':
|
'@push.rocks/tapbundle':
|
||||||
specifier: ^5.0.15
|
specifier: ^5.0.15
|
||||||
version: 5.0.15(sinon@17.0.1)
|
version: 5.0.15(sinon@17.0.1)
|
||||||
'@types/node':
|
'@types/node':
|
||||||
specifier: ^20.11.16
|
specifier: ^20.11.6
|
||||||
version: 20.11.16
|
version: 20.11.16
|
||||||
|
|
||||||
packages:
|
packages:
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/npmextra',
|
name: '@push.rocks/npmextra',
|
||||||
version: '4.0.7',
|
version: '4.0.12',
|
||||||
description: 'do more with npm'
|
description: 'do more with npm'
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,11 @@ import * as plugins from './npmextra.plugins.js';
|
|||||||
import * as paths from './npmextra.paths.js';
|
import * as paths from './npmextra.paths.js';
|
||||||
import { KeyValueStore } from './npmextra.classes.keyvaluestore.js';
|
import { KeyValueStore } from './npmextra.classes.keyvaluestore.js';
|
||||||
|
|
||||||
|
export interface IAppDataOptions {
|
||||||
|
dirPath?: string;
|
||||||
|
requiredKeys?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
export class AppData {
|
export class AppData {
|
||||||
/**
|
/**
|
||||||
* creates appdata. If no pathArg is given, data will be stored here:
|
* creates appdata. If no pathArg is given, data will be stored here:
|
||||||
@ -9,18 +14,18 @@ export class AppData {
|
|||||||
* @param pathArg
|
* @param pathArg
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
public static async createAndInit(pathArg?: string) {
|
public static async createAndInit(optionsArg: IAppDataOptions = {}) {
|
||||||
const appData = new AppData(pathArg);
|
const appData = new AppData(optionsArg);
|
||||||
await appData.readyDeferred.promise;
|
await appData.readyDeferred.promise;
|
||||||
return appData;
|
return appData;
|
||||||
}
|
}
|
||||||
|
|
||||||
// instance
|
// instance
|
||||||
public readyDeferred = plugins.smartpromise.defer();
|
public readyDeferred = plugins.smartpromise.defer();
|
||||||
public dirPathArg: string;
|
public options: IAppDataOptions;
|
||||||
private kvStore: KeyValueStore;
|
private kvStore: KeyValueStore;
|
||||||
constructor(pathArg?: string) {
|
constructor(optionsArg: IAppDataOptions = {}) {
|
||||||
this.dirPathArg = pathArg;
|
this.options = optionsArg;
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,7 +34,7 @@ export class AppData {
|
|||||||
* @param pathArg
|
* @param pathArg
|
||||||
*/
|
*/
|
||||||
private async init(pathArg?: string) {
|
private async init(pathArg?: string) {
|
||||||
if (this.dirPathArg) {
|
if (this.options.dirPath) {
|
||||||
// ok, nothing to do here;
|
// ok, nothing to do here;
|
||||||
} else {
|
} else {
|
||||||
const appDataDir = '/app/data';
|
const appDataDir = '/app/data';
|
||||||
@ -38,15 +43,15 @@ export class AppData {
|
|||||||
const appDataExists = plugins.smartfile.fs.isDirectory(appDataDir);
|
const appDataExists = plugins.smartfile.fs.isDirectory(appDataDir);
|
||||||
const dataExists = plugins.smartfile.fs.isDirectory(dataDir);
|
const dataExists = plugins.smartfile.fs.isDirectory(dataDir);
|
||||||
if (appDataExists) {
|
if (appDataExists) {
|
||||||
this.dirPathArg = appDataDir;
|
this.options.dirPath = appDataDir;
|
||||||
} else if (dataExists) {
|
} else if (dataExists) {
|
||||||
this.dirPathArg = dataDir;
|
this.options.dirPath = dataDir;
|
||||||
} else {
|
} else {
|
||||||
await plugins.smartfile.fs.ensureDir(nogitAppData);
|
await plugins.smartfile.fs.ensureDir(nogitAppData);
|
||||||
this.dirPathArg = nogitAppData;
|
this.options.dirPath = nogitAppData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.kvStore = new KeyValueStore('custom', 'appkv', this.dirPathArg);
|
this.kvStore = new KeyValueStore('custom', 'appkv', this.options.dirPath, this.options.requiredKeys);
|
||||||
this.readyDeferred.resolve();
|
this.readyDeferred.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,4 +62,14 @@ export class AppData {
|
|||||||
await this.readyDeferred.promise;
|
await this.readyDeferred.promise;
|
||||||
return this.kvStore;
|
return this.kvStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async logMissingKeys() {
|
||||||
|
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 -> ')}`);
|
||||||
|
} else {
|
||||||
|
console.log('All mandatory keys are present in the appdata');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user