From 0371bd9e69bd1a468f7d17aa7030b5d902604656 Mon Sep 17 00:00:00 2001 From: Ana Silva Date: Thu, 31 Oct 2024 12:16:51 +0100 Subject: [PATCH 1/2] initial delete implementation --- package.json | 23 ++++ src/config/devtools.ts | 2 +- src/devtools/commands/standard.ts | 17 ++- src/devtools/index.ts | 197 ++++++++++++++++++------------ src/devtools/metadatatypes.ts | 3 +- src/editor/window.ts | 8 +- src/messages/editor.ts | 9 +- src/utils/file.ts | 8 +- 8 files changed, 177 insertions(+), 90 deletions(-) diff --git a/package.json b/package.json index 67821fe..7375615 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,10 @@ { "command": "sfmc-devtools-vscode.copytobu", "title": "mcdev: Copy to Business Unit..." + }, + { + "command": "sfmc-devtools-vscode.delete", + "title": "mcdev: Delete From Server" } ], "menus": { @@ -71,6 +75,10 @@ { "command": "sfmc-devtools-vscode.copytobu", "when": "sfmc-devtools-vscode.config.isproject && editorIsOpen && resourcePath =~ /\\\\retrieve\\\\.*\\\\.*/" + }, + { + "command": "sfmc-devtools-vscode.delete", + "when": "sfmc-devtools-vscode.config.isproject && editorIsOpen && resourcePath =~ /\\\\retrieve\\\\/ && resourceExtname =~ /.(json|html|sql|ssjs|md|amp|txt)/" } ], "editor/context": [ @@ -88,6 +96,11 @@ "command": "sfmc-devtools-vscode.copytobu", "when": "sfmc-devtools-vscode.config.isproject && resourcePath =~ /\\\\retrieve\\\\.*\\\\.*/", "group": "devtools" + }, + { + "command": "sfmc-devtools-vscode.delete", + "when": "sfmc-devtools-vscode.config.isproject && resourcePath =~ /\\\\retrieve\\\\/ && resourceExtname =~ /.(json|html|sql|ssjs|md|amp|txt)/", + "group": "devtools" } ], "explorer/context": [ @@ -105,6 +118,11 @@ "command": "sfmc-devtools-vscode.copytobu", "when": "sfmc-devtools-vscode.config.isproject && resourcePath =~ /\\\\retrieve\\\\.*\\\\.*/", "group": "devtools" + }, + { + "command": "sfmc-devtools-vscode.delete", + "when": "sfmc-devtools-vscode.config.isproject && resourcePath =~ /\\\\retrieve\\\\/ && resourceExtname =~ /.(json|html|sql|ssjs|md|amp|txt)/", + "group": "devtools" } ], "editor/title/context": [ @@ -122,6 +140,11 @@ "command": "sfmc-devtools-vscode.copytobu", "when": "sfmc-devtools-vscode.config.isproject && resourcePath =~ /\\\\retrieve\\\\.*\\\\.*/", "group": "devtools" + }, + { + "command": "sfmc-devtools-vscode.delete", + "when": "sfmc-devtools-vscode.config.isproject && resourcePath =~ /\\\\retrieve\\\\/ && resourceExtname =~ /.(json|html|sql|ssjs|md|amp|txt)/", + "group": "devtools" } ] }, diff --git a/src/config/devtools.ts b/src/config/devtools.ts index 23a5623..fb11c18 100644 --- a/src/config/devtools.ts +++ b/src/config/devtools.ts @@ -1,7 +1,7 @@ const extensionName = "sfmc-devtools-vscode"; const requiredFiles = [".mcdevrc.json", ".mcdev-auth.json"]; const recommendedExtensions = ["IBM.output-colorizer"]; -const menuCommands = ["retrieve", "deploy", "copytobu"]; +const menuCommands = ["retrieve", "deploy", "copytobu", "delete"]; const delayTimeUpdateStatusBar = 10000; // 10 seconds export { extensionName, requiredFiles, recommendedExtensions, menuCommands, delayTimeUpdateStatusBar }; diff --git a/src/devtools/commands/standard.ts b/src/devtools/commands/standard.ts index 14ee9a7..9749311 100644 --- a/src/devtools/commands/standard.ts +++ b/src/devtools/commands/standard.ts @@ -8,7 +8,8 @@ import { TDevTools } from "@types"; */ enum StandardCommandsAlias { retrieve = "r", - deploy = "d" + deploy = "d", + delete = "del" } /** @@ -49,6 +50,9 @@ class StandardCommands extends Commands { case "deploy": config = this.deploy(parameters); break; + case "delete": + config = this.delete(parameters); + break; } return config; } @@ -105,6 +109,17 @@ class StandardCommands extends Commands { return { alias: deployAlias, config: deployConfig }; } + + delete(parameters: TDevTools.ICommandParameters[]): TDevTools.ICommandConfig { + console.log("== StandardCommands: Delete =="); + // command alias + const deleteAlias = StandardCommandsAlias.delete; + + // command parameters configuration + const deleteConfig = parameters.map(parameter => [this.configureParameters(parameter), parameter.projectPath]); + + return { alias: deleteAlias, config: deleteConfig }; + } } export default StandardCommands; diff --git a/src/devtools/index.ts b/src/devtools/index.ts index 5dda164..cfd4946 100644 --- a/src/devtools/index.ts +++ b/src/devtools/index.ts @@ -3,7 +3,7 @@ import { ConfigDevTools } from "@config"; import { MessagesDevTools, MessagesEditor } from "@messages"; import { EnumsExtension } from "@enums"; import { TEditor, TUtils } from "@types"; -import { Lib } from "utils"; +import { File, Lib } from "utils"; /** * DevTools Extension class @@ -113,7 +113,7 @@ class DevToolsExtension { const vscodeCommands = this.vscodeEditor.getCommands(); // Asks user if he wishes to install mcdev - const userAnswer = await this.showModalMessage( + const userAnswer = await this.showInformationMessage( "info", MessagesDevTools.noMcdevInstalled, Object.keys(EnumsExtension.Confirmation) @@ -123,12 +123,12 @@ class DevToolsExtension { // if mcdev was successfully installed -> reloads vscode editor window // else shows information error message if (success) { - const reload = await this.showModalMessage("info", MessagesDevTools.mcdevInstallSuccess, [ + const reload = await this.showInformationMessage("info", MessagesDevTools.mcdevInstallSuccess, [ "Reload Window" ]); if (reload) vscodeCommands.reloadWorkspace(); } else { - this.showModalMessage("error", MessagesDevTools.mcdevInstallError, []); + this.showInformationMessage("error", MessagesDevTools.mcdevInstallError, []); if (error) this.writeLog(this.mcdev.getPackageName(), error, EnumsExtension.LoggerLevel.ERROR); } }; @@ -188,7 +188,7 @@ class DevToolsExtension { if (uninstalledExtensions.length && recommendExtensions) { // Asks the user if he wants to install recommended extensions - const userAnswer = await this.showModalMessage( + const userAnswer = await this.showInformationMessage( "info", MessagesEditor.recommendedExtensions, Object.keys(EnumsExtension.RecommendedExtensionsOptions) @@ -291,7 +291,7 @@ class DevToolsExtension { } /** - * Shows a VScode Modal message + * Shows a VScode Information message * * @async * @param {("info" | "error")} type - modal message type @@ -299,11 +299,16 @@ class DevToolsExtension { * @param {string[]} options - options in the modal * @returns {Promise} returs the option the user clicked or undefined if no option was selected */ - async showModalMessage(type: "info" | "error", title: string, options: string[]): Promise { + async showInformationMessage( + type: "info" | "error", + title: string, + options: string[], + isModal?: boolean + ): Promise { const vscodeWindow = this.vscodeEditor.getWindow(); const answer = type === "info" - ? await vscodeWindow.showInformationMessageWithOptions(title, options) + ? await vscodeWindow.showInformationMessageWithOptions(title, options, isModal || false) : await vscodeWindow.showErrorMessageWithOptions(title, options); return answer; } @@ -406,12 +411,48 @@ class DevToolsExtension { const activeTabFilePath = this.getActiveTabFilePath(); // When the menu command is done from the file tab it requires the active open file path if (!files.length && activeTabFilePath) files = [activeTabFilePath]; - this.executeMenuCommands(command, files); + if (files.length) this.executeMenuCommand(command, files); } }) ); } + executeMenuCommand(command: string, files: string[]) { + const menuCommandsHandlers: { [key: string]: () => void } = { + retrieve: () => this.handleRetrieveCommand(files), + deploy: () => this.handleDeployCommand(files), + delete: () => this.handleDeleteCommand(files) + }; + + const menuCommandHandler = menuCommandsHandlers[command]; + if (menuCommandHandler) menuCommandHandler(); + else + this.writeLog( + this.mcdev.getPackageName(), + `[index_executeMenuCommand]: Invalid Menu Command: ${command}`, + EnumsExtension.LoggerLevel.ERROR + ); + } + + handleRetrieveCommand(files: string[]) { + this.executeCommand("retrieve", files); + } + + handleDeployCommand(files: string[]) { + this.executeCommand("deploy", files); + } + + async handleDeleteCommand(files: string[]) { + const confirmationAnswer = await this.showInformationMessage( + "info", + MessagesEditor.deleteConfirmation(File.extractFileName(files)), + Object.keys(EnumsExtension.Confirmation), + true + ); + if (!confirmationAnswer || confirmationAnswer.toLowerCase() !== EnumsExtension.Confirmation.Yes) return; + this.executeCommand("delete", files); + } + /** * Executes the extension menu commands * @@ -419,83 +460,77 @@ class DevToolsExtension { * @param {string[]} files - file paths detected by selection * @returns {void} */ - executeMenuCommands(command: string, files: string[]): void { + executeCommand(command: string, files: string[]): void { console.log("== Execute Menu Commands =="); - if (files.length > 0) { - const packageName = this.mcdev.getPackageName(); - // inital running command status bar configuration - const initialStatusBarColor = ""; - const initialStatusBarIcon: string = - EnumsExtension.StatusBarIcon[command as keyof typeof EnumsExtension.StatusBarIcon]; - const initialStatusBarTitle = `$(${initialStatusBarIcon}) ${packageName}`; - const inProgressBarTitle = MessagesEditor.runningCommand; - - const mcdevExecuteOnOutput = ({ info = "", output = "", error = "" }: TUtils.IOutputLogger) => { - const message = info || output || error; - - let loggerLevel = EnumsExtension.LoggerLevel.DEBUG; - if (info) loggerLevel = EnumsExtension.LoggerLevel.INFO; - if (output) loggerLevel = EnumsExtension.LoggerLevel.OUTPUT; - if (error) loggerLevel = EnumsExtension.LoggerLevel.WARN; - - this.writeLog(packageName, message, loggerLevel); - }; - - const mcdevExecuteOnResult = async (success: boolean) => { - const statusBarIcon = success - ? EnumsExtension.StatusBarIcon.success - : EnumsExtension.StatusBarIcon.error; - // changes the status bar icon and and color according to the execution result of the command - const newStatusBarColor = success ? initialStatusBarColor : "error"; - const newStatusBarTitle = `$(${statusBarIcon}) ${packageName}`; - - // Sets the message to show in the modal depending on the execution result - const infoMessage = success - ? MessagesEditor.runningCommandSuccess - : MessagesEditor.runningCommandFailure; - - // Options to be displayed in the modal message - const infoMessageOptions = ["More Details"]; - - this.updateContainers(packageName, { text: newStatusBarTitle, backgroundColor: newStatusBarColor }); - - if (!success) - // Changes back the status bar icon and backaground color to inital configuration after some time - Lib.executeAfterDelay( - () => - this.updateContainers(packageName, { - text: `$(${EnumsExtension.StatusBarIcon.success}) ${packageName}`, - backgroundColor: initialStatusBarColor - }), - ConfigDevTools.delayTimeUpdateStatusBar - ); + const packageName = this.mcdev.getPackageName(); + // inital running command status bar configuration + const initialStatusBarColor = ""; + const initialStatusBarIcon: string = + EnumsExtension.StatusBarIcon[command as keyof typeof EnumsExtension.StatusBarIcon]; + const initialStatusBarTitle = `$(${initialStatusBarIcon}) ${packageName}`; + const inProgressBarTitle = MessagesEditor.runningCommand; + + const mcdevExecuteOnOutput = ({ info = "", output = "", error = "" }: TUtils.IOutputLogger) => { + const message = info || output || error; + + let loggerLevel = EnumsExtension.LoggerLevel.DEBUG; + if (info) loggerLevel = EnumsExtension.LoggerLevel.INFO; + if (output) loggerLevel = EnumsExtension.LoggerLevel.OUTPUT; + if (error) loggerLevel = EnumsExtension.LoggerLevel.WARN; + + this.writeLog(packageName, message, loggerLevel); + }; - const moreDetails = await this.showModalMessage( - success ? "info" : "error", - infoMessage, - infoMessageOptions + const mcdevExecuteOnResult = async (success: boolean) => { + const statusBarIcon = success ? EnumsExtension.StatusBarIcon.success : EnumsExtension.StatusBarIcon.error; + // changes the status bar icon and and color according to the execution result of the command + const newStatusBarColor = success ? initialStatusBarColor : "error"; + const newStatusBarTitle = `$(${statusBarIcon}) ${packageName}`; + + // Sets the message to show in the modal depending on the execution result + const infoMessage = success ? MessagesEditor.runningCommandSuccess : MessagesEditor.runningCommandFailure; + + // Options to be displayed in the modal message + const infoMessageOptions = ["More Details"]; + + this.updateContainers(packageName, { text: newStatusBarTitle, backgroundColor: newStatusBarColor }); + + if (!success) + // Changes back the status bar icon and backaground color to inital configuration after some time + Lib.executeAfterDelay( + () => + this.updateContainers(packageName, { + text: `$(${EnumsExtension.StatusBarIcon.success}) ${packageName}`, + backgroundColor: initialStatusBarColor + }), + ConfigDevTools.delayTimeUpdateStatusBar ); - // if user clicks on 'More Details' button it will open the output channel - if (moreDetails) this.showOuputChannel(packageName); - }; - this.updateContainers(packageName, { text: initialStatusBarTitle, backgroundColor: initialStatusBarColor }); - // Execute the commands asynchronously - this.activateNotificationProgressBar( - inProgressBarTitle, - false, - () => - new Promise(async resolve => { - const { success }: { success: boolean } = await this.mcdev.execute( - command, - mcdevExecuteOnOutput, - files - ); - mcdevExecuteOnResult(success); - resolve(success); - }) + const moreDetails = await this.showInformationMessage( + success ? "info" : "error", + infoMessage, + infoMessageOptions ); - } + // if user clicks on 'More Details' button it will open the output channel + if (moreDetails) this.showOuputChannel(packageName); + }; + + this.updateContainers(packageName, { text: initialStatusBarTitle, backgroundColor: initialStatusBarColor }); + // Execute the commands asynchronously + this.activateNotificationProgressBar( + inProgressBarTitle, + false, + () => + new Promise(async resolve => { + const { success }: { success: boolean } = await this.mcdev.execute( + command, + mcdevExecuteOnOutput, + files + ); + mcdevExecuteOnResult(success); + resolve(success); + }) + ); } } export default DevToolsExtension; diff --git a/src/devtools/metadatatypes.ts b/src/devtools/metadatatypes.ts index 33ee650..f219f43 100644 --- a/src/devtools/metadatatypes.ts +++ b/src/devtools/metadatatypes.ts @@ -9,7 +9,8 @@ import { File } from "utils"; */ const MetadataTypesSupportedActions: { [action: string]: TDevTools.MetadataTypesActions[] } = { retrieve: ["retrieve"], - deploy: ["create", "update"] + deploy: ["create", "update"], + delete: ["delete"] }; /** diff --git a/src/editor/window.ts b/src/editor/window.ts index a6fa4ce..2917a8e 100644 --- a/src/editor/window.ts +++ b/src/editor/window.ts @@ -46,8 +46,12 @@ class VSCodeWindow { * @param {string[]} actions - modal action options * @returns {Promise} option selected by user or undefined if no selection */ - async showInformationMessageWithOptions(message: string, actions: string[]): Promise { - const response = await this.window.showInformationMessage(message, ...actions); + async showInformationMessageWithOptions( + message: string, + actions: string[], + modal: boolean + ): Promise { + const response = await this.window.showInformationMessage(message, { modal }, ...actions); return response; } diff --git a/src/messages/editor.ts b/src/messages/editor.ts index b1e3c95..6c78738 100644 --- a/src/messages/editor.ts +++ b/src/messages/editor.ts @@ -3,5 +3,12 @@ const recommendedExtensions = const runningCommand = "Running DevTools command..."; const runningCommandSuccess = "DevTools command has run successfully!"; const runningCommandFailure = "Oh no. Something went wrong while running DevTools Command..."; +const deleteConfirmation = (items: string[]) => + `Are you sure you want to delete the selected item${items.length > 1 ? "s" : ""} from the server?\n\n${items + .slice(0, 3) + .map(item => `Delete: ${item}`) + .join( + "\n" + )}${items.length > 3 ? `\n...and ${items.length - 3} more item${items.length - 3 > 1 ? "s" : ""}.` : ""}`; -export { recommendedExtensions, runningCommand, runningCommandSuccess, runningCommandFailure }; +export { recommendedExtensions, runningCommand, runningCommandSuccess, runningCommandFailure, deleteConfirmation }; diff --git a/src/utils/file.ts b/src/utils/file.ts index e7b23ee..b0707ed 100644 --- a/src/utils/file.ts +++ b/src/utils/file.ts @@ -22,9 +22,11 @@ function fileExists(path: string | string[]): string[] { */ function extractFileName(files: string | string[]): string[] { return [files].flat().map(file => { - const endOfFileNameIndex = file.lastIndexOf(".", file.lastIndexOf(".") - 1); - if (endOfFileNameIndex < 0) return file; - return file.substring(0, endOfFileNameIndex); + const fileName = file.split(/[\/]/).pop() || file; + const lastDotIndex = fileName.lastIndexOf("."); + const secondLastDotIndex = fileName.lastIndexOf(".", fileName.lastIndexOf(".") - 1); + if (secondLastDotIndex < 0) return file.substring(0, lastDotIndex); + return fileName.substring(0, secondLastDotIndex); }); } From b9dc2577340aa0f7bf5c75eeed36da8ed92749cc Mon Sep 17 00:00:00 2001 From: Ana Silva Date: Fri, 1 Nov 2024 10:25:12 +0100 Subject: [PATCH 2/2] mcdev delete implemented --- package.json | 4 +-- src/devtools/commands/standard.ts | 6 +++++ src/devtools/index.ts | 41 ++++++++++++++++++++++++++----- src/devtools/mcdev.ts | 5 ++-- src/devtools/metadatatypes.ts | 4 +-- src/enums/extension.ts | 3 ++- src/utils/file.ts | 10 ++++++-- 7 files changed, 58 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 7375615..f1812c4 100644 --- a/package.json +++ b/package.json @@ -99,7 +99,7 @@ }, { "command": "sfmc-devtools-vscode.delete", - "when": "sfmc-devtools-vscode.config.isproject && resourcePath =~ /\\\\retrieve\\\\/ && resourceExtname =~ /.(json|html|sql|ssjs|md|amp|txt)/", + "when": "sfmc-devtools-vscode.config.isproject && resourcePath =~ /\\\\retrieve\\\\/ && (resourceExtname =~ /.(json|html|sql|ssjs|md|amp|txt)/ || resourceDirname =~ /asset\\\\[a-zA-Z]*/)", "group": "devtools" } ], @@ -121,7 +121,7 @@ }, { "command": "sfmc-devtools-vscode.delete", - "when": "sfmc-devtools-vscode.config.isproject && resourcePath =~ /\\\\retrieve\\\\/ && resourceExtname =~ /.(json|html|sql|ssjs|md|amp|txt)/", + "when": "sfmc-devtools-vscode.config.isproject && resourcePath =~ /\\\\retrieve\\\\/ && (resourceExtname =~ /.(json|html|sql|ssjs|md|amp|txt)/ || resourceDirname =~ /asset\\\\[a-zA-Z]*/)", "group": "devtools" } ], diff --git a/src/devtools/commands/standard.ts b/src/devtools/commands/standard.ts index 9749311..f6b7dd7 100644 --- a/src/devtools/commands/standard.ts +++ b/src/devtools/commands/standard.ts @@ -110,6 +110,12 @@ class StandardCommands extends Commands { return { alias: deployAlias, config: deployConfig }; } + /** + * Standard Command 'delete' execution + * + * @param {TDevTools.ICommandParameters[]} parameters - command parameters + * @returns {TDevTools.ICommandConfig} command configuration + */ delete(parameters: TDevTools.ICommandParameters[]): TDevTools.ICommandConfig { console.log("== StandardCommands: Delete =="); // command alias diff --git a/src/devtools/index.ts b/src/devtools/index.ts index cfd4946..02b8765 100644 --- a/src/devtools/index.ts +++ b/src/devtools/index.ts @@ -3,7 +3,7 @@ import { ConfigDevTools } from "@config"; import { MessagesDevTools, MessagesEditor } from "@messages"; import { EnumsExtension } from "@enums"; import { TEditor, TUtils } from "@types"; -import { File, Lib } from "utils"; +import { Lib } from "utils"; /** * DevTools Extension class @@ -417,7 +417,14 @@ class DevToolsExtension { ); } - executeMenuCommand(command: string, files: string[]) { + /** + * Executes the Menu Command by command name + * + * @param {string} command - command name + * @param {string[]} files - selected files paths + * @returns {void} + */ + executeMenuCommand(command: string, files: string[]): void { const menuCommandsHandlers: { [key: string]: () => void } = { retrieve: () => this.handleRetrieveCommand(files), deploy: () => this.handleDeployCommand(files), @@ -434,18 +441,40 @@ class DevToolsExtension { ); } - handleRetrieveCommand(files: string[]) { + /** + * Handles the Menu Command 'retrieve' + * + * @param {string[]} files - selected files paths + * @returns {void} + */ + handleRetrieveCommand(files: string[]): void { this.executeCommand("retrieve", files); } - handleDeployCommand(files: string[]) { + /** + * Handles the Menu Command 'deploy' + * + * @param {string[]} files - selected files paths + * @returns {void} + */ + handleDeployCommand(files: string[]): void { this.executeCommand("deploy", files); } - async handleDeleteCommand(files: string[]) { + /** + * Handles the Menu Command 'delete' + * + * @async + * @param {string[]} files - selected files paths + * @returns {Promise} + */ + async handleDeleteCommand(files: string[]): Promise { + const fileNamesList = this.mcdev + .convertPathsToFiles(files) + .map(file => `${file.filename} (${file.metadataType})`); const confirmationAnswer = await this.showInformationMessage( "info", - MessagesEditor.deleteConfirmation(File.extractFileName(files)), + MessagesEditor.deleteConfirmation(fileNamesList), Object.keys(EnumsExtension.Confirmation), true ); diff --git a/src/devtools/mcdev.ts b/src/devtools/mcdev.ts index 2cab532..6c77afa 100644 --- a/src/devtools/mcdev.ts +++ b/src/devtools/mcdev.ts @@ -100,11 +100,11 @@ class Mcdev { /** * Convert files paths to DevTools File Format * - * @private + * @public * @param {string[]} paths - file paths * @returns {TDevTools.IFileFormat[]} files formatted in DevTool File Format */ - private convertPathsToFiles(paths: string[]): TDevTools.IFileFormat[] { + public convertPathsToFiles(paths: string[]): TDevTools.IFileFormat[] { console.log("== Mcdev: Convert File Paths =="); const convertToFileFormat = (path: string): TDevTools.IFileFormat => { @@ -319,6 +319,7 @@ class Mcdev { commandHandler({ info: `${MessagesDevTools.mcdevRunningCommand} ${this.getPackageName()} ${commandConfig.alias} ${parameters}\n` }); + const { success }: TUtils.ITerminalCommandResult = await Terminal.executeTerminalCommand( terminalConfig, false diff --git a/src/devtools/metadatatypes.ts b/src/devtools/metadatatypes.ts index f219f43..ccb8221 100644 --- a/src/devtools/metadatatypes.ts +++ b/src/devtools/metadatatypes.ts @@ -100,12 +100,12 @@ class MetadataTypes { // configuration for asset mdtype if (files.length === 1) return { metadataTypeName: `asset-${assetName}` }; else if (files.length > 1) - return { metadataTypeName: `asset-${assetName}`, filename: File.extractFileName(filename)[0] }; + return { metadataTypeName: `asset-${assetName}`, filename: File.extractNameFromPath(filename)[0] }; } if (files.length === 1 || mdt === "folder") { // configuration for other mdtypes - const filenames = File.extractFileName(files); + const filenames = File.extractNameFromPath(files); if (filenames.length) return { filename: filenames[0] }; } return { filename: "" }; diff --git a/src/enums/extension.ts b/src/enums/extension.ts index 28b83ef..909d018 100644 --- a/src/enums/extension.ts +++ b/src/enums/extension.ts @@ -30,7 +30,8 @@ enum StatusBarIcon { deploy = "cloud-upload", error = "warning", copytobu = "file-symlink-directory", - info = "extensions-info-message" + info = "extensions-info-message", + delete = "trash" } /** diff --git a/src/utils/file.ts b/src/utils/file.ts index b0707ed..f5de187 100644 --- a/src/utils/file.ts +++ b/src/utils/file.ts @@ -20,9 +20,15 @@ function fileExists(path: string | string[]): string[] { * @param {(string | string[])} files - file paths * @returns {string[]} list of extracted file names */ -function extractFileName(files: string | string[]): string[] { +function extractNameFromPath(files: string | string[]): string[] { return [files].flat().map(file => { + // splits path const fileName = file.split(/[\/]/).pop() || file; + + // returns folder name + if (!fileName.includes(".")) return fileName; + + // if it's a file in format filename.asset-asset-meta.ext const lastDotIndex = fileName.lastIndexOf("."); const secondLastDotIndex = fileName.lastIndexOf(".", fileName.lastIndexOf(".") - 1); if (secondLastDotIndex < 0) return file.substring(0, lastDotIndex); @@ -30,4 +36,4 @@ function extractFileName(files: string | string[]): string[] { }); } -export { fileExists, extractFileName }; +export { fileExists, extractNameFromPath };