Skip to content
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
1,759 changes: 1,073 additions & 686 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions src/lib/auth.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { commands } from 'vscode';
import { COMMANDS, EVENTS } from './constants';

const {
import {
findConfig,
loadConfig,
validateConfig,
setConfig,
setConfigPath,
} = require('@hubspot/local-dev-lib/config');
} from '@hubspot/local-dev-lib/config';

const onLoadPath = (configPath: string) => {
commands.executeCommand('setContext', 'hubspot.configPath', configPath);
if (!configPath) {
commands.executeCommand(COMMANDS.CONFIG.SET_DEFAULT_ACCOUNT, null);
setConfig(null);
setConfig(undefined);
setConfigPath(null);
}
};
Expand All @@ -26,13 +25,13 @@ export const loadHubspotConfigFile = (rootPath: string) => {
console.log(`rootPath: ${rootPath}`);

const path = findConfig(rootPath);
onLoadPath(path);

console.log(`path: ${path}`);

if (!path) {
return;
}
onLoadPath(path);

loadConfig(path);

Expand Down
19 changes: 14 additions & 5 deletions src/lib/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import { Portal } from '../types';
import { portalNameInvalid } from '../validation';
import { trackEvent } from '../tracking';
import { showAutoDismissedStatusBarMessage } from '../messaging';

const { getConfig } = require('@hubspot/local-dev-lib/config');
const {
import {
getConfig,
deleteAccount,
deleteConfigFile,
renameAccount,
updateDefaultAccount,
} = require('@hubspot/local-dev-lib/config');
} from '@hubspot/local-dev-lib/config';

const showRenameAccountPrompt = (accountToRename: Portal) => {
window
Expand All @@ -23,7 +22,12 @@ const showRenameAccountPrompt = (accountToRename: Portal) => {
.then(async (newName: string | undefined) => {
if (newName) {
const oldName = accountToRename.name || accountToRename.portalId;
const invalidReason = portalNameInvalid(newName, getConfig());
const config = getConfig();
let invalidReason = '';
if (config) {
// @ts-expect-error TODO: Fix this when updating local-dev-lib
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deprecated config and new config types are simply incompatible with one another. We can remove this error, once we account for the new global config in the extension.

invalidReason = portalNameInvalid(newName, config);
}

if (!invalidReason) {
renameAccount(oldName, newName);
Expand Down Expand Up @@ -73,14 +77,18 @@ export const registerCommands = (context: ExtensionContext) => {
COMMANDS.CONFIG.SELECT_DEFAULT_ACCOUNT,
async () => {
const config = getConfig();
// @ts-expect-error TODO: Fix this when updating local-dev-lib
if (config && config.portals) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any utils we could leverage from LDL to get around some of these issues? Would getConfigAccounts help here?

window
.showQuickPick(
// @ts-expect-error TODO: Fix this when updating local-dev-lib
config.portals.map((p: Portal) => {
return {
label: getDisplayedHubspotPortalInfo(p),
description:
// @ts-expect-error TODO: Fix this when updating local-dev-lib
config.defaultPortal === p.portalId ||
// @ts-expect-error TODO: Fix this when updating local-dev-lib
config.defaultPortal === p.name
? '(default)'
: '',
Expand Down Expand Up @@ -134,6 +142,7 @@ export const registerCommands = (context: ExtensionContext) => {
)
.then(async (answer) => {
if (answer === 'Yes') {
// @ts-expect-error TODO: Fix this when updating local-dev-lib
if (config && config.portals.length === 1) {
deleteConfigFile();
showAutoDismissedStatusBarMessage(
Expand Down
29 changes: 14 additions & 15 deletions src/lib/commands/remoteFs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import { existsSync, statSync } from 'fs';
import { join } from 'path';
import { ExtensionContext, window, commands, Uri } from 'vscode';
import { COMMANDS, TRACKED_EVENTS } from '../constants';
import { buildStatusBarItem, getRootPath } from '../helpers';
import { invalidateParentDirectoryCache } from '../helpers';
import {
buildStatusBarItem,
getRootPath,
invalidateParentDirectoryCache,
showMissingAccountError,
} from '../helpers';
import { trackEvent } from '../tracking';

const { deleteFile, upload } = require('@hubspot/local-dev-lib/api/fileMapper');
Expand All @@ -26,6 +30,7 @@ export const registerCommands = (context: ExtensionContext) => {
commands.registerCommand(
COMMANDS.REMOTE_FS.FETCH,
async (clickedFileLink) => {
showMissingAccountError();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no account is specified, we throw an error to the user and exit the command. This guarantees that getAccountId() is not undefined.

const remoteFilePath = clickedFileLink.path;
// We use showOpenDialog instead of showSaveDialog because the latter has worse support for this use-case
const destPath = await window.showOpenDialog({
Expand Down Expand Up @@ -67,7 +72,7 @@ export const registerCommands = (context: ExtensionContext) => {
trackEvent(TRACKED_EVENTS.REMOTE_FS.FETCH);
try {
await downloadFileOrFolder(
getAccountId(),
getAccountId()!,
remoteFilePath,
localFilePath,
undefined,
Expand All @@ -91,6 +96,7 @@ export const registerCommands = (context: ExtensionContext) => {
commands.registerCommand(
COMMANDS.REMOTE_FS.DELETE,
async (clickedFileLink) => {
showMissingAccountError();
console.log(COMMANDS.REMOTE_FS.DELETE);
const filePath = clickedFileLink.path;
const selection = await window.showWarningMessage(
Expand All @@ -103,7 +109,7 @@ export const registerCommands = (context: ExtensionContext) => {
trackEvent(TRACKED_EVENTS.REMOTE_FS.DELETE);
const deletingStatus = buildStatusBarItem(`Deleting...`);
deletingStatus.show();
deleteFile(getAccountId(), filePath)
deleteFile(getAccountId()!, filePath)
.then(() => {
window.showInformationMessage(`Successfully deleted "${filePath}"`);
invalidateParentDirectoryCache(filePath);
Expand All @@ -126,6 +132,7 @@ export const registerCommands = (context: ExtensionContext) => {
commands.registerCommand(
COMMANDS.REMOTE_FS.UPLOAD,
async (clickedFileLink) => {
showMissingAccountError();
let srcPath: string;
if (
clickedFileLink === undefined ||
Expand Down Expand Up @@ -246,7 +253,8 @@ const handleFileUpload = async (srcPath: string, destPath: string) => {
return;
}
trackEvent(TRACKED_EVENTS.REMOTE_FS.UPLOAD_FILE);
upload(getAccountId(), srcPath, destPath)
showMissingAccountError();
upload(getAccountId()!, srcPath, destPath)
.then(() => {
window.showInformationMessage(
`Uploading files to "${destPath}" was successful`
Expand All @@ -268,16 +276,7 @@ const handleFolderUpload = async (srcPath: string, destPath: string) => {
`Beginning upload of "${srcPath}" to "${destPath}"...`
);
trackEvent(TRACKED_EVENTS.REMOTE_FS.UPLOAD_FOLDER);
uploadFolder(
getAccountId(),
srcPath,
destPath,
{
mode: 'publish',
},
{},
filePaths
)
uploadFolder(getAccountId()!, srcPath, destPath, {}, {}, filePaths, 'publish')
.then(async (results: any) => {
if (!hasUploadErrors(results)) {
window.showInformationMessage(
Expand Down
4 changes: 2 additions & 2 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const VSCODE_SEVERITY = {
EXCEPTION: 'Error',
MISSING: 'Warning',
OTHER: 'Information',
};
} as const;

export const EXTENSION_CONFIG_NAME = 'hubspot';
export const HUBL_HTML_ID = 'html-hubl';
Expand Down Expand Up @@ -156,6 +156,6 @@ export const TEMPLATE_NAMES = {
TEMPLATE: 'page-template',
PARTIAL: 'partial',
GLOBAL_PARTIAL: 'global-partial',
};
} as const;

export const VALIDATION_DEBOUNCE_TIME = 250;
12 changes: 12 additions & 0 deletions src/lib/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { dirname } from 'path';
import { window, commands, workspace, StatusBarAlignment } from 'vscode';
import { getAccountId } from '@hubspot/local-dev-lib/config';

import { COMMANDS } from './constants';
import { HubspotConfig, Portal } from './types';

Expand Down Expand Up @@ -99,3 +101,13 @@ export const buildStatusBarItem = (text: string) => {
statusBarItem.text = text;
return statusBarItem;
};

export function showMissingAccountError() {
const accountId = getAccountId();
if (!accountId) {
window.showErrorMessage(
'No account selected; Authorize an account with the HubSpot CLI'
);
return;
}
}
8 changes: 5 additions & 3 deletions src/lib/providers/remoteFileProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TextDocumentContentProvider, EventEmitter, Uri } from 'vscode';
const { download } = require('@hubspot/local-dev-lib/api/fileMapper');
const { getAccountId } = require('@hubspot/local-dev-lib/config');
import { download } from '@hubspot/local-dev-lib/api/fileMapper';
import { getAccountId } from '@hubspot/local-dev-lib/config';
import { showMissingAccountError } from '../helpers';

export const RemoteFileProvider = new (class
implements TextDocumentContentProvider
Expand All @@ -9,11 +10,12 @@ export const RemoteFileProvider = new (class
onDidChange = this.onDidChangeEmitter.event;

async provideTextDocumentContent(uri: Uri): Promise<string | undefined> {
showMissingAccountError();
const filepath = uri.toString().split(':')[1];
// filepath must be de-encoded since it gets reencoded by download in cli-lib
const decodedFilePath = decodeURIComponent(filepath);
try {
const file = await download(getAccountId(), decodedFilePath);
const { data: file } = await download(getAccountId()!, decodedFilePath);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This accounts for changes to the http module in LDL versions 3 and above.

return `[[ READONLY: @remote/${decodedFilePath} ]]\n` + file.source;
} catch (e) {
console.log(e);
Expand Down
25 changes: 16 additions & 9 deletions src/lib/providers/remoteFsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import {
} from 'vscode';
import { FileLink, RemoteFsDirectory } from '../types';
import * as path from 'path';
import { buildStatusBarItem, invalidateParentDirectoryCache } from '../helpers';
import {
buildStatusBarItem,
invalidateParentDirectoryCache,
showMissingAccountError,
} from '../helpers';
import { trackEvent } from '../tracking';
import { TRACKED_EVENTS } from '../constants';
const {
Expand Down Expand Up @@ -100,20 +104,21 @@ export class RemoteFsProvider implements TreeDataProvider<FileLink> {
changeWatch(srcPath: string, destPath: string, filesToUpload: any): void {
trackEvent(TRACKED_EVENTS.REMOTE_FS.WATCH);
const setWatch = () => {
showMissingAccountError();
const uploadingStatus = buildStatusBarItem('Uploading...');
uploadingStatus.show();
window.showInformationMessage(
`Beginning initial upload of ${srcPath} to ${destPath}...`
);
this.currentWatcher = watch(
getAccountId(),
let { data: watcher } = watch(
getAccountId()!,
srcPath,
destPath,
{
mode: 'publish',
cmsPublishMode: 'publish',
remove: true,
disableInitial: false,
notify: false,
notify: 'none',
commandOptions: {},
filePaths: filesToUpload,
},
Expand All @@ -139,13 +144,14 @@ export class RemoteFsProvider implements TreeDataProvider<FileLink> {
window.showErrorMessage(`Upload folder error: ${error}`);
},
// onQueueAddError
null,
undefined,
// onUploadFileError
(error: any) => {
(file: string, dest: string, accountId: number) => (error: any) => {
uploadingStatus.dispose();
window.showErrorMessage(`Upload file error: ${error}`);
}
);
this.currentWatcher = watcher;
this.currentWatcher.on('raw', (event: any, path: any, details: any) => {
if (event === 'created' || event === 'moved') {
const pathToInvalidate = this.equivalentRemotePath(path);
Expand Down Expand Up @@ -174,13 +180,14 @@ export class RemoteFsProvider implements TreeDataProvider<FileLink> {
}

async getChildren(parent?: FileLink): Promise<FileLink[]> {
showMissingAccountError();
const remoteDirectory: string = parent?.path ? parent.path : '/';
let directoryContents: any = this.remoteFsCache.get(remoteDirectory);
if (directoryContents === undefined) {
directoryContents = await getDirectoryContentsByPath(
({ data: directoryContents } = await getDirectoryContentsByPath(
getAccountId(),
remoteDirectory
);
));
// Default content wasn't originally in this endpoint and so doesn't show up unless manually queried
if (remoteDirectory === '/') {
directoryContents.children = [
Expand Down
7 changes: 5 additions & 2 deletions src/lib/providers/treedata/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { getDisplayedHubspotPortalInfo } from '../../helpers';
import { HubspotConfig, Portal } from '../../types';

const { getConfig } = require('@hubspot/local-dev-lib/config');
import { getConfig } from '@hubspot/local-dev-lib/config';

const isDefaultPortal = (portal: Portal, config: HubspotConfig) => {
return (
Expand All @@ -29,8 +29,9 @@ const getAccountIdentifiers = (portal: Portal) => {
};

export class AccountsProvider implements TreeDataProvider<Portal> {
private config: HubspotConfig;
private config: HubspotConfig | null;
constructor() {
// @ts-expect-error TODO: Fix this when updating local-dev-lib
this.config = getConfig();
}

Expand All @@ -48,13 +49,15 @@ export class AccountsProvider implements TreeDataProvider<Portal> {
return new AccountTreeItem(
name,
p,
// @ts-expect-error TODO: Fix this when updating local-dev-lib
{ isDefault: isDefaultPortal(p, this.config) },
TreeItemCollapsibleState.None
);
}

getChildren(): Thenable<Portal[] | undefined> {
console.log('AccountsProvider:getChildren');
// @ts-expect-error TODO: Fix this when updating local-dev-lib
this.config = getConfig();

if (this.config && this.config.portals) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/statusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import {
ThemeColor,
} from 'vscode';
import { COMMANDS } from './constants';

const { getConfig } = require('@hubspot/local-dev-lib/config');
import { getConfig } from '@hubspot/local-dev-lib/config';

let hsStatusBar: StatusBarItem;

export const updateStatusBarItems = () => {
console.log('updateStatusBarItems');

const config = getConfig();
// @ts-expect-error Need to update to use new global config
const defaultAccount = config && config.defaultPortal;

if (defaultAccount) {
Expand Down
Loading