Skip to content

Commit

Permalink
feat(cli): support auto-update params
Browse files Browse the repository at this point in the history
  • Loading branch information
cpselvis committed Apr 9, 2020
1 parent 2e1fdd9 commit 115e742
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/feflow-cli/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export default class Feflow {
} else {
await this.initClient();
await this.initPackageManager();
if (!this.args['disable-check']) {
const disableCheck = !this.args['disable-check'] && !(this.config.disableCheck === 'true');
if (disableCheck) {
await this.checkCliUpdate();
await this.checkUpdate();
}
Expand Down Expand Up @@ -321,19 +322,24 @@ export default class Feflow {
})
}

async checkCliUpdate() {
const { version, config, configPath } = this;
async checkCliUpdate() {
const { args, version, config, configPath } = this;
if (!config) {
return;
}
const packageManager = config.packageManager;
const autoUpdate = args['auto-update'] || config.autoUpdate === 'true';
if (autoUpdate) {
return await this.updateCli(packageManager);
}
if (config.lastUpdateCheck && (+new Date() - parseInt(config.lastUpdateCheck, 10)) <= 1000 * 3600 * 24) {
return;
}
const packageManager = config.packageManager;
const registryUrl = await getRegistryUrl(packageManager);
const latestVersion: any = await packageJson('@feflow/cli', registryUrl).catch(() => {
this.logger.warn(`Network error, can't reach ${ registryUrl }, CLI give up verison check.`);
});

if (latestVersion && semver.gt(latestVersion, version)) {
const askIfUpdateCli = [{
type: "confirm",
Expand Down
4 changes: 4 additions & 0 deletions packages/feflow-cli/src/core/native/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ const showHelp = (commands: Array<Object>) => {
{
name: 'disable-check',
description: 'Disable @feflow/cli and installed plugins check update'
},
{
name: 'auto-update',
description: 'Auto update @feflow/cli and installed plugins'
}
]
}
Expand Down

0 comments on commit 115e742

Please sign in to comment.