-
Notifications
You must be signed in to change notification settings - Fork 3
/
get-preset-options.js
36 lines (28 loc) · 986 Bytes
/
get-preset-options.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var fs = require("fs");
var path = require("path");
var hasOwnProperty = Object.prototype.hasOwnProperty;
module.exports = function getPresetOptions(node, packagePath)
{
var packageJSON = require(packagePath);
var hasGenericJSX = hasDependency("generic-jsx", packageJSON);
var hasReact = hasDependency("react", packageJSON);
return { node: node, "generic-jsx": hasGenericJSX, "react": hasReact };
}
function hasDependency(dependency, packageJSON)
{
if (hasPath(["isomorphic", dependency], packageJSON))
return packageJSON.isomorphic[dependency];
return hasPath(["dependencies", dependency], packageJSON) ||
hasPath(["peerDependencies", dependency], packageJSON);
}
function hasPath(path, object)
{
return !!path.reduce(function (parent, key)
{
if (!parent)
return false;
if (!hasOwnProperty.call(parent, key))
return false;
return parent[key] || { };
}, object);
}