update changes
This commit is contained in:
parent
002f3fc82d
commit
16150541b0
8
dist/index.d.ts
vendored
8
dist/index.d.ts
vendored
@ -1,3 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* the main interface npmextra functions work with
|
||||||
|
*/
|
||||||
export interface IDataFor {
|
export interface IDataFor {
|
||||||
toolName: string;
|
toolName: string;
|
||||||
defaultSettings?: any;
|
defaultSettings?: any;
|
||||||
@ -8,9 +11,8 @@ export interface IDataFor {
|
|||||||
* @executes SYNC
|
* @executes SYNC
|
||||||
*/
|
*/
|
||||||
export declare let dataFor: <IOptions>(optionsArg: IDataFor) => IOptions;
|
export declare let dataFor: <IOptions>(optionsArg: IDataFor) => IOptions;
|
||||||
|
export declare let dataForExists: (optionsArg: IDataFor) => boolean;
|
||||||
/**
|
/**
|
||||||
* tells you if a configfile is present
|
* tells you if a configfile is present
|
||||||
*/
|
*/
|
||||||
export declare let configFilePresent: (optionsArg: {
|
export declare let configFilePresent: (cwdArg: string) => boolean;
|
||||||
cwd?: string;
|
|
||||||
}) => boolean;
|
|
||||||
|
53
dist/index.js
vendored
53
dist/index.js
vendored
@ -1,6 +1,19 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
const plugins = require("./npmextra.plugins");
|
const plugins = require("./npmextra.plugins");
|
||||||
const paths = require("./npmextra.paths");
|
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
|
* gets you the configuration data for
|
||||||
* @executes SYNC
|
* @executes SYNC
|
||||||
@ -15,17 +28,10 @@ exports.dataFor = (optionsArg) => {
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
// set lookup path
|
// set lookup path
|
||||||
let lookupPath;
|
let lookupPath = getLookupPath(optionsArg.cwd);
|
||||||
if (optionsArg.cwd) {
|
|
||||||
lookupPath = plugins.path.join(optionsArg.cwd, 'npmextra.json');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
lookupPath = paths.configFile;
|
|
||||||
}
|
|
||||||
;
|
|
||||||
// get allData
|
// get allData
|
||||||
let allData;
|
let allData;
|
||||||
if (plugins.smartfile.fs.fileExistsSync(lookupPath)) {
|
if (exports.configFilePresent(lookupPath)) {
|
||||||
allData = plugins.smartfile.fs.toObjectSync(lookupPath);
|
allData = plugins.smartfile.fs.toObjectSync(lookupPath);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -48,18 +54,27 @@ exports.dataFor = (optionsArg) => {
|
|||||||
return allData;
|
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
|
* tells you if a configfile is present
|
||||||
*/
|
*/
|
||||||
exports.configFilePresent = (optionsArg) => {
|
exports.configFilePresent = (cwdArg) => {
|
||||||
let lookupPath;
|
let lookupPath = getLookupPath(cwdArg);
|
||||||
if (optionsArg.cwd) {
|
|
||||||
lookupPath = plugins.path.join(optionsArg.cwd, 'npmextra.json');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
lookupPath = paths.configFile;
|
|
||||||
}
|
|
||||||
;
|
|
||||||
return plugins.smartfile.fs.fileExistsSync(lookupPath);
|
return plugins.smartfile.fs.fileExistsSync(lookupPath);
|
||||||
};
|
};
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsOENBQTZDO0FBQzdDLDBDQUF5QztBQVF6Qzs7O0dBR0c7QUFDUSxRQUFBLE9BQU8sR0FBRyxDQUFXLFVBQW9CO0lBRWhELDBCQUEwQjtJQUMxQixFQUFFLENBQUMsQ0FDQyxPQUFPLFVBQVUsQ0FBQyxRQUFRLEtBQUssU0FBUztXQUNyQyxPQUFPLFVBQVUsQ0FBQyxlQUFlLEtBQUssU0FDN0MsQ0FBQyxDQUFDLENBQUM7UUFDQyxJQUFJLGlCQUFpQixHQUFHLEVBQUUsQ0FBQTtRQUMxQixpQkFBaUIsQ0FBQyxVQUFVLENBQUMsUUFBUSxDQUFDLEdBQUcsVUFBVSxDQUFDLGVBQWUsQ0FBQTtRQUNuRSxVQUFVLENBQUMsZUFBZSxHQUFHLGlCQUFpQixDQUFBO0lBQ2xELENBQUM7SUFBQSxDQUFDO0lBRUYsa0JBQWtCO0lBQ2xCLElBQUksVUFBa0IsQ0FBQTtJQUN0QixFQUFFLENBQUMsQ0FBQyxVQUFVLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQztRQUNqQixVQUFVLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsVUFBVSxDQUFDLEdBQUcsRUFBQyxlQUFlLENBQUMsQ0FBQTtJQUNsRSxDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDSixVQUFVLEdBQUcsS0FBSyxDQUFDLFVBQVUsQ0FBQTtJQUNqQyxDQUFDO0lBQUEsQ0FBQztJQUVGLGNBQWM7SU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M7WUFDL0IsTUFBTSxDQUFDLElBQUksQ0FBQTtRQUNmLENBQUM7UUFBQyxJQUFJLENBQUMsQ0FBQztZQUNKLE1BQU0sQ0FBQyxLQUFLLENBQUE7UUFDaEIsQ0FBQztJQUNMLENBQUM7SUFBQyxJQUFJLENBQUMsQ0FBQztRQUNKLE1BQU0sQ0FBQyxLQUFLLENBQUE7SUFDaEIsQ0FBQztBQUNMLENBQUMsQ0FBQTtBQUVEOztHQUVHO0FBQ1EsUUFBQSxpQkFBaUIsR0FBRyxDQUFDLE1BQWM7SUFDMUMsSUFBSSxVQUFVLEdBQVcsYUFBYSxDQUFDLE1BQU0sQ0FBQyxDQUFBO0lBQzlDLE1BQU0sQ0FBQyxPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxjQUFjLENBQUMsVUFBVSxDQUFDLENBQUE7QUFDMUQsQ0FBQyxDQUFBIn0=
|
12
package.json
12
package.json
@ -19,15 +19,15 @@
|
|||||||
"homepage": "https://gitlab.com/pushrocks/npmextra#README",
|
"homepage": "https://gitlab.com/pushrocks/npmextra#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/q": "^0.x.x",
|
"@types/q": "^0.x.x",
|
||||||
"beautylog": "^5.0.20",
|
"beautylog": "^5.0.23",
|
||||||
"lodash": "^4.15.0",
|
"lodash": "^4.16.1",
|
||||||
"q": "^1.4.1",
|
"q": "^1.4.1",
|
||||||
"smartfile": "^4.0.13",
|
"smartfile": "^4.0.20",
|
||||||
"typings-global": "^1.0.6"
|
"typings-global": "^1.0.14"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/should": "^8.1.27",
|
"@types/should": "^8.1.30",
|
||||||
"should": "^11.1.0",
|
"should": "^11.1.0",
|
||||||
"typings-test": "^1.0.1"
|
"typings-test": "^1.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3
test/test.d.ts
vendored
3
test/test.d.ts
vendored
@ -1,2 +1 @@
|
|||||||
import "typings-test";
|
import 'typings-test';
|
||||||
import "should";
|
|
||||||
|
31
test/test.js
31
test/test.js
@ -1,25 +1,28 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
require("typings-test");
|
require("typings-test");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
require("should");
|
const should = 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 state wether a npmextra.json exists', function () {
|
||||||
|
should(npmExtra.configFilePresent('./test/')).be.true();
|
||||||
|
});
|
||||||
|
it('should read a config file', function () {
|
||||||
let testData = npmExtra.dataFor({
|
let testData = npmExtra.dataFor({
|
||||||
toolName: "testTool",
|
toolName: 'testTool',
|
||||||
defaultSettings: { someKey2: "someValue2" },
|
defaultSettings: { someKey2: 'someValue2' },
|
||||||
cwd: path.join(process.cwd(), "test/")
|
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({
|
let testData = npmExtra.dataFor({
|
||||||
toolName: "testTool",
|
toolName: 'testTool',
|
||||||
defaultSettings: { someKey2: "someValue2" },
|
defaultSettings: { someKey2: 'someValue2' },
|
||||||
cwd: path.join(process.cwd(), "test/")
|
cwd: path.join(process.cwd(), 'test/')
|
||||||
});
|
});
|
||||||
testData.should.have.ownProperty("someKey2");
|
should(testData).have.ownProperty('someKey2');
|
||||||
testData.testValue.should.equal(2);
|
should(testData.testValue).equal(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmF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Q0FBQyxPQUFPLENBQUMsR0FBRyxFQUFFLEVBQUMsT0FBTyxDQUFDO1NBQ3hDLENBQUMsQ0FBQTtRQUNGLE1BQU0sQ0FBQyxRQUFRLENBQUMsQ0FBQyxJQUFJLENBQUMsV0FBVyxDQUFDLFVBQVUsQ0FBQyxDQUFBO1FBQzdDLE1BQU0sQ0FBQyxRQUFRLENBQUMsU0FBUyxDQUFDLENBQUMsS0FBSyxDQUFDLENBQUMsQ0FBQyxDQUFBO0lBQ3ZDLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==
|
47
test/test.ts
47
test/test.ts
@ -1,25 +1,30 @@
|
|||||||
import "typings-test";
|
import 'typings-test'
|
||||||
import path = require("path");
|
import path = require('path')
|
||||||
import "should";
|
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({
|
let testData = npmExtra.dataFor({
|
||||||
toolName:"testTool",
|
toolName: 'testTool',
|
||||||
defaultSettings:{someKey2:"someValue2"},
|
defaultSettings: {someKey2: 'someValue2'},
|
||||||
cwd: path.join(process.cwd(),"test/")
|
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({
|
let testData = npmExtra.dataFor({
|
||||||
toolName:"testTool",
|
toolName: 'testTool',
|
||||||
defaultSettings:{someKey2:"someValue2"},
|
defaultSettings: {someKey2: 'someValue2'},
|
||||||
cwd: path.join(process.cwd(),"test/")
|
cwd: path.join(process.cwd(),'test/')
|
||||||
});
|
})
|
||||||
testData.should.have.ownProperty("someKey2");
|
should(testData).have.ownProperty('someKey2')
|
||||||
testData.testValue.should.equal(2);
|
should(testData.testValue).equal(2)
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
68
ts/index.ts
68
ts/index.ts
@ -1,68 +1,4 @@
|
|||||||
import * as plugins from './npmextra.plugins'
|
import * as plugins from './npmextra.plugins'
|
||||||
import * as paths from './npmextra.paths'
|
|
||||||
|
|
||||||
export interface IDataFor {
|
export * from './npmextra.classes.npmextra'
|
||||||
toolName: string
|
export * from './npmextra.classes.keyvaluestore'
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
88
ts/npmextra.classes.npmextra.ts
Normal file
88
ts/npmextra.classes.npmextra.ts
Normal 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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user