工具生成版本
This commit is contained in:
@@ -0,0 +1,199 @@
|
||||
# Symlink Management Scripts
|
||||
|
||||
This directory contains PowerShell scripts for managing symbolic links between package directories in the Lepton project. These scripts help optimize development workflow by creating symlinks to shared dependencies instead of duplicating them across multiple package directories.
|
||||
|
||||
You will need to run these scripts if you need to reference an installed package on the main angular application.
|
||||
|
||||
## 📁 Files Overview
|
||||
|
||||
| File | Purpose | Description |
|
||||
| --------------------- | ------------- | ------------------------------------------------------------------------------ |
|
||||
| `symlink-config.ps1` | Configuration | Shared configuration file defining package directories and packages to symlink |
|
||||
| `setup-symlinks.ps1` | Setup | Creates selective symlinks for specific packages across library directories |
|
||||
| `remove-symlinks.ps1` | Cleanup | Removes all symlinked node_modules directories |
|
||||
|
||||
## 🚀 Quick Start
|
||||
|
||||
### Prerequisites
|
||||
|
||||
1. **PowerShell**: Ensure you have PowerShell Core (pwsh) installed
|
||||
2. **Dependencies**: Run `yarn install` in the main demo app directory first (`Demo/angular`)
|
||||
3. **Permissions**: On Windows, you may need to run PowerShell as Administrator for symlink creation
|
||||
|
||||
### Basic Usage
|
||||
|
||||
```powershell
|
||||
# Navigate to the scripts directory
|
||||
cd Demo/angular/scripts
|
||||
|
||||
# Setup symlinks (run this first)
|
||||
./setup-symlinks.ps1
|
||||
|
||||
# Remove symlinks when done
|
||||
./remove-symlinks.ps1
|
||||
```
|
||||
|
||||
## 📋 Detailed Script Documentation
|
||||
|
||||
### 🔧 symlink-config.ps1
|
||||
|
||||
**Purpose**: Centralized configuration for all symlink operations.
|
||||
|
||||
**Configuration**:
|
||||
|
||||
- **Package Directories**: Defines all library directories that need symlink management
|
||||
- **Packages to Symlink**: Lists specific npm packages that should be symlinked
|
||||
|
||||
**Key Variables**:
|
||||
|
||||
- `$script:PackageDirectories`: Array of relative paths to library directories
|
||||
- `$script:PackagesToSymlink`: Array of package names to symlink
|
||||
|
||||
**Functions**:
|
||||
|
||||
- `Get-PackageDirectories()`: Returns the list of package directories
|
||||
- `Get-PackagesToSymlink()`: Returns the list of packages to symlink
|
||||
|
||||
### 🔗 setup-symlinks.ps1
|
||||
|
||||
**Purpose**: Creates selective symlinks for shared dependencies across library directories.
|
||||
|
||||
**What it does**:
|
||||
|
||||
1. Reads configuration from `symlink-config.ps1`
|
||||
2. Identifies the main app's `node_modules` directory
|
||||
3. For each library directory:
|
||||
- Creates a `node_modules` directory if it doesn't exist
|
||||
- Creates symlinks for each configured package
|
||||
- Skips packages that don't exist in the main `node_modules`
|
||||
- Avoids circular symlinks
|
||||
|
||||
**Example Output**:
|
||||
|
||||
```
|
||||
🔗 Setting up selective symlinks for specific packages...
|
||||
|
||||
📦 Packages to symlink:
|
||||
• @angular
|
||||
• @abp
|
||||
• @volo
|
||||
• @volosoft
|
||||
• @ngx-validate
|
||||
• @swimlane
|
||||
• rxjs
|
||||
• cropperjs
|
||||
• angularx-qrcode
|
||||
• qrcode
|
||||
|
||||
📁 Processing ./../modules/Volo.Abp.Identity.Pro/angular/projects/account..
|
||||
✅ Linked @angular
|
||||
✅ Linked @abp
|
||||
✅ Linked @volo
|
||||
...
|
||||
|
||||
🎉 Symlinks completed! Linked: 45, Skipped: 3
|
||||
```
|
||||
|
||||
### 🗑️ remove-symlinks.ps1
|
||||
|
||||
**Purpose**: Removes all symlinked `node_modules` directories to clean up the workspace.
|
||||
|
||||
**What it does**:
|
||||
|
||||
1. Reads configuration from `symlink-config.ps1`
|
||||
2. For each library directory:
|
||||
- Locates the `node_modules` directory
|
||||
- Removes the entire directory (which contains symlinks)
|
||||
- Reports success/failure for each operation
|
||||
|
||||
**Example Output**:
|
||||
|
||||
```
|
||||
🗑️ Removing symlinks from library directories...
|
||||
|
||||
📁 Processing ../../modules/Volo.Abp.Identity.Pro/angular/projects/account...
|
||||
✅ Removed node_modules directory
|
||||
|
||||
📁 Processing ./../modules/Volo.Abp.Identity.Pro/angular/projects/account...
|
||||
✅ Removed node_modules directory
|
||||
|
||||
🎉 Cleanup completed! Removed: 8, Skipped: 0
|
||||
💡 Libraries will now use their own local dependencies (if any)
|
||||
```
|
||||
|
||||
## ⚙️ Configuration
|
||||
|
||||
### Adding New Package Directories
|
||||
|
||||
Edit `symlink-config.ps1` and add new paths to the `$script:PackageDirectories` array:
|
||||
|
||||
```powershell
|
||||
$script:PackageDirectories = @(
|
||||
"./../modules/Volo.Abp.Identity.Pro/angular"
|
||||
# Add your new directory here
|
||||
)
|
||||
```
|
||||
|
||||
### Adding New Packages to Symlink
|
||||
|
||||
Edit `symlink-config.ps1` and add package names to the `$script:PackagesToSymlink` array:
|
||||
|
||||
```powershell
|
||||
$script:PackagesToSymlink = @(
|
||||
"@angular",
|
||||
"@abp",
|
||||
# Add your new package here
|
||||
"your-new-package"
|
||||
)
|
||||
```
|
||||
|
||||
## 🚨 Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
**Error: "Export-ModuleMember can only be called from inside a module"**
|
||||
|
||||
- ✅ **Fixed**: This was resolved by removing the `Export-ModuleMember` line from `symlink-config.ps1`
|
||||
|
||||
**Error: "Main app node_modules not found"**
|
||||
|
||||
- **Solution**: Run `yarn install` in the main demo app directory first
|
||||
|
||||
**Error: "Access denied" on Windows**
|
||||
|
||||
- **Solution**: Run PowerShell as Administrator
|
||||
|
||||
**Symlinks not working on Windows**
|
||||
|
||||
- **Solution**: Enable Developer Mode in Windows Settings, or run as Administrator
|
||||
|
||||
### Platform-Specific Notes
|
||||
|
||||
**Windows**:
|
||||
|
||||
- Uses `cmd /c "mklink /J"` for directory junctions
|
||||
- May require Administrator privileges
|
||||
- Consider enabling Developer Mode for easier symlink creation
|
||||
|
||||
**macOS/Linux**:
|
||||
|
||||
- Uses `New-Item -ItemType SymbolicLink`
|
||||
- Generally works without special permissions
|
||||
- May require `ln -s` if PowerShell symlinks don't work
|
||||
|
||||
## 📝 Notes
|
||||
|
||||
- These scripts are designed for development environments
|
||||
- Always run `remove-symlinks.ps1` before committing changes
|
||||
- The scripts use relative paths, so they must be run from the scripts directory
|
||||
- Symlinks are automatically detected and handled by most development tools
|
||||
- Consider adding symlinked directories to `.gitignore` if needed
|
||||
|
||||
## 🤝 Contributing
|
||||
|
||||
When modifying these scripts:
|
||||
|
||||
1. Test on both Windows and macOS/Linux
|
||||
2. Update this README if you change functionality
|
||||
3. Ensure error handling is robust
|
||||
4. Maintain backward compatibility with existing configurations
|
||||
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env pwsh
|
||||
|
||||
# Import shared configuration
|
||||
. "$PSScriptRoot/symlink-config.ps1"
|
||||
|
||||
# Get configuration from shared module
|
||||
$packageDirectories = Get-PackageDirectories
|
||||
|
||||
function Remove-Symlinks {
|
||||
Write-Host "🗑️ Removing symlinks from library directories...`n" -ForegroundColor Cyan
|
||||
|
||||
$totalRemoved = 0
|
||||
$totalSkipped = 0
|
||||
|
||||
foreach ($packageDir in $packageDirectories) {
|
||||
$resolvedPath = Resolve-Path $packageDir -ErrorAction SilentlyContinue
|
||||
$targetNodeModules = Join-Path $resolvedPath "node_modules"
|
||||
|
||||
if (-not $targetNodeModules) {
|
||||
Write-Host "⚠️ Skipping $packageDir (directory not found)" -ForegroundColor Yellow
|
||||
$totalSkipped++
|
||||
continue
|
||||
}
|
||||
|
||||
Write-Host "📁 Processing $packageDir..." -ForegroundColor Cyan
|
||||
|
||||
if (-not (Test-Path $targetNodeModules)) {
|
||||
Write-Host " ⚠️ No node_modules directory found" -ForegroundColor Yellow
|
||||
$totalSkipped++
|
||||
continue
|
||||
}
|
||||
|
||||
try {
|
||||
# Remove the entire node_modules directory (which contains symlinks)
|
||||
Remove-Item $targetNodeModules -Recurse -Force
|
||||
Write-Host " ✅ Removed node_modules directory" -ForegroundColor Green
|
||||
$totalRemoved++
|
||||
}
|
||||
catch {
|
||||
Write-Host " ❌ Failed to remove $targetNodeModules`: $($_.Exception.Message)" -ForegroundColor Red
|
||||
$totalSkipped++
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "`n🎉 Cleanup completed! Removed: $totalRemoved, Skipped: $totalSkipped" -ForegroundColor Green
|
||||
Write-Host "💡 Libraries will now use their own local dependencies (if any)" -ForegroundColor Cyan
|
||||
}
|
||||
|
||||
# Run the cleanup
|
||||
Remove-Symlinks
|
||||
@@ -0,0 +1,106 @@
|
||||
#!/usr/bin/env pwsh
|
||||
|
||||
# Import shared configuration
|
||||
. "$PSScriptRoot/symlink-config.ps1"
|
||||
|
||||
# Get configuration from shared module
|
||||
$packagesToSymlink = Get-PackagesToSymlink
|
||||
$packageDirectories = Get-PackageDirectories
|
||||
|
||||
# Global variables for interactive mode
|
||||
$scriptPath = $PSCommandPath
|
||||
|
||||
function Setup-SelectiveSymlinks {
|
||||
Write-Host "🔗 Setting up selective symlinks for specific packages...`n" -ForegroundColor Cyan
|
||||
|
||||
$mainNodeModules = Resolve-Path "./../node_modules" -ErrorAction SilentlyContinue
|
||||
|
||||
Write-Host " • $mainNodeModules" -ForegroundColor Gray
|
||||
|
||||
|
||||
if (-not $mainNodeModules) {
|
||||
Write-Host "❌ Main app node_modules not found. Run npm install first." -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
if ($packagesToSymlink.Count -eq 0 -or $packageDirectories.Count -eq 0) {
|
||||
Write-Host "✅ You are all set. There are no packages to symlink." -ForegroundColor Green
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
Write-Host "📦 Packages to symlink:" -ForegroundColor Yellow
|
||||
foreach ($package in $packagesToSymlink) {
|
||||
Write-Host " • $package" -ForegroundColor Gray
|
||||
}
|
||||
Write-Host ""
|
||||
|
||||
$totalLinked = 0
|
||||
$totalSkipped = 0
|
||||
|
||||
foreach ($packageDir in $packageDirectories) {
|
||||
$resolvedPath = Resolve-Path $packageDir
|
||||
$targetNodeModules = Join-Path $resolvedPath "node_modules"
|
||||
|
||||
Write-Host "📁 Processing $packageDir..." -ForegroundColor Cyan
|
||||
|
||||
# Skip if this is the main node_modules directory (avoid circular symlinks)
|
||||
if ($targetNodeModules -eq $mainNodeModules) {
|
||||
Write-Host " ⚠️ Skipping main node_modules directory" -ForegroundColor Yellow
|
||||
continue
|
||||
}
|
||||
|
||||
# Create node_modules directory if it doesn't exist
|
||||
if (-not (Test-Path $targetNodeModules)) {
|
||||
New-Item -ItemType Directory -Path $targetNodeModules -Force | Out-Null
|
||||
Write-Host " 📁 Created node_modules directory" -ForegroundColor Gray
|
||||
}
|
||||
|
||||
foreach ($package in $packagesToSymlink) {
|
||||
$sourcePackage = Join-Path $mainNodeModules $package
|
||||
$targetPackage = Join-Path $targetNodeModules $package
|
||||
|
||||
# Skip if trying to symlink to the same location (avoid circular symlinks)
|
||||
if ($sourcePackage -eq $targetPackage) {
|
||||
Write-Host " ⚠️ Skipping $package (would create circular symlink)" -ForegroundColor Yellow
|
||||
$totalSkipped++
|
||||
continue
|
||||
}
|
||||
|
||||
# Check if source package exists
|
||||
if (-not (Test-Path $sourcePackage)) {
|
||||
Write-Host " ⚠️ Package $package not found in main node_modules" -ForegroundColor Yellow
|
||||
$totalSkipped++
|
||||
continue
|
||||
}
|
||||
|
||||
try {
|
||||
# Remove existing symlink/folder if it exists
|
||||
if (Test-Path $targetPackage) {
|
||||
Remove-Item $targetPackage -Recurse -Force
|
||||
}
|
||||
|
||||
# Create symlink for the specific package
|
||||
if ($IsWindows) {
|
||||
cmd /c "mklink /J `"$targetPackage`" `"$sourcePackage`""
|
||||
} else {
|
||||
New-Item -ItemType SymbolicLink -Path $targetPackage -Target $sourcePackage | Out-Null
|
||||
}
|
||||
|
||||
Write-Host " ✅ Linked $package" -ForegroundColor Green
|
||||
$totalLinked++
|
||||
}
|
||||
catch {
|
||||
Write-Host " ❌ Failed to link $package`: $($_.Exception.Message)" -ForegroundColor Red
|
||||
$totalSkipped++
|
||||
}
|
||||
}
|
||||
Write-Host ""
|
||||
}
|
||||
|
||||
Write-Host "🎉 Symlinks completed! Linked: $totalLinked, Skipped: $totalSkipped" -ForegroundColor Green
|
||||
}
|
||||
|
||||
# Main execution
|
||||
Setup-SelectiveSymlinks
|
||||
@@ -0,0 +1,33 @@
|
||||
# Symlink Configuration
|
||||
# Shared configuration for symlink management scripts
|
||||
|
||||
# Define the package directories that need symlink management
|
||||
# example: "../../modules/Volo.Abp.Identity.Pro/angular"
|
||||
$script:PackageDirectories = @()
|
||||
|
||||
# Define packages that should be symlinked
|
||||
$script:PackagesToSymlink = @(
|
||||
"@angular",
|
||||
"@abp",
|
||||
"@volo",
|
||||
"@volosoft",
|
||||
"@swimlane",
|
||||
"@ngx-validate",
|
||||
"@ng-bootstrap",
|
||||
"rxjs",
|
||||
"cropperjs",
|
||||
"angularx-qrcode",
|
||||
"qrcode"
|
||||
)
|
||||
|
||||
# Helper function to get package directories
|
||||
function Get-PackageDirectories {
|
||||
return $script:PackageDirectories
|
||||
}
|
||||
|
||||
# Helper function to get packages to symlink
|
||||
function Get-PackagesToSymlink {
|
||||
return $script:PackagesToSymlink
|
||||
}
|
||||
|
||||
# Functions are available when script is dot-sourced
|
||||
Reference in New Issue
Block a user