The Angular Generate Command extension for Visual Studio Code simplifies the process of generating Angular artifacts (components, directives, services, etc.) by providing a user-friendly interface to create Angular CLI commands. Instead of running commands directly, the extension copies the generated command to your clipboard, allowing you to paste and execute it in your preferred terminal.
- Generate Angular artifacts including:
- Components
- Directives
- Services
- Interceptors
- Modules
- Pipes
- Guards
- Environments
- Interactive input for artifact names and options (e.g., standalone, skip tests, inline styles).
- Copies the full Angular CLI command to the clipboard.
- Displays a confirmation message when the command is copied.
- Supports context menu integration for folder-based generation in the VS Code Explorer.
- Visual Studio Code (version 1.60.0 or higher recommended).
- Angular CLI installed globally or locally in your project (
npm install -g @angular/clior as a dev dependency). - An Angular project with a
src/appfolder structure for accurate path detection.
-
Install the Extension:
- Open VS Code.
- Go to the Extensions view (
Ctrl+Shift+XorCmd+Shift+Xon macOS). - Search for Angular Generate Command.
- Click Install.
-
Alternatively, if packaging manually:
- Download the
.vsixfile from the release page (if available). - In VS Code, go to Extensions >
...> Install from VSIX and select the file.
- Download the
-
Open Your Angular Project:
- Ensure your workspace contains an Angular project with a
src/appfolder.
- Ensure your workspace contains an Angular project with a
-
Access the Command:
- Option 1: Right-click on a folder in the VS Code Explorer (preferably under
src/app) and select one of theAngular Generate Command: <Artifact>commands (e.g.,Angular Generate Command: Component). - Option 2: Open the Command Palette (
Ctrl+Shift+PorCmd+Shift+Pon macOS), typeAngular Generate Command, and select the desired artifact (e.g.,Angular Generate Command: Component).
- Option 1: Right-click on a folder in the VS Code Explorer (preferably under
-
Provide Input:
- Name: Enter the name of the artifact (e.g.,
my-componentfor a component) in the input box. - Options (if applicable): Select options from the multi-select list (e.g.,
--standalone,--skip-tests). Use arrow keys to navigate andSpaceto select multiple options.
- Name: Enter the name of the artifact (e.g.,
-
Copy and Paste:
- The extension generates an Angular CLI command (e.g.,
ng generate component my-component --standalone). - The command is copied to your clipboard.
- A notification appears (e.g.,
Command for Component "my-component" copied to clipboard!).
- The extension generates an Angular CLI command (e.g.,
-
Execute the Command:
- Open your terminal (within VS Code or externally).
- Paste the command (
Ctrl+VorCmd+V). - Press
Enterto run the Angular CLI command and generate the artifact.
To generate a standalone component named my-component:
- Right-click on
src/appin the Explorer. - Select
Angular Generate Command: Component. - Enter
my-componentin the input box. - Select
StandaloneandSkip Testfrom the options list. - The command
ng generate component my-component --standalone --skip-testsis copied. - Paste and run it in your terminal to create the component.
The extension provides the following commands, accessible via the Command Palette or Explorer context menu:
| Command | Description | Options Available |
|---|---|---|
Angular Generate Command: Component |
Generates an Angular component. | Standalone, Not Standalone, Change Detection, Display Block, Skip Test, Flat, Inline Template, Inline Style, Skip Import, View Encapsulation |
Angular Generate Command: Directive |
Generates an Angular directive. | Standalone, Not Standalone, Skip Test, Flat, Skip Import |
Angular Generate Command: Service |
Generates an Angular service. | Skip Test |
Angular Generate Command: Interceptor |
Generates an Angular interceptor. | Functional, Skip Test |
Angular Generate Command: Module |
Generates an Angular module. | Flat, Add Router |
Angular Generate Command: Pipe |
Generates an Angular pipe. | Standalone, Not Standalone, Skip Test, Skip Import |
Angular Generate Command: Guard |
Generates an Angular guard. | Functional, Skip Test |
Angular Generate Command: Environments |
Generates Angular environment files. | None |
- Standalone: Generates a standalone artifact (v14+).
- Not Standalone: Generates a non-standalone artifact (default in v17+ for standalone).
- Skip Test: Omits test files.
- Flat: Places files in the same directory without a subfolder.
- Inline Template/Style: Embeds template/styles in the component file.
- Skip Import: Prevents auto-import into the nearest module.
- Change Detection: OnPush: Sets component change detection to OnPush.
- Display Block: Sets component display to block in styles.
- View Encapsulation: Sets encapsulation to None or ShadowDom.
- Functional: Generates a functional guard or interceptor.
- Add Router: Includes a routing module.
No additional configuration is required. The extension automatically detects the workspace path based on the folder you right-click or the project root. Ensure your Angular project is structured correctly (e.g., contains src/app).
- Command Not Copied: Ensure you have permissions to access the clipboard. Try restarting VS Code.
- Invalid Path: Make sure you’re triggering the command from a folder within an Angular project. The extension splits paths at
src/appto determine the relative path. - Angular CLI Errors: After pasting the command, check that Angular CLI is installed (
ng --version) and your project is set up correctly. - No Options Shown: Some artifacts (e.g., environments) have no options by design.
Feedback and contributions are welcome! To report issues or suggest features:
- Open an issue on the GitHub repository (replace with your repo link).
- For code contributions, fork the repository, make changes, and submit a pull request.
This extension is written by Nguyen Van Huu
Built to support the Angular and VS Code communities.