update changes

This commit is contained in:
Philipp Kunz 2016-09-23 22:13:06 +02:00
parent 002f3fc82d
commit 16150541b0
9 changed files with 181 additions and 133 deletions

8
dist/index.d.ts vendored
View File

@ -1,3 +1,6 @@
/**
* the main interface npmextra functions work with
*/
export interface IDataFor {
toolName: string;
defaultSettings?: any;
@ -8,9 +11,8 @@ export interface IDataFor {
* @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: (optionsArg: {
cwd?: string;
}) => boolean;
export declare let configFilePresent: (cwdArg: string) => boolean;

53
dist/index.js vendored
View File

@ -1,6 +1,19 @@
"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
@ -15,17 +28,10 @@ exports.dataFor = (optionsArg) => {
}
;
// set lookup path
let lookupPath;
if (optionsArg.cwd) {
lookupPath = plugins.path.join(optionsArg.cwd, 'npmextra.json');
}
else {
lookupPath = paths.configFile;
}
;
let lookupPath = getLookupPath(optionsArg.cwd);
// get allData
let allData;
if (plugins.smartfile.fs.fileExistsSync(lookupPath)) {
if (exports.configFilePresent(lookupPath)) {
allData = plugins.smartfile.fs.toObjectSync(lookupPath);
}
else {
@ -48,18 +54,27 @@ exports.dataFor = (optionsArg) => {
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 = (optionsArg) => {
let lookupPath;
if (optionsArg.cwd) {
lookupPath = plugins.path.join(optionsArg.cwd, 'npmextra.json');
}
else {
lookupPath = paths.configFile;
}
;
exports.configFilePresent = (cwdArg) => {
let lookupPath = getLookupPath(cwdArg);
return plugins.smartfile.fs.fileExistsSync(lookupPath);
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsOENBQTZDO0FBQzdDLDBDQUF5QztBQVF6Qzs7O0dBR0c7QUFDUSxRQUFBLE9BQU8sR0FBRyxDQUFXLFVBQW9CO0lBRWhELDBCQUEwQjtJQUMxQixFQUFFLENBQUMsQ0FDQyxPQUFPLFVBQVUsQ0FBQyxRQUFRLEtBQUssU0FBUztXQUNyQyxPQUFPLFVBQVUsQ0FBQyxlQUFlLEtBQUssU0FDN0MsQ0FBQyxDQUFDLENBQUM7UUFDQyxJQUFJLGlCQUFpQixHQUFHLEVBQUUsQ0FBQTtRQUMxQixpQkFBaUIsQ0FBQyxVQUFVLENBQUMsUUFBUSxDQUFDLEdBQUcsVUFBVSxDQUFDLGVBQWUsQ0FBQTtRQUNuRSxVQUFVLENBQUMsZUFBZSxHQUFHLGlCQUFpQixDQUFBO0lBQ2xELENBQUM7SUFBQSxDQUFDO0lBRUYsa0JBQWtCO0lBQ2xCLElBQUksVUFBa0IsQ0FBQTtJQUN0QixFQUFFLENBQUMsQ0FBQyxVQUFVLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQztRQUNqQixVQUFVLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsVUFBVSxDQUFDLEdBQUcsRUFBQyxlQUFlLENBQUMsQ0FBQTtJQUNsRSxDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDSixVQUFVLEdBQUcsS0FBSyxDQUF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T0FBTyxDQUFDLFVBQVUsQ0FBQyxRQUFRLENBQUMsQ0FBQyxDQUFDLENBQUM7WUFDL0IsTUFBTSxDQUFDLElBQUksQ0FBQTtRQUNmLENBQUM7UUFBQyxJQUFJLENBQUMsQ0FBQztZQUNKLE1BQU0sQ0FBQyxLQUFLLENBQUE7UUFDaEIsQ0FBQztJQUNMLENBQUM7SUFBQyxJQUFJLENBQUMsQ0FBQztRQUNKLE1BQU0sQ0FBQyxLQUFLLENBQUE7SUFDaEIsQ0FBQztBQUNMLENBQUMsQ0FBQTtBQUVEOztHQUVHO0FBQ1EsUUFBQSxpQkFBaUIsR0FBRyxDQUFDLE1BQWM7SUFDMUMsSUFBSSxVQUFVLEdBQVcsYUFBYSxDQUFDLE1BQU0sQ0FBQyxDQUFBO0lBQzlDLE1BQU0sQ0FBQyxPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxjQUFjLENBQUMsVUFBVSxDQUFDLENBQUE7QUFDMUQsQ0FBQyxDQUFBIn0=

View File

@ -19,15 +19,15 @@
"homepage": "https://gitlab.com/pushrocks/npmextra#README",
"dependencies": {
"@types/q": "^0.x.x",
"beautylog": "^5.0.20",
"lodash": "^4.15.0",
"beautylog": "^5.0.23",
"lodash": "^4.16.1",
"q": "^1.4.1",
"smartfile": "^4.0.13",
"typings-global": "^1.0.6"
"smartfile": "^4.0.20",
"typings-global": "^1.0.14"
},
"devDependencies": {
"@types/should": "^8.1.27",
"@types/should": "^8.1.30",
"should": "^11.1.0",
"typings-test": "^1.0.1"
"typings-test": "^1.0.3"
}
}

3
test/test.d.ts vendored
View File

@ -1,2 +1 @@
import "typings-test";
import "should";
import 'typings-test';

View File

@ -1,25 +1,28 @@
"use strict";
require("typings-test");
const path = require("path");
require("should");
const should = require("should");
const npmExtra = require("../dist/index");
describe("npmextra", function () {
it("should read a config file", function () {
describe('npmextra', function () {
it('should state wether a npmextra.json exists', function () {
should(npmExtra.configFilePresent('./test/')).be.true();
});
it('should read a config file', function () {
let testData = npmExtra.dataFor({
toolName: "testTool",
defaultSettings: { someKey2: "someValue2" },
cwd: path.join(process.cwd(), "test/")
toolName: 'testTool',
defaultSettings: { someKey2: 'someValue2' },
cwd: path.join(process.cwd(), 'test/')
});
testData.should.have.ownProperty("someKey2");
should(testData).have.ownProperty('someKey2');
});
it("should read a config file", function () {
it('should read a config file', function () {
let testData = npmExtra.dataFor({
toolName: "testTool",
defaultSettings: { someKey2: "someValue2" },
cwd: path.join(process.cwd(), "test/")
toolName: 'testTool',
defaultSettings: { someKey2: 'someValue2' },
cwd: path.join(process.cwd(), 'test/')
});
testData.should.have.ownProperty("someKey2");
testData.testValue.should.equal(2);
should(testData).have.ownProperty('someKey2');
should(testData.testValue).equal(2);
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFzQjtBQUN0Qiw2QkFBOEI7QUFDOUIsa0JBQWdCO0FBRWhCLDBDQUEyQztBQUUzQyxRQUFRLENBQUMsVUFBVSxFQUFDO0lBQ2hCLEVBQUUsQ0FBQywyQkFBMkIsRUFBQztRQUMzQixJQUFJLFFBQVEsR0FBRyxRQUFRLENBQUMsT0FBTyxDQUFDO1lBQzVCLFFBQVEsRUFBQyxVQUFVO1lBQ25CLGVBQWUsRUFBQyxFQUFDLFFBQVEsRUFBQyxZQUFZLEVBQUM7WUFDdkMsR0FBRyxFQUFFLElBQUksQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLEdBQUcsRUFBRSxFQUFDLE9BQU8sQ0FBQztTQUN4QyxDQUFDLENBQUM7UUFDSCxRQUFRLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxXQUFXLENBQUMsVUFBVSxDQUFDLENBQUM7SUFDakQsQ0FBQyxDQUFDLENBQUM7SUFDSCxFQU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VU7WUFDcEIsZUFBZSxFQUFFLEVBQUMsUUFBUSxFQUFFLFlBQVksRUFBQztZQUN6QyxHQUFHLEVBQUUsSUFBSSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsR0FBRyxFQUFFLEVBQUMsT0FBTyxDQUFDO1NBQ3hDLENBQUMsQ0FBQTtRQUNGLE1BQU0sQ0FBQyxRQUFRLENBQUMsQ0FBQyxJQUFJLENBQUMsV0FBVyxDQUFDLFVBQVUsQ0FBQyxDQUFBO0lBQ2pELENBQUMsQ0FBQyxDQUFBO0lBQ0YsRUFBRSxDQUFDLDJCQUEyQixFQUFDO1FBQzNCLElBQUksUUFBUSxHQUFHLFFBQVEsQ0FBQyxPQUFPLENBQUM7WUFDNUIsUUFBUSxFQUFFLFVBQVU7WUFDcEIsZUFBZSxFQUFFLEVBQUMsUUFBUSxFQUFFLFlBQVksRUFBQztZQUN6QyxHQUFHLEVBQUUsSUFBSSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsR0FBRyxFQUFFLEVBQUMsT0FBTyxDQUFDO1NBQ3hDLENBQUMsQ0FBQTtRQUNGLE1BQU0sQ0FBQyxRQUFRLENBQUMsQ0FBQyxJQUFJLENBQUMsV0FBVyxDQUFDLFVBQVUsQ0FBQyxDQUFBO1FBQzdDLE1BQU0sQ0FBQyxRQUFRLENBQUMsU0FBUyxDQUFDLENBQUMsS0FBSyxDQUFDLENBQUMsQ0FBQyxDQUFBO0lBQ3ZDLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==

View File

@ -1,25 +1,30 @@
import "typings-test";
import path = require("path");
import "should";
import 'typings-test'
import path = require('path')
import * as should from 'should'
import npmExtra = require("../dist/index");
describe("npmextra",function(){
it("should read a config file",function(){
import npmExtra = require('../dist/index')
describe('npmextra',function(){
it('should state wether a npmextra.json exists', function() {
should(npmExtra.configFilePresent('./test/')).be.true()
})
it('should read a config file',function(){
let testData = npmExtra.dataFor({
toolName:"testTool",
defaultSettings:{someKey2:"someValue2"},
cwd: path.join(process.cwd(),"test/")
});
testData.should.have.ownProperty("someKey2");
});
it("should read a config file",function(){
toolName: 'testTool',
defaultSettings: {someKey2: 'someValue2'},
cwd: path.join(process.cwd(),'./test/')
})
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/")
});
testData.should.have.ownProperty("someKey2");
testData.testValue.should.equal(2);
});
});
toolName: 'testTool',
defaultSettings: {someKey2: 'someValue2'},
cwd: path.join(process.cwd(),'test/')
})
should(testData).have.ownProperty('someKey2')
should(testData.testValue).equal(2)
})
})

View File

@ -1,68 +1,4 @@
import * as plugins from './npmextra.plugins'
import * as paths from './npmextra.paths'
export interface IDataFor {
toolName: string
defaultSettings?
cwd?: string
}
/**
* 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
};
// set lookup path
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 = {}
};
// 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
}
}
/**
* 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)
}
export * from './npmextra.classes.npmextra'
export * from './npmextra.classes.keyvaluestore'

View File

@ -0,0 +1,88 @@
import * as plugins from './npmextra.plugins'
import * as paths from './npmextra.paths'
/**
* the main interface npmextra functions work with
*/
export interface IDataFor {
toolName: string
defaultSettings?
cwd?: string
}
/**
* 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]
} else {
plugins.beautylog.error(`There is no data for ${optionsArg.toolName}`)
return undefined
}
} else {
return allData
}
}
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
} else {
return false
}
} 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)
}