added new NpmExtra class

This commit is contained in:
Philipp Kunz 2016-09-24 16:44:48 +02:00
parent 16150541b0
commit 2911dd4972
9 changed files with 212 additions and 226 deletions

20
dist/index.d.ts vendored
View File

@ -1,18 +1,2 @@
/**
* the main interface npmextra functions work with
*/
export interface IDataFor {
toolName: string;
defaultSettings?: any;
cwd?: string;
}
/**
* gets you the configuration data for
* @executes SYNC
*/
export declare let dataFor: <IOptions>(optionsArg: IDataFor) => IOptions;
export declare let dataForExists: (optionsArg: IDataFor) => boolean;
/**
* tells you if a configfile is present
*/
export declare let configFilePresent: (cwdArg: string) => boolean;
export * from './npmextra.classes.npmextra';
export * from './npmextra.classes.keyvaluestore';

85
dist/index.js vendored
View File

@ -1,80 +1,7 @@
"use strict";
const plugins = require("./npmextra.plugins");
const paths = require("./npmextra.paths");
/**
* gets lookupPath
*/
let getLookupPath = (cwdArg) => {
if (cwdArg) {
let cwdResolved = plugins.path.resolve(cwdArg);
return plugins.path.join(cwdResolved, 'npmextra.json');
}
else {
return paths.configFile;
}
;
};
/**
* gets you the configuration data for
* @executes SYNC
*/
exports.dataFor = (optionsArg) => {
// handle default settings
if (typeof optionsArg.toolName !== undefined
&& typeof optionsArg.defaultSettings !== undefined) {
let newDefaultOptions = {};
newDefaultOptions[optionsArg.toolName] = optionsArg.defaultSettings;
optionsArg.defaultSettings = newDefaultOptions;
}
;
// set lookup path
let lookupPath = getLookupPath(optionsArg.cwd);
// get allData
let allData;
if (exports.configFilePresent(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;
}
}
else {
return allData;
}
};
exports.dataForExists = (optionsArg) => {
// set lookup path
let lookupPath = getLookupPath(optionsArg.cwd);
if (exports.configFilePresent(optionsArg.cwd)) {
let allData = plugins.smartfile.fs.toObjectSync(lookupPath);
if (allData[optionsArg.toolName]) {
return true;
}
else {
return false;
}
}
else {
return false;
}
};
/**
* tells you if a configfile is present
*/
exports.configFilePresent = (cwdArg) => {
let lookupPath = getLookupPath(cwdArg);
return plugins.smartfile.fs.fileExistsSync(lookupPath);
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsOENBQTZDO0FBQzdDLDBDQUF5QztBQVd6Qzs7R0FFRztBQUNILElBQUksYUFBYSxHQUFHLENBQUMsTUFBYztJQUMvQixFQUFFLENBQUMsQ0FBQyxNQUFNLENBQUMsQ0FBQyxDQUFDO1FBQ1QsSUFBSSxXQUFXLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUE7UUFDOUMsTUFBTSxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLFdBQVcsRUFBRSxlQUFlLENBQUMsQ0FBQTtJQUMxRCxDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDSixNQUFNLENBQUMsS0FBSyxDQUFDLFVBQVUsQ0FBQTtJQUMzQixDQUFDO0lBQUEsQ0FBQztBQUNOLENBQUMsQ0FBQTtBQUVEOzs7R0FHRztBQUNRLFFBQUEsT0FBTyxHQUFHLENBQVcsVUFBb0I7SUFFaEQsMEJBQTBCO0lBQzFCLEVBQUUsQ0FBQyxDQUNDLE9BQU8sVUFBVSxDQUFDLFFBQVEsS0FBSyxTQUFTO1dBQ3JDLE9BQU8sVUFBVSxDQUFDLGVBQWUsS0FBSyxTQUM3QyxDQUFDLENBQUMsQ0FBQztRQUNDLElBQUksaUJBQWlCLEdB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0FBQyxDQUFBO0lBQzlDLE1BQU0sQ0FBQyxPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxjQUFjLENBQUMsVUFBVSxDQUFDLENBQUE7QUFDMUQsQ0FBQyxDQUFBIn0=
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
__export(require("./npmextra.classes.npmextra"));
__export(require("./npmextra.classes.keyvaluestore"));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBRUEsaURBQTJDO0FBQzNDLHNEQUFnRCJ9

View File

@ -1,7 +1,12 @@
"use strict";
class KeyValueStore {
constructor(optionsArg) {
}
}
exports.KeyValueStore = KeyValueStore;
/**
* reads a keyValueFile from disk
*/
* reads a keyValueFile from disk
*/
let kvRead = () => {
};
/**
@ -14,9 +19,4 @@ let kvWrite = () => {
*/
let kevWipe = () => {
};
class KeyValueStore {
constructor(optionsArg) {
}
}
exports.KeyValueStore = KeyValueStore;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZXh0cmEuY2xhc3Nlcy5rZXlWYWx1ZVN0b3JlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvbnBtZXh0cmEuY2xhc3Nlcy5rZXlWYWx1ZVN0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFJQTs7R0FFRztBQUNILElBQUksTUFBTSxHQUFHO0FBRWIsQ0FBQyxDQUFBO0FBRUQ7O0dBRUc7QUFDSCxJQUFJLE9BQU8sR0FBRztBQUVkLENBQUMsQ0FBQTtBQUVEOztHQUVHO0FBQ0gsSUFBSSxPQUFPLEdBQUc7QUFFZCxDQUFDLENBQUE7QUFFRDtJQUNJLFlBQVksVUFFWDtJQUVELENBQUM7Q0FDSjtBQU5ELHNDQU1DIn0=
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZXh0cmEuY2xhc3Nlcy5rZXl2YWx1ZXN0b3JlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvbnBtZXh0cmEuY2xhc3Nlcy5rZXl2YWx1ZXN0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFNQTtJQUNJLFlBQVksVUFFWDtJQUVELENBQUM7Q0FBQTtBQUxMLHNDQUtLO0FBQ0Q7O0VBRUQ7QUFDSCxJQUFJLE1BQU0sR0FBQztBQUVYLENBQUMsQ0FBQTtBQUVEOztHQUVHO0FBQ0gsSUFBSSxPQUFPLEdBQUM7QUFFWixDQUFDLENBQUE7QUFFRDs7R0FFRztBQUNILElBQUksT0FBTyxHQUFDO0FBRVosQ0FBQyxDQUFBIn0=

29
dist/npmextra.classes.npmextra.d.ts vendored Normal file
View File

@ -0,0 +1,29 @@
/**
* Npmextra class allows easy configuration of tools
*/
export declare class Npmextra {
cwd: string;
lookupPath: string;
npmextraJsonExists: boolean;
npmextraJsonData: boolean;
/**
* creates instance of Npmextra
*/
constructor(cwdArg?: string);
/**
* merges the supplied options with the ones from npmextra.json
*/
dataFor(toolnameArg: string, defaultOptionsArg: any): any;
/**
* checks if the JSON exists
*/
private checkNpmextraJsonExists();
/**
* gets lookupPath
*/
private checkLookupPath();
/**
* get npmextraJsonData
*/
private checkNpmextraJsonData();
}

64
dist/npmextra.classes.npmextra.js vendored Normal file
View File

@ -0,0 +1,64 @@
"use strict";
const plugins = require("./npmextra.plugins");
const paths = require("./npmextra.paths");
/**
* Npmextra class allows easy configuration of tools
*/
class Npmextra {
/**
* creates instance of Npmextra
*/
constructor(cwdArg) {
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(toolnameArg, defaultOptionsArg) {
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
*/
checkNpmextraJsonExists() {
this.npmextraJsonExists = plugins.smartfile.fs.fileExistsSync(this.lookupPath);
}
/**
* gets lookupPath
*/
checkLookupPath() {
if (this.cwd) {
this.lookupPath = plugins.path.join(this.cwd, 'npmextra.json');
}
else {
this.lookupPath = paths.configFile;
}
;
}
/**
* get npmextraJsonData
*/
checkNpmextraJsonData() {
if (this.npmextraJsonExists) {
this.npmextraJsonData = plugins.smartfile.fs.toObjectSync(this.lookupPath);
}
}
}
exports.Npmextra = Npmextra;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZXh0cmEuY2xhc3Nlcy5ucG1leHRyYS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWV4dHJhLmNsYXNzZXMubnBtZXh0cmEudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDhDQUE2QztBQUM3QywwQ0FBeUM7QUFFekM7O0dBRUc7QUFDSDtJQU1JOztPQUVHO0lBQ0gsWUFBWSxNQUFlO1FBQ3ZCLEVBQUUsQ0FBQyxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUM7WUFDVCxJQUFJLENBQUMsR0FBRyxHQUFHLE1BQU0sQ0FBQTtRQUNyQixDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDSixJQUFJLENBQUMsR0FBRyxHQUFHLEtBQUssQ0FBQyxHQUFHLENBQUE7UUFDeEIsQ0FBQztRQUNELElBQUksQ0FBQyxlQUFl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ElBQUksQ0FBQyxDQUFDO1lBQ0osSUFBSSxDQUFDLFVBQVUsR0FBRyxLQUFLLENBQUMsVUFBVSxDQUFBO1FBQ3RDLENBQUM7UUFBQSxDQUFDO0lBQ04sQ0FBQztJQUVEOztPQUVHO0lBQ0sscUJBQXFCO1FBQ3pCLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxrQkFBa0IsQ0FBQyxDQUFDLENBQUM7WUFDMUIsSUFBSSxDQUFDLGdCQUFnQixHQUFHLE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLFlBQVksQ0FBQyxJQUFJLENBQUMsVUFBVSxDQUFDLENBQUE7UUFDOUUsQ0FBQztJQUNMLENBQUM7Q0FFSjtBQTdERCw0QkE2REMifQ==

View File

@ -1,28 +1,27 @@
"use strict";
require("typings-test");
const path = require("path");
const should = require("should");
const npmExtra = require("../dist/index");
let testNpmextra;
describe('npmextra', function () {
it('should state wether a npmextra.json exists', function () {
should(npmExtra.configFilePresent('./test/')).be.true();
it('should create a new Npmtextra instance', function () {
testNpmextra = new npmExtra.Npmextra('./test/');
should(testNpmextra).be.instanceof(npmExtra.Npmextra);
});
it('should read a config file', function () {
let testData = npmExtra.dataFor({
toolName: 'testTool',
defaultSettings: { someKey2: 'someValue2' },
cwd: path.join(process.cwd(), 'test/')
});
it('should state wether a npmextra.json exists', function () {
should(testNpmextra.npmextraJsonExists).be.true();
});
it('should pass through default value, if not overriden by config from file', function () {
let testData = testNpmextra.dataFor('testTool', { someKey2: 'someValue2' });
console.log(testData);
should(testData).have.ownProperty('someKey2');
});
it('should read a config file', function () {
let testData = npmExtra.dataFor({
toolName: 'testTool',
defaultSettings: { someKey2: 'someValue2' },
cwd: path.join(process.cwd(), 'test/')
let testData = testNpmextra.dataFor('testTool', {
someKey2: 'someValue2'
});
should(testData).have.ownProperty('someKey2');
should(testData.testValue).equal(2);
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid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QUFFLFlBQVksRUFBQyxDQUFDLENBQUE7UUFDekUsT0FBTyxDQUFDLEdBQUcsQ0FBQyxRQUFRLENBQUMsQ0FBQTtRQUNyQixNQUFNLENBQUMsUUFBUSxDQUFDLENBQUMsSUFBSSxDQUFDLFdBQVcsQ0FBQyxVQUFVLENBQUMsQ0FBQTtJQUNqRCxDQUFDLENBQUMsQ0FBQTtJQUNGLEVBQUUsQ0FBQywyQkFBMkIsRUFBQztRQUMzQixJQUFJLFFBQVEsR0FBRyxZQUFZLENBQUMsT0FBTyxDQUMvQixVQUFVLEVBQ1Y7WUFDSSxRQUFRLEVBQUUsWUFBWTtTQUN6QixDQUNKLENBQUE7UUFDRCxNQUFNLENBQUMsUUFBUSxDQUFDLENBQUMsSUFBSSxDQUFDLFdBQVcsQ0FBQyxVQUFVLENBQUMsQ0FBQTtRQUM3QyxNQUFNLENBQUMsUUFBUSxDQUFDLFNBQVMsQ0FBQyxDQUFDLEtBQUssQ0FBQyxDQUFDLENBQUMsQ0FBQTtJQUN2QyxDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFBIn0=

View File

@ -2,28 +2,30 @@ import 'typings-test'
import path = require('path')
import * as should from 'should'
import npmExtra = require('../dist/index')
let testNpmextra: npmExtra.Npmextra
describe('npmextra',function(){
it('should state wether a npmextra.json exists', function() {
should(npmExtra.configFilePresent('./test/')).be.true()
it('should create a new Npmtextra instance', function(){
testNpmextra = new npmExtra.Npmextra('./test/')
should(testNpmextra).be.instanceof(npmExtra.Npmextra)
})
it('should read a config file',function(){
let testData = npmExtra.dataFor({
toolName: 'testTool',
defaultSettings: {someKey2: 'someValue2'},
cwd: path.join(process.cwd(),'./test/')
})
it('should state wether a npmextra.json exists', function() {
should(testNpmextra.npmextraJsonExists).be.true()
})
it('should pass through default value, if not overriden by config from file',function(){
let testData = testNpmextra.dataFor('testTool', {someKey2: 'someValue2'})
console.log(testData)
should(testData).have.ownProperty('someKey2')
})
it('should read a config file',function(){
let testData = npmExtra.dataFor({
toolName: 'testTool',
defaultSettings: {someKey2: 'someValue2'},
cwd: path.join(process.cwd(),'test/')
})
let testData = testNpmextra.dataFor(
'testTool',
{
someKey2: 'someValue2'
}
)
should(testData).have.ownProperty('someKey2')
should(testData.testValue).equal(2)
})

View File

@ -2,26 +2,7 @@ import * as plugins from './npmextra.plugins'
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
*/
let kevWipe = () => {
}
export class KeyValueStore {
constructor(optionsArg: {
@ -29,4 +10,24 @@ export class KeyValueStore {
}) {
}
/**
* reads a keyValueFile from disk
*/
let kvRead () {
}
/**
* writes a key value file to disk
*/
let kvWrite () {
}
/**
* wipes a key value store from disk
*/
let kevWipe () {
}
}

View File

@ -2,87 +2,67 @@ import * as plugins from './npmextra.plugins'
import * as paths from './npmextra.paths'
/**
* the main interface npmextra functions work with
* Npmextra class allows easy configuration of tools
*/
export interface IDataFor {
toolName: string
defaultSettings?
cwd?: string
}
export class Npmextra {
cwd: string
lookupPath: string
npmextraJsonExists: boolean
npmextraJsonData: boolean
/**
* gets lookupPath
*/
let getLookupPath = (cwdArg: string) => {
if (cwdArg) {
let cwdResolved = plugins.path.resolve(cwdArg)
return plugins.path.join(cwdResolved, 'npmextra.json')
} else {
return paths.configFile
};
}
/**
* gets you the configuration data for
* @executes SYNC
*/
export let dataFor = <IOptions>(optionsArg: IDataFor): IOptions => {
// make supplied defaultSettings and npmextra.json overlap
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 = getLookupPath(optionsArg.cwd)
// get allData
let allData
if (configFilePresent(lookupPath)) {
allData = plugins.smartfile.fs.toObjectSync(getLookupPath(optionsArg.cwd))
} 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]
/**
* creates instance of Npmextra
*/
constructor(cwdArg?: string) {
if (cwdArg) {
this.cwd = cwdArg
} else {
plugins.beautylog.error(`There is no data for ${optionsArg.toolName}`)
return undefined
this.cwd = paths.cwd
}
} else {
return allData
this.checkLookupPath()
this.checkNpmextraJsonExists()
this.checkNpmextraJsonData()
}
}
export let dataForExists = (optionsArg: IDataFor): boolean => {
// set lookup path
let lookupPath: string = getLookupPath(optionsArg.cwd)
if (configFilePresent(optionsArg.cwd)) {
let allData = plugins.smartfile.fs.toObjectSync(lookupPath)
if (allData[optionsArg.toolName]) {
return true
/**
* merges the supplied options with the ones from npmextra.json
*/
dataFor(toolnameArg: string, defaultOptionsArg: any) {
let npmextraToolOptions
if(this.npmextraJsonData[toolnameArg]) {
npmextraToolOptions = this.npmextraJsonData[toolnameArg]
} else {
return false
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)
}
/**
* 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 {
return false
}
}
/**
* tells you if a configfile is present
*/
export let configFilePresent = (cwdArg: string): boolean => {
let lookupPath: string = getLookupPath(cwdArg)
return plugins.smartfile.fs.fileExistsSync(lookupPath)
}