Skip to content

Commit

Permalink
Merge pull request #264 from HubSpot/js/migrate-LDL
Browse files Browse the repository at this point in the history
Migrate VSCE to use local-dev-lib instead of cli-lib
  • Loading branch information
jsines committed May 14, 2024
2 parents 2629b84 + 2a759ff commit 76191d8
Show file tree
Hide file tree
Showing 22 changed files with 1,529 additions and 4,704 deletions.
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

node ./scripts/sanityCheckEnLyaml.js
git add src/lang/en.lyaml
4,792 changes: 1,435 additions & 3,357 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
"path": "./snippets/auto_gen/hubl_expTests.json"
},
{
"language": "html-hubl",
"path": "./snippets/man_gen/hubl_required_page_template_variables.json"
"language": "html-hubl",
"path": "./snippets/man_gen/hubl_required_page_template_variables.json"
},
{
"language": "html-hubl",
Expand Down Expand Up @@ -84,24 +84,24 @@
"path": "./snippets/man_gen/hubl_required_email_template_variables.json"
},
{
"language": "html-hubl",
"path": "./snippets/man_gen/hubl_private_content_email_variables.json"
"language": "html-hubl",
"path": "./snippets/man_gen/hubl_private_content_email_variables.json"
},
{
"language": "html-hubl",
"path": "./snippets/man_gen/hubl_crm_object_dynamic_pages.json"
"language": "html-hubl",
"path": "./snippets/man_gen/hubl_crm_object_dynamic_pages.json"
},
{
"language": "html-hubl",
"path": "./snippets/man_gen/hubl_hubdb_variables.json"
"language": "html-hubl",
"path": "./snippets/man_gen/hubl_hubdb_variables.json"
},
{
"language": "html-hubl",
"path": "./snippets/man_gen/hubl_menu_node_variables.json"
"language": "html-hubl",
"path": "./snippets/man_gen/hubl_menu_node_variables.json"
},
{
"language": "html-hubl",
"path": "./snippets/man_gen/hubl_in_app_editor_and_preview_variables.json"
"language": "html-hubl",
"path": "./snippets/man_gen/hubl_in_app_editor_and_preview_variables.json"
},
{
"language": "html-hubl",
Expand Down Expand Up @@ -587,7 +587,7 @@
]
},
"dependencies": {
"@hubspot/cli-lib": "^4.1.8-beta.2",
"@hubspot/local-dev-lib": "^1.3.0",
"dayjs": "^1.11.7",
"findup-sync": "^5.0.0",
"fs-extra": "^9.0.1",
Expand Down
22 changes: 0 additions & 22 deletions scripts/sanityCheckEnLyaml.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { registerCommands } from './lib/commands';
import { registerEvents } from './lib/events';
import { registerURIHandler } from './lib/uri';

import { initializeCliLibLang } from './lib/lang';
import { initializeCliLibLogger } from './lib/logger';
import { initializeStatusBar } from './lib/statusBar';
import { initializeProviders } from './lib/providers';
Expand All @@ -19,7 +18,6 @@ import { initializeGlobalState } from './lib/globalState';
import { initializeHubLAutoDetect } from './lib/autoDetect';

export const activate = async (context: ExtensionContext) => {
initializeCliLibLang();
initializeCliLibLogger();
await initializeTracking(context);
await trackEvent(TRACKED_EVENTS.ACTIVATE);
Expand Down
1,239 changes: 0 additions & 1,239 deletions src/lang/en.lyaml

This file was deleted.

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

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

const onLoadPath = (configPath: string) => {
commands.executeCommand('setContext', 'hubspot.configPath', configPath);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/commands/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { portalNameInvalid } from '../validation';
import { trackEvent } from '../tracking';
import { showAutoDismissedStatusBarMessage } from '../messaging';

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

const showRenameAccountPrompt = (accountToRename: Portal) => {
window
Expand Down
2 changes: 1 addition & 1 deletion src/lib/commands/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { COMMANDS, TRACKED_EVENTS } from '../constants';
import { onClickCreateFolder } from '../fileHelpers';
import { trackEvent } from '../tracking';

const { createModule } = require('@hubspot/cli-lib/modules');
const { createModule } = require('@hubspot/local-dev-lib/cms/modules');

export const registerCommands = (context: ExtensionContext) => {
context.subscriptions.push(
Expand Down
32 changes: 18 additions & 14 deletions src/lib/commands/remoteFs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ import { buildStatusBarItem, getRootPath } from '../helpers';
import { invalidateParentDirectoryCache } from '../helpers';
import { trackEvent } from '../tracking';

const { deleteFile } = require('@hubspot/cli-lib/api/fileMapper');
const { downloadFileOrFolder } = require('@hubspot/cli-lib/fileMapper');
const { getPortalId } = require('@hubspot/cli-lib');
const { validateSrcAndDestPaths } = require('@hubspot/cli-lib/modules');
const { shouldIgnoreFile } = require('@hubspot/cli-lib/ignoreRules');
const { isAllowedExtension } = require('@hubspot/cli-lib/path');
const { upload } = require('@hubspot/cli-lib/api/fileMapper');
const { createIgnoreFilter } = require('@hubspot/cli-lib/ignoreRules');
const { uploadFolder, hasUploadErrors } = require('@hubspot/cli-lib');
const { walk } = require('@hubspot/cli-lib/lib/walk');
const { deleteFile, upload } = require('@hubspot/local-dev-lib/api/fileMapper');
const { downloadFileOrFolder } = require('@hubspot/local-dev-lib/fileMapper');
const { getAccountId } = require('@hubspot/local-dev-lib/config');
const {
validateSrcAndDestPaths,
} = require('@hubspot/local-dev-lib/cms/modules');
const { shouldIgnoreFile } = require('@hubspot/local-dev-lib/ignoreRules');
const { isAllowedExtension } = require('@hubspot/local-dev-lib/path');
const { createIgnoreFilter } = require('@hubspot/local-dev-lib/ignoreRules');
const {
uploadFolder,
hasUploadErrors,
} = require('@hubspot/local-dev-lib/cms/uploadFolder');
const { walk } = require('@hubspot/local-dev-lib/fs');

export const registerCommands = (context: ExtensionContext) => {
context.subscriptions.push(
Expand Down Expand Up @@ -62,7 +66,7 @@ export const registerCommands = (context: ExtensionContext) => {
downloadingStatus.show();
trackEvent(TRACKED_EVENTS.REMOTE_FS.FETCH);
await downloadFileOrFolder({
accountId: getPortalId(),
accountId: getAccountId(),
src: remoteFilePath,
dest: localFilePath,
options: {
Expand Down Expand Up @@ -92,7 +96,7 @@ export const registerCommands = (context: ExtensionContext) => {
trackEvent(TRACKED_EVENTS.REMOTE_FS.DELETE);
const deletingStatus = buildStatusBarItem(`Deleting...`);
deletingStatus.show();
deleteFile(getPortalId(), filePath)
deleteFile(getAccountId(), filePath)
.then(() => {
window.showInformationMessage(`Successfully deleted "${filePath}"`);
invalidateParentDirectoryCache(filePath);
Expand Down Expand Up @@ -235,7 +239,7 @@ const handleFileUpload = async (srcPath: string, destPath: string) => {
return;
}
trackEvent(TRACKED_EVENTS.REMOTE_FS.UPLOAD_FILE);
upload(getPortalId(), srcPath, destPath)
upload(getAccountId(), srcPath, destPath)
.then(() => {
window.showInformationMessage(
`Uploading files to "${destPath}" was successful`
Expand All @@ -258,7 +262,7 @@ const handleFolderUpload = async (srcPath: string, destPath: string) => {
);
trackEvent(TRACKED_EVENTS.REMOTE_FS.UPLOAD_FOLDER);
uploadFolder(
getPortalId(),
getAccountId(),
srcPath,
destPath,
{
Expand Down
2 changes: 1 addition & 1 deletion src/lib/commands/serverless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { basename, dirname, join, parse } from 'path';
import { trackEvent } from '../tracking';

const findup = require('findup-sync');
const { createFunction } = require('@hubspot/cli-lib/functions');
const { createFunction } = require('@hubspot/local-dev-lib/cms/functions');

export const registerCommands = (context: ExtensionContext) => {
context.subscriptions.push(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/commands/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { onClickCreateFile } from '../fileHelpers';
import { basename, dirname } from 'path';
import { trackEvent } from '../tracking';

const { createTemplate } = require('@hubspot/cli-lib/templates');
const { createTemplate } = require('@hubspot/local-dev-lib/cms/templates');

export const registerCommands = (context: ExtensionContext) => {
context.subscriptions.push(
Expand Down
6 changes: 0 additions & 6 deletions src/lib/lang.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/lib/logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { window } from 'vscode';

const { setLogger } = require('@hubspot/cli-lib/logger');
const { setLogger } = require('@hubspot/local-dev-lib/logger');

class Logger {
error(...args: any[]) {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/providers/remoteFileProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TextDocumentContentProvider, EventEmitter, Uri } from 'vscode';
const { download } = require('@hubspot/cli-lib/api/fileMapper');
const { getPortalId } = require('@hubspot/cli-lib');
const { download } = require('@hubspot/local-dev-lib/api/fileMapper');
const { getAccountId } = require('@hubspot/local-dev-lib/config');

export const RemoteFileProvider = new (class
implements TextDocumentContentProvider
Expand All @@ -13,7 +13,7 @@ export const RemoteFileProvider = new (class
// filepath must be de-encoded since it gets reencoded by download in cli-lib
const decodedFilePath = decodeURIComponent(filepath);
try {
const file = await download(getPortalId(), decodedFilePath);
const file = await download(getAccountId(), decodedFilePath);
return `[[ READONLY: @remote/${decodedFilePath} ]]\n` + file.source;
} catch (e) {
console.log(e);
Expand Down
27 changes: 21 additions & 6 deletions src/lib/providers/remoteFsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import { trackEvent } from '../tracking';
import { TRACKED_EVENTS } from '../constants';
const {
getDirectoryContentsByPath,
} = require('@hubspot/cli-lib/api/fileMapper');
const { getPortalId } = require('@hubspot/cli-lib');
const { FOLDER_DOT_EXTENSIONS } = require('@hubspot/cli-lib/lib/constants');
const { watch } = require('@hubspot/cli-lib/lib/watch');
} = require('@hubspot/local-dev-lib/api/fileMapper');
const { getAccountId } = require('@hubspot/local-dev-lib/config');
const {
FOLDER_DOT_EXTENSIONS,
} = require('@hubspot/local-dev-lib/constants/extensions');
const { watch } = require('@hubspot/local-dev-lib/cms/watch');

function isPathFolder(path: string) {
const splitPath = path.split('/');
Expand Down Expand Up @@ -104,7 +106,7 @@ export class RemoteFsProvider implements TreeDataProvider<FileLink> {
`Beginning initial upload of ${srcPath} to ${destPath}...`
);
this.currentWatcher = watch(
getPortalId(),
getAccountId(),
srcPath,
destPath,
{
Expand All @@ -115,6 +117,7 @@ export class RemoteFsProvider implements TreeDataProvider<FileLink> {
commandOptions: {},
filePaths: filesToUpload,
},
// postInitialUploadCallback
(results: any) => {
uploadingStatus.dispose();
if (results.length > 0) {
Expand All @@ -129,6 +132,18 @@ export class RemoteFsProvider implements TreeDataProvider<FileLink> {
`Finished initial upload of ${srcPath} to ${destPath}! Now watching for changes.`
);
invalidateParentDirectoryCache(destPath);
},
// onUploadFolderError
(error: any) => {
uploadingStatus.dispose();
window.showErrorMessage(`Upload folder error: ${error}`);
},
// onQueueAddError
null,
// onUploadFileError
(error: any) => {
uploadingStatus.dispose();
window.showErrorMessage(`Upload file error: ${error}`);
}
);
this.currentWatcher.on('raw', (event: any, path: any, details: any) => {
Expand Down Expand Up @@ -163,7 +178,7 @@ export class RemoteFsProvider implements TreeDataProvider<FileLink> {
let directoryContents: any = this.remoteFsCache.get(remoteDirectory);
if (directoryContents === undefined) {
directoryContents = await getDirectoryContentsByPath(
getPortalId(),
getAccountId(),
remoteDirectory
);
// Default content wasn't originally in this endpoint and so doesn't show up unless manually queried
Expand Down
2 changes: 1 addition & 1 deletion 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/cli-lib');
const { getConfig } = require('@hubspot/local-dev-lib/config');

const isDefaultPortal = (portal: Portal, config: HubspotConfig) => {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/lib/statusBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from 'vscode';
import { COMMANDS } from './constants';

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

let hsStatusBar: StatusBarItem;

Expand Down
4 changes: 2 additions & 2 deletions src/lib/tracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const {
getAccountId,
isTrackingAllowed,
getAccountConfig,
} = require('@hubspot/cli-lib');
const { trackUsage } = require('@hubspot/cli-lib/api/fileMapper');
} = require('@hubspot/local-dev-lib/config');
const { trackUsage } = require('@hubspot/local-dev-lib/trackUsage');

const vscodeTelemetryDocsUrl =
'https://code.visualstudio.com/docs/getstarted/telemetry';
Expand Down
12 changes: 0 additions & 12 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,6 @@ export function instanceOfCommand(object: any): object is Command {
return 'title' in object && 'command' in object;
}

export interface HubLValidationError {
reason: string;
message: string;
lineno: number;
startPosition: number;
categoryErrors: {
fullName?: string;
path?: string;
};
category: string;
}

export interface FileLink {
label: string;
path: string;
Expand Down
Loading

0 comments on commit 76191d8

Please sign in to comment.