npmextra/dist/index.js

50 lines
3.6 KiB
JavaScript
Raw Normal View History

2016-07-16 23:23:22 +00:00
"use strict";
const plugins = require("./npmextra.plugins");
const paths = require("./npmextra.paths");
2016-07-17 14:34:31 +00:00
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;
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 {
2016-07-17 15:10:53 +00:00
plugins.beautylog.warn(`${lookupPath} is missing!`);
2016-07-17 14:34:31 +00:00
allData = {};
2016-07-16 23:23:22 +00:00
}
;
2016-07-17 14:34:31 +00:00
//assign all data
allData = plugins.lodash.merge({}, optionsArg.defaultSettings, allData);
if (optionsArg.toolName) {
if (allData[optionsArg.toolName]) {
return allData[optionsArg.toolName];
2016-07-16 23:23:22 +00:00
}
else {
2016-07-17 14:34:31 +00:00
plugins.beautylog.error(`There is no data for ${optionsArg.toolName}`);
2016-07-16 23:23:22 +00:00
return undefined;
}
}
else {
return allData;
}
};
exports.configFilePresent = () => {
return plugins.smartfile.fs.fileExistsSync(paths.configFile);
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsTUFBWSxPQUFPLFdBQU0sb0JBQ3pCLENBQUMsQ0FENEM7QUFDN0MsTUFBWSxLQUFLLFdBQU0sa0JBQWtCLENBQUMsQ0FBQTtBQVEvQixl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