Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/npm_and_yarn/develop/eslint-8.…
Browse files Browse the repository at this point in the history
…56.0
  • Loading branch information
anasilva105 authored Jan 24, 2024
2 parents 5245814 + 6df3d6d commit 84267a7
Show file tree
Hide file tree
Showing 16 changed files with 375 additions and 144 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

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

37 changes: 34 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Accenture Salesforce Marketing Cloud DevTools Vscode Extension",
"version": "0.0.1",
"peerDependencies": {
"mcdev": "^6.0.0"
"mcdev": ">=5.2.0"
},
"repository": {
"type": "git",
Expand All @@ -29,6 +29,10 @@
{
"command": "sfmc-devtools-vscext.devtoolsCMDeploy",
"title": "mcdev: Deploy"
},
{
"command": "sfmc-devtools-vscext.devtoolsCMCopyToBU",
"title": "mcdev: Copy to Business Unit"
}
],
"menus": {
Expand All @@ -39,8 +43,35 @@
"group": "devtools"
},
{
"when": "resourcePath =~ /deploy/ || (resourcePath =~ /retrieve/ && (resourceLangId == json || resourceLangId == html || resourceLangId == sql || resourceLangId == markdown))",
"when": "resourcePath =~ /deploy/ || (resourcePath =~ /retrieve/ && (resourceExtname == '.json' || resourceExtname == '.html' || resourceExtname == '.sql' || resourceLangId == 'markdown'))",
"command": "sfmc-devtools-vscext.devtoolsCMDeploy",
"group": "devtools"
},
{
"when": "(resourcePath =~ /retrieve/ || resourcePath =~ /deploy/) && resourceFilename != 'retrieve' && resourceFilename != 'deploy'",
"command": "sfmc-devtools-vscext.devtoolsCMCopyToBU",
"group": "devtools"
}
],
"commandPalette": [
{
"command": "sfmc-devtools-vscext.devtoolsCMRetrieve",
"when": "false"
},
{
"command": "sfmc-devtools-vscext.devtoolsCMDeploy",
"when": "false"
}
],
"editor/title/context": [
{
"when": "resourcePath =~ /retrieve/",
"command": "sfmc-devtools-vscext.devtoolsCMRetrieve",
"group": "devtools"
},
{
"when": "resourcePath =~ /deploy/ || (resourcePath =~ /retrieve/ && (resourceLangId == json || resourceLangId == html || resourceLangId == sql || resourceLangId == markdown || resourceLangId == ssjs))",
"command": "sfmc-devtools-vscext.devtoolsCMDeploy",
"group": "devtools"
}
]
Expand Down Expand Up @@ -78,4 +109,4 @@
"@vscode/codicons": "^0.0.35",
"winston": "^3.11.0"
}
}
}
8 changes: 5 additions & 3 deletions src/config/containers.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ export const containersConfig: {
statusBarDevToolsInitializeTitle: string,
statusBarDevToolsInitializeCommand: string,
contextMenuRetrieveCommand: string,
contextMenuDeployCommand: string
contextMenuDeployCommand: string,
contextMenuCopyToBUCommand: string
} = {
statusBarDevToolsName: "devtoolsmcdev",
statusBarDevToolsName: "mcdev",
statusBarDevToolsTitle: "mcdev",
statusBarDevToolsCommand: "sfmc-devtools-vscext.devtoolsSBMcdev",
statusBarDevToolsCredentialBUName: "devtoolscredentialbu",
Expand All @@ -27,5 +28,6 @@ export const containersConfig: {
statusBarDevToolsInitializeTitle: "Initialize",
statusBarDevToolsInitializeCommand: "sfmc-devtools-vscext.devtoolsSBInitialize",
contextMenuRetrieveCommand: "sfmc-devtools-vscext.devtoolsCMRetrieve",
contextMenuDeployCommand: "sfmc-devtools-vscext.devtoolsCMDeploy"
contextMenuDeployCommand: "sfmc-devtools-vscext.devtoolsCMDeploy",
contextMenuCopyToBUCommand: "sfmc-devtools-vscext.devtoolsCMCopyToBU"
};
9 changes: 6 additions & 3 deletions src/config/main.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const mainConfig: {
credentialsFilename: string,
requiredFiles: string[],
fileExtensions: string[],
allPlaceholder: string,
messages: {
selectedCredentialsBU: string,
Expand All @@ -12,15 +13,17 @@ export const mainConfig: {
initiatingDevTools: string,
runningCommand: string,
successRunningCommand: string,
failureRunningCommand: string
failureRunningCommand: string,

}
} = {
credentialsFilename: ".mcdevrc.json",
requiredFiles: [".mcdevrc.json", ".mcdev-auth.json"],
fileExtensions: ["meta.json", "meta.sql", "meta.html", "meta.ssjs", "doc.md"],
allPlaceholder: "*All*",
messages: {
selectedCredentialsBU: "Please select a Credential/BU before running the command",
selectCredential: "Select all or one of the credentials below...",
selectedCredentialsBU: "Select a Credential/BU before running the command",
selectCredential: "Select one of the credentials below...",
selectBusinessUnit: "Select all or one of the business units below...",
selectCommandType: "Select one DevTools command type...",
selectCommand: "Select one DevTools Command...",
Expand Down
73 changes: 44 additions & 29 deletions src/devtools/commands/DevToolsAdminCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class DevToolsAdminCommands extends DevToolsCommands {
private commandMethods: {
[key: string]: (
config: DevToolsCommandSetting,
args: {[key: string]: any },
args: {[key: string]: string | string[] | boolean },
path: string,
handleResult: (result?: any) => void)
=> void
commandHandlers: { [key: string]: (args?: any) => void }
) => void
} = {};
constructor(){
super();
Expand All @@ -29,20 +29,25 @@ class DevToolsAdminCommands extends DevToolsCommands {
commandConfig,
commandArgs,
commandPath,
commandResultHandler
commandHandlers
}: DevToolsCommandRunner = commandRunner;

log("debug", `Running DevTools Admin Command for id '${commandId}'.`);
if(commandId in this.commandMethods){
this.commandMethods[commandId](commandConfig, commandArgs, commandPath, commandResultHandler);
this.commandMethods[commandId](commandConfig, commandArgs, commandPath, commandHandlers);
}else{
log("error", `DevTools Admin Command method for id '${commandId}' is not implemented.`);
}
}

setMetadataTypes(_: SupportedMetadataTypes[]): void {}

async init(config: DevToolsCommandSetting, _: {[key: string]: any}, path: string, handleResult: (result?: any) => void){
async init(
config: DevToolsCommandSetting,
_: {[key: string]: string | string[] | boolean},
path: string,
{ handleCommandResult }: { [key: string]: (args?: any) => void }){

log("info", `Running DevTools Admin Command: Init...`);
const initArgs: {[key: string]: string } = {};
if("command" in config && config.command){
Expand All @@ -67,39 +72,49 @@ class DevToolsAdminCommands extends DevToolsCommands {
// Checks if the command is still missing so required parameter
if(this.hasPlaceholders(commandConfigured)){
log("debug", `Required Parameters missing from Init command: ${commandConfigured}`);
handleCommandResult({ success: false, cancelled: true });
return;
}
log("debug", `Init final command: ${commandConfigured}`);
await this.executeCommand(commandConfigured, path, true);
handleResult();
const commandResult: string | number = await this.executeCommand(commandConfigured, path, true);
if(typeof(commandResult) === "number"){
handleCommandResult({ success: commandResult === 0, cancelled: false });
}
}else{
log("error", "DevToolsAdminCommand_Init: Command is empty or missing the configuration.");
}

}

async explainTypes(config: DevToolsCommandSetting, args: {[key: string]: any }, path: string, handleResult: (result: any) => void){
try{
log("info", `Running DevTools Admin Command: Explain Types...`);
if("command" in config && config.command){
const commandConfigured: string | undefined =
await this.configureCommandWithParameters(
config,
args,
[]
);
log("debug", `Explain types final command: ${commandConfigured}`);
const commandResult = await this.executeCommand(
commandConfigured,
path,
!("json" in args));
handleResult(commandResult);
}else{
log("error", "DevToolsAdminCommand_explainTypes: Command is empty or missing the configuration.");
async explainTypes(
config: DevToolsCommandSetting,
args: {[key: string]: string | string[] | boolean },
path: string,
{ handleCommandResult }: { [key: string]: (args?: any) => void }){

try{
log("info", `Running DevTools Admin Command: Explain Types...`);
if("command" in config && config.command){
const commandConfigured: string | undefined =
await this.configureCommandWithParameters(
config,
args,
[]
);
log("debug", `Explain types final command: ${commandConfigured}`);
const commandResult: string | number = await this.executeCommand(
commandConfigured,
path,
!("json" in args));
if(typeof(commandResult) === "string"){
handleCommandResult({ success: commandResult.length > 0, data: commandResult});
}
}else{
log("error", "DevToolsAdminCommand_explainTypes: Command is empty or missing some configuration.");
}
}catch(error){
log("error", `DevToolsAdminCommand_explainTypes Error: ${error}`);
}
}catch(error){
log("error", `DevToolsAdminCommand_explainTypes Error: ${error}`);
}
}
}

Expand Down
59 changes: 30 additions & 29 deletions src/devtools/commands/DevToolsCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,10 @@ abstract class DevToolsCommands {
resolve(code);
}
if(error){
log("error",
`[DevToolsCommands_executeCommand] Exit Code: ${error}`
);
log("error", `[DevToolsCommands_executeCommand] Exit Code: ${error}`);
}
if(output){
if(showOnTerminal){
log("info", output);
}else{
resolve(output);
}
showOnTerminal ? log("info", output) : resolve(output);
}
},
});
Expand All @@ -48,7 +42,7 @@ abstract class DevToolsCommands {

async configureCommandWithParameters(
config: DevToolsCommandSetting,
args: {[key: string]: string },
args: {[key: string]: string | string[] | boolean },
mdTypes: SupportedMetadataTypes[]): Promise<string> {

log("debug", `ConfigureCommandWithParameters: ${JSON.stringify(config)}`);
Expand All @@ -57,7 +51,7 @@ abstract class DevToolsCommands {
if("requiredParams" in config && config.requiredParams.length){
for(const param of config.requiredParams){
if(param in args && args[param]){
command = command.replace(`{{${param}}}`, args[param]);
command = command.replace(`{{${param}}}`, args[param] as string);
}else{
// Requests user
if(param.toLowerCase() === "mdtypes" && mdTypes.length){
Expand All @@ -79,7 +73,7 @@ abstract class DevToolsCommands {
? `--${param}`
: "";
}
command = command.replace(`{{${param}}}`, param in args ? args[param] : "");
command = command.replace(`{{${param}}}`, param in args ? args[param] as string : "");
});
}
return command;
Expand Down Expand Up @@ -145,28 +139,35 @@ abstract class DevToolsCommands {
"etypes",
path,
{ json: true },
((result: any) => {
// Parses the list of supported mtdata types
const parsedResult: SupportedMetadataTypes[] = JSON.parse(result);
if(parsedResult && parsedResult.length){
// Sends the supported mtdata types to each DevTools Command
Object.keys(this.commandMap).forEach((key: string) => {
const devToolCommand: DevToolsCommands =
this.commandMap[key];
devToolCommand.setMetadataTypes(parsedResult);
});
}else{
log("error", "DevToolsCommands_init: Failed to parse supported metadata type result.");
{
handleCommandResult: ({ success, data }: { success: boolean, data: string}) => {
if(success){
// Parses the list of supported mtdata types
const parsedResult: SupportedMetadataTypes[] = JSON.parse(data);
if(parsedResult && parsedResult.length){
// Sends the supported mtdata types to each DevTools Command
Object.keys(this.commandMap).forEach((key: string) => {
const devToolCommand: DevToolsCommands =
this.commandMap[key];
devToolCommand.setMetadataTypes(parsedResult);
});
}else{
log("error", "DevToolsCommands_init: Failed to parse supported metadata type result.");
}
}else{
log("error", "DevToolsCommands_init: Admin Command etypes failed.");
}
}
}
}));
);
}

static async runCommand(
typeId: string,
typeId: string | null,
commandId: string,
commandPath: string,
args: any,
handleResult: (result: any) => void) {
args: {[key: string]: string | string[] | boolean},
commandHandlers: {[key: string]: (args?: any) => void}){
// When the DevTools command type is unknown to the application
if(!typeId && commandId){
const [{ id }]: { id: string }[] =
Expand All @@ -186,7 +187,7 @@ abstract class DevToolsCommands {
}

if(this.commandMap){
if(typeId in this.commandMap){
if(typeId && typeId in this.commandMap){
const [ commandConfig ]: DevToolsCommandSetting[] =
this.getCommandsListByType(typeId)
.filter((commandSetting: DevToolsCommandSetting) => commandSetting.id === commandId);
Expand All @@ -198,7 +199,7 @@ abstract class DevToolsCommands {
commandConfig,
commandArgs: args,
commandPath,
commandResultHandler: handleResult
commandHandlers: commandHandlers
});
return;
}
Expand Down
Loading

0 comments on commit 84267a7

Please sign in to comment.