Skip to content

Commit df21c69

Browse files
committed
Make updates to LDL imports
1 parent 050ea88 commit df21c69

File tree

13 files changed

+1201
-756
lines changed

13 files changed

+1201
-756
lines changed

package-lock.json

Lines changed: 1073 additions & 686 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/auth.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
import { commands } from 'vscode';
22
import { COMMANDS, EVENTS } from './constants';
3-
4-
const {
3+
import {
54
findConfig,
65
loadConfig,
76
validateConfig,
87
setConfig,
98
setConfigPath,
10-
} = require('@hubspot/local-dev-lib/config');
9+
} from '@hubspot/local-dev-lib/config';
1110

1211
const onLoadPath = (configPath: string) => {
1312
commands.executeCommand('setContext', 'hubspot.configPath', configPath);
1413
if (!configPath) {
1514
commands.executeCommand(COMMANDS.CONFIG.SET_DEFAULT_ACCOUNT, null);
16-
setConfig(null);
15+
setConfig(undefined);
1716
setConfigPath(null);
1817
}
1918
};
@@ -26,13 +25,13 @@ export const loadHubspotConfigFile = (rootPath: string) => {
2625
console.log(`rootPath: ${rootPath}`);
2726

2827
const path = findConfig(rootPath);
29-
onLoadPath(path);
3028

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

3331
if (!path) {
3432
return;
3533
}
34+
onLoadPath(path);
3635

3736
loadConfig(path);
3837

src/lib/commands/config.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ import { Portal } from '../types';
66
import { portalNameInvalid } from '../validation';
77
import { trackEvent } from '../tracking';
88
import { showAutoDismissedStatusBarMessage } from '../messaging';
9-
10-
const { getConfig } = require('@hubspot/local-dev-lib/config');
11-
const {
9+
import {
10+
getConfig,
1211
deleteAccount,
1312
deleteConfigFile,
1413
renameAccount,
1514
updateDefaultAccount,
16-
} = require('@hubspot/local-dev-lib/config');
15+
} from '@hubspot/local-dev-lib/config';
1716

1817
const showRenameAccountPrompt = (accountToRename: Portal) => {
1918
window
@@ -23,7 +22,12 @@ const showRenameAccountPrompt = (accountToRename: Portal) => {
2322
.then(async (newName: string | undefined) => {
2423
if (newName) {
2524
const oldName = accountToRename.name || accountToRename.portalId;
26-
const invalidReason = portalNameInvalid(newName, getConfig());
25+
const config = getConfig();
26+
let invalidReason = '';
27+
if (config) {
28+
// @ts-expect-error TODO: Fix this when updating local-dev-lib
29+
invalidReason = portalNameInvalid(newName, config);
30+
}
2731

2832
if (!invalidReason) {
2933
renameAccount(oldName, newName);
@@ -73,14 +77,18 @@ export const registerCommands = (context: ExtensionContext) => {
7377
COMMANDS.CONFIG.SELECT_DEFAULT_ACCOUNT,
7478
async () => {
7579
const config = getConfig();
80+
// @ts-expect-error TODO: Fix this when updating local-dev-lib
7681
if (config && config.portals) {
7782
window
7883
.showQuickPick(
84+
// @ts-expect-error TODO: Fix this when updating local-dev-lib
7985
config.portals.map((p: Portal) => {
8086
return {
8187
label: getDisplayedHubspotPortalInfo(p),
8288
description:
89+
// @ts-expect-error TODO: Fix this when updating local-dev-lib
8390
config.defaultPortal === p.portalId ||
91+
// @ts-expect-error TODO: Fix this when updating local-dev-lib
8492
config.defaultPortal === p.name
8593
? '(default)'
8694
: '',
@@ -134,6 +142,7 @@ export const registerCommands = (context: ExtensionContext) => {
134142
)
135143
.then(async (answer) => {
136144
if (answer === 'Yes') {
145+
// @ts-expect-error TODO: Fix this when updating local-dev-lib
137146
if (config && config.portals.length === 1) {
138147
deleteConfigFile();
139148
showAutoDismissedStatusBarMessage(

src/lib/commands/remoteFs.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ import { existsSync, statSync } from 'fs';
22
import { join } from 'path';
33
import { ExtensionContext, window, commands, Uri } from 'vscode';
44
import { COMMANDS, TRACKED_EVENTS } from '../constants';
5-
import { buildStatusBarItem, getRootPath } from '../helpers';
6-
import { invalidateParentDirectoryCache } from '../helpers';
5+
import {
6+
buildStatusBarItem,
7+
getRootPath,
8+
invalidateParentDirectoryCache,
9+
showMissingAccountError,
10+
} from '../helpers';
711
import { trackEvent } from '../tracking';
812

913
const { deleteFile, upload } = require('@hubspot/local-dev-lib/api/fileMapper');
@@ -26,6 +30,7 @@ export const registerCommands = (context: ExtensionContext) => {
2630
commands.registerCommand(
2731
COMMANDS.REMOTE_FS.FETCH,
2832
async (clickedFileLink) => {
33+
showMissingAccountError();
2934
const remoteFilePath = clickedFileLink.path;
3035
// We use showOpenDialog instead of showSaveDialog because the latter has worse support for this use-case
3136
const destPath = await window.showOpenDialog({
@@ -67,7 +72,7 @@ export const registerCommands = (context: ExtensionContext) => {
6772
trackEvent(TRACKED_EVENTS.REMOTE_FS.FETCH);
6873
try {
6974
await downloadFileOrFolder(
70-
getAccountId(),
75+
getAccountId()!,
7176
remoteFilePath,
7277
localFilePath,
7378
undefined,
@@ -91,6 +96,7 @@ export const registerCommands = (context: ExtensionContext) => {
9196
commands.registerCommand(
9297
COMMANDS.REMOTE_FS.DELETE,
9398
async (clickedFileLink) => {
99+
showMissingAccountError();
94100
console.log(COMMANDS.REMOTE_FS.DELETE);
95101
const filePath = clickedFileLink.path;
96102
const selection = await window.showWarningMessage(
@@ -103,7 +109,7 @@ export const registerCommands = (context: ExtensionContext) => {
103109
trackEvent(TRACKED_EVENTS.REMOTE_FS.DELETE);
104110
const deletingStatus = buildStatusBarItem(`Deleting...`);
105111
deletingStatus.show();
106-
deleteFile(getAccountId(), filePath)
112+
deleteFile(getAccountId()!, filePath)
107113
.then(() => {
108114
window.showInformationMessage(`Successfully deleted "${filePath}"`);
109115
invalidateParentDirectoryCache(filePath);
@@ -126,6 +132,7 @@ export const registerCommands = (context: ExtensionContext) => {
126132
commands.registerCommand(
127133
COMMANDS.REMOTE_FS.UPLOAD,
128134
async (clickedFileLink) => {
135+
showMissingAccountError();
129136
let srcPath: string;
130137
if (
131138
clickedFileLink === undefined ||
@@ -246,7 +253,8 @@ const handleFileUpload = async (srcPath: string, destPath: string) => {
246253
return;
247254
}
248255
trackEvent(TRACKED_EVENTS.REMOTE_FS.UPLOAD_FILE);
249-
upload(getAccountId(), srcPath, destPath)
256+
showMissingAccountError();
257+
upload(getAccountId()!, srcPath, destPath)
250258
.then(() => {
251259
window.showInformationMessage(
252260
`Uploading files to "${destPath}" was successful`
@@ -268,16 +276,7 @@ const handleFolderUpload = async (srcPath: string, destPath: string) => {
268276
`Beginning upload of "${srcPath}" to "${destPath}"...`
269277
);
270278
trackEvent(TRACKED_EVENTS.REMOTE_FS.UPLOAD_FOLDER);
271-
uploadFolder(
272-
getAccountId(),
273-
srcPath,
274-
destPath,
275-
{
276-
mode: 'publish',
277-
},
278-
{},
279-
filePaths
280-
)
279+
uploadFolder(getAccountId()!, srcPath, destPath, {}, {}, filePaths, 'publish')
281280
.then(async (results: any) => {
282281
if (!hasUploadErrors(results)) {
283282
window.showInformationMessage(

src/lib/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const VSCODE_SEVERITY = {
1616
EXCEPTION: 'Error',
1717
MISSING: 'Warning',
1818
OTHER: 'Information',
19-
};
19+
} as const;
2020

2121
export const EXTENSION_CONFIG_NAME = 'hubspot';
2222
export const HUBL_HTML_ID = 'html-hubl';
@@ -156,6 +156,6 @@ export const TEMPLATE_NAMES = {
156156
TEMPLATE: 'page-template',
157157
PARTIAL: 'partial',
158158
GLOBAL_PARTIAL: 'global-partial',
159-
};
159+
} as const;
160160

161161
export const VALIDATION_DEBOUNCE_TIME = 250;

src/lib/helpers.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { dirname } from 'path';
22
import { window, commands, workspace, StatusBarAlignment } from 'vscode';
3+
import { getAccountId } from '@hubspot/local-dev-lib/config';
4+
35
import { COMMANDS } from './constants';
46
import { HubspotConfig, Portal } from './types';
57

@@ -99,3 +101,13 @@ export const buildStatusBarItem = (text: string) => {
99101
statusBarItem.text = text;
100102
return statusBarItem;
101103
};
104+
105+
export function showMissingAccountError() {
106+
const accountId = getAccountId();
107+
if (!accountId) {
108+
window.showErrorMessage(
109+
'No account selected; Authorize an account with the HubSpot CLI'
110+
);
111+
return;
112+
}
113+
}

src/lib/providers/remoteFileProvider.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { TextDocumentContentProvider, EventEmitter, Uri } from 'vscode';
2-
const { download } = require('@hubspot/local-dev-lib/api/fileMapper');
3-
const { getAccountId } = require('@hubspot/local-dev-lib/config');
2+
import { download } from '@hubspot/local-dev-lib/api/fileMapper';
3+
import { getAccountId } from '@hubspot/local-dev-lib/config';
4+
import { showMissingAccountError } from '../helpers';
45

56
export const RemoteFileProvider = new (class
67
implements TextDocumentContentProvider
@@ -9,11 +10,12 @@ export const RemoteFileProvider = new (class
910
onDidChange = this.onDidChangeEmitter.event;
1011

1112
async provideTextDocumentContent(uri: Uri): Promise<string | undefined> {
13+
showMissingAccountError();
1214
const filepath = uri.toString().split(':')[1];
1315
// filepath must be de-encoded since it gets reencoded by download in cli-lib
1416
const decodedFilePath = decodeURIComponent(filepath);
1517
try {
16-
const file = await download(getAccountId(), decodedFilePath);
18+
const { data: file } = await download(getAccountId()!, decodedFilePath);
1719
return `[[ READONLY: @remote/${decodedFilePath} ]]\n` + file.source;
1820
} catch (e) {
1921
console.log(e);

src/lib/providers/remoteFsProvider.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import {
1010
} from 'vscode';
1111
import { FileLink, RemoteFsDirectory } from '../types';
1212
import * as path from 'path';
13-
import { buildStatusBarItem, invalidateParentDirectoryCache } from '../helpers';
13+
import {
14+
buildStatusBarItem,
15+
invalidateParentDirectoryCache,
16+
showMissingAccountError,
17+
} from '../helpers';
1418
import { trackEvent } from '../tracking';
1519
import { TRACKED_EVENTS } from '../constants';
1620
const {
@@ -100,20 +104,21 @@ export class RemoteFsProvider implements TreeDataProvider<FileLink> {
100104
changeWatch(srcPath: string, destPath: string, filesToUpload: any): void {
101105
trackEvent(TRACKED_EVENTS.REMOTE_FS.WATCH);
102106
const setWatch = () => {
107+
showMissingAccountError();
103108
const uploadingStatus = buildStatusBarItem('Uploading...');
104109
uploadingStatus.show();
105110
window.showInformationMessage(
106111
`Beginning initial upload of ${srcPath} to ${destPath}...`
107112
);
108-
this.currentWatcher = watch(
109-
getAccountId(),
113+
let { data: watcher } = watch(
114+
getAccountId()!,
110115
srcPath,
111116
destPath,
112117
{
113-
mode: 'publish',
118+
cmsPublishMode: 'publish',
114119
remove: true,
115120
disableInitial: false,
116-
notify: false,
121+
notify: 'none',
117122
commandOptions: {},
118123
filePaths: filesToUpload,
119124
},
@@ -139,13 +144,14 @@ export class RemoteFsProvider implements TreeDataProvider<FileLink> {
139144
window.showErrorMessage(`Upload folder error: ${error}`);
140145
},
141146
// onQueueAddError
142-
null,
147+
undefined,
143148
// onUploadFileError
144-
(error: any) => {
149+
(file: string, dest: string, accountId: number) => (error: any) => {
145150
uploadingStatus.dispose();
146151
window.showErrorMessage(`Upload file error: ${error}`);
147152
}
148153
);
154+
this.currentWatcher = watcher;
149155
this.currentWatcher.on('raw', (event: any, path: any, details: any) => {
150156
if (event === 'created' || event === 'moved') {
151157
const pathToInvalidate = this.equivalentRemotePath(path);
@@ -174,13 +180,14 @@ export class RemoteFsProvider implements TreeDataProvider<FileLink> {
174180
}
175181

176182
async getChildren(parent?: FileLink): Promise<FileLink[]> {
183+
showMissingAccountError();
177184
const remoteDirectory: string = parent?.path ? parent.path : '/';
178185
let directoryContents: any = this.remoteFsCache.get(remoteDirectory);
179186
if (directoryContents === undefined) {
180-
directoryContents = await getDirectoryContentsByPath(
187+
({ data: directoryContents } = await getDirectoryContentsByPath(
181188
getAccountId(),
182189
remoteDirectory
183-
);
190+
));
184191
// Default content wasn't originally in this endpoint and so doesn't show up unless manually queried
185192
if (remoteDirectory === '/') {
186193
directoryContents.children = [

src/lib/providers/treedata/accounts.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { getDisplayedHubspotPortalInfo } from '../../helpers';
1010
import { HubspotConfig, Portal } from '../../types';
1111

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

1414
const isDefaultPortal = (portal: Portal, config: HubspotConfig) => {
1515
return (
@@ -29,8 +29,9 @@ const getAccountIdentifiers = (portal: Portal) => {
2929
};
3030

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

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

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

6063
if (this.config && this.config.portals) {

src/lib/statusBar.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import {
66
ThemeColor,
77
} from 'vscode';
88
import { COMMANDS } from './constants';
9-
10-
const { getConfig } = require('@hubspot/local-dev-lib/config');
9+
import { getConfig } from '@hubspot/local-dev-lib/config';
1110

1211
let hsStatusBar: StatusBarItem;
1312

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

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

2020
if (defaultAccount) {

0 commit comments

Comments
 (0)