#!/usr/bin/env pwsh # Migration script for moving from packages/ to libs/ # This script helps maintain backward compatibility during the transition $ErrorActionPreference = "Stop" $PackagesDir = "g:\repos\stock-bot\packages" $LibsDir = "g:\repos\stock-bot\libs" function Write-ColorOutput($ForegroundColor) { $fc = $host.UI.RawUI.ForegroundColor $host.UI.RawUI.ForegroundColor = $ForegroundColor if ($args) { Write-Output $args } $host.UI.RawUI.ForegroundColor = $fc } function Create-PackageAlias { param ( [string]$PackageName ) $PackageDir = Join-Path $PackagesDir $PackageName $LibDir = Join-Path $LibsDir $PackageName # Check if the lib already exists if (-not (Test-Path $LibDir)) { Write-ColorOutput "Red" "Error: Library $PackageName not found in $LibsDir" return } # Create the package directory if it doesn't exist if (-not (Test-Path $PackageDir)) { New-Item -ItemType Directory -Force -Path $PackageDir | Out-Null Write-ColorOutput "Green" "Created directory: $PackageDir" } # Create a package.json that points to the lib $PackageJsonPath = Join-Path $PackageDir "package.json" $PackageJson = @{ name = "@stock-bot/$PackageName" version = "1.0.0" description = "Alias package that points to the new library location" main = "../../libs/$PackageName/dist/index.js" types = "../../libs/$PackageName/dist/index.d.ts" files = @("README.md") } $JsonContent = $PackageJson | ConvertTo-Json -Depth 10 Set-Content -Path $PackageJsonPath -Value $JsonContent Write-ColorOutput "Green" "Created alias package.json: $PackageJsonPath" # Create a README explaining what this is $ReadmePath = Join-Path $PackageDir "README.md" $ReadmeContent = @" # $PackageName (Deprecated Path) This package is now maintained in the \`libs/$PackageName\` directory. This is a compatibility alias that points to the new location. ## Migration Please update your imports to use the new path: \`\`\`diff - import { ... } from '@stock-bot/$PackageName' + import { ... } from '@stock-bot/$PackageName' \`\`\` You don't need to change your imports yet, but this path will be removed in a future version. "@ Set-Content -Path $ReadmePath -Value $ReadmeContent Write-ColorOutput "Green" "Created README: $ReadmePath" } # Create aliases for each library Write-ColorOutput "Yellow" "Creating package aliases for backward compatibility..." Create-PackageAlias "types" # Create additional aliases as needed for other libraries Write-ColorOutput "Blue" "✓ Aliases created successfully. Importing from either packages/ or libs/ will work." Write-ColorOutput "Blue" " Please prefer importing from libs/ in new code."