now merges default options
This commit is contained in:
parent
dc53498f22
commit
93bbe75f37
7
dist/index.d.ts
vendored
7
dist/index.d.ts
vendored
@ -1 +1,6 @@
|
|||||||
export declare let dataFor: (toolNameArg: string, cwdArg?: string) => any;
|
export interface IDataFor {
|
||||||
|
toolName: string;
|
||||||
|
defaultSettings?: any;
|
||||||
|
cwd?: string;
|
||||||
|
}
|
||||||
|
export declare let dataFor: (optionsArg: IDataFor) => any;
|
||||||
|
50
dist/index.js
vendored
50
dist/index.js
vendored
@ -1,26 +1,42 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
const plugins = require("./npmextra.plugins");
|
const plugins = require("./npmextra.plugins");
|
||||||
const paths = require("./npmextra.paths");
|
const paths = require("./npmextra.paths");
|
||||||
let allData;
|
exports.dataFor = (optionsArg) => {
|
||||||
exports.dataFor = (toolNameArg, cwdArg) => {
|
// handle default settings
|
||||||
if (typeof allData == "undefined") {
|
if (typeof optionsArg.toolName != undefined
|
||||||
let lookupPath;
|
&& typeof optionsArg.defaultSettings != undefined) {
|
||||||
if (cwdArg) {
|
let newDefaultOptions = {};
|
||||||
lookupPath = plugins.path.join(cwdArg, "npmextra.json");
|
newDefaultOptions[optionsArg.toolName] = optionsArg.defaultSettings;
|
||||||
}
|
optionsArg.defaultSettings = newDefaultOptions;
|
||||||
else {
|
|
||||||
lookupPath = paths.configFile;
|
|
||||||
}
|
|
||||||
;
|
|
||||||
allData = plugins.smartfile.fs.toObjectSync(plugins.path.join(lookupPath));
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
if (toolNameArg) {
|
// set lookup path
|
||||||
if (allData[toolNameArg]) {
|
let lookupPath;
|
||||||
return allData[toolNameArg];
|
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 misssing!`);
|
||||||
|
allData = {};
|
||||||
|
}
|
||||||
|
;
|
||||||
|
//assign all data
|
||||||
|
allData = plugins.lodash.merge({}, optionsArg.defaultSettings, allData);
|
||||||
|
if (optionsArg.toolName) {
|
||||||
|
if (allData[optionsArg.toolName]) {
|
||||||
|
return allData[optionsArg.toolName];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
plugins.beautylog.error(`There is no data for ${toolNameArg}`);
|
plugins.beautylog.error(`There is no data for ${optionsArg.toolName}`);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -28,4 +44,4 @@ exports.dataFor = (toolNameArg, cwdArg) => {
|
|||||||
return allData;
|
return allData;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsTUFBWSxPQUFPLFdBQU0sb0JBQ3pCLENBQUMsQ0FENEM7QUFDN0MsTUFBWSxLQUFLLFdBQU0sa0JBQWtCLENBQUMsQ0FBQTtBQUMxQyxJQUFJLE9BQU8sQ0FBQztBQUVELGVBQU8sR0FBRyxDQUFDLFdBQWtCLEVBQUMsTUFBYztJQUNuRCxFQUFFLENBQUEsQ0FBQyxPQUFPLE9BQU8sSUFBSSxXQUFXLENBQUMsQ0FBQSxDQUFDO1FBQzlCLElBQUksVUFBVSxDQUFDO1FBQ2YsRUFBRSxDQUFBLENBQUMsTUFBTSxDQUFDLENBQUEsQ0FBQztZQUNQLFVBQVUsR0FBRyxPQUFPLENBQUMsSUFBSS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QUFPLENBQUMsU0FBUyxDQUFDLElBQUksQ0FBQyxHQUFHLFVBQVUsZUFBZSxDQUFDLENBQUM7UUFDckQsT0FBTyxHQUFHLEVBQUUsQ0FBQztJQUNqQixDQUFDO0lBQUEsQ0FBQztJQUVGLGlCQUFpQjtJQUNqQixPQUFPLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxLQUFLLENBQUMsRUFBRSxFQUFDLFVBQVUsQ0FBQyxlQUFlLEVBQUMsT0FBTyxDQUFDLENBQUM7SUFDdEUsRUFBRSxDQUFBLENBQUMsVUFBVSxDQUFDLFFBQVEsQ0FBQyxDQUFBLENBQUM7UUFDcEIsRUFBRSxDQUFBLENBQUMsT0FBTyxDQUFDLFVBQVUsQ0FBQyxRQUFRLENBQUMsQ0FBQyxDQUFBLENBQUM7WUFDN0IsTUFBTSxDQUFDLE9BQU8sQ0FBQyxVQUFVLENBQUMsUUFBUSxDQUFDLENBQUM7UUFDeEMsQ0FBQztRQUFDLElBQUksQ0FBQyxDQUFDO1lBQ0osT0FBTyxDQUFDLFNBQVMsQ0FBQyxLQUFLLENBQUMsd0JBQXdCLFVBQVUsQ0FBQyxRQUFRLEVBQUUsQ0FBQyxDQUFDO1lBQ3ZFLE1BQU0sQ0FBQyxTQUFTLENBQUM7UUFDckIsQ0FBQztJQUNMLENBQUM7SUFBQyxJQUFJLENBQUMsQ0FBQztRQUNKLE1BQU0sQ0FBQyxPQUFPLENBQUM7SUFDbkIsQ0FBQztBQUNMLENBQUMsQ0FBQSJ9
|
1
dist/npmextra.plugins.d.ts
vendored
1
dist/npmextra.plugins.d.ts
vendored
@ -1,5 +1,6 @@
|
|||||||
import "typings-global";
|
import "typings-global";
|
||||||
export import beautylog = require("beautylog");
|
export import beautylog = require("beautylog");
|
||||||
|
export import lodash = require("lodash");
|
||||||
export import path = require("path");
|
export import path = require("path");
|
||||||
export import smartfile = require("smartfile");
|
export import smartfile = require("smartfile");
|
||||||
export import q = require("q");
|
export import q = require("q");
|
||||||
|
3
dist/npmextra.plugins.js
vendored
3
dist/npmextra.plugins.js
vendored
@ -1,7 +1,8 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
require("typings-global");
|
require("typings-global");
|
||||||
exports.beautylog = require("beautylog");
|
exports.beautylog = require("beautylog");
|
||||||
|
exports.lodash = require("lodash");
|
||||||
exports.path = require("path");
|
exports.path = require("path");
|
||||||
exports.smartfile = require("smartfile");
|
exports.smartfile = require("smartfile");
|
||||||
exports.q = require("q");
|
exports.q = require("q");
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZXh0cmEucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWV4dHJhLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUNWLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDakMsWUFBSSxXQUFXLE1BQU0sQ0FBQyxDQUFDO0FBQ3ZCLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDakMsU0FBQyxXQUFXLEdBQUcsQ0FBQyxDQUFDIn0=
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZXh0cmEucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWV4dHJhLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUNWLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDakMsY0FBTSxXQUFXLFFBQVEsQ0FBQyxDQUFDO0FBQzNCLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQztBQUN2QixpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDO0FBQ2pDLFNBQUMsV0FBVyxHQUFHLENBQUMsQ0FBQyJ9
|
@ -18,13 +18,15 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/npmextra#README",
|
"homepage": "https://gitlab.com/pushrocks/npmextra#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/q": "*",
|
"@types/q": "^0.0.27",
|
||||||
"beautylog": "^5.0.14",
|
"beautylog": "^5.0.14",
|
||||||
|
"lodash": "^4.13.1",
|
||||||
"q": "^1.4.1",
|
"q": "^1.4.1",
|
||||||
"smartfile": "^4.0.10",
|
"smartfile": "^4.0.10",
|
||||||
"typings-global": "^1.0.6"
|
"typings-global": "^1.0.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/should": "^8.1.26",
|
||||||
"should": "^9.0.2",
|
"should": "^9.0.2",
|
||||||
"typings-test": "^1.0.1"
|
"typings-test": "^1.0.1"
|
||||||
}
|
}
|
||||||
|
10
test/test.js
10
test/test.js
@ -5,8 +5,12 @@ require("should");
|
|||||||
const npmExtra = require("../dist/index");
|
const npmExtra = require("../dist/index");
|
||||||
describe("npmextra", function () {
|
describe("npmextra", function () {
|
||||||
it("should read a config file", function () {
|
it("should read a config file", function () {
|
||||||
let testData = npmExtra.dataFor("testTool", path.join(process.cwd(), "test/"));
|
let testData = npmExtra.dataFor({
|
||||||
console.log(testData);
|
toolName: "testTool",
|
||||||
|
defaultSettings: { someKey2: "someValue2" },
|
||||||
|
cwd: path.join(process.cwd(), "test/")
|
||||||
|
});
|
||||||
|
testData.should.have.ownProperty("someKey2");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFF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QyxJQUFJLENBQUMsT0FBTyxDQUFDLEdBQUcsRUFBRSxFQUFDLE9BQU8sQ0FBQztTQUN4QyxDQUFDLENBQUM7UUFDSCxRQUFRLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxXQUFXLENBQUMsVUFBVSxDQUFDLENBQUM7SUFDakQsQ0FBQyxDQUFDLENBQUM7QUFDUCxDQUFDLENBQUMsQ0FBQyJ9
|
@ -6,7 +6,11 @@ import npmExtra = require("../dist/index");
|
|||||||
|
|
||||||
describe("npmextra",function(){
|
describe("npmextra",function(){
|
||||||
it("should read a config file",function(){
|
it("should read a config file",function(){
|
||||||
let testData = npmExtra.dataFor("testTool",path.join(process.cwd(),"test/"));
|
let testData = npmExtra.dataFor({
|
||||||
console.log(testData);
|
toolName:"testTool",
|
||||||
|
defaultSettings:{someKey2:"someValue2"},
|
||||||
|
cwd: path.join(process.cwd(),"test/")
|
||||||
|
});
|
||||||
|
testData.should.have.ownProperty("someKey2");
|
||||||
});
|
});
|
||||||
});
|
});
|
56
ts/index.ts
56
ts/index.ts
@ -1,24 +1,48 @@
|
|||||||
import * as plugins from "./npmextra.plugins"
|
import * as plugins from "./npmextra.plugins"
|
||||||
import * as paths from "./npmextra.paths";
|
import * as paths from "./npmextra.paths";
|
||||||
let allData;
|
|
||||||
|
|
||||||
export let dataFor = (toolNameArg:string,cwdArg?:string) => {
|
export interface IDataFor {
|
||||||
if(typeof allData == "undefined"){
|
toolName:string;
|
||||||
let lookupPath;
|
defaultSettings?;
|
||||||
if(cwdArg){
|
cwd?:string
|
||||||
lookupPath = plugins.path.join(cwdArg,"npmextra.json");
|
}
|
||||||
} else {
|
|
||||||
lookupPath = paths.configFile;
|
export let dataFor = (optionsArg:IDataFor) => {
|
||||||
};
|
|
||||||
allData = plugins.smartfile.fs.toObjectSync(
|
// handle default settings
|
||||||
plugins.path.join(lookupPath)
|
if(
|
||||||
);
|
typeof optionsArg.toolName != undefined
|
||||||
|
&& typeof optionsArg.defaultSettings != undefined
|
||||||
|
){
|
||||||
|
let newDefaultOptions = {};
|
||||||
|
newDefaultOptions[optionsArg.toolName] = optionsArg.defaultSettings;
|
||||||
|
optionsArg.defaultSettings = newDefaultOptions;
|
||||||
};
|
};
|
||||||
if(toolNameArg){
|
|
||||||
if(allData[toolNameArg]){
|
// set lookup path
|
||||||
return allData[toolNameArg];
|
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 misssing!`);
|
||||||
|
allData = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
//assign all data
|
||||||
|
allData = plugins.lodash.merge({},optionsArg.defaultSettings,allData);
|
||||||
|
if(optionsArg.toolName){
|
||||||
|
if(allData[optionsArg.toolName]){
|
||||||
|
return allData[optionsArg.toolName];
|
||||||
} else {
|
} else {
|
||||||
plugins.beautylog.error(`There is no data for ${toolNameArg}`);
|
plugins.beautylog.error(`There is no data for ${optionsArg.toolName}`);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import "typings-global";
|
import "typings-global";
|
||||||
export import beautylog = require("beautylog");
|
export import beautylog = require("beautylog");
|
||||||
|
export import lodash = require("lodash");
|
||||||
export import path = require("path");
|
export import path = require("path");
|
||||||
export import smartfile = require("smartfile");
|
export import smartfile = require("smartfile");
|
||||||
export import q = require("q");
|
export import q = require("q");
|
||||||
|
Loading…
Reference in New Issue
Block a user