Skip to content

Commit

Permalink
fix: install packages when not exists (#161) (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpselvis authored Nov 28, 2019
1 parent 22af6ec commit 721f1d8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/feflow-cli/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ export default class Feflow {
const pkg: any = JSON.parse(content);
const localVersion = pkg.version;
const registryUrl = await getRegistryUrl(packageManager);
const latestVersion = await packageJson(name, 'latest', registryUrl);
const latestVersion = await packageJson(name, 'latest', registryUrl).catch((err) => {
logger.debug('Check plugin update error', err);
});

if (latestVersion !== localVersion) {
table.cell('Name', name);
Expand Down
20 changes: 18 additions & 2 deletions packages/feflow-cli/src/core/native/install.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
import { install } from '../../shared/npm';
import {
getRegistryUrl,
install
} from '../../shared/npm';
import packageJson from '../../shared/packageJson';

module.exports = (ctx: any) => {
const packageManager = ctx.config && ctx.config.packageManager;
ctx.commander.register('install', 'Install a devkit or plugin', () => {
ctx.commander.register('install', 'Install a devkit or plugin', async () => {
const registryUrl = await getRegistryUrl(packageManager);
const dependencies = ctx.args['_'];

await Promise.all(
dependencies.map((dependency: string) => {
return packageJson(dependency, 'latest', registryUrl)
.catch(() => {
ctx.logger.error(`${ dependency } not found on ${ packageManager }`);
process.exit(2);
});
})
);

ctx.logger.info('Installing packages. This might take a couple of minutes.');

return install(
Expand Down
2 changes: 1 addition & 1 deletion packages/feflow-cli/src/shared/packageJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function packageJson(name: string, version: string, registry: str
resolve(response.version);
})
.catch((err: object) => {
resolve(err);
reject(err);
});
});
}

0 comments on commit 721f1d8

Please sign in to comment.