mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
Simplify promises in cli/api.js (#3198)
This commit is contained in:
parent
51db83c581
commit
27c1893fb8
1 changed files with 21 additions and 29 deletions
50
cli/api.js
50
cli/api.js
|
|
@ -90,40 +90,32 @@ function getPackageName(plugin) {
|
||||||
|
|
||||||
function install(plugin, locally) {
|
function install(plugin, locally) {
|
||||||
const array = locally ? getLocalPlugins() : getPlugins();
|
const array = locally ? getLocalPlugins() : getPlugins();
|
||||||
return new Promise((resolve, reject) => {
|
return existsOnNpm(plugin)
|
||||||
existsOnNpm(plugin)
|
.catch(err => {
|
||||||
.then(() => {
|
const {statusCode} = err;
|
||||||
if (isInstalled(plugin, locally)) {
|
if (statusCode && (statusCode === 404 || statusCode === 200)) {
|
||||||
return reject(`${plugin} is already installed`);
|
return Promise.reject(`${plugin} not found on npm`);
|
||||||
}
|
}
|
||||||
|
return Promise.reject(`${err.message}\nPlugin check failed. Check your internet connection or retry later.`);
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
if (isInstalled(plugin, locally)) {
|
||||||
|
return Promise.reject(`${plugin} is already installed`);
|
||||||
|
}
|
||||||
|
|
||||||
array.push(recast.types.builders.literal(plugin));
|
array.push(recast.types.builders.literal(plugin));
|
||||||
save()
|
return save();
|
||||||
.then(resolve)
|
});
|
||||||
.catch(err => reject(err));
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
const {statusCode} = err;
|
|
||||||
if (statusCode && (statusCode === 404 || statusCode === 200)) {
|
|
||||||
return reject(`${plugin} not found on npm`);
|
|
||||||
}
|
|
||||||
return reject(`${err.message}\nPlugin check failed. Check your internet connection or retry later.`);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function uninstall(plugin) {
|
function uninstall(plugin) {
|
||||||
return new Promise((resolve, reject) => {
|
if (!isInstalled(plugin)) {
|
||||||
if (!isInstalled(plugin)) {
|
return Promise.reject(`${plugin} is not installed`);
|
||||||
return reject(`${plugin} is not installed`);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const index = getPlugins().findIndex(entry => entry.value === plugin);
|
const index = getPlugins().findIndex(entry => entry.value === plugin);
|
||||||
getPlugins().splice(index, 1);
|
getPlugins().splice(index, 1);
|
||||||
save()
|
return save();
|
||||||
.then(resolve)
|
|
||||||
.catch(err => reject(err));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function list() {
|
function list() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue