Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/npm_and_yarn/develop/typescrip…
Browse files Browse the repository at this point in the history
…t-eslint/parser-7.18.0
  • Loading branch information
anasilva105 authored Aug 28, 2024
2 parents 7e35130 + d7fc713 commit f30aa27
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 120 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 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 Expand Up @@ -165,7 +165,7 @@
},
"dependencies": {
"@salesforce-ux/design-system": "^2.23.2",
"@vscode/codicons": "^0.0.35",
"@vscode/codicons": "^0.0.36",
"winston": "^3.13.0"
}
}
12 changes: 2 additions & 10 deletions src/devtools/commands/DevToolsAdminCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ class DevToolsAdminCommands extends DevToolsCommands {
}
log("debug", `Init payload: ${JSON.stringify(initArgs)}`);

const commandConfigured: string | undefined = await this.configureCommandWithParameters(
config,
initArgs,
[]
);
const commandConfigured: string | undefined = await this.configureCommandWithParameters(config, initArgs);
// Checks if the command is still missing so required parameter
if (this.hasPlaceholders(commandConfigured)) {
log("debug", `Required Parameters missing from Init command: ${commandConfigured}`);
Expand All @@ -89,11 +85,7 @@ class DevToolsAdminCommands extends DevToolsCommands {
try {
log("info", `Running DevTools Admin Command: Explain Types...`);
if ("command" in config && config.command) {
const commandConfigured: string | undefined = await this.configureCommandWithParameters(
config,
args,
[]
);
const commandConfigured: string | undefined = await this.configureCommandWithParameters(config, args);
log("debug", `Explain types final command: ${commandConfigured}`);
const commandResult: string | number = await this.executeCommand(
commandConfigured,
Expand Down
56 changes: 15 additions & 41 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 @@ -44,8 +42,7 @@ abstract class DevToolsCommands {

async configureCommandWithParameters(
config: DevToolsCommandSetting,
args: { [key: string]: string | string[] | boolean },
mdTypes: SupportedMetadataTypes[]
args: { [key: string]: string | string[] | boolean }
): Promise<string> {
log("debug", `ConfigureCommandWithParameters: ${JSON.stringify(config)}`);
let { command } = config;
Expand All @@ -54,14 +51,6 @@ abstract class DevToolsCommands {
for (const param of config.requiredParams) {
if (param in args && args[param]) {
command = command.replace(`{{${param}}}`, args[param] as string);
} else {
// Requests user
if (param.toLowerCase() === "mdtypes" && mdTypes.length) {
const userSelecteMDTypes: string | undefined = await this.handleMetadataTypeRequest(mdTypes);
if (userSelecteMDTypes) {
command = command.replace(`{{${param}}}`, `"${userSelecteMDTypes}"`);
}
}
}
}
}
Expand All @@ -78,26 +67,6 @@ abstract class DevToolsCommands {
return command;
}

async handleMetadataTypeRequest(mdTypes: SupportedMetadataTypes[]): Promise<string | undefined> {
const mdTypeInputOptions: InputOptionsSettings[] = mdTypes.map((mdType: SupportedMetadataTypes) => ({
id: mdType.apiName,
label: mdType.name,
detail: ""
}));
const userResponse: InputOptionsSettings | InputOptionsSettings[] | undefined =
await editorInput.handleQuickPickSelection(
mdTypeInputOptions,
"Please select one or multiple metadata types...",
true
);
if (userResponse && Array.isArray(userResponse)) {
const mdTypes: string = `${userResponse.map((response: InputOptionsSettings) => response.id)}`;
log("debug", `User selected metadata types: "${mdTypes}"`);
return mdTypes;
}
return;
}

hasPlaceholders(command: string): boolean {
const pattern: RegExp = /{{.*?}}/g;
return pattern.test(command);
Expand Down Expand Up @@ -130,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 @@ -219,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
35 changes: 8 additions & 27 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 All @@ -70,15 +63,8 @@ class DevToolsStandardCommands extends DevToolsCommands {
) {
log("info", `Running DevTools Standard Command: Retrieve...`);
if ("command" in config && config.command) {
// Gets that metadata types that are supported for retrieve
const supportedMdTypes: SupportedMetadataTypes[] = this.getSupportedMetadataTypeByAction("retrieve");

// Configures the command to replace all the parameters with the values
const commandConfigured: string | undefined = await this.configureCommandWithParameters(
config,
args,
supportedMdTypes
);
const commandConfigured: string | undefined = await this.configureCommandWithParameters(config, args);

// Checks if the command is still missing so required parameter
if (this.hasPlaceholders(commandConfigured)) {
Expand All @@ -89,6 +75,7 @@ class DevToolsStandardCommands extends DevToolsCommands {

log("debug", `Retrieve Command configured: ${commandConfigured}`);
loadingNotification();

const commandResult: string | number = await this.executeCommand(commandConfigured, path, true);
if (typeof commandResult === "number") {
handleCommandResult({ success: commandResult === 0, cancelled: false });
Expand All @@ -106,15 +93,8 @@ class DevToolsStandardCommands extends DevToolsCommands {
) {
log("info", `Running DevTools Standard Command: Deploy...`);
if ("command" in config && config.command) {
// Gets that metadata types that are supported for deploy
const supportedMdTypes: SupportedMetadataTypes[] = this.getSupportedMetadataTypeByAction("deploy");

// Configures the command to replace all the parameters with the values
const commandConfigured: string | undefined = await this.configureCommandWithParameters(
config,
args,
supportedMdTypes
);
const commandConfigured: string | undefined = await this.configureCommandWithParameters(config, args);

// Checks if the command is still missing so required parameter
if (this.hasPlaceholders(commandConfigured)) {
Expand All @@ -125,6 +105,7 @@ class DevToolsStandardCommands extends DevToolsCommands {

log("debug", `Deploy Command configured: ${commandConfigured}`);
loadingNotification();

const commandResult: string | number = await this.executeCommand(commandConfigured, path, true);
if (typeof commandResult === "number") {
handleCommandResult({ success: commandResult === 0, cancelled: false });
Expand Down
8 changes: 4 additions & 4 deletions src/devtools/commands/commands.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@
"id":"retrieve",
"title": "Retrieve",
"command": "mcdev retrieve {{bu}} {{mdtypes}} {{key}} --skipInteraction",
"requiredParams": ["bu", "mdtypes"],
"optionalParams": ["key"],
"requiredParams": ["bu"],
"optionalParams": ["key", "mdtypes"],
"description": "Retrieves metadata of a business unit.",
"isAvailable": true
},
{
"id":"deploy",
"title": "Deploy",
"command": "mcdev deploy {{bu}} {{mdtypes}} {{key}} {{fromRetrieve}} --skipInteraction",
"requiredParams": ["bu", "mdtypes"],
"optionalParams": ["key", "fromRetrieve"],
"requiredParams": ["bu"],
"optionalParams": ["key", "mdtypes", "fromRetrieve"],
"description": "Deploys local metadata to a business unit.",
"isAvailable": true
},
Expand Down
42 changes: 29 additions & 13 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 @@ -60,8 +61,6 @@ async function handleDevToolsRequirements(/*isDevToolsProject: boolean*/): Promi
}
log("info", "SFMC DevTools is installed.");

// Deactivates Compact folders for command right execution
editorDependencies.deactivateCompactFolders();
// init DevTools Commands
DevToolsCommands.init();
return;
Expand Down Expand Up @@ -624,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 @@ -687,21 +702,23 @@ async function handleCopyToBuCMCommand(selectedPaths: string[]) {
const buSelected: string[] = buOptions.map((bu: InputOptionsSettings) => bu.id);

const filePathsConfigured: FileCopyConfig[] = supportedMetadataTypes
.map((configPath: DevToolsPathConfiguration) => {
const { absolutePath, businessUnit } = configPath;

.map(({ absolutePath, businessUnit, metadataType, keys }: DevToolsPathConfiguration) => {
if (businessUnit) {
let paths: string[] = [];

if (file.isPathADirectory(absolutePath)) {
paths = [...paths, absolutePath];
// When the selected file to copy is inside a folder in asset type
// the whole folder and all files inside should be copied
if (metadataType === "asset" && keys.length > 2) {
const [_, assetKey]: string[] = keys;
paths.push(absolutePath.split(assetKey).shift() + assetKey);
} else if (file.isPathADirectory(absolutePath)) {
paths.push(absolutePath);
} else {
const [currentFileExt]: string[] = mainConfig.fileExtensions.filter(
(fileExt: string) => absolutePath.endsWith(fileExt)
);
if (currentFileExt) {
paths = [
...paths,
// Copies the same file for multiple extensions, eg sql & json
paths.push(
...file.fileExists(
mainConfig.fileExtensions
.filter(
Expand All @@ -712,12 +729,11 @@ async function handleCopyToBuCMCommand(selectedPaths: string[]) {
absolutePath.replace(currentFileExt, fileExtension)
)
)
];
);
}
}

return buSelected
.filter((buSelected: string) => buSelected !== businessUnit)
.map((buSelected: string) =>
paths.map((keyFilePath: string) => ({
sourceFilePath: keyFilePath,
Expand Down
Loading

0 comments on commit f30aa27

Please sign in to comment.