Search This Blog

2025/03/07

Automating installation of Visual Studio Code extensions

Usually when we install Visual Studio for say node.js or
angular or react developement we need to install multiple
VS-Code Extension.

   If you have to setup multiple machines with same configuration
doing same task on multiple systems is boaring & kind of tidious.  
One can automate installtion of VS-Code Extension using Bash(.sh) or Window
script(.bat).

As I am planning to do developement on node.js/express.js & Angular.

    List of Required/Desirable Packages for Node.js Developement:
        a)Node.js Extension Pack – A collection of useful extensions for Node.js development.
        b)ESLint – Helps maintain code quality by enforcing linting rules.
        c)Debugger for Node.js – Provides a robust debugging environment.
        d)NPM Intellisense – Auto-suggestions for npm modules.
        e)Path Intellisense – Autocomplete for file paths.
        f)REST Client – Test APIs directly from VS Code.
        g)DotENV – Syntax highlighting for .env files.

    List of Required/Desirable Packages for Angular Extensions:
        a)Angular Language Service – Provides Angular-specific IntelliSense, navigation, and type checking.
        b)Angular Snippets (Version 14+) – John Papa’s Angular snippets for faster coding.
        c)Angular Schematics – Run Angular CLI commands directly inside VS Code.
        d)Material Icon Theme – Adds Angular-related icons for better file visibility.
        e)Prettier - Code Formatter – Ensures consistent code formatting.

Lets build script for this purpose.

    To install the listed packages we need to run the following command in PowerShell
    or a Window Command Line(cmd):

        Window Terminal/Powershell Command:

            code --install-extension waderyan.nodejs-extension-pack `
                 --install-extension dbaeumer.vscode-eslint `
                 --install-extension ms-vscode.node-debug2 `
                 --install-extension christian-kohler.npm-intellisense `
                 --install-extension christian-kohler.path-intellisense `
                 --install-extension humao.rest-client `
                 --install-extension mikestead.dotenv `
                 --install-extension Angular.ng-template `
                 --install-extension johnpapa.Angular2 `
                 --install-extension cyrilletuzi.angular-schematics `
                 --install-extension PKief.material-icon-theme `
                 --install-extension esbenp.prettier-vscode
         
        We can create a Batch Script for Windows say(install-vscode-extensions.bat)
        Save this as a .bat file and run it:

            install-vscode-extensions.bat file content:

                @echo off
                code --install-extension waderyan.nodejs-extension-pack
                code --install-extension dbaeumer.vscode-eslint
                code --install-extension ms-vscode.node-debug2
                code --install-extension christian-kohler.npm-intellisense
                code --install-extension christian-kohler.path-intellisense
                code --install-extension humao.rest-client
                code --install-extension mikestead.dotenv
                code --install-extension Angular.ng-template
                code --install-extension johnpapa.Angular2
                code --install-extension cyrilletuzi.angular-schematics
                code --install-extension PKief.material-icon-theme
                code --install-extension esbenp.prettier-vscode
                echo All extensions installed successfully!
               
            Run it by double-clicking the .bat file.

    On Linux & MAC os we need to use bash/shell script instead of batch file.

        Shell Script for Linux/macOS say(install-vscode-extensions.sh)
            Save this as a .sh file and run:

        install-vscode-extensions.sh file content:

            #!/bin/bash
            extensions=(
                "waderyan.nodejs-extension-pack"
                "dbaeumer.vscode-eslint"
                "ms-vscode.node-debug2"
                "christian-kohler.npm-intellisense"
                "christian-kohler.path-intellisense"
                "humao.rest-client"
                "mikestead.dotenv"
                "Angular.ng-template"
                "johnpapa.Angular2"
                "cyrilletuzi.angular-schematics"
                "PKief.material-icon-theme"
                "esbenp.prettier-vscode"
            )

            for extension in "${extensions[@]}"; do
                code --install-extension $extension
            done

            echo "All extensions installed successfully!"
       
    Run it using:

    bash
        chmod +x install-vscode-extensions.sh
        ./install-vscode-extensions.sh


Batch Script has been practically validated for on MS-Window 11

No comments:

Post a Comment