Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC auto update the CLI #1196

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion packages/cli/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
const yargs = require('yargs');
const updateNotifier = require('update-notifier');
const chalk = require('chalk');
const { exec: execAsync } = require('child_process');
const util = require('util');

const { logger } = require('@hubspot/local-dev-lib/logger');
const { addUserAgentHeader } = require('@hubspot/local-dev-lib/http');
Expand All @@ -17,6 +19,7 @@ const pkg = require('../package.json');
const { i18n } = require('../lib/lang');
const { EXIT_CODES } = require('../lib/enums/exitCodes');
const { UI_COLORS, uiCommandReference } = require('../lib/ui');
const SpinniesManager = require('../lib/ui/SpinniesManager');

const removeCommand = require('../commands/remove');
const initCommand = require('../commands/init');
Expand Down Expand Up @@ -134,9 +137,36 @@ const setRequestHeaders = () => {
addUserAgentHeader('HubSpot CLI', pkg.version);
};

const updateCLIVersion = async () => {
if (
!process.env.BYPASS_HUBSPOT_CLI_AUTO_UPDATES &&
notifier &&
notifier.shouldNotifyInNpmScript
) {
const updateInfo = await notifier.fetchInfo();
SpinniesManager.init({
succeedColor: 'white',
});
SpinniesManager.add('cliAutoUpdate', {
text: `New HubSpot CLI version available. Updating to version ${updateInfo.latest}`,
});
const exec = util.promisify(execAsync);
try {
await exec(`npm install -g @hubspot/cli@latest`);
SpinniesManager.succeed('cliAutoUpdate', {
text: `Successfully updated HubSpot CLI to version ${updateInfo.latest}`,
});
} catch (e) {
SpinniesManager.fail('cliAutoUpdate', {
text: `Failed to update HubSpot CLI to version ${updateInfo.latest}`,
});
}
}
};

const argv = yargs
.usage('The command line interface to interact with HubSpot.')
.middleware([setLogLevel, setRequestHeaders])
.middleware([setLogLevel, setRequestHeaders, updateCLIVersion])
.exitProcess(false)
.fail(handleFailure)
.option('debug', {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hubspot/cli",
"version": "6.2.0",
"version": "6.1.0",
"description": "CLI for working with HubSpot",
"license": "Apache-2.0",
"repository": {
Expand Down
Loading