setup-plan.ps1 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. # Ensure the feature directory exists
  21. New-Item -ItemType Directory -Path $paths.FEATURE_DIR -Force | Out-Null
  22. # Copy plan template if plan doesn't already exist
  23. if (Test-Path $paths.IMPL_PLAN -PathType Leaf) {
  24. if ($Json) {
  25. [Console]::Error.WriteLine("Plan already exists at $($paths.IMPL_PLAN), skipping template copy")
  26. } else {
  27. Write-Output "Plan already exists at $($paths.IMPL_PLAN), skipping template copy"
  28. }
  29. } else {
  30. $template = Resolve-Template -TemplateName 'plan-template' -RepoRoot $paths.REPO_ROOT
  31. if ($template -and (Test-Path $template)) {
  32. # Read the template content and write it to the implementation plan file with UTF-8 encoding without BOM
  33. $content = [System.IO.File]::ReadAllText($template)
  34. $utf8NoBom = New-Object System.Text.UTF8Encoding($false)
  35. [System.IO.File]::WriteAllText($paths.IMPL_PLAN, $content, $utf8NoBom)
  36. } else {
  37. Write-Warning "Plan template not found"
  38. # Create a basic plan file if template doesn't exist
  39. New-Item -ItemType File -Path $paths.IMPL_PLAN -Force | Out-Null
  40. }
  41. }
  42. # Output results
  43. if ($Json) {
  44. $result = [PSCustomObject]@{
  45. FEATURE_SPEC = $paths.FEATURE_SPEC
  46. IMPL_PLAN = $paths.IMPL_PLAN
  47. SPECS_DIR = $paths.FEATURE_DIR
  48. BRANCH = $paths.CURRENT_BRANCH
  49. }
  50. $result | ConvertTo-Json -Compress
  51. } else {
  52. Write-Output "FEATURE_SPEC: $($paths.FEATURE_SPEC)"
  53. Write-Output "IMPL_PLAN: $($paths.IMPL_PLAN)"
  54. Write-Output "SPECS_DIR: $($paths.FEATURE_DIR)"
  55. Write-Output "BRANCH: $($paths.CURRENT_BRANCH)"
  56. }