diff --git a/CHANGELOG.md b/CHANGELOG.md index 539be4b..3806e87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,4 +43,8 @@ - Path bug ## [0.3.2] -- Publish bug \ No newline at end of file +- Publish bug + +## [0.3.3] +- Load / error messages controlled via verbosity setting +- Update internal fspath handling \ No newline at end of file diff --git a/package.json b/package.json index f19490b..e5ce581 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "url": "https://github.com/Root16/bamboo" }, "description": "Enables users to create, update, and publish Web Resources and Custom Controls for Microsoft Power Platform — directly from VS Code.", - "version": "0.3.2", + "version": "0.3.3", "icon": "resources/bamboo-green.png", "engines": { "vscode": "^1.73.0" @@ -29,7 +29,7 @@ "high" ], "default": "low", - "description": "Set the verbosity level of how many messages are diaplayed." + "description": "Set the verbosity level of how many messages are displayed." }, "bamboo.general.listSolutionComponentsOnStartup": { "type": "boolean", @@ -44,7 +44,7 @@ "bamboo.customControl.publishAfterSync": { "type": "boolean", "default": true, - "description": "When syncing a custom control soution, publish after a successful upload." + "description": "When syncing a custom control solution, publish after a successful upload." } } }, diff --git a/src/classes/syncer/BambooManager.ts b/src/classes/syncer/BambooManager.ts index 55759ac..3a6e0fc 100644 --- a/src/classes/syncer/BambooManager.ts +++ b/src/classes/syncer/BambooManager.ts @@ -250,22 +250,36 @@ export class BambooManager { return ctrls; } - public async syncCurrentFile(currentWorkspacePath: string, filePath: string): Promise { + public async syncCurrentFile( + currentWorkspace: vscode.WorkspaceFolder, + currentOpenFile: vscode.TextDocument + ): Promise { const config = await this.getConfig(); - if (!config) { return; } const token = await this.getToken(); - if (token === null) { return; } - const relativePathOnDisk = filePath.replace(currentWorkspacePath, "").substring(1); + const workspaceRoot = currentWorkspace.uri.fsPath; + + const openFileFsPath = currentOpenFile.uri.fsPath; - const matchingFiles = config.webResources.filter(w => w.relativePathOnDisk === relativePathOnDisk); + const relativePathOnDisk = path.relative(workspaceRoot, openFileFsPath).replace(/\\/g, "/"); + + const matchingFiles = config.webResources.filter(w => { + const webResourcePath = w.relativePathOnDisk.replace(/\\/g, "/"); + + logTemporaryMessage( + `Comparing target: "${relativePathOnDisk}" with web resource: "${webResourcePath}"`, + VerboseSetting.High + ); + + return webResourcePath === relativePathOnDisk; + }); if (matchingFiles.length !== 1) { logErrorMessage( @@ -277,12 +291,10 @@ export class BambooManager { const matchingFile = matchingFiles[0]; - const fullPath = currentWorkspacePath + "/" + matchingFile.relativePathOnDisk; - const fixedPath = fullPath.replace(/^\/([a-zA-Z]):\//, "$1:/"); // Remove extra leading slash if present - const normalizedPath = path.normalize(fixedPath); + const fullUri = vscode.Uri.joinPath(currentWorkspace.uri, ...matchingFile.relativePathOnDisk.split("/")); const [success, errorMessage] = await this.client.uploadJavaScriptFile( - normalizedPath, + fullUri.fsPath, matchingFile.dataverseName, config.solutionUniqueName, token @@ -295,27 +307,32 @@ export class BambooManager { logTemporaryMessage(`${matchingFile.dataverseName} synced successfully.`, VerboseSetting.Low); } - public async syncCustomControl(currentWorkspacePath: string, customControl: CustomControlMapping): Promise { - const config = await this.getConfig(); + public async syncCustomControl( + currentWorkspace: vscode.WorkspaceFolder, + customControl: CustomControlMapping + ): Promise { + const config = await this.getConfig(); if (!config) { return; } const token = await this.getToken(); - if (token === null) { return; } - const fullPath = currentWorkspacePath + "/" + customControl.relativePathOnDiskToSolution; - const fixedPath = fullPath.replace(/^\/([a-zA-Z]):\//, "$1:/"); // Remove extra leading slash if present - const normalizedPath = path.normalize(fixedPath); + const workspaceRoot = currentWorkspace.uri.fsPath; + + const fullPath = path.join(workspaceRoot, customControl.relativePathOnDiskToSolution); + + const normalizedPath = path.normalize(fullPath).replace(/\\/g, "/"); const [success, errorMessage] = await this.client.syncSolution( customControl.solutionName, normalizedPath, - token); + token + ); if (success) { logTemporaryMessage(`Synced control: ${customControl.dataverseName}.`, VerboseSetting.Low); @@ -323,4 +340,5 @@ export class BambooManager { logErrorMessage(errorMessage!, VerboseSetting.Low); } } + } diff --git a/src/extension.ts b/src/extension.ts index 2a652fd..f126412 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -61,11 +61,11 @@ export async function activate(context: vscode.ExtensionContext) { return; } - const filePath = editor!.document.uri.path; + const currentOpenFile = editor!.document; - const currentWorkspacePath = currentWorkspaceFolders![0].uri.path; + const currentWorkspace = currentWorkspaceFolders![0]; - await bambooManager.syncCurrentFile(currentWorkspacePath, filePath); + await bambooManager.syncCurrentFile(currentWorkspace, currentOpenFile); }); vscode.commands.registerCommand('bamboo.syncAllFiles', async () => { @@ -87,7 +87,7 @@ export async function activate(context: vscode.ExtensionContext) { return; } - const currentWorkspacePath = currentWorkspaceFolders![0].uri.path; + const currentWorkspacePath = currentWorkspaceFolders![0]; const config = await bambooManager.getConfig(); @@ -105,13 +105,13 @@ export async function activate(context: vscode.ExtensionContext) { }); if (selected) { - const selectedCustomConrol = config.customControls.filter(c => c.dataverseName === selected.label)![0]; + const selectedCustomControl = config.customControls.filter(c => c.dataverseName === selected.label)![0]; - await bambooManager.syncCustomControl(currentWorkspacePath, selectedCustomConrol); + await bambooManager.syncCustomControl(currentWorkspacePath, selectedCustomControl); } }); - logMessage(`Bamboo initialized successfully.`, VerboseSetting.Low) + logMessage(`Bamboo initialized successfully.`, VerboseSetting.High) } function deactivate() { } \ No newline at end of file diff --git a/src/log/message.ts b/src/log/message.ts index 2ca00a1..f1843e8 100644 --- a/src/log/message.ts +++ b/src/log/message.ts @@ -54,30 +54,38 @@ export async function logMessageWithProgress(message: string, action: () => P export function logMessage(message: string, verboseSetting: VerboseSetting) { console.log(message); + const verbosityPreference = vscode.workspace + .getConfiguration() + .get<"low" | "high">("bamboo.general.messageVerbosity"); - const verbosityPreference: "low" | "high" | undefined = vscode.workspace.getConfiguration().get<"low" | "high">("bamboo.general.messageVerbosity"); + let shouldShow = false; - if (verboseSetting === VerboseSetting.Low && ( - verbosityPreference === "low" || - verbosityPreference === "high" - )) { - vscode.window.showInformationMessage(message); - } else if (verboseSetting === VerboseSetting.High && verbosityPreference === "high") { + if (verboseSetting === VerboseSetting.Low) { + shouldShow = verbosityPreference === "low" || verbosityPreference === "high"; + } else if (verboseSetting === VerboseSetting.High) { + shouldShow = verbosityPreference === "high"; + } + + if (shouldShow) { vscode.window.showInformationMessage(message); } } export function logErrorMessage(message: string, verboseSetting: VerboseSetting) { - console.error(message); + console.log(message); + const verbosityPreference = vscode.workspace + .getConfiguration() + .get<"low" | "high">("bamboo.general.messageVerbosity"); - const verbosityPreference: "low" | "high" | undefined = vscode.workspace.getConfiguration().get<"low" | "high">("bamboo.general.messageVerbosity"); + let shouldShow = false; - if (verboseSetting === VerboseSetting.Low && ( - verbosityPreference === "low" || - verbosityPreference === "high" - )) { - vscode.window.showErrorMessage(message); - } else if (verboseSetting === VerboseSetting.High && verbosityPreference === "high") { + if (verboseSetting === VerboseSetting.Low) { + shouldShow = verbosityPreference === "low" || verbosityPreference === "high"; + } else if (verboseSetting === VerboseSetting.High) { + shouldShow = verbosityPreference === "high"; + } + + if (shouldShow) { vscode.window.showErrorMessage(message); } }