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

Adding File Management #138

Merged
merged 28 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
dbb4358
added button to install the CLI
miketalley Nov 21, 2022
a4daf7b
added TERMINAL_IDS constant
miketalley Nov 21, 2022
560e874
cleanup
miketalley Nov 21, 2022
04c88d0
added checks for hs and npm in terminal and logic to show install but…
miketalley Nov 21, 2022
96b7434
merged base branch and fixed conflict
miketalley Nov 30, 2022
728dbd1
Merge branch 'mike-testing' into file-management
miketalley Nov 30, 2022
4b43a05
Merge branch 'mike-testing' into file-management
miketalley Nov 30, 2022
63871c5
saving WIP changes
miketalley Nov 30, 2022
f4a83cd
saving wip
miketalley Nov 30, 2022
d762706
merged base and fixed conflict, added tools and quickLinks sections
miketalley Dec 1, 2022
45b420d
merged base branch and fixed conflicts
miketalley Dec 1, 2022
e2211ca
updated to polling for hs installation
miketalley Dec 1, 2022
39ca868
got quicklinks tree skeleton set up
miketalley Dec 2, 2022
2702d5e
merged base and fixed conflicts
miketalley Dec 2, 2022
5b8e8e7
updated quickLinks
miketalley Dec 2, 2022
a254ce1
added update CLI button
miketalley Dec 2, 2022
2c383cf
saving WIP for hiding Update button after updating
miketalley Dec 2, 2022
a75cd39
added update command to fix flow
miketalley Dec 5, 2022
f6ad341
updating variables
miketalley Dec 5, 2022
30ce617
renaming variables and adding events
miketalley Dec 5, 2022
6ebdbb8
removed terminal ids as it is no longer used
miketalley Dec 5, 2022
0a60068
removed unused code
miketalley Dec 5, 2022
f696153
added version to output when install/update is complete
miketalley Dec 5, 2022
8eb1310
Merge branch 'v1.0.0' into file-management
miketalley Dec 5, 2022
ae2f6ff
merged base and fixed conflicts
miketalley Dec 6, 2022
5431d4f
merged base and fixed conflicts
miketalley Dec 6, 2022
3b9b37e
saving package.json changes
miketalley Dec 7, 2022
4f98299
renamed quickLinks to helpAndFeedback and adjusted links
miketalley Dec 9, 2022
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
25 changes: 18 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"Linters"
],
"icon": "images/hubspot-logo.png",

