From b8aac4b94b960bfc2eb42d1c5e169c9c35644035 Mon Sep 17 00:00:00 2001 From: Ana Silva Date: Tue, 27 Aug 2024 15:38:01 +0200 Subject: [PATCH 1/4] removed "mcdev: Copy to ..." option from menu for the Credential folder --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 30389b0..b9d8e75 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "group": "devtools" }, { - "when": "sfmc-devtools-vscode.isDevToolsProject && resourcePath =~ /retrieve/ && resourceFilename != 'retrieve' && resourceFilename != 'deploy'", + "when": "sfmc-devtools-vscode.isDevToolsProject && resourcePath =~ /retrieve/ && resourceFilename != 'retrieve' && resourceFilename != 'deploy' && resourcePath =~ /retrieve\\\\.*\\\\.*/", "command": "sfmc-devtools-vscext.devtoolsCMCopyToBU", "group": "devtools" } @@ -119,7 +119,7 @@ "group": "devtools" }, { - "when": "sfmc-devtools-vscode.isDevToolsProject && resourcePath =~ /retrieve/ && resourceFilename != 'retrieve' && resourceFilename != 'deploy'", + "when": "sfmc-devtools-vscode.isDevToolsProject && resourcePath =~ /retrieve/ && resourceFilename != 'retrieve' && resourceFilename != 'deploy' && resourcePath =~ /retrieve\\\\.*\\\\.*/", "command": "sfmc-devtools-vscext.devtoolsCMCopyToBU", "group": "devtools" } From 00f98e4433ddcaf2edee16b97fb49ed8b5ded9f8 Mon Sep 17 00:00:00 2001 From: Ana Silva Date: Wed, 28 Aug 2024 13:00:04 +0200 Subject: [PATCH 2/4] Copy action is copying only valid mdtypes when selected on the BU folder. --- src/devtools/commands/DevToolsCommands.ts | 25 +++++++++++-------- .../commands/DevToolsStandardCommands.ts | 15 +++-------- src/devtools/main.ts | 19 +++++++++++++- src/shared/utils/file.ts | 6 +---- 4 files changed, 37 insertions(+), 28 deletions(-) diff --git a/src/devtools/commands/DevToolsCommands.ts b/src/devtools/commands/DevToolsCommands.ts index a7f1d6a..65a1221 100644 --- a/src/devtools/commands/DevToolsCommands.ts +++ b/src/devtools/commands/DevToolsCommands.ts @@ -3,7 +3,6 @@ import * as commandsConfig from "./commands.config.json"; import DevToolsCommandSetting from "../../shared/interfaces/devToolsCommandSetting"; import DevToolsCommandRunner from "../../shared/interfaces/devToolsCommandRunner"; import SupportedMetadataTypes from "../../shared/interfaces/supportedMetadataTypes"; -import InputOptionsSettings from "../../shared/interfaces/inputOptionsSettings"; import { editorInput } from "../../editor/input"; import { log } from "../../editor/output"; import { lib } from "../../shared/utils/lib"; @@ -13,10 +12,9 @@ import { metadatatypes } from "../../config/metadatatypes.config"; abstract class DevToolsCommands { static readonly commandPrefix: string = "mcdev"; static commandMap: { [key: string]: DevToolsCommands }; + static metadataTypes: SupportedMetadataTypes[]; abstract run(commandRunner: DevToolsCommandRunner): void; - abstract setMetadataTypes(mdTypes: SupportedMetadataTypes[]): void; - abstract getMetadataTypes(): SupportedMetadataTypes[] | void; abstract isSupportedMetadataType(action: string, metadataType: string): boolean | void; executeCommand(command: string, path: string, showOnTerminal: boolean): Promise { @@ -101,14 +99,11 @@ abstract class DevToolsCommands { }, {}); } - // Sends the supported mtdata types to each DevTools Command - Object.keys(this.commandMap).forEach((key: string) => { - const devToolCommand: DevToolsCommands = this.commandMap[key]; - const sortedSuppMdtByName: SupportedMetadataTypes[] = metadatatypes.sort((a, b) => - a.name.localeCompare(b.name) - ); - devToolCommand.setMetadataTypes(sortedSuppMdtByName); - }); + // Sets the metadata types sorted by name + const sortedSuppMdtByName: SupportedMetadataTypes[] = metadatatypes.sort((a, b) => + a.name.localeCompare(b.name) + ); + this.setMetadataTypes(sortedSuppMdtByName); } static async runCommand( @@ -190,6 +185,14 @@ abstract class DevToolsCommands { return false; } + static setMetadataTypes(mdTypes: SupportedMetadataTypes[]): void { + this.metadataTypes = mdTypes; + } + + static getMetadataTypes(): SupportedMetadataTypes[] { + return this.metadataTypes; + } + static isSupportedMetadataType(action: string, metadataType: string) { if ("standard" in this.commandMap) { const devToolsCommand: DevToolsCommands = this.commandMap["standard"]; diff --git a/src/devtools/commands/DevToolsStandardCommands.ts b/src/devtools/commands/DevToolsStandardCommands.ts index ccbc968..6d40682 100644 --- a/src/devtools/commands/DevToolsStandardCommands.ts +++ b/src/devtools/commands/DevToolsStandardCommands.ts @@ -13,7 +13,6 @@ class DevToolsStandardCommands extends DevToolsCommands { commandHandlers: { [key: string]: (args?: any) => void } ) => void; } = {}; - private metadataTypes: SupportedMetadataTypes[] = []; constructor() { super(); log("debug", "DevToolsStandardCommands Class created"); @@ -35,20 +34,14 @@ class DevToolsStandardCommands extends DevToolsCommands { } } - setMetadataTypes(mdTypes: SupportedMetadataTypes[]): void { - this.metadataTypes = mdTypes; - } - - getMetadataTypes(): SupportedMetadataTypes[] { - return this.metadataTypes; - } - getSupportedMetadataTypeByAction(action: string) { const supportedActions: { [key: string]: () => SupportedMetadataTypes[] } = { retrieve: () => - this.getMetadataTypes().filter((mdType: SupportedMetadataTypes) => mdType.supports.retrieve), + DevToolsCommands.getMetadataTypes().filter( + (mdType: SupportedMetadataTypes) => mdType.supports.retrieve + ), deploy: () => - this.getMetadataTypes().filter( + DevToolsCommands.getMetadataTypes().filter( (mdType: SupportedMetadataTypes) => mdType.supports.create || mdType.supports.update ) }; diff --git a/src/devtools/main.ts b/src/devtools/main.ts index fe6521c..4f2e679 100644 --- a/src/devtools/main.ts +++ b/src/devtools/main.ts @@ -15,6 +15,7 @@ import DevToolsPathComponents from "../shared/interfaces/devToolsPathComponents" import { lib } from "../shared/utils/lib"; import { file } from "../shared/utils/file"; import { editorCommands } from "../editor/commands"; +import SupportedMetadataTypes from "../shared/interfaces/supportedMetadataTypes"; async function initDevToolsExtension(): Promise { try { @@ -622,7 +623,23 @@ async function handleCopyToBuCMCommand(selectedPaths: string[]) { const { supportedMetadataTypes, unsupportedMetadataTypes }: SupportedMetadataTypeConfiguration = configuredSelectedPaths.reduce( (accObj: SupportedMetadataTypeConfiguration, configPath: DevToolsPathConfiguration) => { - if (DevToolsCommands.isSupportedMetadataType("deploy", configPath.metadataType)) { + if (!configPath.metadataType) { + // Gets all the metadata types that are supported for deployment + const allDeployMetadataTypes: SupportedMetadataTypes[] = + DevToolsCommands.getMetadataTypes().filter((mdType: SupportedMetadataTypes) => + DevToolsCommands.isSupportedMetadataType("deploy", mdType.apiName) + ); + // Configures and adds all the metadata types that exist in the BU folder + accObj.supportedMetadataTypes = allDeployMetadataTypes + .map((mdType: SupportedMetadataTypes) => ({ + ...configPath, + absolutePath: `${configPath.absolutePath}/${mdType.apiName}`, + metadataType: mdType.apiName + })) + .filter((pathConfig: DevToolsPathConfiguration) => + file.isPathADirectory(pathConfig.absolutePath) + ); + } else if (DevToolsCommands.isSupportedMetadataType("deploy", configPath.metadataType)) { accObj.supportedMetadataTypes.push(configPath); } else { accObj.unsupportedMetadataTypes = lib.removeDuplicates([ diff --git a/src/shared/utils/file.ts b/src/shared/utils/file.ts index ae2a5e0..0ea1bcb 100644 --- a/src/shared/utils/file.ts +++ b/src/shared/utils/file.ts @@ -18,11 +18,7 @@ function fileExists(path: string | string[]): string[] { } function isPathADirectory(path: string): boolean { - try { - return fs.lstatSync(path.replace(/^\/[a-zA-Z]:/g, "")).isDirectory(); - } catch (error) { - throw error; - } + return fileExists(path).length > 0 && fs.lstatSync(path.replace(/^\/[a-zA-Z]:/g, "")).isDirectory(); } function createFilePath(pathArray: string[]): string { From 8ee8c029516feaa19bac56c08fc4a2096f5ec743 Mon Sep 17 00:00:00 2001 From: Ana Silva Date: Wed, 28 Aug 2024 14:11:15 +0200 Subject: [PATCH 3/4] mcdev: Copy... allows to copy to same business unit --- src/devtools/main.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/devtools/main.ts b/src/devtools/main.ts index 4f2e679..51e1dca 100644 --- a/src/devtools/main.ts +++ b/src/devtools/main.ts @@ -734,7 +734,6 @@ async function handleCopyToBuCMCommand(selectedPaths: string[]) { } return buSelected - .filter((buSelected: string) => buSelected !== businessUnit) .map((buSelected: string) => paths.map((keyFilePath: string) => ({ sourceFilePath: keyFilePath, From 6f0a8196d38207d41738ffeb69d2324addcd755d Mon Sep 17 00:00:00 2001 From: Ana Silva Date: Wed, 28 Aug 2024 16:19:33 +0200 Subject: [PATCH 4/4] Removed ununecessary conditions for mcdev Copy in package.json --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index b9d8e75..ad18861 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ }, { "command": "sfmc-devtools-vscext.devtoolsCMCopyToBU", - "when": "sfmc-devtools-vscode.isDevToolsProject && editorIsOpen && resourcePath =~ /retrieve/" + "when": "sfmc-devtools-vscode.isDevToolsProject && editorIsOpen && resourcePath =~ /\\\\retrieve\\\\.*\\\\.*/" } ], "explorer/context": [ @@ -85,7 +85,7 @@ "group": "devtools" }, { - "when": "sfmc-devtools-vscode.isDevToolsProject && resourcePath =~ /retrieve/ && resourceFilename != 'retrieve' && resourceFilename != 'deploy' && resourcePath =~ /retrieve\\\\.*\\\\.*/", + "when": "sfmc-devtools-vscode.isDevToolsProject && resourcePath =~ /\\\\retrieve\\\\.*\\\\.*/", "command": "sfmc-devtools-vscext.devtoolsCMCopyToBU", "group": "devtools" } @@ -102,7 +102,7 @@ "group": "devtools" }, { - "when": "sfmc-devtools-vscode.isDevToolsProject && resourcePath =~ /retrieve/ && resourceFilename != 'retrieve' && resourceFilename != 'deploy'", + "when": "sfmc-devtools-vscode.isDevToolsProject && resourcePath =~ /\\\\retrieve\\\\.*\\\\.*/", "command": "sfmc-devtools-vscext.devtoolsCMCopyToBU", "group": "devtools" } @@ -119,7 +119,7 @@ "group": "devtools" }, { - "when": "sfmc-devtools-vscode.isDevToolsProject && resourcePath =~ /retrieve/ && resourceFilename != 'retrieve' && resourceFilename != 'deploy' && resourcePath =~ /retrieve\\\\.*\\\\.*/", + "when": "sfmc-devtools-vscode.isDevToolsProject && resourcePath =~ /\\\\retrieve\\\\.*\\\\.*/", "command": "sfmc-devtools-vscext.devtoolsCMCopyToBU", "group": "devtools" }