Angular Components Symlink Setup
This directory contains scripts to automatically set up symlinks for Angular components before running Angular commands.
Overview
The Angular project needs access to components from the main src/components directory. This is achieved through a symlink from angular/components to ../src/components.
Scripts
setup-symlinks.mjs
- Checks if the symlink exists and points to the correct location
- Creates the symlink if it doesn't exist
- Fixes the symlink if it points to the wrong location
- Backs up existing directories if they conflict
- Verifies the symlink works correctly
ng-wrapper.mjs
- Wrapper script that runs
setup-symlinks.mjsbefore any Angular command - Ensures symlinks are always set up before running
ngcommands - Uses
npx ngto run Angular CLI commands
Usage
Option 1: Use npm scripts (Recommended)
bash
npm run dev # Start development server
npm run build # Build the project
npm run watch # Build and watch for changes
npm run serve # Start development server
npm run start # Start development server
npm run setup-symlinks # Just setup symlinks without running ngOption 2: Use wrapper script directly
bash
node ./ng-wrapper.mjs serve --port 4200
node ./ng-wrapper.mjs build --configuration production
node ./ng-wrapper.mjs generate component my-componentOption 3: Manual symlink setup
bash
node ./setup-symlinks.mjs
npx ng serve # or any other ng commandWhat the scripts do
- Check source directory: Verifies that
../src/componentsexists - Check existing symlink:
- If symlink exists and points to correct location → ✅ Continue
- If symlink exists but points to wrong location → 🔧 Fix it
- If directory exists but isn't a symlink → 📦 Backup and create symlink
- If nothing exists → 🔗 Create symlink
- Verify: Ensures the symlink works by checking for a known file
- Run Angular command: Proceeds with the requested ng command
Benefits
- Automatic: No need to manually create symlinks
- Safe: Backs up existing directories before making changes
- Reliable: Verifies symlinks work before proceeding
- Team-friendly: Symlinks are committed to git so everyone gets them
- Cross-platform: Works on macOS, Linux, and Windows
Troubleshooting
If you encounter issues:
- Run
npm run setup-symlinksto check the current state - Check that
../src/componentsdirectory exists - Ensure you have write permissions in the angular directory
- On Windows, make sure you're using Git Bash or WSL
Files
setup-symlinks.mjs- Main symlink setup scriptng-wrapper.mjs- Angular command wrapperpackage.json- Updated with new npm scriptscomponents- Symlink to../src/components(committed to git)