diff --git a/package.json b/package.json index a52bd0c..4d7a75f 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,9 @@ "Other" ], "main": "./dist/extension.js", - "activationEvents": [ "onStartupFinished" ], + "activationEvents": [ + "onStartupFinished" + ], "contributes": { "commands": [ { @@ -34,7 +36,7 @@ "command": "sfmc-devtools-vscext.devToolsMenuActionDeploy", "group": "devtools" } - ] + ] } }, "scripts": { @@ -57,10 +59,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", diff --git a/src/commands.json b/src/commands.json index bc362ba..e7da1b7 100644 --- a/src/commands.json +++ b/src/commands.json @@ -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}, @@ -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": { diff --git a/src/devToolsCommands.ts b/src/devToolsCommands.ts index dc9c4b4..24e4193 100644 --- a/src/devToolsCommands.ts +++ b/src/devToolsCommands.ts @@ -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, @@ -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...", @@ -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} = { +const COMMAND_PARAMETERS_HANDLERS: {[key: string]: (param: {[key: string]: any}, supportedAction: string) => Promise} = { bu: buHandler, credentialsName: credentialsHandler, type: typeHandler }; +let supportedMdTypes: Array = []; + function getCommandsTypes(): Array<{id: string, label: string}>{ return Object.keys(commandsConfig) .filter((cmd: string) => commandsConfig[cmd as keyof typeof commandsConfig].isAvailable) @@ -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 = 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 = ''; @@ -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; } @@ -105,13 +126,27 @@ 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){ + console.log("Get supported Types..."); + const availableDTCommands: Array = getCommandsListByType("admin").filter(cmd => cmd.isAvailable); + if(availableDTCommands.length){ + const [ { command, parameters }]: Array = 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; } @@ -131,7 +166,7 @@ async function executeCommandBarSelection(selectedCredBU: string){ // Gets list of types of Commands (admin, standard, templating) configured const cmdTypeSettingsList: Array = 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 diff --git a/webpack.config.js b/webpack.config.js index d2af4bf..4176e80 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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; \ No newline at end of file