Skip to content

Commit a2723f9

Browse files
authored
Merge pull request #308 from HubSpot/handle-ldl-config-revamp
Handle ldl config revamp
2 parents c61c2ae + 5b4e07c commit a2723f9

File tree

13 files changed

+207
-187
lines changed

13 files changed

+207
-187
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,8 @@
557557
]
558558
},
559559
"dependencies": {
560-
"@hubspot/local-dev-lib": "^3.21.0",
561-
"@hubspot/project-parsing-lib": "0.2.0",
560+
"@hubspot/local-dev-lib": "4.0.2",
561+
"@hubspot/project-parsing-lib": "0.10.3",
562562
"dayjs": "^1.11.7",
563563
"debounce": "1.2.1",
564564
"findup-sync": "^5.0.0",

src/commands/account.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import { commands, ExtensionContext, Uri } from 'vscode';
2-
import { CLIAccount_DEPRECATED } from '@hubspot/local-dev-lib/types/Accounts';
3-
import { getAccountIdentifier } from '@hubspot/local-dev-lib/config/getAccountIdentifier';
4-
2+
import { HubSpotConfigAccount } from '@hubspot/local-dev-lib/types/Accounts';
53
import { COMMANDS } from '../lib/constants';
64

75
export const registerCommands = (context: ExtensionContext) => {
86
context.subscriptions.push(
97
commands.registerCommand(
108
COMMANDS.ACCOUNT.VIEW_PERSONAL_ACCESS_KEY,
11-
async (hubspotAccount: CLIAccount_DEPRECATED) => {
9+
async (hubspotAccount: HubSpotConfigAccount) => {
1210
const pakUrl = `https://app.hubspot${
1311
hubspotAccount.env === 'qa' ? 'qa' : ''
14-
}.com/personal-access-key/${getAccountIdentifier(hubspotAccount)}`;
12+
}.com/personal-access-key/${hubspotAccount.accountId}`;
1513

1614
commands.executeCommand('vscode.open', Uri.parse(pakUrl));
1715
}
@@ -20,10 +18,10 @@ export const registerCommands = (context: ExtensionContext) => {
2018
context.subscriptions.push(
2119
commands.registerCommand(
2220
COMMANDS.ACCOUNT.OPEN_DESIGN_MANAGER,
23-
async (hubspotAccount: CLIAccount_DEPRECATED) => {
21+
async (hubspotAccount: HubSpotConfigAccount) => {
2422
const designManagerUrl = `https://app.hubspot${
2523
hubspotAccount.env === 'qa' ? 'qa' : ''
26-
}.com/design-manager/${getAccountIdentifier(hubspotAccount)}`;
24+
}.com/design-manager/${hubspotAccount.accountId}`;
2725

2826
commands.executeCommand('vscode.open', Uri.parse(designManagerUrl));
2927
}

src/commands/config.ts

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
import { commands, window, ExtensionContext } from 'vscode';
22
import {
33
getConfig,
4-
deleteAccount,
5-
deleteConfigFile,
6-
renameAccount,
7-
updateDefaultAccount,
8-
getConfigDefaultAccount,
9-
getConfigAccounts,
4+
getAllConfigAccounts,
5+
getConfigDefaultAccountIfExists,
6+
removeAccountFromConfig,
7+
renameConfigAccount,
8+
setConfigAccountAsDefault,
109
} from '@hubspot/local-dev-lib/config';
11-
import { CLIConfig } from '@hubspot/local-dev-lib/types/Config';
12-
import {
13-
CLIAccount,
14-
CLIAccount_DEPRECATED,
15-
} from '@hubspot/local-dev-lib/types/Accounts';
16-
import { getAccountIdentifier } from '@hubspot/local-dev-lib/config/getAccountIdentifier';
10+
import { HubSpotConfigAccount } from '@hubspot/local-dev-lib/types/Accounts';
1711

1812
import { updateStatusBarItems } from '../features/statusBar';
1913
import { COMMANDS, EVENTS, TRACKED_EVENTS } from '../lib/constants';
@@ -22,16 +16,15 @@ import { portalNameInvalid } from '../lib/config';
2216
import { trackEvent } from '../lib/tracking';
2317
import { showAutoDismissedStatusBarMessage } from '../lib/statusBar';
2418

25-
const showRenameAccountPrompt = (accountToRename: CLIAccount_DEPRECATED) => {
19+
const showRenameAccountPrompt = (accountToRename: HubSpotConfigAccount) => {
2620
window
2721
.showInputBox({
2822
placeHolder: 'Enter a new name for the account',
2923
})
3024
.then(async (newName: string | undefined) => {
3125
if (newName) {
32-
const oldName =
33-
accountToRename.name || getAccountIdentifier(accountToRename);
34-
const config: CLIConfig | null = getConfig();
26+
const oldName = accountToRename.name;
27+
const config = getConfig();
3528
let invalidReason = '';
3629
if (config) {
3730
invalidReason = portalNameInvalid(newName, config);
@@ -44,7 +37,7 @@ const showRenameAccountPrompt = (accountToRename: CLIAccount_DEPRECATED) => {
4437
);
4538
return;
4639
}
47-
renameAccount(String(oldName), newName);
40+
renameConfigAccount(String(oldName), newName);
4841
commands.executeCommand(EVENTS.ACCOUNT.REFRESH);
4942
showAutoDismissedStatusBarMessage(
5043
`Successfully renamed default account from ${oldName} to ${newName}.`
@@ -73,9 +66,9 @@ export const registerCommands = (context: ExtensionContext) => {
7366
typeof defaultAccount === 'string' ||
7467
typeof defaultAccount === 'number'
7568
? defaultAccount
76-
: defaultAccount.name || getAccountIdentifier(defaultAccount);
69+
: defaultAccount.name;
7770
console.log('Setting default account to: ', newDefaultAccount);
78-
updateDefaultAccount(newDefaultAccount);
71+
setConfigAccountAsDefault(newDefaultAccount);
7972
trackEvent(TRACKED_EVENTS.UPDATE_DEFAULT_ACCOUNT);
8073
commands.executeCommand(COMMANDS.REMOTE_FS.HARD_REFRESH);
8174
if (!silenceNotification) {
@@ -91,18 +84,18 @@ export const registerCommands = (context: ExtensionContext) => {
9184
commands.registerCommand(
9285
COMMANDS.CONFIG.SELECT_DEFAULT_ACCOUNT,
9386
async () => {
94-
const defaultAccount = getConfigDefaultAccount();
95-
const accounts: CLIAccount[] = getConfigAccounts() || [];
87+
const defaultAccount = getConfigDefaultAccountIfExists();
88+
const accounts: HubSpotConfigAccount[] = getAllConfigAccounts() || [];
9689

9790
if (accounts && accounts.length !== 0) {
9891
window
9992
.showQuickPick(
100-
accounts.map((a: CLIAccount) => {
93+
accounts.map((a: HubSpotConfigAccount) => {
10194
return {
10295
label: getDisplayedHubspotPortalInfo(a),
10396
description:
104-
defaultAccount === getAccountIdentifier(a) ||
105-
defaultAccount === a.name
97+
defaultAccount?.accountId === a.accountId ||
98+
defaultAccount?.name === a.name
10699
? '(default)'
107100
: '',
108101
account: a,
@@ -114,17 +107,15 @@ export const registerCommands = (context: ExtensionContext) => {
114107
)
115108
.then(async (selection) => {
116109
if (selection) {
117-
const newDefaultAccount =
118-
selection.account.name ||
119-
getAccountIdentifier(selection.account);
110+
const newDefaultAccount = selection.account.name;
120111
if (!newDefaultAccount) {
121112
window.showErrorMessage(
122113
'No account selected; Choose an account to set as default'
123114
);
124115
return;
125116
}
126117
trackEvent(TRACKED_EVENTS.SELECT_DEFAULT_ACCOUNT);
127-
updateDefaultAccount(newDefaultAccount);
118+
setConfigAccountAsDefault(newDefaultAccount);
128119
showAutoDismissedStatusBarMessage(
129120
`Successfully set default account to ${newDefaultAccount}.`
130121
);
@@ -149,9 +140,7 @@ export const registerCommands = (context: ExtensionContext) => {
149140
commands.registerCommand(
150141
COMMANDS.CONFIG.DELETE_ACCOUNT,
151142
async (accountToDelete) => {
152-
const accounts: CLIAccount[] = getConfigAccounts() || [];
153-
const accountIdentifier =
154-
accountToDelete.name || getAccountIdentifier(accountToDelete);
143+
const accountIdentifier = accountToDelete.name;
155144

156145
await window
157146
.showInformationMessage(
@@ -161,17 +150,10 @@ export const registerCommands = (context: ExtensionContext) => {
161150
)
162151
.then(async (answer) => {
163152
if (answer === 'Yes') {
164-
if (accounts && accounts.length === 1) {
165-
deleteConfigFile();
166-
showAutoDismissedStatusBarMessage(
167-
`Successfully deleted account ${accountIdentifier}. The config file has been deleted because there are no more authenticated accounts.`
168-
);
169-
} else {
170-
deleteAccount(accountIdentifier);
171-
showAutoDismissedStatusBarMessage(
172-
`Successfully deleted account ${accountIdentifier}.`
173-
);
174-
}
153+
removeAccountFromConfig(accountIdentifier);
154+
showAutoDismissedStatusBarMessage(
155+
`Successfully deleted account ${accountIdentifier}.`
156+
);
175157
trackEvent(TRACKED_EVENTS.DELETE_ACCOUNT);
176158
commands.executeCommand(COMMANDS.REMOTE_FS.HARD_REFRESH);
177159
commands.executeCommand(EVENTS.ACCOUNT.REFRESH);

src/commands/remoteFs.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { ExtensionContext, window, commands, Uri } from 'vscode';
22
import { existsSync, statSync } from 'fs';
33
import { join } from 'path';
4+
import { getConfigDefaultAccountIfExists } from '@hubspot/local-dev-lib/config';
45
const { deleteFile, upload } = require('@hubspot/local-dev-lib/api/fileMapper');
56
const { downloadFileOrFolder } = require('@hubspot/local-dev-lib/fileMapper');
6-
const { getAccountId } = require('@hubspot/local-dev-lib/config');
77
const {
88
validateSrcAndDestPaths,
99
} = require('@hubspot/local-dev-lib/cms/modules');
10+
1011
const { shouldIgnoreFile } = require('@hubspot/local-dev-lib/ignoreRules');
1112
const { isAllowedExtension } = require('@hubspot/local-dev-lib/path');
1213
const { createIgnoreFilter } = require('@hubspot/local-dev-lib/ignoreRules');
@@ -20,15 +21,17 @@ import { COMMANDS, EVENTS, TRACKED_EVENTS } from '../lib/constants';
2021
import { getRootPath } from '../lib/helpers';
2122
import { invalidateParentDirectoryCache } from '../lib/remoteDesignManagerFs';
2223
import { buildStatusBarItem } from '../lib/statusBar';
23-
import { requireAccountId } from '../lib/config';
2424
import { trackEvent } from '../lib/tracking';
2525

2626
export const registerCommands = (context: ExtensionContext) => {
27+
const accountId = getConfigDefaultAccountIfExists()?.accountId;
28+
if (!accountId) {
29+
return;
30+
}
2731
context.subscriptions.push(
2832
commands.registerCommand(
2933
COMMANDS.REMOTE_FS.FETCH,
3034
async (clickedFileLink) => {
31-
requireAccountId();
3235
const remoteFilePath = clickedFileLink.path;
3336
// We use showOpenDialog instead of showSaveDialog because the latter has worse support for this use-case
3437
const destPath = await window.showOpenDialog({
@@ -70,7 +73,7 @@ export const registerCommands = (context: ExtensionContext) => {
7073
trackEvent(TRACKED_EVENTS.REMOTE_FS.FETCH);
7174
try {
7275
await downloadFileOrFolder(
73-
getAccountId()!,
76+
accountId,
7477
remoteFilePath,
7578
localFilePath,
7679
undefined,
@@ -96,7 +99,6 @@ export const registerCommands = (context: ExtensionContext) => {
9699
commands.registerCommand(
97100
COMMANDS.REMOTE_FS.DELETE,
98101
async (clickedFileLink) => {
99-
requireAccountId();
100102
console.log(COMMANDS.REMOTE_FS.DELETE);
101103
const filePath = clickedFileLink.path;
102104
const selection = await window.showWarningMessage(
@@ -109,7 +111,7 @@ export const registerCommands = (context: ExtensionContext) => {
109111
trackEvent(TRACKED_EVENTS.REMOTE_FS.DELETE);
110112
const deletingStatus = buildStatusBarItem(`Deleting...`);
111113
deletingStatus.show();
112-
deleteFile(getAccountId()!, filePath)
114+
deleteFile(accountId, filePath)
113115
.then(() => {
114116
window.showInformationMessage(`Successfully deleted "${filePath}"`);
115117
invalidateParentDirectoryCache(filePath);
@@ -132,7 +134,6 @@ export const registerCommands = (context: ExtensionContext) => {
132134
commands.registerCommand(
133135
COMMANDS.REMOTE_FS.UPLOAD,
134136
async (clickedFileLink) => {
135-
requireAccountId();
136137
let srcPath: string;
137138
if (
138139
clickedFileLink === undefined ||
@@ -240,6 +241,8 @@ const getUploadableFileList = async (src: any) => {
240241
};
241242

242243
const handleFileUpload = async (srcPath: string, destPath: string) => {
244+
const accountId = getConfigDefaultAccountIfExists()?.accountId;
245+
243246
if (!isAllowedExtension(srcPath)) {
244247
window.showErrorMessage(
245248
`The file "${srcPath}" does not have a valid extension`
@@ -253,8 +256,7 @@ const handleFileUpload = async (srcPath: string, destPath: string) => {
253256
return;
254257
}
255258
trackEvent(TRACKED_EVENTS.REMOTE_FS.UPLOAD_FILE);
256-
requireAccountId();
257-
upload(getAccountId()!, srcPath, destPath)
259+
upload(accountId, srcPath, destPath)
258260
.then(() => {
259261
window.showInformationMessage(
260262
`Uploading files to "${destPath}" was successful`
@@ -271,14 +273,16 @@ const handleFileUpload = async (srcPath: string, destPath: string) => {
271273
};
272274

273275
const handleFolderUpload = async (srcPath: string, destPath: string) => {
276+
const accountId = getConfigDefaultAccountIfExists()?.accountId;
277+
274278
const filePaths = await getUploadableFileList(srcPath);
275279
const uploadingStatus = buildStatusBarItem('Uploading...');
276280
uploadingStatus.show();
277281
window.showInformationMessage(
278282
`Beginning upload of "${srcPath}" to "${destPath}"...`
279283
);
280284
trackEvent(TRACKED_EVENTS.REMOTE_FS.UPLOAD_FOLDER);
281-
uploadFolder(getAccountId()!, srcPath, destPath, {}, {}, filePaths, 'publish')
285+
uploadFolder(accountId, srcPath, destPath, {}, {}, filePaths, 'publish')
282286
.then(async (results: any) => {
283287
if (!hasUploadErrors(results)) {
284288
window.showInformationMessage(

src/features/projectConfigValidation.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ import {
2828
Components,
2929
hsProjectJsonFilename,
3030
} from '@hubspot/project-parsing-lib';
31-
import { getAccountId } from '@hubspot/local-dev-lib/config';
32-
31+
import { getConfigDefaultAccountIfExists } from '@hubspot/local-dev-lib/config';
3332
import * as jsonc from 'jsonc-parser';
3433
import { debounce } from 'debounce';
3534
import { doesFileExist, dirname } from '../lib/fileHelpers';
@@ -132,7 +131,7 @@ async function validateDocumentDiagnostics(
132131
if (!metaFile.config) {
133132
return [newErrorDiagnostic(getMissingConfigError())];
134133
}
135-
const accountId = getAccountId();
134+
const accountId = getConfigDefaultAccountIfExists()?.accountId;
136135
if (!accountId) {
137136
return [
138137
newErrorDiagnostic(

0 commit comments

Comments
 (0)