fix(core): update
This commit is contained in:
parent
349f074bb9
commit
779883fbab
@ -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.8',
|
||||||
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.readyDeferred.resolve();
|
this.readyDeferred.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user