setup-plan.ps1 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env pwsh
  2. # Setup implementation plan for a feature
  3. [CmdletBinding()]
  4. param(
  5. [switch]$Json,
  6. [switch]$Help
  7. )
  8. $ErrorActionPreference = 'Stop'
  9. # Show help if requested
  10. if ($Help) {
  11. Write-Output "Usage: ./setup-plan.ps1 [-Json] [-Help]"
  12. Write-Output " -Json Output results in JSON format"
  13. Write-Output " -Help Show this help message"
  14. exit 0
  15. }
  16. # Load common functions
  17. . "$PSScriptRoot/common.ps1"
  18. # Get all paths and variables from common functions
  19. $paths = Get-FeaturePathsEnv
  20. # If feature.json pins an existing feature directory, branch naming is not required.
  21. if (-not (Test-FeatureJsonMatchesFeatureDir -RepoRoot $paths.REPO_ROOT -ActiveFeatureDir $paths.FEATURE_DIR)) {
  22. if (-not (Test-FeatureBranch -Branch $paths.CURRENT_BRANCH -HasGit $paths.HAS_GIT)) {
  23. exit 1
  24. }
  25. }
  26. # Ensure the feature directory exists
  27. New-Item -ItemType Directory -Path $paths.FEATURE_DIR -Force | Out-Null
  28. # Copy plan template if it exists, otherwise note it or create empty file
  29. $template = Resolve-Template -TemplateName 'plan-template' -RepoRoot $paths.REPO_ROOT
  30. if ($template -and (Test-Path $template)) {
  31. # Read the template content and write it to the implementation plan file with UTF-8 encoding without BOM
  32. $content = [System.IO.File]::ReadAllText($template)
  33. $utf8NoBom = New-Object System.Text.UTF8Encoding($false)
  34. [System.IO.File]::WriteAllText($paths.IMPL_PLAN, $content, $utf8NoBom)
  35. } else {
  36. Write-Warning "Plan template not found"
  37. # Create a basic plan file if template doesn't exist
  38. New-Item -ItemType File -Path $paths.IMPL_PLAN -Force | Out-Null
  39. }
  40. # Output results
  41. if ($Json) {
  42. $result = [PSCustomObject]@{
  43. FEATURE_SPEC = $paths.FEATURE_SPEC
  44. IMPL_PLAN = $paths.IMPL_PLAN
  45. SPECS_DIR = $paths.FEATURE_DIR
  46. BRANCH = $paths.CURRENT_BRANCH
  47. HAS_GIT = $paths.HAS_GIT
  48. }
  49. $result | ConvertTo-Json -Compress
  50. } else {
  51. Write-Output "FEATURE_SPEC: $($paths.FEATURE_SPEC)"
  52. Write-Output "IMPL_PLAN: $($paths.IMPL_PLAN)"
  53. Write-Output "SPECS_DIR: $($paths.FEATURE_DIR)"
  54. Write-Output "BRANCH: $($paths.CURRENT_BRANCH)"
  55. Write-Output "HAS_GIT: $($paths.HAS_GIT)"
  56. }