Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@
- Path bug

## [0.3.2]
- Publish bug
- Publish bug

## [0.3.3]
- Load / error messages controlled via verbosity setting
- Update internal fspath handling
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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",
Expand All @@ -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."
}
}
},
Expand Down
50 changes: 34 additions & 16 deletions src/classes/syncer/BambooManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
public static workspaceConfigFileName: string = 'bamboo.conf.json';
public static workspaceTokenCacheFolderName: string = '.bamboo_tokens';

private static ExceptionMessages = {

Check warning on line 12 in src/classes/syncer/BambooManager.ts

View workflow job for this annotation

GitHub Actions / test-extension-frontend

Class Property name `ExceptionMessages` must match one of the following formats: camelCase
UnableToAuthenticateToD365: "Unable to authenticate with the CRM instance. Please check your connection details.",

Check warning on line 13 in src/classes/syncer/BambooManager.ts

View workflow job for this annotation

GitHub Actions / test-extension-frontend

Object Literal Property name `UnableToAuthenticateToD365` must match one of the following formats: camelCase
CantFindBambooConfig: "Cannot find bamboo config file.",

Check warning on line 14 in src/classes/syncer/BambooManager.ts

View workflow job for this annotation

GitHub Actions / test-extension-frontend

Object Literal Property name `CantFindBambooConfig` must match one of the following formats: camelCase
UndefinedWorkspace: "Cannot activate Bamboo. Workspace is undefined.",

Check warning on line 15 in src/classes/syncer/BambooManager.ts

View workflow job for this annotation

GitHub Actions / test-extension-frontend

Object Literal Property name `UndefinedWorkspace` must match one of the following formats: camelCase
NoBambooConfig: `There is no ${BambooManager.workspaceConfigFileName} in the root of the current workspace!`,

Check warning on line 16 in src/classes/syncer/BambooManager.ts

View workflow job for this annotation

GitHub Actions / test-extension-frontend

Object Literal Property name `NoBambooConfig` must match one of the following formats: camelCase
};

private static instance: BambooManager;
Expand Down Expand Up @@ -104,8 +104,8 @@
const rawData = JSON.parse(jsonString);

const credentialTypeMap: Record<string, CredentialType> = {
ClientSecret: CredentialType.ClientSecret,

Check warning on line 107 in src/classes/syncer/BambooManager.ts

View workflow job for this annotation

GitHub Actions / test-extension-frontend

Object Literal Property name `ClientSecret` must match one of the following formats: camelCase
OAuth: CredentialType.OAuth,

Check warning on line 108 in src/classes/syncer/BambooManager.ts

View workflow job for this annotation

GitHub Actions / test-extension-frontend

Object Literal Property name `OAuth` must match one of the following formats: camelCase
};

return {
Expand Down Expand Up @@ -142,7 +142,7 @@
}

const tokenFileFolderPath = await BambooManager.getTokenCacheFolderPath();
if (tokenFileFolderPath === null) return null;

Check warning on line 145 in src/classes/syncer/BambooManager.ts

View workflow job for this annotation

GitHub Actions / test-extension-frontend

Expected { after 'if' condition

const tokenFileFolderPathStr = tokenFileFolderPath instanceof vscode.Uri ? tokenFileFolderPath.fsPath : tokenFileFolderPath;

Expand Down Expand Up @@ -250,22 +250,36 @@
return ctrls;
}

public async syncCurrentFile(currentWorkspacePath: string, filePath: string): Promise<void> {
public async syncCurrentFile(
currentWorkspace: vscode.WorkspaceFolder,
currentOpenFile: vscode.TextDocument
): Promise<void> {
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(
Expand All @@ -277,12 +291,10 @@

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
Expand All @@ -295,32 +307,38 @@

logTemporaryMessage(`${matchingFile.dataverseName} synced successfully.`, VerboseSetting.Low);
}
public async syncCustomControl(currentWorkspacePath: string, customControl: CustomControlMapping): Promise<void> {
const config = await this.getConfig();

public async syncCustomControl(
currentWorkspace: vscode.WorkspaceFolder,
customControl: CustomControlMapping
): Promise<void> {
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);
} else {
logErrorMessage(errorMessage!, VerboseSetting.Low);
}
}

}
14 changes: 7 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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();

Expand All @@ -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() { }
38 changes: 23 additions & 15 deletions src/log/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,38 @@ export async function logMessageWithProgress<T>(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);
}
}
Expand Down
Loading