"main": "./dist/extension.js",
"activationEvents": [
"onStartupFinished"
Expand Down Expand Up @@ -244,6 +243,15 @@
{
"id": "hubspot.viewsWelcome.accountAuth",
"name": "Authentication"
},
{
"id": "hubspot.viewsWelcome.tools",
"name": "Tools",
"when": "hubspot.versionChecksComplete && hubspot.terminal.versions.installed.npm && !hubspot.terminal.versions.installed.hs || hubspot.updateAvailableForCLI"
},
{
"id": "hubspot.treedata.quickLinks",
"name": "Quick Links"
}
]
},
Expand All @@ -257,11 +265,22 @@
"view": "hubspot.viewsWelcome.accountAuth",
"contents": "In order to use HubSpot VSCode features, you need to authenticate your account(s). \n[Authenticate HubSpot Account](command:hubspot.auth.onClickAuthorize)\nTo learn more about authentication using personal access keys, [read our docs](https://developers.hubspot.com/docs/cms/personal-access-key).",
"when": "hubspot.configPath"
},
{
"view": "hubspot.viewsWelcome.tools",
"contents": "In order to use additional features that are not currently available within the HubSpot VSCode extension, you can install the [HubSpot CLI](https://developers.hubspot.com/docs/cms/developer-reference/local-development-cli). \n[Install CLI](command:hubspot.hs.install)",
"when": "!hubspot.terminal.versions.installed.hs"
},
{
"view": "hubspot.viewsWelcome.tools",
"contents": "An update is available for the [HubSpot CLI](https://developers.hubspot.com/docs/cms/developer-reference/local-development-cli). \n[Update CLI](command:hubspot.hs.update)",
"when": "hubspot.updateAvailableForCLI"
}
]
},
"dependencies": {
"@hubspot/cli-lib": "^4.1.3",
"@hubspot/cli-lib": "^4.1.4-beta.0",
"compare-versions": "^5.0.1",
"fs-extra": "^9.0.1",
"js-yaml": "^4.1.0",
"node-fetch": "^3.1.1",
Expand Down
4 changes: 4 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ import { initializeStatusBar } from './lib/statusBar';
import { getRootPath } from './lib/helpers';
import { initializeProviders } from './lib/providers';
import { initializeConfig } from './lib/auth';
import { initializeTerminal } from './lib/terminal';
import { registerEvents } from './lib/events';

export const activate = async (context: vscode.ExtensionContext) => {
console.log('Activating Extension...');
const rootPath = getRootPath();

registerCommands(context);
registerEvents(context);
registerURIHandler(context, rootPath);

initializeProviders(context);
initializeTerminal(context);
initializeStatusBar(context);

initializeConfig(rootPath);
Expand Down
9 changes: 4 additions & 5 deletions src/lib/auth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as vscode from 'vscode';
import { Portal } from './types';
import { COMMANDS } from './constants';
import { COMMANDS, EVENTS } from './constants';

const { findConfig, loadConfig, validateConfig } = require('@hubspot/cli-lib');
const { setConfig, setConfigPath } = require('@hubspot/cli-lib/lib/config');
Expand All @@ -12,7 +11,7 @@ const onLoadPath = (configPath: string) => {
configPath
);
if (!configPath) {
vscode.commands.executeCommand(COMMANDS.CONFIG_SET_DEFAULT_ACCOUNT, null);
vscode.commands.executeCommand(COMMANDS.CONFIG.SET_DEFAULT_ACCOUNT, null);
setConfig(null);
setConfigPath(null);
}
Expand All @@ -39,7 +38,7 @@ export const loadHubspotConfigFile = (rootPath: string) => {
if (!validateConfig()) {
throw new Error(`Invalid config could not be loaded: ${path}`);
} else {
vscode.commands.executeCommand(COMMANDS.ON_CONFIG_UPDATED);
vscode.commands.executeCommand(EVENTS.ON_CONFIG_UPDATED);
return path;
}
};
Expand All @@ -50,7 +49,7 @@ export const initializeConfig = (rootPath: string) => {
if (configPath) {
console.log(`HubSpot config loaded from: ${configPath}`);
vscode.commands.executeCommand(
COMMANDS.ON_CONFIG_FOUND,
EVENTS.ON_CONFIG_FOUND,
rootPath,
configPath
);
Expand Down
2 changes: 2 additions & 0 deletions src/lib/commands.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import * as vscode from 'vscode';
import { registerCommands as registerConfigCommands } from './commands/config';
import { registerCommands as registerAuthCommands } from './commands/auth';
import { registerCommands as registerTerminalCommands } from './commands/terminal';

export const registerCommands = (context: vscode.ExtensionContext) => {
registerConfigCommands(context);
registerAuthCommands(context);
registerTerminalCommands(context);
};
26 changes: 3 additions & 23 deletions src/lib/commands/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
setLintingEnabledState,
} from '../../lib/lint';
import { updateStatusBarItems } from '../../lib/statusBar';
import { COMMANDS } from '../constants';
import { COMMANDS, EVENTS } from '../constants';
import { loadHubspotConfigFile } from '../auth';

let configFoundAndLoaded = false;
Expand All @@ -14,11 +14,11 @@ let hubspotConfigWatcher: fs.FSWatcher | null;
export const registerCommands = (context: vscode.ExtensionContext) => {
context.subscriptions.push(
vscode.commands.registerCommand(
COMMANDS.ON_CONFIG_FOUND,
EVENTS.ON_CONFIG_FOUND,
(rootPath, configPath) => {
if (!configFoundAndLoaded) {
configFoundAndLoaded = true;
console.log(COMMANDS.ON_CONFIG_FOUND);
console.log(EVENTS.ON_CONFIG_FOUND);
setLintingEnabledState();
context.subscriptions.push(getUpdateLintingOnConfigChange());
updateStatusBarItems();
Expand Down Expand Up @@ -47,24 +47,4 @@ export const registerCommands = (context: vscode.ExtensionContext) => {
}
)
);

context.subscriptions.push(
vscode.commands.registerCommand(COMMANDS.ON_CONFIG_UPDATED, () => {
console.log(COMMANDS.ON_CONFIG_UPDATED);
vscode.commands.executeCommand(COMMANDS.ACCOUNTS_REFRESH);
updateStatusBarItems();
})
);

context.subscriptions.push(
vscode.commands.registerCommand(COMMANDS.AUTHORIZE_ACCOUNT, async () => {
const authUrl =
'https://app.hubspot.com/l/personal-access-key/auth/vscode';

const callableUri = await vscode.env.asExternalUri(
vscode.Uri.parse(authUrl)
);
await vscode.env.openExternal(callableUri);
})
);
};
8 changes: 4 additions & 4 deletions src/lib/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const showRenameAccountPrompt = (accountToRename: Portal) => {
export const registerCommands = (context: vscode.ExtensionContext) => {
context.subscriptions.push(
vscode.commands.registerCommand(
COMMANDS.CONFIG_SET_DEFAULT_ACCOUNT,
COMMANDS.CONFIG.SET_DEFAULT_ACCOUNT,
(defaultAccount, { silenceNotification = false } = {}) => {
if (!defaultAccount) return;
const newDefaultAccount =
Expand All @@ -60,7 +60,7 @@ export const registerCommands = (context: vscode.ExtensionContext) => {

context.subscriptions.push(
vscode.commands.registerCommand(
COMMANDS.CONFIG_SELECT_DEFAULT_ACCOUNT,
COMMANDS.CONFIG.SELECT_DEFAULT_ACCOUNT,
async () => {
const config = getConfig();
if (config && config.portals) {
Expand Down Expand Up @@ -99,7 +99,7 @@ export const registerCommands = (context: vscode.ExtensionContext) => {

context.subscriptions.push(
vscode.commands.registerCommand(
COMMANDS.CONFIG_RENAME_ACCOUNT,
COMMANDS.CONFIG.RENAME_ACCOUNT,
async (accountToRename) => {
showRenameAccountPrompt(accountToRename);
}
Expand All @@ -108,7 +108,7 @@ export const registerCommands = (context: vscode.ExtensionContext) => {

context.subscriptions.push(
vscode.commands.registerCommand(
COMMANDS.CONFIG_DELETE_ACCOUNT,
COMMANDS.CONFIG.DELETE_ACCOUNT,
async (accountToDelete) => {
const config = getConfig();
const accountIdentifier =
Expand Down
132 changes: 132 additions & 0 deletions src/lib/commands/terminal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import * as vscode from 'vscode';
import { compare } from 'compare-versions';
import { checkTerminalCommandVersion, runTerminalCommand } from '../helpers';
import { COMMANDS, POLLING_INTERVALS } from '../constants';

export const registerCommands = (context: vscode.ExtensionContext) => {
context.subscriptions.push(
vscode.commands.registerCommand(COMMANDS.HUBSPOT_CLI.INSTALL, () => {
const terminal = vscode.window.createTerminal();

terminal.show();

const hubspotInstalledPoll = setInterval(async () => {
miketalley marked this conversation as resolved.
Show resolved Hide resolved
const hsVersion = await vscode.commands.executeCommand(
COMMANDS.VERSION_CHECK.HS
);

if (hsVersion) {
clearInterval(hubspotInstalledPoll);
vscode.window.showInformationMessage(
`HubSpot CLI version ${hsVersion} installed.`
);
}
}, POLLING_INTERVALS.FAST);

terminal.sendText("echo 'Installing the HubSpot CLI.'");
terminal.sendText('npm i -g @hubspot/cli@latest');
terminal.sendText(
"echo 'Installation complete. You can now close this terminal window.'"
);
})
);

context.subscriptions.push(
vscode.commands.registerCommand(COMMANDS.HUBSPOT_CLI.UPDATE, async () => {
const terminal = vscode.window.createTerminal();
const latestVersion = await vscode.commands.executeCommand(
COMMANDS.VERSION_CHECK.HS_LATEST
);
terminal.show();

const hubspotUpdatedPoll = setInterval(async () => {
const hsVersion = await vscode.commands.executeCommand(
COMMANDS.VERSION_CHECK.HS
);

if (hsVersion === latestVersion) {
clearInterval(hubspotUpdatedPoll);
vscode.window.showInformationMessage(
`HubSpot CLI updated to version ${latestVersion}.`
);
}
}, POLLING_INTERVALS.FAST);

terminal.sendText("echo 'Updating the HubSpot CLI.'");
terminal.sendText('npm i -g @hubspot/cli@latest');
terminal.sendText(
"echo 'Update complete. You can now close this terminal window.'"
);
})
);

context.subscriptions.push(
vscode.commands.registerCommand(
COMMANDS.VERSION_CHECK.HS_LATEST,
async () => {
const hsVersion = (await runTerminalCommand('hs --version')).trim();
const latestHsVersion = (
await runTerminalCommand(
`npm info @hubspot/cli@latest | grep 'latest: ' | sed -n -e 's/^latest: //p'`
)
).trim();
vscode.commands.executeCommand(
'setContext',
'hubspot.terminal.versions.latest.hs',
hsVersion
);
console.log('latestVersion: ', latestHsVersion);

console.log(
'Newer CLI Version Available: ',
compare(latestHsVersion, hsVersion, '>')
);

vscode.commands.executeCommand(
'setContext',
'hubspot.updateAvailableForCLI',
compare(latestHsVersion, hsVersion, '>')
);

return latestHsVersion;
}
)
);

context.subscriptions.push(
vscode.commands.registerCommand(COMMANDS.VERSION_CHECK.HS, async () => {
const hsVersion = await checkTerminalCommandVersion('hs');
vscode.commands.executeCommand(
'setContext',
'hubspot.terminal.versions.installed.hs',
hsVersion
);
vscode.commands.executeCommand(
'setContext',
'hubspot.versionChecksComplete',
true
);

console.log('hsVersion: ', hsVersion);
if (hsVersion) {
vscode.commands.executeCommand(COMMANDS.VERSION_CHECK.HS_LATEST);
}

return hsVersion;
})
);

context.subscriptions.push(
vscode.commands.registerCommand(COMMANDS.VERSION_CHECK.NPM, async () => {
const npmVersion = await checkTerminalCommandVersion('npm');
vscode.commands.executeCommand(
'setContext',
'hubspot.terminal.versions.installed.npm',
npmVersion
);

console.log('npmVersion: ', npmVersion);
return npmVersion;
})
);
};
Loading