BREAKING CHANGE(scope): change to @pushrocks scope
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import * as plugins from './npmextra.plugins'
|
||||
import * as plugins from './npmextra.plugins';
|
||||
|
||||
export * from './npmextra.classes.npmextra'
|
||||
export * from './npmextra.classes.keyvaluestore'
|
||||
export * from './npmextra.classes.npmextra';
|
||||
export * from './npmextra.classes.keyvaluestore';
|
||||
|
@ -1,21 +1,21 @@
|
||||
import * as plugins from './npmextra.plugins'
|
||||
import * as paths from './npmextra.paths'
|
||||
import * as plugins from './npmextra.plugins';
|
||||
import * as paths from './npmextra.paths';
|
||||
|
||||
import { Task, TaskOnce } from 'taskbuffer'
|
||||
import { Task, TaskOnce } from '@pushrocks/taskbuffer';
|
||||
|
||||
export type TKeyValueStore = 'path' | 'gitProject' | 'custom'
|
||||
export type TKeyValueStore = 'path' | 'gitProject' | 'custom';
|
||||
|
||||
/**
|
||||
* kvStore is a simple key vlaue store to store data about projects between runs
|
||||
*/
|
||||
export class KeyValueStore {
|
||||
dataObject: any
|
||||
deletedObject: any = {}
|
||||
dataObject: any;
|
||||
deletedObject: any = {};
|
||||
initialReadTask = new TaskOnce({
|
||||
taskFunction: async () => {
|
||||
this.dataObject = plugins.smartfile.fs.toObjectSync(this.filePath)
|
||||
this.dataObject = plugins.smartfile.fs.toObjectSync(this.filePath);
|
||||
}
|
||||
})
|
||||
});
|
||||
syncTask = new Task({
|
||||
buffered: true,
|
||||
bufferMax: 2,
|
||||
@ -25,21 +25,18 @@ export class KeyValueStore {
|
||||
{},
|
||||
plugins.smartfile.fs.toObjectSync(this.filePath),
|
||||
this.dataObject
|
||||
)
|
||||
);
|
||||
for (let key in this.deletedObject) {
|
||||
delete this.dataObject[key]
|
||||
delete this.dataObject[key];
|
||||
}
|
||||
this.deletedObject = {}
|
||||
await plugins.smartfile.memory.toFs(
|
||||
JSON.stringify(this.dataObject),
|
||||
this.filePath
|
||||
)
|
||||
this.deletedObject = {};
|
||||
await plugins.smartfile.memory.toFs(JSON.stringify(this.dataObject), this.filePath);
|
||||
},
|
||||
name: 'syncTask'
|
||||
})
|
||||
type: TKeyValueStore // the type of the kvStore
|
||||
identity: string // the identity of the kvStore
|
||||
filePath: string // the filePath of the kvStore
|
||||
});
|
||||
type: TKeyValueStore; // the type of the kvStore
|
||||
identity: string; // the identity of the kvStore
|
||||
filePath: string; // the filePath of the kvStore
|
||||
|
||||
/**
|
||||
* the constructor of keyvalue store
|
||||
@ -48,79 +45,76 @@ export class KeyValueStore {
|
||||
*/
|
||||
constructor(typeArg: TKeyValueStore, customStringArg: string) {
|
||||
// set kvStoreType
|
||||
this.type = typeArg
|
||||
this.identity = customStringArg
|
||||
this.initFilePath()
|
||||
this.type = typeArg;
|
||||
this.identity = customStringArg;
|
||||
this.initFilePath();
|
||||
}
|
||||
|
||||
/**
|
||||
* reads all keyValue pairs at once and returns them
|
||||
*/
|
||||
async readAll () {
|
||||
await this.initialReadTask.trigger()
|
||||
this.syncTask.trigger()
|
||||
return this.dataObject
|
||||
async readAll() {
|
||||
await this.initialReadTask.trigger();
|
||||
this.syncTask.trigger();
|
||||
return this.dataObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* reads a keyValueFile from disk
|
||||
*/
|
||||
async readKey (keyArg: string) {
|
||||
let data = await this.readAll()
|
||||
return data[keyArg]
|
||||
async readKey(keyArg: string) {
|
||||
let data = await this.readAll();
|
||||
return data[keyArg];
|
||||
}
|
||||
|
||||
/**
|
||||
* writes a specific key to the keyValueStore
|
||||
*/
|
||||
async writeKey (keyArg: string, valueArg: any) {
|
||||
let writeObject: any = {}
|
||||
writeObject[keyArg] = valueArg
|
||||
this.writeAll(writeObject)
|
||||
async writeKey(keyArg: string, valueArg: any) {
|
||||
let writeObject: any = {};
|
||||
writeObject[keyArg] = valueArg;
|
||||
this.writeAll(writeObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* writes all keyValue pairs in the object argument
|
||||
*/
|
||||
async writeAll (keyValueObject) {
|
||||
plugins.smartlodash.merge(this.dataObject, keyValueObject)
|
||||
this.syncTask.trigger()
|
||||
async writeAll(keyValueObject) {
|
||||
plugins.smartlodash.merge(this.dataObject, keyValueObject);
|
||||
this.syncTask.trigger();
|
||||
}
|
||||
|
||||
/**
|
||||
* wipes a key value store from disk
|
||||
*/
|
||||
async wipe () {
|
||||
async wipe() {
|
||||
for (let key in this.dataObject) {
|
||||
this.deletedObject[key] = this.dataObject[key]
|
||||
this.deletedObject[key] = this.dataObject[key];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* updates a value
|
||||
*/
|
||||
async update (keyObject) {
|
||||
|
||||
}
|
||||
async update(keyObject) {}
|
||||
|
||||
/**
|
||||
* computes the identity
|
||||
*/
|
||||
private initFilePath () {
|
||||
private initFilePath() {
|
||||
// determine the right base directory
|
||||
let baseDir: string
|
||||
let baseDir: string;
|
||||
if (this.type === 'custom') {
|
||||
baseDir = paths.kvCustomDir
|
||||
baseDir = paths.kvCustomDir;
|
||||
} else if (this.type === 'gitProject') {
|
||||
baseDir = paths.kvGitDir
|
||||
baseDir = paths.kvGitDir;
|
||||
} else if (this.type === 'path') {
|
||||
|
||||
baseDir = paths.kvPathDir
|
||||
baseDir = paths.kvPathDir;
|
||||
}
|
||||
this.filePath = plugins.path.join(baseDir, this.identity + '.json')
|
||||
plugins.smartfile.fs.ensureDirSync(paths.kvCustomDir)
|
||||
plugins.smartfile.fs.ensureDirSync(paths.kvGitDir)
|
||||
plugins.smartfile.fs.ensureDirSync(paths.kvPathDir)
|
||||
plugins.smartfile.fs.ensureFileSync(this.filePath, '{}')
|
||||
this.filePath = plugins.path.join(baseDir, this.identity + '.json');
|
||||
plugins.smartfile.fs.ensureDirSync(paths.kvCustomDir);
|
||||
plugins.smartfile.fs.ensureDirSync(paths.kvGitDir);
|
||||
plugins.smartfile.fs.ensureDirSync(paths.kvPathDir);
|
||||
plugins.smartfile.fs.ensureFileSync(this.filePath, '{}');
|
||||
}
|
||||
}
|
||||
|
@ -1,48 +1,48 @@
|
||||
import * as plugins from './npmextra.plugins'
|
||||
import * as paths from './npmextra.paths'
|
||||
import * as plugins from './npmextra.plugins';
|
||||
import * as paths from './npmextra.paths';
|
||||
|
||||
/**
|
||||
* Npmextra class allows easy configuration of tools
|
||||
*/
|
||||
export class Npmextra {
|
||||
cwd: string
|
||||
lookupPath: string
|
||||
npmextraJsonExists: boolean
|
||||
npmextraJsonData: any
|
||||
cwd: string;
|
||||
lookupPath: string;
|
||||
npmextraJsonExists: boolean;
|
||||
npmextraJsonData: any;
|
||||
|
||||
/**
|
||||
* creates instance of Npmextra
|
||||
*/
|
||||
constructor (cwdArg?: string) {
|
||||
constructor(cwdArg?: string) {
|
||||
if (cwdArg) {
|
||||
this.cwd = cwdArg
|
||||
this.cwd = cwdArg;
|
||||
} else {
|
||||
this.cwd = paths.cwd
|
||||
this.cwd = paths.cwd;
|
||||
}
|
||||
this.checkLookupPath()
|
||||
this.checkNpmextraJsonExists()
|
||||
this.checkNpmextraJsonData()
|
||||
this.checkLookupPath();
|
||||
this.checkNpmextraJsonExists();
|
||||
this.checkNpmextraJsonData();
|
||||
}
|
||||
|
||||
/**
|
||||
* merges the supplied options with the ones from npmextra.json
|
||||
*/
|
||||
dataFor<IToolConfig>(toolnameArg: string, defaultOptionsArg: any): IToolConfig {
|
||||
let npmextraToolOptions
|
||||
if (this.npmextraJsonData[ toolnameArg ]) {
|
||||
npmextraToolOptions = this.npmextraJsonData[ toolnameArg ]
|
||||
let npmextraToolOptions;
|
||||
if (this.npmextraJsonData[toolnameArg]) {
|
||||
npmextraToolOptions = this.npmextraJsonData[toolnameArg];
|
||||
} else {
|
||||
npmextraToolOptions = {}
|
||||
npmextraToolOptions = {};
|
||||
}
|
||||
let mergedOptions = plugins.smartlodash.merge({}, defaultOptionsArg, npmextraToolOptions)
|
||||
return mergedOptions
|
||||
let mergedOptions = plugins.smartlodash.merge({}, defaultOptionsArg, npmextraToolOptions);
|
||||
return mergedOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the JSON exists
|
||||
*/
|
||||
private checkNpmextraJsonExists() {
|
||||
this.npmextraJsonExists = plugins.smartfile.fs.fileExistsSync(this.lookupPath)
|
||||
this.npmextraJsonExists = plugins.smartfile.fs.fileExistsSync(this.lookupPath);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -50,10 +50,10 @@ export class Npmextra {
|
||||
*/
|
||||
private checkLookupPath() {
|
||||
if (this.cwd) {
|
||||
this.lookupPath = plugins.path.join(this.cwd, 'npmextra.json')
|
||||
this.lookupPath = plugins.path.join(this.cwd, 'npmextra.json');
|
||||
} else {
|
||||
this.lookupPath = paths.configFile
|
||||
};
|
||||
this.lookupPath = paths.configFile;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,10 +61,9 @@ export class Npmextra {
|
||||
*/
|
||||
private checkNpmextraJsonData() {
|
||||
if (this.npmextraJsonExists) {
|
||||
this.npmextraJsonData = plugins.smartfile.fs.toObjectSync(this.lookupPath)
|
||||
this.npmextraJsonData = plugins.smartfile.fs.toObjectSync(this.lookupPath);
|
||||
} else {
|
||||
this.npmextraJsonData = {}
|
||||
this.npmextraJsonData = {};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,35 +1,34 @@
|
||||
import * as plugins from './npmextra.plugins'
|
||||
import * as plugins from './npmextra.plugins';
|
||||
|
||||
// directories
|
||||
export let cwd = process.cwd()
|
||||
export let packageDir = plugins.path.join(__dirname,'../')
|
||||
export let cwd = process.cwd();
|
||||
export let packageDir = plugins.path.join(__dirname, '../');
|
||||
|
||||
// ----------------------
|
||||
// keyValueStore specific
|
||||
// ----------------------
|
||||
|
||||
export let home = plugins.smartpath.get.home()
|
||||
export let home = plugins.smartpath.get.home();
|
||||
|
||||
/**
|
||||
* keyValue base path
|
||||
*/
|
||||
export let kvBase = plugins.path.join(home,'.npmextra/kv')
|
||||
|
||||
export let kvBase = plugins.path.join(home, '.npmextra/kv');
|
||||
|
||||
/**
|
||||
* the base directory for custom string based key value store
|
||||
*/
|
||||
export let kvCustomDir = plugins.path.join(kvBase, 'custom')
|
||||
export let kvCustomDir = plugins.path.join(kvBase, 'custom');
|
||||
|
||||
/**
|
||||
* the subdir for git based keyValue
|
||||
*/
|
||||
export let kvGitDir = plugins.path.join(kvBase, 'git')
|
||||
export let kvGitDir = plugins.path.join(kvBase, 'git');
|
||||
|
||||
/**
|
||||
* keyValue for path based keyValue store
|
||||
*/
|
||||
export let kvPathDir = plugins.path.join(kvBase, 'path')
|
||||
export let kvPathDir = plugins.path.join(kvBase, 'path');
|
||||
|
||||
// files
|
||||
export let configFile = plugins.path.join(cwd,'npmextra.json')
|
||||
export let configFile = plugins.path.join(cwd, 'npmextra.json');
|
||||
|
@ -1,18 +1,9 @@
|
||||
import 'typings-global'
|
||||
import * as beautylog from 'beautylog'
|
||||
import * as path from 'path'
|
||||
import * as smartfile from 'smartfile'
|
||||
import smartlodash from 'smartlodash'
|
||||
import * as smartpath from 'smartpath'
|
||||
import * as smartq from 'smartq'
|
||||
import * as taskbuffer from 'taskbuffer'
|
||||
import * as beautylog from '@pushrocks/smartlog';
|
||||
import * as path from 'path';
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
import smartlodash from 'smartlodash';
|
||||
import * as smartpath from '@pushrocks/smartpath';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as taskbuffer from '@pushrocks/taskbuffer';
|
||||
|
||||
export {
|
||||
beautylog,
|
||||
path,
|
||||
smartfile,
|
||||
smartpath,
|
||||
smartq,
|
||||
smartlodash,
|
||||
taskbuffer
|
||||
}
|
||||
export { beautylog, path, smartfile, smartpath, smartpromise, smartlodash, taskbuffer };
|
||||
|
Reference in New Issue
Block a user