mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-15 21:28:40 -09:00
syntax fixes in cli/api.js
This commit is contained in:
parent
8931ce486b
commit
a4e2c791a9
1 changed files with 23 additions and 17 deletions
40
cli/api.js
40
cli/api.js
|
|
@ -56,23 +56,29 @@ const getParsedFile = memoize(() => recast.parse(getFileContents()));
|
||||||
const getProperties = memoize(() => getParsedFile().program.body.map(obj => obj));
|
const getProperties = memoize(() => getParsedFile().program.body.map(obj => obj));
|
||||||
|
|
||||||
const getPlugins = memoize(() => {
|
const getPlugins = memoize(() => {
|
||||||
let plugins;
|
const properties = getProperties();
|
||||||
getProperties().find(property => {
|
for (let i = 0; i < properties.length; i++) {
|
||||||
return Object.values(property.expression.right.properties).filter(plugin =>
|
const rightProperties = Object.values(properties[i].expression.right.properties);
|
||||||
plugin.key.name === 'plugins' ? (plugins = plugin.value.elements) : null
|
for (let j = 0; j < rightProperties.length; j++) {
|
||||||
);
|
const plugin = rightProperties[j];
|
||||||
});
|
if (plugin.key.name === 'plugins') {
|
||||||
return plugins;
|
return plugin.value.elements;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const getLocalPlugins = memoize(() => {
|
const getLocalPlugins = memoize(() => {
|
||||||
let localPlugins;
|
const properties = getProperties();
|
||||||
getProperties().find(property => {
|
for (let i = 0; i < properties.length; i++) {
|
||||||
return Object.values(property.expression.right.properties).filter(plugin =>
|
const rightProperties = Object.values(properties[i].expression.right.properties);
|
||||||
plugin.key.name === 'localPlugins' ? (localPlugins = plugin.value.elements) : null
|
for (let j = 0; j < rightProperties.length; j++) {
|
||||||
);
|
const plugin = rightProperties[j];
|
||||||
});
|
if (plugin.key.name === 'localPlugins') {
|
||||||
return localPlugins;
|
return plugin.value.elements;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function exists() {
|
function exists() {
|
||||||
|
|
@ -80,9 +86,9 @@ function exists() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function isInstalled(plugin, locally) {
|
function isInstalled(plugin, locally) {
|
||||||
const array = locally ? getLocalPlugins() : getPlugins();
|
const array = (locally ? getLocalPlugins() : getPlugins()) || [];
|
||||||
if (array && Array.isArray(array)) {
|
if (array && Array.isArray(array)) {
|
||||||
return array.find(entry => entry.value === plugin) !== undefined;
|
return array.some(entry => entry.value === plugin);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -114,7 +120,7 @@ function getPackageName(plugin) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function install(plugin, locally) {
|
function install(plugin, locally) {
|
||||||
const array = locally ? getLocalPlugins() : getPlugins();
|
const array = (locally ? getLocalPlugins() : getPlugins()) || [];
|
||||||
return existsOnNpm(plugin)
|
return existsOnNpm(plugin)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
const {statusCode} = err;
|
const {statusCode} = err;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue