-
Notifications
You must be signed in to change notification settings - Fork 24
Make updates to imports after bumping local-dev-lib version #281
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
invalidReason = portalNameInvalid(newName, config); | ||
} | ||
|
||
if (!invalidReason) { | ||
renameAccount(oldName, newName); | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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)' | ||
: '', | ||
|
@@ -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( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'); | ||
|
@@ -26,6 +30,7 @@ export const registerCommands = (context: ExtensionContext) => { | |
commands.registerCommand( | ||
COMMANDS.REMOTE_FS.FETCH, | ||
async (clickedFileLink) => { | ||
showMissingAccountError(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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({ | ||
|
@@ -67,7 +72,7 @@ export const registerCommands = (context: ExtensionContext) => { | |
trackEvent(TRACKED_EVENTS.REMOTE_FS.FETCH); | ||
try { | ||
await downloadFileOrFolder( | ||
getAccountId(), | ||
getAccountId()!, | ||
remoteFilePath, | ||
localFilePath, | ||
undefined, | ||
|
@@ -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( | ||
|
@@ -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); | ||
|
@@ -126,6 +132,7 @@ export const registerCommands = (context: ExtensionContext) => { | |
commands.registerCommand( | ||
COMMANDS.REMOTE_FS.UPLOAD, | ||
async (clickedFileLink) => { | ||
showMissingAccountError(); | ||
let srcPath: string; | ||
if ( | ||
clickedFileLink === undefined || | ||
|
@@ -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` | ||
|
@@ -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( | ||
|
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 | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This accounts for changes to the |
||
return `[[ READONLY: @remote/${decodedFilePath} ]]\n` + file.source; | ||
} catch (e) { | ||
console.log(e); | ||
|
There was a problem hiding this comment.
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.