-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(scripts): add local package linking for PHP dependency testing #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| # Setup local package linking for PHP dependency testing | ||
| # Usage: .\scripts\setup-local-packages.ps1 [package-name] | ||
| # Example: .\scripts\setup-local-packages.ps1 core-tenant | ||
|
|
||
| param( | ||
| [string]$PackageName | ||
| ) | ||
|
|
||
| $ErrorActionPreference = "Stop" | ||
|
|
||
| $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path | ||
| $RootDir = Split-Path -Parent $ScriptDir | ||
| $PackagesDir = Join-Path $RootDir "packages" | ||
|
|
||
| function Write-Info { param($msg) Write-Host "[INFO] $msg" -ForegroundColor Green } | ||
| function Write-Warn { param($msg) Write-Host "[WARN] $msg" -ForegroundColor Yellow } | ||
| function Write-Step { param($msg) Write-Host "[STEP] $msg" -ForegroundColor Cyan } | ||
|
|
||
| # Path repositories to inject | ||
| $PathRepositories = @( | ||
| @{type = "path"; url = "../core-php"; options = @{symlink = $true}} | ||
| @{type = "path"; url = "../core-tenant"; options = @{symlink = $true}} | ||
| @{type = "path"; url = "../core-admin"; options = @{symlink = $true}} | ||
| @{type = "path"; url = "../core-api"; options = @{symlink = $true}} | ||
| @{type = "path"; url = "../core-mcp"; options = @{symlink = $true}} | ||
| @{type = "path"; url = "../core-agentic"; options = @{symlink = $true}} | ||
| @{type = "path"; url = "../core-commerce"; options = @{symlink = $true}} | ||
| @{type = "path"; url = "../core-content"; options = @{symlink = $true}} | ||
| @{type = "path"; url = "../core-tools"; options = @{symlink = $true}} | ||
| ) | ||
|
|
||
| function Setup-Package { | ||
| param([string]$pkg) | ||
|
|
||
| $pkgDir = Join-Path $PackagesDir $pkg | ||
| $composerJson = Join-Path $pkgDir "composer.json" | ||
| $target = Join-Path $pkgDir "composer.local.json" | ||
|
|
||
| if (-not (Test-Path $pkgDir)) { | ||
| Write-Warn "Package directory not found: $pkgDir" | ||
| return | ||
| } | ||
|
|
||
| if (-not (Test-Path $composerJson)) { | ||
| Write-Warn "No composer.json found in $pkg (skipping)" | ||
| return | ||
| } | ||
|
|
||
| if (Test-Path $target) { | ||
| Write-Warn "composer.local.json already exists in $pkg (skipping)" | ||
| return | ||
| } | ||
|
|
||
| Write-Step "Setting up $pkg..." | ||
|
|
||
| # Read original composer.json | ||
| $original = Get-Content $composerJson -Raw | ConvertFrom-Json | ||
|
|
||
| # Add repositories array (path repos must come first) | ||
| $original | Add-Member -NotePropertyName "repositories" -NotePropertyValue $PathRepositories -Force | ||
|
|
||
| # Write merged composer.local.json (UTF-8 without BOM for Composer compatibility) | ||
| $json = $original | ConvertTo-Json -Depth 10 | ||
| [System.IO.File]::WriteAllText($target, $json, [System.Text.UTF8Encoding]::new($false)) | ||
|
Comment on lines
+59
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: cat -n scripts/setup-local-packages.ps1Repository: host-uk/core-devops Length of output: 4965 Preserve any existing Composer repositories when generating Overwriting 🛠️ Suggested merge (path repos first)- $original | Add-Member -NotePropertyName "repositories" -NotePropertyValue $PathRepositories -Force
+ $existing = @()
+ if ($original.PSObject.Properties.Name -contains "repositories") {
+ $existing = $original.repositories
+ }
+ $merged = @($PathRepositories + $existing)
+ $original | Add-Member -NotePropertyName "repositories" -NotePropertyValue $merged -Force🤖 Prompt for AI Agents |
||
|
|
||
| # Add to .gitignore if not already there | ||
| $gitignore = Join-Path $pkgDir ".gitignore" | ||
| if (Test-Path $gitignore) { | ||
| $content = Get-Content $gitignore -Raw | ||
| if ($content -notmatch "composer\.local\.json") { | ||
| Add-Content $gitignore "composer.local.json" | ||
| } | ||
| } else { | ||
| "composer.local.json" | Out-File $gitignore -Encoding utf8 | ||
| } | ||
|
|
||
| Write-Info "Created $target" | ||
| } | ||
|
|
||
| # Main | ||
| if ($PackageName) { | ||
| # Setup specific package | ||
| Setup-Package $PackageName | ||
| } else { | ||
| # Setup all packages that depend on host-uk/core | ||
| Write-Info "Setting up local package linking for all packages..." | ||
|
|
||
| $packages = Get-ChildItem -Path $PackagesDir -Directory | ||
|
|
||
| foreach ($dir in $packages) { | ||
| $pkg = $dir.Name | ||
|
|
||
| # Skip packages that don't need it | ||
| if ($pkg -eq "core-php" -or $pkg -eq "core-template") { | ||
| continue | ||
| } | ||
|
|
||
| # Check if composer.json exists and has host-uk dependencies | ||
| $composerJson = Join-Path $dir.FullName "composer.json" | ||
| if (Test-Path $composerJson) { | ||
| $content = Get-Content $composerJson -Raw | ||
| if ($content -match '"host-uk/') { | ||
| Setup-Package $pkg | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Write-Host "" | ||
| Write-Info "Done! To install dependencies with local packages:" | ||
| Write-Host "" | ||
| Write-Host " cd packages\<package>" | ||
| Write-Host " `$env:COMPOSER='composer.local.json'; composer install" | ||
| Write-Host "" | ||
| Write-Host "Or on a single line:" | ||
| Write-Host "" | ||
| Write-Host " powershell -Command `"`$env:COMPOSER='composer.local.json'; composer install`"" | ||
| Write-Host "" | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,115 @@ | ||||||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||||||
| # Setup local package linking for PHP dependency testing | ||||||||||||||||||||||
| # Usage: ./scripts/setup-local-packages.sh [package-name] | ||||||||||||||||||||||
| # Example: ./scripts/setup-local-packages.sh core-tenant | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| set -e | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||||||||||||||||||||||
| ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" | ||||||||||||||||||||||
| PACKAGES_DIR="$ROOT_DIR/packages" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Colour output | ||||||||||||||||||||||
| GREEN='\033[0;32m' | ||||||||||||||||||||||
| YELLOW='\033[1;33m' | ||||||||||||||||||||||
| CYAN='\033[0;36m' | ||||||||||||||||||||||
| NC='\033[0m' # No colour | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| info() { echo -e "${GREEN}[INFO]${NC} $1"; } | ||||||||||||||||||||||
| warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } | ||||||||||||||||||||||
| step() { echo -e "${CYAN}[STEP]${NC} $1"; } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Path repositories JSON to inject | ||||||||||||||||||||||
| REPOSITORIES='[ | ||||||||||||||||||||||
| {"type": "path", "url": "../core-php", "options": {"symlink": true}}, | ||||||||||||||||||||||
| {"type": "path", "url": "../core-tenant", "options": {"symlink": true}}, | ||||||||||||||||||||||
| {"type": "path", "url": "../core-admin", "options": {"symlink": true}}, | ||||||||||||||||||||||
| {"type": "path", "url": "../core-api", "options": {"symlink": true}}, | ||||||||||||||||||||||
| {"type": "path", "url": "../core-mcp", "options": {"symlink": true}}, | ||||||||||||||||||||||
| {"type": "path", "url": "../core-agentic", "options": {"symlink": true}}, | ||||||||||||||||||||||
| {"type": "path", "url": "../core-commerce", "options": {"symlink": true}}, | ||||||||||||||||||||||
| {"type": "path", "url": "../core-content", "options": {"symlink": true}}, | ||||||||||||||||||||||
| {"type": "path", "url": "../core-tools", "options": {"symlink": true}} | ||||||||||||||||||||||
| ]' | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Check for jq (required for JSON manipulation) | ||||||||||||||||||||||
| if ! command -v jq &> /dev/null; then | ||||||||||||||||||||||
| echo "Error: jq is required but not installed. Install it with: brew install jq" | ||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||
|
Comment on lines
+35
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Locate and examine the setup-local-packages.sh file
find . -name "setup-local-packages.sh" -type f 2>/dev/null | head -5Repository: host-uk/core-devops Length of output: 96 🏁 Script executed: #!/bin/bash
# Read the setup-local-packages.sh file with line numbers
cat -n ./scripts/setup-local-packages.shRepository: host-uk/core-devops Length of output: 4474 Provide cross-platform installation guidance for jq. The error message at line 37 references only 📝 Suggested fix# Check for jq (required for JSON manipulation)
if ! command -v jq &> /dev/null; then
- echo "Error: jq is required but not installed. Install it with: brew install jq"
+ echo "Error: jq is required but not installed."
+ echo "Install: macOS (brew install jq) | Debian/Ubuntu (sudo apt-get install jq) | Fedora (sudo dnf install jq)"
exit 1
fiPer coding guidelines: scripts/** must ensure cross-platform compatibility (macOS, Linux, Windows). 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| fi | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Setup function for a single package | ||||||||||||||||||||||
| setup_package() { | ||||||||||||||||||||||
| local pkg="$1" | ||||||||||||||||||||||
| local pkg_dir="$PACKAGES_DIR/$pkg" | ||||||||||||||||||||||
| local composer_json="$pkg_dir/composer.json" | ||||||||||||||||||||||
| local target="$pkg_dir/composer.local.json" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if [[ ! -d "$pkg_dir" ]]; then | ||||||||||||||||||||||
| warn "Package directory not found: $pkg_dir" | ||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if [[ ! -f "$composer_json" ]]; then | ||||||||||||||||||||||
| warn "No composer.json found in $pkg (skipping)" | ||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if [[ -f "$target" ]]; then | ||||||||||||||||||||||
| warn "composer.local.json already exists in $pkg (skipping)" | ||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| step "Setting up $pkg..." | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Merge repositories into composer.json and write to composer.local.json | ||||||||||||||||||||||
| jq --argjson repos "$REPOSITORIES" '. + {repositories: $repos}' "$composer_json" > "$target" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
Comment on lines
+65
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Read the setup script to examine lines 65-67 and surrounding context
wc -l scripts/setup-local-packages.shRepository: host-uk/core-devops Length of output: 98 🏁 Script executed: # View the file around lines 65-67 with context
sed -n '50,80p' scripts/setup-local-packages.sh | cat -nRepository: host-uk/core-devops Length of output: 1106 🏁 Script executed: # Also check what REPOSITORIES variable contains and how it's defined
cat scripts/setup-local-packages.sh | cat -nRepository: host-uk/core-devops Length of output: 4474 Merge path repositories before existing entries instead of replacing them. The current jq command completely overwrites any pre-existing 🛠️ Suggested fix- jq --argjson repos "$REPOSITORIES" '. + {repositories: $repos}' "$composer_json" > "$target"
+ jq --argjson repos "$REPOSITORIES" '.repositories = ($repos + (.repositories // []))' "$composer_json" > "$target"🤖 Prompt for AI Agents |
||||||||||||||||||||||
| # Add to .gitignore if not already there | ||||||||||||||||||||||
| local gitignore="$pkg_dir/.gitignore" | ||||||||||||||||||||||
| if [[ -f "$gitignore" ]]; then | ||||||||||||||||||||||
| if ! grep -q "composer.local.json" "$gitignore"; then | ||||||||||||||||||||||
| echo "composer.local.json" >> "$gitignore" | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
| else | ||||||||||||||||||||||
| echo "composer.local.json" > "$gitignore" | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| info "Created $target" | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Main | ||||||||||||||||||||||
| if [[ -n "$1" ]]; then | ||||||||||||||||||||||
| # Setup specific package | ||||||||||||||||||||||
| setup_package "$1" | ||||||||||||||||||||||
| else | ||||||||||||||||||||||
| # Setup all packages that depend on host-uk/core | ||||||||||||||||||||||
| info "Setting up local package linking for all packages..." | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| for dir in "$PACKAGES_DIR"/*/; do | ||||||||||||||||||||||
| pkg="$(basename "$dir")" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Skip packages that don't need it (core-php has no deps, core-template is a project) | ||||||||||||||||||||||
| if [[ "$pkg" == "core-php" || "$pkg" == "core-template" ]]; then | ||||||||||||||||||||||
| continue | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Check if composer.json exists and has host-uk dependencies | ||||||||||||||||||||||
| if [[ -f "$dir/composer.json" ]]; then | ||||||||||||||||||||||
| if grep -q '"host-uk/' "$dir/composer.json"; then | ||||||||||||||||||||||
| setup_package "$pkg" | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
| done | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| echo "" | ||||||||||||||||||||||
| info "Done! To install dependencies with local packages:" | ||||||||||||||||||||||
| echo "" | ||||||||||||||||||||||
| echo " cd packages/<package>" | ||||||||||||||||||||||
| echo " COMPOSER=composer.local.json composer install" | ||||||||||||||||||||||
| echo "" | ||||||||||||||||||||||
| echo "Or use the dev:packages script if available:" | ||||||||||||||||||||||
| echo "" | ||||||||||||||||||||||
| echo " composer dev:packages" | ||||||||||||||||||||||
| echo "" | ||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
# Find and examine the setup script fd setup-local-packages.shRepository: host-uk/core-devops
Length of output: 94
🏁 Script executed:
Repository: host-uk/core-devops
Length of output: 873
🏁 Script executed:
Repository: host-uk/core-devops
Length of output: 45
🏁 Script executed:
# Read the setup script cat scripts/setup-local-packages.shRepository: host-uk/core-devops
Length of output: 3669
Add a short jq prerequisite note for macOS/Linux.
The setup script requires jq for JSON manipulation, but the Quick Setup section doesn't mention it. Add a brief prerequisite line to prevent users from encountering errors.
📚 Suggested doc tweak
🤖 Prompt for AI Agents