check-prerequisites.ps1 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/usr/bin/env pwsh
  2. # Consolidated prerequisite checking script (PowerShell)
  3. #
  4. # This script provides unified prerequisite checking for Spec-Driven Development workflow.
  5. # It replaces the functionality previously spread across multiple scripts.
  6. #
  7. # Usage: ./check-prerequisites.ps1 [OPTIONS]
  8. #
  9. # OPTIONS:
  10. # -Json Output in JSON format
  11. # -RequireTasks Require tasks.md to exist (for implementation phase)
  12. # -IncludeTasks Include tasks.md in AVAILABLE_DOCS list
  13. # -PathsOnly Only output path variables (no validation)
  14. # -Help, -h Show help message
  15. [CmdletBinding()]
  16. param(
  17. [switch]$Json,
  18. [switch]$RequireTasks,
  19. [switch]$IncludeTasks,
  20. [switch]$PathsOnly,
  21. [switch]$Help
  22. )
  23. $ErrorActionPreference = 'Stop'
  24. # Show help if requested
  25. if ($Help) {
  26. Write-Output @"
  27. Usage: check-prerequisites.ps1 [OPTIONS]
  28. Consolidated prerequisite checking for Spec-Driven Development workflow.
  29. OPTIONS:
  30. -Json Output in JSON format
  31. -RequireTasks Require tasks.md to exist (for implementation phase)
  32. -IncludeTasks Include tasks.md in AVAILABLE_DOCS list
  33. -PathsOnly Only output path variables (no prerequisite validation)
  34. -Help, -h Show this help message
  35. EXAMPLES:
  36. # Check task prerequisites (plan.md required)
  37. .\check-prerequisites.ps1 -Json
  38. # Check implementation prerequisites (plan.md + tasks.md required)
  39. .\check-prerequisites.ps1 -Json -RequireTasks -IncludeTasks
  40. # Get feature paths only (no validation)
  41. .\check-prerequisites.ps1 -PathsOnly
  42. "@
  43. exit 0
  44. }
  45. # Source common functions
  46. . "$PSScriptRoot/common.ps1"
  47. # Get feature paths
  48. $paths = Get-FeaturePathsEnv
  49. # If paths-only mode, output paths and exit (no validation)
  50. if ($PathsOnly) {
  51. if ($Json) {
  52. [PSCustomObject]@{
  53. REPO_ROOT = $paths.REPO_ROOT
  54. BRANCH = $paths.CURRENT_BRANCH
  55. FEATURE_DIR = $paths.FEATURE_DIR
  56. FEATURE_SPEC = $paths.FEATURE_SPEC
  57. IMPL_PLAN = $paths.IMPL_PLAN
  58. TASKS = $paths.TASKS
  59. } | ConvertTo-Json -Compress
  60. } else {
  61. Write-Output "REPO_ROOT: $($paths.REPO_ROOT)"
  62. Write-Output "BRANCH: $($paths.CURRENT_BRANCH)"
  63. Write-Output "FEATURE_DIR: $($paths.FEATURE_DIR)"
  64. Write-Output "FEATURE_SPEC: $($paths.FEATURE_SPEC)"
  65. Write-Output "IMPL_PLAN: $($paths.IMPL_PLAN)"
  66. Write-Output "TASKS: $($paths.TASKS)"
  67. }
  68. exit 0
  69. }
  70. # Validate required directories and files
  71. if (-not (Test-Path $paths.FEATURE_DIR -PathType Container)) {
  72. Write-Output "ERROR: Feature directory not found: $($paths.FEATURE_DIR)"
  73. $specifyCommand = '/speckit-specify'
  74. Write-Output "Run $specifyCommand first to create the feature structure."
  75. exit 1
  76. }
  77. if (-not (Test-Path $paths.IMPL_PLAN -PathType Leaf)) {
  78. Write-Output "ERROR: plan.md not found in $($paths.FEATURE_DIR)"
  79. $planCommand = '/speckit-plan'
  80. Write-Output "Run $planCommand first to create the implementation plan."
  81. exit 1
  82. }
  83. # Check for tasks.md if required
  84. if ($RequireTasks -and -not (Test-Path $paths.TASKS -PathType Leaf)) {
  85. Write-Output "ERROR: tasks.md not found in $($paths.FEATURE_DIR)"
  86. $tasksCommand = '/speckit-tasks'
  87. Write-Output "Run $tasksCommand first to create the task list."
  88. exit 1
  89. }
  90. # Build list of available documents
  91. $docs = @()
  92. # Always check these optional docs
  93. if (Test-Path $paths.RESEARCH) { $docs += 'research.md' }
  94. if (Test-Path $paths.DATA_MODEL) { $docs += 'data-model.md' }
  95. # Check contracts directory (only if it exists and has files)
  96. if ((Test-Path $paths.CONTRACTS_DIR) -and (Get-ChildItem -Path $paths.CONTRACTS_DIR -ErrorAction SilentlyContinue | Select-Object -First 1)) {
  97. $docs += 'contracts/'
  98. }
  99. if (Test-Path $paths.QUICKSTART) { $docs += 'quickstart.md' }
  100. # Include tasks.md if requested and it exists
  101. if ($IncludeTasks -and (Test-Path $paths.TASKS)) {
  102. $docs += 'tasks.md'
  103. }
  104. # Output results
  105. if ($Json) {
  106. # JSON output
  107. [PSCustomObject]@{
  108. FEATURE_DIR = $paths.FEATURE_DIR
  109. AVAILABLE_DOCS = $docs
  110. } | ConvertTo-Json -Compress
  111. } else {
  112. # Text output
  113. Write-Output "FEATURE_DIR:$($paths.FEATURE_DIR)"
  114. Write-Output "AVAILABLE_DOCS:"
  115. # Show status of each potential document
  116. Test-FileExists -Path $paths.RESEARCH -Description 'research.md' | Out-Null
  117. Test-FileExists -Path $paths.DATA_MODEL -Description 'data-model.md' | Out-Null
  118. Test-DirHasFiles -Path $paths.CONTRACTS_DIR -Description 'contracts/' | Out-Null
  119. Test-FileExists -Path $paths.QUICKSTART -Description 'quickstart.md' | Out-Null
  120. if ($IncludeTasks) {
  121. Test-FileExists -Path $paths.TASKS -Description 'tasks.md' | Out-Null
  122. }
  123. }