npmextra/dist/npmextra.classes.npmextra.js

68 lines
3.8 KiB
JavaScript
Raw Normal View History

2016-09-24 14:44:48 +00:00
"use strict";
2017-03-18 15:23:47 +00:00
Object.defineProperty(exports, "__esModule", { value: true });
2016-09-24 14:44:48 +00:00
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 = {};
}
2017-07-12 15:13:29 +00:00
let mergedOptions = plugins.smartlodash.merge({}, defaultOptionsArg, npmextraToolOptions);
2016-09-24 14:44:48 +00:00
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);
}
2016-09-25 11:12:16 +00:00
else {
this.npmextraJsonData = {};
}
2016-09-24 14:44:48 +00:00
}
}
exports.Npmextra = Npmextra;
2017-07-12 15:13:29 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZXh0cmEuY2xhc3Nlcy5ucG1leHRyYS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3R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