now adheres to standard js
This commit is contained in:
91
ts/index.ts
91
ts/index.ts
@ -1,55 +1,68 @@
|
||||
import * as plugins from "./npmextra.plugins"
|
||||
import * as paths from "./npmextra.paths";
|
||||
import * as plugins from './npmextra.plugins'
|
||||
import * as paths from './npmextra.paths'
|
||||
|
||||
export interface IDataFor {
|
||||
toolName:string;
|
||||
defaultSettings?;
|
||||
cwd?:string
|
||||
toolName: string
|
||||
defaultSettings?
|
||||
cwd?: string
|
||||
}
|
||||
|
||||
export let dataFor = (optionsArg:IDataFor) => {
|
||||
|
||||
/**
|
||||
* gets you the configuration data for
|
||||
* @executes SYNC
|
||||
*/
|
||||
export let dataFor = <IOptions>(optionsArg: IDataFor): IOptions => {
|
||||
|
||||
// handle default settings
|
||||
if(
|
||||
typeof optionsArg.toolName != undefined
|
||||
&& typeof optionsArg.defaultSettings != undefined
|
||||
){
|
||||
let newDefaultOptions = {};
|
||||
newDefaultOptions[optionsArg.toolName] = optionsArg.defaultSettings;
|
||||
optionsArg.defaultSettings = newDefaultOptions;
|
||||
if (
|
||||
typeof optionsArg.toolName !== undefined
|
||||
&& typeof optionsArg.defaultSettings !== undefined
|
||||
) {
|
||||
let newDefaultOptions = {}
|
||||
newDefaultOptions[optionsArg.toolName] = optionsArg.defaultSettings
|
||||
optionsArg.defaultSettings = newDefaultOptions
|
||||
};
|
||||
|
||||
// set lookup path
|
||||
let lookupPath:string;
|
||||
if(optionsArg.cwd){
|
||||
lookupPath = plugins.path.join(optionsArg.cwd,"npmextra.json");
|
||||
let lookupPath: string
|
||||
if (optionsArg.cwd) {
|
||||
lookupPath = plugins.path.join(optionsArg.cwd,'npmextra.json')
|
||||
} else {
|
||||
lookupPath = paths.configFile;
|
||||
};
|
||||
|
||||
// get allData
|
||||
let allData;
|
||||
if(plugins.smartfile.fs.fileExistsSync(lookupPath)){
|
||||
allData = plugins.smartfile.fs.toObjectSync(lookupPath);
|
||||
} else {
|
||||
plugins.beautylog.warn(`${lookupPath} is missing!`);
|
||||
allData = {};
|
||||
lookupPath = paths.configFile
|
||||
};
|
||||
|
||||
//assign all data
|
||||
allData = plugins.lodash.merge({},optionsArg.defaultSettings,allData);
|
||||
if(optionsArg.toolName){
|
||||
if(allData[optionsArg.toolName]){
|
||||
return allData[optionsArg.toolName];
|
||||
// get allData
|
||||
let allData
|
||||
if (plugins.smartfile.fs.fileExistsSync(lookupPath)) {
|
||||
allData = plugins.smartfile.fs.toObjectSync(lookupPath)
|
||||
} else {
|
||||
plugins.beautylog.warn(`${lookupPath} is missing!`)
|
||||
allData = {}
|
||||
};
|
||||
|
||||
// assign all data
|
||||
allData = plugins.lodash.merge({},optionsArg.defaultSettings,allData)
|
||||
if (optionsArg.toolName) {
|
||||
if (allData[optionsArg.toolName]) {
|
||||
return allData[optionsArg.toolName]
|
||||
} else {
|
||||
plugins.beautylog.error(`There is no data for ${optionsArg.toolName}`);
|
||||
return undefined;
|
||||
plugins.beautylog.error(`There is no data for ${optionsArg.toolName}`)
|
||||
return undefined
|
||||
}
|
||||
} else {
|
||||
return allData;
|
||||
return allData
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export let configFilePresent = ():boolean => {
|
||||
return plugins.smartfile.fs.fileExistsSync(paths.configFile);
|
||||
}
|
||||
/**
|
||||
* tells you if a configfile is present
|
||||
*/
|
||||
export let configFilePresent = (optionsArg: {cwd?: string}): boolean => {
|
||||
let lookupPath: string
|
||||
if (optionsArg.cwd) {
|
||||
lookupPath = plugins.path.join(optionsArg.cwd,'npmextra.json')
|
||||
} else {
|
||||
lookupPath = paths.configFile
|
||||
};
|
||||
return plugins.smartfile.fs.fileExistsSync(lookupPath)
|
||||
}
|
||||
|
@ -1,20 +1,20 @@
|
||||
import * as plugins from "./npmextra.plugins";
|
||||
import * as plugins from './npmextra.plugins'
|
||||
|
||||
type keyValueStoreTypes = "path" | "gitProject"
|
||||
export type keyValueStoreTypes = 'path' | 'gitProject'
|
||||
|
||||
/**
|
||||
* reads a keyValueFile from disk
|
||||
*/
|
||||
let kvRead = () => {
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* writes a key value file to disk
|
||||
*/
|
||||
let kvWrite = () => {
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* wipes a key value store from disk
|
||||
@ -24,11 +24,9 @@ let kevWipe = () => {
|
||||
}
|
||||
|
||||
export class KeyValueStore {
|
||||
constructor(optionsArg:{
|
||||
constructor(optionsArg: {
|
||||
type: keyValueStoreTypes
|
||||
}){
|
||||
}) {
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
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,'../')
|
||||
|
||||
//
|
||||
export let configFile = plugins.path.join(cwd,"npmextra.json");
|
||||
// files
|
||||
export let configFile = plugins.path.join(cwd,'npmextra.json')
|
||||
|
@ -1,6 +1,6 @@
|
||||
import "typings-global";
|
||||
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");
|
||||
import 'typings-global'
|
||||
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')
|
||||
|
Reference in New Issue
Block a user