update to latest standards
This commit is contained in:
@ -1,68 +1,69 @@
|
||||
import * as plugins from './npmextra.plugins'
|
||||
import * as paths from './npmextra.paths'
|
||||
|
||||
export type keyValueStoreTypes = 'path' | 'gitProject' | 'customString'
|
||||
|
||||
export type TKeyValueStore = 'path' | 'gitProject' | 'custom'
|
||||
|
||||
export class KeyValueStore {
|
||||
type: string // the type of the kvStore
|
||||
identity: string // the identity of the kvStore
|
||||
filePath: string // the filePath of the kvStore
|
||||
constructor(typeArg: keyValueStoreTypes, identityStringArg?: string) {
|
||||
// set kvStoreType
|
||||
this.type = typeArg
|
||||
this.initIdentity(identityStringArg)
|
||||
this.initFilePath()
|
||||
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)
|
||||
}
|
||||
|
||||
/**
|
||||
* reads a keyValueFile from disk
|
||||
*/
|
||||
read() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* writes a key value file to disk
|
||||
*/
|
||||
write() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* wipes a key value store from disk
|
||||
*/
|
||||
wipe() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* updates a value
|
||||
*/
|
||||
update() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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') {
|
||||
|
||||
baseDir = paths.kvPathDir
|
||||
}
|
||||
this.filePath = plugins.path.join(baseDir, this.identity + '.json')
|
||||
plugins.smartfile.fs.ensureFileSync(this.filePath, '{}')
|
||||
}
|
||||
|
||||
/**
|
||||
* reads a keyValueFile from disk
|
||||
*/
|
||||
read() {
|
||||
/**
|
||||
* computes the filePath
|
||||
*/
|
||||
private initFilePath() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* writes a key value file to disk
|
||||
*/
|
||||
write() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* wipes a key value store from disk
|
||||
*/
|
||||
wipe() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* updates a value
|
||||
*/
|
||||
update() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* computes the identity
|
||||
*/
|
||||
private initIdentity(identityStringArg: string) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* computes the filePath
|
||||
*/
|
||||
private initFilePath() {
|
||||
let baseDir: string
|
||||
if (this.type === 'customString') {
|
||||
baseDir = paths.kvCusomDir
|
||||
} else if (this.type === 'gitProject') {
|
||||
baseDir = paths.kvGitDir
|
||||
} else if (this.type === 'path') {
|
||||
baseDir = paths.kvPathDir
|
||||
}
|
||||
this.filePath = plugins.path.join(baseDir, this.identity + '.json')
|
||||
plugins.smartfile.fs.ensureFileSync(this.filePath,'{}')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,66 +5,66 @@ 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) {
|
||||
if (cwdArg) {
|
||||
this.cwd = cwdArg
|
||||
} else {
|
||||
this.cwd = paths.cwd
|
||||
}
|
||||
this.checkLookupPath()
|
||||
this.checkNpmextraJsonExists()
|
||||
this.checkNpmextraJsonData()
|
||||
/**
|
||||
* creates instance of Npmextra
|
||||
*/
|
||||
constructor(cwdArg?: string) {
|
||||
if (cwdArg) {
|
||||
this.cwd = cwdArg
|
||||
} else {
|
||||
this.cwd = paths.cwd
|
||||
}
|
||||
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]
|
||||
} else {
|
||||
npmextraToolOptions = {}
|
||||
}
|
||||
let mergedOptions = plugins.lodash.merge({}, defaultOptionsArg, npmextraToolOptions)
|
||||
return mergedOptions
|
||||
/**
|
||||
* 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 ]
|
||||
} else {
|
||||
npmextraToolOptions = {}
|
||||
}
|
||||
let mergedOptions = plugins.lodash.merge({}, defaultOptionsArg, npmextraToolOptions)
|
||||
return mergedOptions
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the JSON exists
|
||||
*/
|
||||
private checkNpmextraJsonExists() {
|
||||
this.npmextraJsonExists = plugins.smartfile.fs.fileExistsSync(this.lookupPath)
|
||||
}
|
||||
/**
|
||||
* checks if the JSON exists
|
||||
*/
|
||||
private checkNpmextraJsonExists() {
|
||||
this.npmextraJsonExists = plugins.smartfile.fs.fileExistsSync(this.lookupPath)
|
||||
}
|
||||
|
||||
/**
|
||||
* gets lookupPath
|
||||
*/
|
||||
private checkLookupPath() {
|
||||
if (this.cwd) {
|
||||
this.lookupPath = plugins.path.join(this.cwd, 'npmextra.json')
|
||||
} else {
|
||||
this.lookupPath = paths.configFile
|
||||
};
|
||||
}
|
||||
/**
|
||||
* gets lookupPath
|
||||
*/
|
||||
private checkLookupPath() {
|
||||
if (this.cwd) {
|
||||
this.lookupPath = plugins.path.join(this.cwd, 'npmextra.json')
|
||||
} else {
|
||||
this.lookupPath = paths.configFile
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* get npmextraJsonData
|
||||
*/
|
||||
private checkNpmextraJsonData() {
|
||||
if (this.npmextraJsonExists) {
|
||||
this.npmextraJsonData = plugins.smartfile.fs.toObjectSync(this.lookupPath)
|
||||
} else {
|
||||
this.npmextraJsonData = {}
|
||||
}
|
||||
/**
|
||||
* get npmextraJsonData
|
||||
*/
|
||||
private checkNpmextraJsonData() {
|
||||
if (this.npmextraJsonExists) {
|
||||
this.npmextraJsonData = plugins.smartfile.fs.toObjectSync(this.lookupPath)
|
||||
} else {
|
||||
this.npmextraJsonData = {}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,10 +4,28 @@ import * as plugins from './npmextra.plugins'
|
||||
export let cwd = process.cwd()
|
||||
export let packageDir = plugins.path.join(__dirname,'../')
|
||||
|
||||
// ----------------------
|
||||
// keyValueStore specific
|
||||
// ----------------------
|
||||
|
||||
/**
|
||||
* keyValue base path
|
||||
*/
|
||||
export let kvBase = '~/.npmextra/kv'
|
||||
export let kvCusomDir = plugins.path.join(kvBase, 'custom')
|
||||
|
||||
/**
|
||||
* the base directory for custom string based key value store
|
||||
*/
|
||||
export let kvCustomDir = plugins.path.join(kvBase, 'custom')
|
||||
|
||||
/**
|
||||
* the subdir for git based keyValue
|
||||
*/
|
||||
export let kvGitDir = plugins.path.join(kvBase, 'git')
|
||||
|
||||
/**
|
||||
* keyValue for path based Key
|
||||
*/
|
||||
export let kvPathDir = plugins.path.join(kvBase, 'path')
|
||||
|
||||
// files
|
||||
|
@ -3,4 +3,4 @@ export import beautylog = require('beautylog')
|
||||
export import lodash = require('lodash')
|
||||
export import path = require('path')
|
||||
export import smartfile = require('smartfile')
|
||||
export import q = require('q')
|
||||
export import q = require('smartq')
|
||||
|
Reference in New Issue
Block a user