Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/196 copy to bu fails when trying to copy from the credential and business unit folder #200

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
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -85,7 +85,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"
}
Expand All @@ -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"
}
Expand All @@ -119,7 +119,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"
}
Expand Down
25 changes: 14 additions & 11 deletions src/devtools/commands/DevToolsCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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<string | number> {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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"];
Expand Down
15 changes: 4 additions & 11 deletions src/devtools/commands/DevToolsStandardCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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
)
};
Expand Down
20 changes: 18 additions & 2 deletions src/devtools/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
try {
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -717,7 +734,6 @@ async function handleCopyToBuCMCommand(selectedPaths: string[]) {
}

return buSelected
.filter((buSelected: string) => buSelected !== businessUnit)
.map((buSelected: string) =>
paths.map((keyFilePath: string) => ({
sourceFilePath: keyFilePath,
Expand Down
6 changes: 1 addition & 5 deletions src/shared/utils/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down