2016-09-16 20:28:38 +00:00
|
|
|
import * as plugins from './npmextra.plugins'
|
2016-09-24 19:49:53 +00:00
|
|
|
import * as paths from './npmextra.paths'
|
2016-08-28 12:51:04 +00:00
|
|
|
|
2017-03-18 15:23:47 +00:00
|
|
|
export type TKeyValueStore = 'path' | 'gitProject' | 'custom'
|
2016-09-24 14:44:48 +00:00
|
|
|
|
|
|
|
export class KeyValueStore {
|
2017-03-18 15:23:47 +00:00
|
|
|
type: TKeyValueStore // the type of the kvStore
|
|
|
|
identity: string // the identity of the kvStore
|
|
|
|
filePath: string // the filePath of the kvStore
|
|
|
|
constructor(typeArg: TKeyValueStore, customStringArg?: string) {
|
|
|
|
// set kvStoreType
|
|
|
|
this.type = typeArg
|
|
|
|
this.identity = customStringArg
|
|
|
|
this.initIdentity(customStringArg)
|
|
|
|
}
|
2016-09-24 19:49:53 +00:00
|
|
|
|
2017-03-18 15:23:47 +00:00
|
|
|
/**
|
|
|
|
* reads a keyValueFile from disk
|
|
|
|
*/
|
|
|
|
read() {
|
2016-08-28 12:51:04 +00:00
|
|
|
|
2017-03-18 15:23:47 +00:00
|
|
|
}
|
2016-08-28 12:51:04 +00:00
|
|
|
|
2017-03-18 15:23:47 +00:00
|
|
|
/**
|
|
|
|
* writes a key value file to disk
|
|
|
|
*/
|
|
|
|
write() {
|
2016-08-28 12:51:04 +00:00
|
|
|
|
2017-03-18 15:23:47 +00:00
|
|
|
}
|
2016-08-28 12:51:04 +00:00
|
|
|
|
2017-03-18 15:23:47 +00:00
|
|
|
/**
|
|
|
|
* wipes a key value store from disk
|
|
|
|
*/
|
|
|
|
wipe() {
|
2016-09-24 19:49:53 +00:00
|
|
|
|
2017-03-18 15:23:47 +00:00
|
|
|
}
|
2016-09-24 19:49:53 +00:00
|
|
|
|
2017-03-18 15:23:47 +00:00
|
|
|
/**
|
|
|
|
* updates a value
|
|
|
|
*/
|
|
|
|
update() {
|
2016-08-28 12:51:04 +00:00
|
|
|
|
2017-03-18 15:23:47 +00:00
|
|
|
}
|
2016-09-24 19:49:53 +00:00
|
|
|
|
2017-03-18 15:23:47 +00:00
|
|
|
/**
|
|
|
|
* computes the identity
|
|
|
|
*/
|
|
|
|
private initIdentity(customStringArg: string) {
|
|
|
|
let baseDir: string
|
|
|
|
if (this.type === 'custom') {
|
|
|
|
this.identity = customStringArg
|
|
|
|
baseDir = paths.kvCustomDir
|
|
|
|
} else if (this.type === 'gitProject') {
|
|
|
|
baseDir = paths.kvGitDir
|
|
|
|
} else if (this.type === 'path') {
|
2016-09-24 19:53:44 +00:00
|
|
|
|
2017-03-18 15:23:47 +00:00
|
|
|
baseDir = paths.kvPathDir
|
2016-09-24 19:49:53 +00:00
|
|
|
}
|
2017-03-18 15:23:47 +00:00
|
|
|
this.filePath = plugins.path.join(baseDir, this.identity + '.json')
|
|
|
|
plugins.smartfile.fs.ensureFileSync(this.filePath, '{}')
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* computes the filePath
|
|
|
|
*/
|
|
|
|
private initFilePath() {
|
|
|
|
|
|
|
|
}
|
2016-09-16 20:28:38 +00:00
|
|
|
}
|