diff --git a/README.md b/README.md index 881f276..b837936 100644 --- a/README.md +++ b/README.md @@ -6,24 +6,29 @@ Dev Pack for Salesforce is a collection of useful VS Code extensions for Salesfo ## Included Extensions -- [Salesforce Extension Pack](https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-vscode) - - [Salesforce Apex](https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-vscode-apex) - - [Salesforce Lightning Web Components](https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-vscode-lwc) - - [Salesforce SOQL](https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-vscode-soql) - - [Salesforce Core](https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-vscode-core) -- [Agentforce for Developers](https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-einstein-gpt) -- [Markdownlint](https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint) -- [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) -- [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) -- [VSCode Icons](https://marketplace.visualstudio.com/items?itemName=vscode-icons-team.vscode-icons) -- [One Dark Pro Theme](https://marketplace.visualstudio.com/items?itemName=zhuangtongfa.Material-theme) -- [Better Comments](https://marketplace.visualstudio.com/items?itemName=aaron-bond.better-comments) -- [Indent Rainbow](https://marketplace.visualstudio.com/items?itemName=oderwat.indent-rainbow) -- [Apex Log Analyzer](https://marketplace.visualstudio.com/items?itemName=financialforce.lana) -- [Code Spell Checker](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker) -- [Lightning Flow Scanner](https://marketplace.visualstudio.com/items?itemName=ForceConfigControl.lightningflowscanner) -- [Salesforce Code Analyzer](https://marketplace.visualstudio.com/items?itemName=salesforce.sfdx-code-analyzer-vscode) -- [Log File Highlighter](https://marketplace.visualstudio.com/items?itemName=emilast.LogFileHighlighter) +- [Salesforce Extension Pack](https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-vscode-expanded) + - [Salesforce CLI Integration](https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-vscode-core) - This extension (salesforcedx-vscode-core) interacts with Salesforce CLI to provide core functionality. + - [Salesforce Apex](https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-vscode-apex) - This extension (salesforcedx-vscode-apex) uses the Apex Language Server to provide features such as syntax highlighting and code completion. + - [Apex Interactive Debugger](https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-vscode-apex-debugger) - This extension (salesforcedx-vscode-apex-debugger) enables VS Code to use the real-time Apex Debugger with your scratch orgs or to use ISV Customer Debugger for your subscribers’ orgs. + - [Apex Replay Debugger](https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-vscode-apex-replay-debugger) - This extension (salesforcedx-vscode-apex-replay-debugger) enables VS Code to replay Apex execution from Apex debug logs. + - [Salesforce Lightning Web Components](https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-vscode-lwc) - This extension supports Lightning web component bundles. It uses the HTML language server from VS Code. + - [Aura Components](https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-vscode-lightning) - This extension (salesforcedx-vscode-lightning) supports Aura component bundles. It uses the HTML language server from VS Code. + - [Visualforce](https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-vscode-visualforce) - This extension (salesforcedx-vscode-visualforce) supports Visualforce pages and components. It uses the Visualforce Language Server and the HTML language server from VS Code. + - [SOQL](https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-vscode-soql) - This extension (salesforcedx-vscode-soql) enables you to interactively build a SOQL query via a form-based visual editor, view the query as you build, and save the output to a .csv or .json file. + - [Salesforce Lightning Design System (SLDS) Validator](https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-vscode-slds) - This extension (salesforcedx-vscode-slds) simplifies working with the Salesforce Lightning Design System (SLDS). It provides code completion, syntax highlighting, and validation with recommended tokens and utility classes. + - [Agentforce for Developers](https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-einstein-gpt) - This extension (salesforcedx-einstein-gpt) uses generative AI to make Salesforce development in Visual Studio Code richer with features such as natural language to code generation, inline autocompletion for Apex and LWC code, and test case generation for Apex classes. + - [Salesforce Code Analyzer](https://marketplace.visualstudio.com/items?itemName=salesforce.sfdx-code-analyzer-vscode) - This extension (sfdx-code-analyzer-vscode) scans your code using multiple rule engines to produce lists of violations that you can use to improve your code. + - [Apex Log Analyzer](https://marketplace.visualstudio.com/items?itemName=financialforce.lana) - This extension helps you analyze Apex logs. +- [One Dark Pro Theme](https://marketplace.visualstudio.com/items?itemName=zhuangtongfa.Material-theme) - A popular dark theme for Visual Studio Code. +- [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) - An opinionated code formatter that enforces a consistent style. +- [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) - Integrates ESLint JavaScript into VS Code. +- [VSCode Icons](https://marketplace.visualstudio.com/items?itemName=vscode-icons-team.vscode-icons) - Adds icons to the Visual Studio Code editor. +- [Better Comments](https://marketplace.visualstudio.com/items?itemName=aaron-bond.better-comments) - Improves your comment annotations with different colors. +- [Indent Rainbow](https://marketplace.visualstudio.com/items?itemName=oderwat.indent-rainbow) - Makes indentation levels more readable with color coding. +- [Markdownlint](https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint) - Provides Markdown linting and style checking. +- [Code Spell Checker](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker) - A basic spell checker that works well with code. +- [Lightning Flow Scanner](https://marketplace.visualstudio.com/items?itemName=ForceConfigControl.lightningflowscanner) - Scans and validates Salesforce Lightning Flows. +- [Log File Highlighter](https://marketplace.visualstudio.com/items?itemName=emilast.LogFileHighlighter) - Highlights log files to make them easier to read. ## Installation @@ -46,7 +51,8 @@ This setup is only done the first time the extension is installed. Feel free to ## Automatic Package Detection and Installation -Dev Pack for Salesforce automatically detects and prompts you to install the following required npm packages if they are not already installed: +The Dev Pack for Salesforce simplifies and automates the setup of your developer environment. Upon installation, the pack automatically detects and installs required npm packages, as long as Node.js is installed in your system. The required npm packages include: + - `@salesforce/cli` - `prettier` diff --git a/dev-pack-salesforce-1.0.9.vsix b/dev-pack-salesforce-1.0.9.vsix deleted file mode 100644 index b94d59a..0000000 Binary files a/dev-pack-salesforce-1.0.9.vsix and /dev/null differ diff --git a/package.json b/package.json index 0699821..3db3d16 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "dev-pack-salesforce", "displayName": "Dev Pack for Salesforce", "description": "A collection of useful VS Code extensions for Salesforce development", - "version": "1.0.9", + "version": "1.1.0", "publisher": "avidev9", "scripts": { "package": "npx vsce package" @@ -24,8 +24,7 @@ ], "main": "./src/extension.js", "extensionPack": [ - "salesforce.salesforcedx-vscode", - "salesforce.salesforcedx-einstein-gpt", + "salesforce.salesforcedx-vscode-expanded", "davidanson.vscode-markdownlint", "esbenp.prettier-vscode", "dbaeumer.vscode-eslint", @@ -33,11 +32,10 @@ "zhuangtongfa.material-theme", "aaron-bond.better-comments", "oderwat.indent-rainbow", - "financialforce.lana", "streetsidesoftware.code-spell-checker", - "ForceConfigControl.lightningflowscanner", - "salesforce.sfdx-code-analyzer-vscode", - "emilast.LogFileHighlighter" + "ForceConfigControl.lightning-flow-scanner-vsx", + "emilast.LogFileHighlighter", + "usernamehw.errorlens" ], "repository": { "type": "git", @@ -78,6 +76,11 @@ "command": "dev-pack-salesforce.updateBetterCommentsSettings", "title": "Dev Pack for Salesforce: Update better comments settings", "shortTitle": "Update better comments settings" + }, + { + "command": "dev-pack-salesforce.deleteApexLogs", + "title": "Dev Pack for Salesforce: Delete all apex logs", + "shortTitle": "Delete all apex logs" } ] } diff --git a/src/commands/betterComments.js b/src/commands/BetterComments.js similarity index 60% rename from src/commands/betterComments.js rename to src/commands/BetterComments.js index 3f2257e..b186a7b 100644 --- a/src/commands/betterComments.js +++ b/src/commands/BetterComments.js @@ -1,5 +1,6 @@ const vscode = require("vscode"); -const { EXTENSION_NAME, BETTER_COMMENTS_TAG } = require("../utils/constants"); +const { BETTER_COMMENTS_TAG } = require("../utils/constants"); +const CommonUtils = require("../utils/CommonUtils"); class BetterComments { static updateSettings() { @@ -9,8 +10,8 @@ class BetterComments { BETTER_COMMENTS_TAG, vscode.ConfigurationTarget.Global ); - vscode.window.showInformationMessage( - `${EXTENSION_NAME}: Updated Better Comments settings globally.` + CommonUtils.showInformationMessage( + "Updated Better Comments settings globally." ); } } diff --git a/src/commands/ForceCheckPackages.js b/src/commands/ForceCheckPackages.js new file mode 100644 index 0000000..4a643d3 --- /dev/null +++ b/src/commands/ForceCheckPackages.js @@ -0,0 +1,16 @@ +const vscode = require("vscode"); +const NodePackageManager = require("./NodePackageManager"); +const CommonUtils = require("../utils/CommonUtils"); + +class ForceCheckPackages { + static async checkPackages(context) { + CommonUtils.showInformationMessage( + "Checking and installing required packages and plugins..." + ); + context.globalState.update("dev-pack-salesforce.packages-checked", false); + context.globalState.update("dev-pack-salesforce.sf-plugins-checked", false); + await NodePackageManager.managePackages(context); + } +} + +module.exports = ForceCheckPackages; diff --git a/src/commands/NodePackageManager.js b/src/commands/NodePackageManager.js new file mode 100644 index 0000000..506f7bb --- /dev/null +++ b/src/commands/NodePackageManager.js @@ -0,0 +1,111 @@ +const vscode = require("vscode"); +const { EXTENSION_NAME, REQUIRED_PACKAGES } = require("../utils/constants"); +const SfdxScannerInstaller = require("./SfdxScannerInstaller"); +const CommonUtils = require("../utils/CommonUtils"); + +class NodePackageManager { + static async managePackages(context) { + try { + await this.checkNodeInstallation(); + const missingPackages = await this.checkRequiredPackages(context); + if (missingPackages.length > 0) { + const userConfirmed = await CommonUtils.promptForConfirmation( + `The following node packages will be installed globally: ${missingPackages.join( + ", " + )}. Do you want to proceed?` + ); + if (userConfirmed) { + await this.installMissingPackages(missingPackages); + } else { + return; // Exit if user doesn't confirm package installation + } + } + // Only install SF plugins after ensuring @salesforce/cli is installed + await SfdxScannerInstaller.install(context); + } catch (error) { + vscode.window.showErrorMessage(error); + } + } + + static async checkNodeInstallation() { + try { + await CommonUtils.execCommand("node -v"); + } catch (error) { + throw new Error( + `${EXTENSION_NAME}: Node.js is not installed. Please install Node.js to use this extension.` + ); + } + } + + static async checkRequiredPackages(context) { + try { + const packagesToCheck = REQUIRED_PACKAGES; + const stdout = await CommonUtils.execCommand( + `npm list -g ${packagesToCheck.join(" ")}` + ); + + if (!context.globalState.get("dev-pack-salesforce.packages-checked")) { + CommonUtils.showInformationMessage( + "Required packages are already installed." + ); + context.globalState.update( + "dev-pack-salesforce.packages-checked", + true + ); + } + + const missingPackages = this.getMissingPackages(stdout, packagesToCheck); + return missingPackages; + } catch (error) { + const stdout = error.message; + const missingPackages = this.getMissingPackages( + stdout, + REQUIRED_PACKAGES + ); + if (missingPackages.length === 0) { + if (!context.globalState.get("dev-pack-salesforce.packages-checked")) { + CommonUtils.showInformationMessage( + "All required packages are already installed." + ); + context.globalState.update( + "dev-pack-salesforce.packages-checked", + true + ); + } + } + return missingPackages; + } + } + + static getMissingPackages(stdout, packagesToInstall) { + const missingPackages = packagesToInstall.filter( + (pkg) => !stdout.includes(pkg) + ); + const hasPrettierPluginApex = stdout.includes("prettier-plugin-apex"); + const hasIlyamatsuevPrettierPluginApex = stdout.includes( + "@ilyamatsuev/prettier-plugin-apex" + ); + + if (!hasPrettierPluginApex && !hasIlyamatsuevPrettierPluginApex) { + missingPackages.push("prettier-plugin-apex"); + } + + return missingPackages; + } + + static async installMissingPackages(missingPackages) { + try { + const installCommand = `npm install -g ${missingPackages.join(" ")}`; + await CommonUtils.execCommand(installCommand); + CommonUtils.showInformationMessage( + `Successfully installed npm packages: ${missingPackages.join(", ")}` + ); + } catch (error) { + throw new Error( + `${EXTENSION_NAME}: Failed to install npm packages: ${error.message}` + ); + } + } +} + +module.exports = NodePackageManager; diff --git a/src/commands/Sfdx.js b/src/commands/Sfdx.js new file mode 100644 index 0000000..a1969b8 --- /dev/null +++ b/src/commands/Sfdx.js @@ -0,0 +1,46 @@ +const vscode = require("vscode"); +const CommonUtils = require("../utils/CommonUtils"); +const { EXTENSION_NAME } = require("../utils/constants"); + +const apexLogFileName = "apexlog-out.csv"; + +class Sfdx { + static async deleteApexLogs() { + await vscode.window.withProgress( + { + location: vscode.ProgressLocation.Notification, + title: "Deleting Apex Logs", + cancellable: false, + }, + async (progress) => { + try { + progress.report({ message: "Querying ApexLog IDs..." }); + // Step 1: Query ApexLog IDs and save to apexlog-out.csv + await CommonUtils.execCommand( + `sf data query -q "SELECT Id FROM ApexLog" -r "csv" > ${apexLogFileName}` + ); + + progress.report({ message: "Deleting ApexLogs..." }); + // Step 2: Delete ApexLogs using the apexlog-out.csv file + await CommonUtils.execCommand( + `sf data delete bulk --sobject ApexLog --file ${apexLogFileName} --wait 1000` + ); + + CommonUtils.showInformationMessage( + "Successfully deleted all Apex logs." + ); + + // Step 3: Delete the apexlog-out.csv file using vscode API + const file = vscode.Uri.file(apexLogFileName); + await vscode.workspace.fs.delete(file); + } catch (error) { + vscode.window.showErrorMessage( + `${EXTENSION_NAME}: Failed to delete Apex logs: ${error.message}` + ); + } + } + ); + } +} + +module.exports = Sfdx; diff --git a/src/commands/SfdxScannerInstaller.js b/src/commands/SfdxScannerInstaller.js new file mode 100644 index 0000000..7827e31 --- /dev/null +++ b/src/commands/SfdxScannerInstaller.js @@ -0,0 +1,72 @@ +const vscode = require("vscode"); +const CommonUtils = require("../utils/CommonUtils"); + +class SfdxScannerInstaller { + static async install(context) { + try { + // Check if sf command is available + await this.verifySfCliInstalled(); + + const plugins = await CommonUtils.execCommand("sf plugins"); + const pluginsToInstall = []; + + if (!plugins.includes("@salesforce/sfdx-scanner")) { + pluginsToInstall.push("@salesforce/sfdx-scanner"); + } + + if (!plugins.includes("code-analyzer")) { + pluginsToInstall.push("code-analyzer"); + } + + if (pluginsToInstall.length > 0) { + const userConfirmed = await CommonUtils.promptForConfirmation( + `The following SF plugins will be installed: ${pluginsToInstall.join( + ", " + )}. Do you want to proceed?` + ); + if (userConfirmed) { + await this.installPlugins(pluginsToInstall); + } + } else { + if ( + !context.globalState.get("dev-pack-salesforce.sf-plugins-checked") + ) { + CommonUtils.showInformationMessage( + "All required SF plugins are already installed. SF setup is complete." + ); + context.globalState.update( + "dev-pack-salesforce.sf-plugins-checked", + true + ); + } + } + } catch (error) { + vscode.window.showErrorMessage(error); + } + } + + static async verifySfCliInstalled() { + try { + await CommonUtils.execCommand("sf --version"); + } catch (error) { + throw new Error( + "Salesforce CLI (sf) is not available. Please ensure @salesforce/cli is installed first." + ); + } + } + + static async installPlugins(pluginsToInstall) { + try { + for (const plugin of pluginsToInstall) { + await CommonUtils.execCommand(`sf plugins install ${plugin}`); + } + CommonUtils.showInformationMessage( + `Successfully installed SF plugins: ${pluginsToInstall.join(", ")}` + ); + } catch (error) { + throw new Error(`Failed to install SF plugins: ${error.message}`); + } + } +} + +module.exports = SfdxScannerInstaller; diff --git a/src/commands/WorkspaceSettings.js b/src/commands/WorkspaceSettings.js new file mode 100644 index 0000000..6782d55 --- /dev/null +++ b/src/commands/WorkspaceSettings.js @@ -0,0 +1,45 @@ +const vscode = require("vscode"); +const { APEX_SETTINGS, JAVASCRIPT_SETTINGS } = require("../utils/constants"); +const BetterCommentsUpdater = require("./BetterComments"); +const CommonUtils = require("../utils/CommonUtils"); + +class WorkspaceSettings { + static checkAndUpdateSettings(context) { + const config = vscode.workspace.getConfiguration("devPackSalesforce"); + const autoUpdateSettings = config.get("autoUpdateSettings"); + const isNewWorkspace = !context.globalState.get( + "dev-pack-salesforce.workspace-initialized" + ); + + if (autoUpdateSettings && isNewWorkspace) { + this.updateSettings(); + context.globalState.update( + "dev-pack-salesforce.workspace-initialized", + true + ); + } + } + + static updateSettings() { + const config = vscode.workspace.getConfiguration(); + + config.update( + "[apex]", + APEX_SETTINGS, + vscode.ConfigurationTarget.Workspace + ); + config.update( + "[javascript]", + JAVASCRIPT_SETTINGS, + vscode.ConfigurationTarget.Workspace + ); + + BetterCommentsUpdater.updateSettings(); + + CommonUtils.showInformationMessage( + "Updated settings for Apex and JavaScript" + ); + } +} + +module.exports = WorkspaceSettings; diff --git a/src/commands/forceCheckPackages.js b/src/commands/forceCheckPackages.js deleted file mode 100644 index 077658f..0000000 --- a/src/commands/forceCheckPackages.js +++ /dev/null @@ -1,19 +0,0 @@ -const vscode = require("vscode"); -const NodePackageManager = require("./nodePackageManager"); -const { EXTENSION_NAME } = require("../utils/constants"); - -class ForceCheckPackages { - static async checkPackages(context) { - vscode.window.showInformationMessage( - `${EXTENSION_NAME}: Checking and installing required packages and plugins...` - ); - context.globalState.update("dev-pack-salesforce.packages-checked", false); - context.globalState.update( - "dev-pack-salesforce.sfdx-scanner-checked", - false - ); - await NodePackageManager.managePackages(context); - } -} - -module.exports = ForceCheckPackages; diff --git a/src/commands/nodePackageManager.js b/src/commands/nodePackageManager.js deleted file mode 100644 index 47e9569..0000000 --- a/src/commands/nodePackageManager.js +++ /dev/null @@ -1,140 +0,0 @@ -const vscode = require("vscode"); -const { exec } = require("child_process"); -const { EXTENSION_NAME, REQUIRED_PACKAGES } = require("../utils/constants"); -const SfdxScannerInstaller = require("./sfdxScannerInstaller"); - -class NodePackageManager { - static async managePackages(context) { - try { - await this.checkNodeInstallation(); - const missingPackages = await this.checkRequiredPackages(context); - if (missingPackages.length > 0) { - const userConfirmed = await this.promptForPackageInstallation( - missingPackages - ); - if (userConfirmed) { - await this.installMissingPackages(missingPackages); - } - } - await SfdxScannerInstaller.install(context); - } catch (error) { - vscode.window.showErrorMessage(error); - } - } - - static checkNodeInstallation() { - return new Promise((resolve, reject) => { - exec("node -v", (error, stdout, stderr) => { - if (error) { - reject( - `${EXTENSION_NAME}: Node.js is not installed. Please install Node.js to use this extension.` - ); - } else { - resolve(); - } - }); - }); - } - - static checkRequiredPackages(context) { - return new Promise((resolve, reject) => { - const packagesToCheck = REQUIRED_PACKAGES; - const packagesToInstall = REQUIRED_PACKAGES; - - exec( - `npm list -g ${packagesToCheck.join(" ")}`, - (error, stdout, stderr) => { - if (!error) { - if ( - !context.globalState.get("dev-pack-salesforce.packages-checked") - ) { - vscode.window.showInformationMessage( - `${EXTENSION_NAME}: Required packages are already installed.` - ); - context.globalState.update( - "dev-pack-salesforce.packages-checked", - true - ); - } - resolve([]); - } else { - const missingPackages = this.getMissingPackages( - stdout, - packagesToInstall - ); - if (missingPackages.length === 0) { - if ( - !context.globalState.get("dev-pack-salesforce.packages-checked") - ) { - vscode.window.showInformationMessage( - `${EXTENSION_NAME}: All required packages are already installed.` - ); - context.globalState.update( - "dev-pack-salesforce.packages-checked", - true - ); - } - resolve([]); - } else { - resolve(missingPackages); - } - } - } - ); - }); - } - - static getMissingPackages(stdout, packagesToInstall) { - const missingPackages = packagesToInstall.filter( - (pkg) => !stdout.includes(pkg) - ); - const hasPrettierPluginApex = stdout.includes("prettier-plugin-apex"); - const hasIlyamatsuevPrettierPluginApex = stdout.includes( - "@ilyamatsuev/prettier-plugin-apex" - ); - - if (!hasPrettierPluginApex && !hasIlyamatsuevPrettierPluginApex) { - missingPackages.push("prettier-plugin-apex"); - } - - return missingPackages; - } - - static promptForPackageInstallation(missingPackages) { - return new Promise((resolve) => { - vscode.window - .showInformationMessage( - `${EXTENSION_NAME}: The following node packages will be installed globally: ${missingPackages.join( - ", " - )}. Do you want to proceed?`, - "Yes", - "No" - ) - .then((selection) => { - resolve(selection === "Yes"); - }); - }); - } - - static installMissingPackages(missingPackages) { - return new Promise((resolve, reject) => { - const installCommand = `npm install -g ${missingPackages.join(" ")}`; - exec(installCommand, (error, stdout, stderr) => { - if (error) { - reject( - `${EXTENSION_NAME}: Failed to install npm packages: ${stderr}` - ); - } else { - vscode.window.showInformationMessage( - `${EXTENSION_NAME}: Successfully installed npm packages: ${missingPackages.join( - ", " - )}` - ); - resolve(); - } - }); - }); - } -} - -module.exports = NodePackageManager; diff --git a/src/commands/sfdxScannerInstaller.js b/src/commands/sfdxScannerInstaller.js deleted file mode 100644 index 3d52ae2..0000000 --- a/src/commands/sfdxScannerInstaller.js +++ /dev/null @@ -1,81 +0,0 @@ -const vscode = require("vscode"); -const { exec } = require("child_process"); -const { EXTENSION_NAME } = require("../utils/constants"); - -class SfdxScannerInstaller { - static async install(context) { - try { - const plugins = await this.execCommand("sf plugins"); - if (!plugins.includes("@salesforce/sfdx-scanner")) { - const userConfirmed = await this.promptForInstallation(); - if (userConfirmed) { - await this.installPlugin(); - } - } else { - if ( - !context.globalState.get("dev-pack-salesforce.sfdx-scanner-checked") - ) { - vscode.window.showInformationMessage( - `${EXTENSION_NAME}: The @salesforce/sfdx-scanner plugin is already installed. SFDX setup is complete.` - ); - context.globalState.update( - "dev-pack-salesforce.sfdx-scanner-checked", - true - ); - } - } - } catch (error) { - vscode.window.showErrorMessage(error); - } - } - - static execCommand(command) { - return new Promise((resolve, reject) => { - exec(command, (error, stdout, stderr) => { - if (error) { - reject( - `${EXTENSION_NAME}: Failed to execute command "${command}": ${stderr}` - ); - } else { - resolve(stdout); - } - }); - }); - } - - static promptForInstallation() { - return new Promise((resolve) => { - vscode.window - .showInformationMessage( - `${EXTENSION_NAME}: The @salesforce/sfdx-scanner plugin is not installed. Do you want to install it?`, - "Yes", - "No" - ) - .then((selection) => { - resolve(selection === "Yes"); - }); - }); - } - - static installPlugin() { - return new Promise((resolve, reject) => { - exec( - "sf plugins:install @salesforce/sfdx-scanner", - (error, stdout, stderr) => { - if (error) { - reject( - `${EXTENSION_NAME}: Failed to install SFDX scanner plugin: ${stderr}` - ); - } else { - vscode.window.showInformationMessage( - `${EXTENSION_NAME}: Successfully installed SFDX scanner plugin.` - ); - resolve(); - } - } - ); - }); - } -} - -module.exports = SfdxScannerInstaller; diff --git a/src/commands/workspaceSettings.js b/src/commands/workspaceSettings.js deleted file mode 100644 index 398f90e..0000000 --- a/src/commands/workspaceSettings.js +++ /dev/null @@ -1,32 +0,0 @@ -const vscode = require("vscode"); -const { - EXTENSION_NAME, - APEX_SETTINGS, - JAVASCRIPT_SETTINGS, -} = require("../utils/constants"); -const BetterCommentsUpdater = require("./betterComments"); - -class Workspace { - static updateSettings() { - const config = vscode.workspace.getConfiguration(); - - config.update( - "[apex]", - APEX_SETTINGS, - vscode.ConfigurationTarget.Workspace - ); - config.update( - "[javascript]", - JAVASCRIPT_SETTINGS, - vscode.ConfigurationTarget.Workspace - ); - - BetterCommentsUpdater.updateSettings(); - - vscode.window.showInformationMessage( - `${EXTENSION_NAME}: Updated settings for Apex and JavaScript` - ); - } -} - -module.exports = Workspace; diff --git a/src/extension.js b/src/extension.js index ae23638..d16c8fc 100644 --- a/src/extension.js +++ b/src/extension.js @@ -1,91 +1,67 @@ const vscode = require("vscode"); const { EXTENSION_NAME } = require("./utils/constants"); -const NodePackageManager = require("./commands/nodePackageManager"); -const SettingsManager = require("./utils/settingsManager"); -const WorkspaceSettings = require("./commands/workspaceSettings"); -const BetterComments = require("./commands/betterComments"); -const ForceCheckPackages = require("./commands/forceCheckPackages"); +const NodePackageManager = require("./commands/NodePackageManager"); +const SettingsManager = require("./utils/SettingsManager"); +const WorkspaceSettings = require("./commands/WorkspaceSettings"); +const BetterComments = require("./commands/BetterComments"); +const ForceCheckPackages = require("./commands/ForceCheckPackages"); +const InitialSetup = require("./utils/InitialSetup"); +const Sfdx = require("./commands/Sfdx"); -async function activate(context) { - console.log( - `Congratulations, your extension "${EXTENSION_NAME}" is now active!` - ); - - await setInitialTheme(context); - await NodePackageManager.managePackages(context); - registerCommands(context); - await SettingsManager.manageSettings(context); - await checkAndUpdateSettings(context); -} - -async function setInitialTheme(context) { - if (!context.globalState.get("dev-pack-salesforce.has-theme-set")) { - await vscode.workspace - .getConfiguration() - .update("workbench.iconTheme", "vscode-icons", true); - await vscode.workspace - .getConfiguration() - .update("workbench.colorTheme", "One Dark Pro Darker", true); - context.globalState.update("dev-pack-salesforce.has-theme-set", true); +class Extension { + constructor(context) { + this.context = context; } - if (!context.globalState.get("dev-pack-salesforce.has-better-comments-set")) { - BetterComments.updateSettings(); - context.globalState.update( - "dev-pack-salesforce.has-better-comments-set", - true + async activate() { + console.log( + `Congratulations, your extension "${EXTENSION_NAME}" is now active!` ); + this.registerCommands(); + await InitialSetup.setup(this.context); + await NodePackageManager.managePackages(this.context); + await SettingsManager.manageSettings(this.context); + WorkspaceSettings.checkAndUpdateSettings(this.context); } -} -function registerCommands(context) { - context.subscriptions.push( - vscode.commands.registerCommand( - "dev-pack-salesforce.forceCheckPackages", - () => { - ForceCheckPackages.checkPackages(context); - } - ) - ); + registerCommands() { + const commands = [ + { + command: "dev-pack-salesforce.forceCheckPackages", + callback: () => ForceCheckPackages.checkPackages(this.context), + }, + { + command: "dev-pack-salesforce.updateSettings", + callback: () => WorkspaceSettings.updateSettings(), + }, + { + command: "dev-pack-salesforce.updateBetterCommentsSettings", + callback: () => BetterComments.updateSettings(), + }, + { + command: "dev-pack-salesforce.deleteApexLogs", + callback: () => Sfdx.deleteApexLogs(), + }, + ]; - context.subscriptions.push( - vscode.commands.registerCommand( - "dev-pack-salesforce.updateSettings", - () => { - WorkspaceSettings.updateSettings(); - } - ) - ); + commands.forEach(({ command, callback }) => { + this.context.subscriptions.push( + vscode.commands.registerCommand(command, callback) + ); + }); + } - context.subscriptions.push( - vscode.commands.registerCommand( - "dev-pack-salesforce.updateBetterCommentsSettings", - () => { - BetterComments.updateSettings(); - } - ) - ); + deactivate() {} } -async function checkAndUpdateSettings(context) { - const config = vscode.workspace.getConfiguration("devPackSalesforce"); - const autoUpdateSettings = config.get("autoUpdateSettings"); - const isNewWorkspace = !context.globalState.get( - "dev-pack-salesforce.workspace-initialized" - ); - - if (autoUpdateSettings && isNewWorkspace) { - WorkspaceSettings.updateSettings(); - context.globalState.update( - "dev-pack-salesforce.workspace-initialized", - true - ); - } +function activate(context) { + const extension = new Extension(context); + extension.activate(); } -exports.activate = activate; - -function deactivate() {} +function deactivate() { + // Add any cleanup logic here if needed +} module.exports = { activate, diff --git a/src/utils/CommonUtils.js b/src/utils/CommonUtils.js new file mode 100644 index 0000000..337d41e --- /dev/null +++ b/src/utils/CommonUtils.js @@ -0,0 +1,34 @@ +const vscode = require("vscode"); +const { exec } = require("child_process"); +const { EXTENSION_NAME } = require("../utils/constants"); + +class CommonUtils { + static execCommand(command) { + return new Promise((resolve, reject) => { + exec(command, (error, stdout, stderr) => { + if (error) { + reject( + `${EXTENSION_NAME}: Failed to execute command "${command}": ${stderr}` + ); + } else { + resolve(stdout); + } + }); + }); + } + + static showInformationMessage(message) { + vscode.window.showInformationMessage(`${EXTENSION_NAME}: ${message}`); + } + + static async promptForConfirmation(message) { + const selection = await vscode.window.showInformationMessage( + `${EXTENSION_NAME}: ${message}`, + "Yes", + "No" + ); + return selection === "Yes"; + } +} + +module.exports = CommonUtils; diff --git a/src/utils/InitialSetup.js b/src/utils/InitialSetup.js new file mode 100644 index 0000000..373c433 --- /dev/null +++ b/src/utils/InitialSetup.js @@ -0,0 +1,39 @@ +const vscode = require("vscode"); +const BetterComments = require("./commands/betterComments"); + +class InitialSetup { + static async setup(context) { + try { + await this.setInitialTheme(context); + await this.setBetterComments(context); + } catch (error) { + vscode.window.showErrorMessage(error); + } + } + + static async setInitialTheme(context) { + if (!context.globalState.get("dev-pack-salesforce.has-theme-set")) { + await vscode.workspace + .getConfiguration() + .update("workbench.iconTheme", "vscode-icons", true); + await vscode.workspace + .getConfiguration() + .update("workbench.colorTheme", "One Dark Pro Darker", true); + context.globalState.update("dev-pack-salesforce.has-theme-set", true); + } + } + + static async setBetterComments(context) { + if ( + !context.globalState.get("dev-pack-salesforce.has-better-comments-set") + ) { + BetterComments.updateSettings(); + await context.globalState.update( + "dev-pack-salesforce.has-better-comments-set", + true + ); + } + } +} + +module.exports = InitialSetup; diff --git a/src/utils/settingsManager.js b/src/utils/SettingsManager.js similarity index 96% rename from src/utils/settingsManager.js rename to src/utils/SettingsManager.js index 9a6ee12..688a6e8 100644 --- a/src/utils/settingsManager.js +++ b/src/utils/SettingsManager.js @@ -1,5 +1,5 @@ const vscode = require("vscode"); -const WorkspaceSettings = require("../commands/workspaceSettings"); +const WorkspaceSettings = require("../commands/WorkspaceSettings"); const { EXTENSION_NAME } = require("./constants"); class SettingsManager {