From f7296df2223e20d42d9d633bfc5b1a59f520d27f Mon Sep 17 00:00:00 2001 From: Anirudh V Date: Mon, 17 Apr 2023 13:07:34 +0530 Subject: [PATCH 1/2] Created a new command BootstrapDiff --- package.json | 5 + src/client/extension.ts | 13 ++ .../bootstrapdiff/BootstrapDiff.ts | 111 ++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 src/client/power-pages/bootstrapdiff/BootstrapDiff.ts diff --git a/package.json b/package.json index 8cf42e90..a7a6fce6 100644 --- a/package.json +++ b/package.json @@ -304,6 +304,11 @@ "command": "microsoft-powerapps-portals.pagetemplate", "category": "Powerpages", "title": "New Page Template" + }, + { + "command": "microsoft-powerapps-portals.bootstrap-diff", + "category": "Powerpages", + "title": "Bootstrap Diff" } ], "configuration": { diff --git a/src/client/extension.ts b/src/client/extension.ts index d30bbd07..a8850d0d 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -31,6 +31,7 @@ import { handleFileSystemCallbacks } from "./power-pages/fileSystemCallbacks"; import { readUserSettings } from "./telemetry/localfileusersettings"; import { initializeGenerator } from "./power-pages/create/CreateCommandWrapper"; import { disposeDiagnostics } from "./power-pages/validationDiagnostics"; +import { bootstrapDiff } from "./power-pages/bootstrapdiff/BootstrapDiff"; let client: LanguageClient; let _context: vscode.ExtensionContext; @@ -96,6 +97,18 @@ export async function activate( ) ); + // registering bootstrapdiff command + _context.subscriptions.push( + vscode.commands.registerCommand('microsoft-powerapps-portals.bootstrap-diff', async() => { + _telemetry.sendTelemetryEvent("StartCommand", { + commandId: "microsoft-powerapps-portals.bootstrap-diff", + }); + bootstrapDiff(); + } + ) + ); + + _context.subscriptions.push( vscode.workspace.onDidOpenTextDocument(() => { if (vscode.window.activeTextEditor === undefined) { diff --git a/src/client/power-pages/bootstrapdiff/BootstrapDiff.ts b/src/client/power-pages/bootstrapdiff/BootstrapDiff.ts new file mode 100644 index 00000000..84626780 --- /dev/null +++ b/src/client/power-pages/bootstrapdiff/BootstrapDiff.ts @@ -0,0 +1,111 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + */ + +import * as vscode from 'vscode'; + +// Green highlight for modifications in the output file +const outputDecorationType = vscode.window.createTextEditorDecorationType({ + backgroundColor: '#90ee90' +}); + +// Red highlight for the classes output in the input file +const inputDecorationType = vscode.window.createTextEditorDecorationType({ + backgroundColor: '#E1AEAD' +}); + +// object for storing class range +type ClassRange = { + start: number; + end : number; + offset : number; + matchedClass : string; + replacedClass: string; + message: string; +}; + +let matchedClasses : ClassRange[][]; + +export async function bootstrapDiff() +{ + const editor = vscode.window.activeTextEditor; + if(!editor) + { + // Handle this to prompt the user to open a file and the run the command + return; + } + + const inputPath = editor.document.uri.path; + + const diffFileName = inputPath + "-diff.json"; + let diffData = ""; + await vscode.workspace.openTextDocument(vscode.Uri.file(diffFileName)).then((document) => { + diffData = document.getText(); + }); + + matchedClasses = JSON.parse(diffData); + hihglightReplacedClasses(editor); + + const workspaceFolders = vscode.workspace?.workspaceFolders; + if(!workspaceFolders) + { + // Handle open the website folder in vscode + return; + } + + const websiteFolder = workspaceFolders[0].name; + const v3websiteFolder = websiteFolder.substring(0,websiteFolder.length - 2); + const v3FilePath = inputPath.replace(websiteFolder,v3websiteFolder); + + const options : vscode.TextDocumentShowOptions = { + viewColumn : 2, + preserveFocus : false + }; + + await vscode.window.showTextDocument(vscode.Uri.file(v3FilePath),options); + const v3editor = vscode.window.activeTextEditor; + if(!v3editor) + { + // Handle this case + return; + } + hihglightMatchedClasses(v3editor); +} + +// Hihglights the replaced classes in V5 file +function hihglightReplacedClasses(editor: vscode.TextEditor) +{ + const hoverMessages : vscode.DecorationOptions[] = []; + let offset = 0; + + for(let l=0;l Date: Fri, 28 Apr 2023 15:26:40 +0530 Subject: [PATCH 2/2] handling multi-root wroksapce --- .../power-pages/bootstrapdiff/BootstrapDiff.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/client/power-pages/bootstrapdiff/BootstrapDiff.ts b/src/client/power-pages/bootstrapdiff/BootstrapDiff.ts index 84626780..a5a3433b 100644 --- a/src/client/power-pages/bootstrapdiff/BootstrapDiff.ts +++ b/src/client/power-pages/bootstrapdiff/BootstrapDiff.ts @@ -33,6 +33,7 @@ export async function bootstrapDiff() if(!editor) { // Handle this to prompt the user to open a file and the run the command + vscode.window.showErrorMessage("Open a file before executing the command") return; } @@ -47,14 +48,13 @@ export async function bootstrapDiff() matchedClasses = JSON.parse(diffData); hihglightReplacedClasses(editor); - const workspaceFolders = vscode.workspace?.workspaceFolders; - if(!workspaceFolders) - { - // Handle open the website folder in vscode - return; - } + const websiteFolder = vscode.workspace.getWorkspaceFolder(editor.document.uri)?.name; + if(!websiteFolder) + { + vscode.window.showErrorMessage("Open Website folder in the wrokspace") + return;`` + } - const websiteFolder = workspaceFolders[0].name; const v3websiteFolder = websiteFolder.substring(0,websiteFolder.length - 2); const v3FilePath = inputPath.replace(websiteFolder,v3websiteFolder);