Skip to content

Commit

Permalink
Merge pull request #10 from Accenture/feature/implement-explainType-l…
Browse files Browse the repository at this point in the history
…ogic

added explainTypes logic
  • Loading branch information
anasilva105 authored May 16, 2023
2 parents 28d3801 + 6c0641a commit 94e4315
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 21 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# sfmc-devtools-vscode README

This is the README for your extension "sfmc-devtools-vscode".
SFMC DevTools VSCODE Extension
Accenture SFMC (Salesforce Marketing Cloud) DevTools vscode extension was created in order to support the user interaction with SFMC DevTools.

In Beta testing...

**Enjoy!**
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
{
"name": "sfmc-devtools-vscode",
"displayName": "sfmc-devtools-vscode",
"description": "",
"description": "Accenture Salesforce Marketing Cloud DevTools Vscode Extension",
"version": "0.0.1",
"repository": {
"type": "git",
"url": "https://github.com/Accenture/sfmc-devtools-vscode.git"
},
"engines": {
"vscode": "^1.60.0"
},
"categories": [
"Other"
],
"main": "./dist/extension.js",
"activationEvents": [ "onStartupFinished" ],
"activationEvents": [
"onStartupFinished"
],
"contributes": {
"commands": [
{
Expand All @@ -34,7 +40,7 @@
"command": "sfmc-devtools-vscext.devToolsMenuActionDeploy",
"group": "devtools"
}
]
]
}
},
"scripts": {
Expand All @@ -57,10 +63,10 @@
"@types/vscode": "^1.60.0",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"copy-webpack-plugin": "^5.1.1",
"copy-webpack-plugin": "^11.0.0",
"eslint": "^7.27.0",
"glob": "^7.1.7",
"mocha": "^8.4.0",
"mocha": "^10.2.0",
"ts-loader": "^9.2.2",
"typescript": "^4.3.2",
"vscode-test": "^1.5.2",
Expand Down
Binary file added sfmc-devtools-vscode-0.0.1.vsix
Binary file not shown.
4 changes: 2 additions & 2 deletions src/commands.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"admin": {
"isAvailable": false,
"isAvailable": true,
"title": "Admin",
"commands": [
{"id":"init", "title": "Init", "command": "mcdev init", "parameters": [], "description": "Initates SFMC DevTools or adds additional credentials to your project.", "isAvailable": false},
Expand All @@ -10,7 +10,7 @@
{"id":"badkeys", "title": "Bad Keys", "command": "", "parameters": [], "description": "Lists metadata with random API names in specified Business Unit directory.", "isAvailable": false},
{"id":"doc", "title": "Document", "command": "", "parameters": [], "description": "Creates Markdown or HTML documentation for the selected type.", "isAvailable": false},
{"id":"stypes", "title": "Select Types", "command": "", "parameters": [], "description": "Allows you choose what metadata types to retrieve.", "isAvailable": false},
{"id":"etypes", "title": "Explain Types", "command": "", "parameters": [], "description": "Explains metadata types that can be retrieved.", "isAvailable": false}
{"id":"etypes", "title": "Explain Types", "command": "mcdev explainTypes", "parameters": ["json"], "description": "Explains metadata types that can be retrieved.", "isAvailable": true}
]
},
"standard": {
Expand Down
56 changes: 45 additions & 11 deletions src/devToolsCommands.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { window } from "vscode";
import * as commandsConfig from "./commands.json";
import { execInWindowTerminal, readFile } from "./utils";
import { execInTerminal, execInWindowTerminal, readFile } from "./utils";

interface DTCommand {
id: string,
Expand All @@ -18,6 +18,14 @@ interface CommandOptionsSettings {
dtCommand?: {command: string, args: {[key: string]: string}},
};

interface SupportedMdTypes {
name: string,
apiName: string,
retrievedByDefault: boolean,
supports: { [key: string]: boolean },
description: string
}

const allPlaceholder: string = "*All*";
const COMMAND_INPUT_TITLES: { [key: string]: string } = {
selectType: "Select the DevTools Command Type...",
Expand All @@ -34,12 +42,14 @@ const COMMAND_TYPES_HANDLERS: { [key: string]: (command: string, args: {[key: st
templating: handleTemplatingCommand
};

const COMMAND_PARAMETERS_HANDLERS: {[key: string]: (mcdevrc: {[key: string]: any}) => Promise<string>} = {
const COMMAND_PARAMETERS_HANDLERS: {[key: string]: (param: {[key: string]: any}, supportedAction: string) => Promise<string>} = {
bu: buHandler,
credentialsName: credentialsHandler,
type: typeHandler
};

let supportedMdTypes: Array<SupportedMdTypes> = [];

function getCommandsTypes(): Array<{id: string, label: string}>{
return Object.keys(commandsConfig)
.filter((cmd: string) => commandsConfig[cmd as keyof typeof commandsConfig].isAvailable)
Expand All @@ -56,11 +66,22 @@ async function executeCredentialsSelection(){
return selectedCredentialBU;
}

function handleAdminCommand(command: string, args: {[key: string]: string}) {
async function handleAdminCommand(command: string, args: {[key: string]: string}) {
if(command){
if("json" in args){
if(args.json !== ""){
const mdTypes: Array<SupportedMdTypes> = JSON.parse(
await execInTerminal(`${command} ${args["json"]}`)
);
return mdTypes;
}else{
execInWindowTerminal(command);
}
}
}
}

async function handleStandardCommand(command: string, args: {[key: string]: string}) {
const mcdevrc: {[key: string]: any} = JSON.parse(await readFile(".mcdevrc.json"));
if(command){
const paramArray = await Promise.all(Object.keys(args).map(async(param: string) => {
let paramInput: string = '';
Expand All @@ -69,7 +90,7 @@ async function handleStandardCommand(command: string, args: {[key: string]: stri
}else{
if(Object.keys(COMMAND_PARAMETERS_HANDLERS).includes(param.toLowerCase())){
const paramHandler = COMMAND_PARAMETERS_HANDLERS[param.toLowerCase()];
paramInput = await paramHandler(mcdevrc);
paramInput = await paramHandler({}, command.includes("retrieve") ? "retrieve" : "update");
if(!paramInput){
return paramInput;
}
Expand Down Expand Up @@ -105,13 +126,26 @@ async function buHandler(mcdevrc: {[key: string]: any}){
return null;
}

async function typeHandler(mcdevrc: {[key: string]: any}){
if(Object.keys(mcdevrc).includes("metaDataTypes") && Object.keys(mcdevrc["metaDataTypes"]).includes("retrieve")){
const selectedTypes = await window.showQuickPick(
mcdevrc["metaDataTypes"]["retrieve"],
async function typeHandler(mcdevrcJson: {[key: string]: any}, supportedAction: string){
if(!supportedMdTypes.length){
const availableDTCommands: Array<DTCommand> = getCommandsListByType("admin").filter(cmd => cmd.isAvailable);
if(availableDTCommands.length){
const [ { command, parameters }]: Array<DTCommand> = availableDTCommands;
supportedMdTypes = await handleAdminCommand(
command,
parameters.reduce((prev, curr) => ({...prev, [curr]: curr === "json" ? "--json" : curr}), {})
);
}
}
const supportedMdTypesByAction = supportedMdTypes.filter(
(mdType: SupportedMdTypes) => supportedAction in mdType.supports && mdType.supports[supportedAction]
);
const selectedTypes = await window.showQuickPick(
supportedMdTypesByAction.map((mdType: SupportedMdTypes) => ({id: mdType.apiName, label: mdType.name})),
{ placeHolder: COMMAND_INPUT_TITLES['metaDataType'], canPickMany: true, ignoreFocusOut: true }
);
return selectedTypes ? `"${selectedTypes}"` : undefined;
if(selectedTypes.length){
return `"${selectedTypes.map((type: {id: string, label: string}) => type.id).join(",")}"`;
}
return null;
}
Expand All @@ -131,7 +165,7 @@ async function executeCommandBarSelection(selectedCredBU: string){
// Gets list of types of Commands (admin, standard, templating) configured
const cmdTypeSettingsList: Array<CommandOptionsSettings> = getCommandsTypes().map((type: {id:string, label: string}) => ({
...type,
detail: `Example: ${getCommandsListByType(type.id).map(cmd => cmd.title)}`
detail: `Example: ${getCommandsListByType(type.id).filter(cmd => cmd.isAvailable).map(cmd => cmd.title)}`
}));

// Makes user select the command type
Expand Down
6 changes: 4 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ const config = {
},
plugins: [
// @ts-ignore
new CopyPlugin([
new CopyPlugin({
patterns: [
{
from: path.resolve(__dirname, './node_modules/@salesforce-ux/design-system/assets'),
to: path.resolve(__dirname, 'dist/design-system')
},
])
]
})
]
};
module.exports = config;

0 comments on commit 94e4315

Please sign in to comment.