setup-tasks.ps1 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env pwsh
  2. [CmdletBinding()]
  3. param(
  4. [switch]$Json,
  5. [switch]$Help
  6. )
  7. $ErrorActionPreference = 'Stop'
  8. if ($Help) {
  9. Write-Output "Usage: setup-tasks.ps1 [-Json] [-Help]"
  10. exit 0
  11. }
  12. # Source common functions
  13. . "$PSScriptRoot/common.ps1"
  14. # Get feature paths and validate branch
  15. $paths = Get-FeaturePathsEnv
  16. # If feature.json pins an existing feature directory, branch naming is not required.
  17. if (-not (Test-FeatureJsonMatchesFeatureDir -RepoRoot $paths.REPO_ROOT -ActiveFeatureDir $paths.FEATURE_DIR)) {
  18. if (-not (Test-FeatureBranch -Branch $paths.CURRENT_BRANCH -HasGit $paths.HAS_GIT)) {
  19. exit 1
  20. }
  21. }
  22. if (-not (Test-Path $paths.IMPL_PLAN -PathType Leaf)) {
  23. [Console]::Error.WriteLine("ERROR: plan.md not found in $($paths.FEATURE_DIR)")
  24. [Console]::Error.WriteLine("Run /speckit.plan first to create the implementation plan.")
  25. exit 1
  26. }
  27. if (-not (Test-Path $paths.FEATURE_SPEC -PathType Leaf)) {
  28. [Console]::Error.WriteLine("ERROR: spec.md not found in $($paths.FEATURE_DIR)")
  29. [Console]::Error.WriteLine("Run /speckit.specify first to create the feature structure.")
  30. exit 1
  31. }
  32. # Build available docs list
  33. $docs = @()
  34. if (Test-Path $paths.RESEARCH) { $docs += 'research.md' }
  35. if (Test-Path $paths.DATA_MODEL) { $docs += 'data-model.md' }
  36. if ((Test-Path $paths.CONTRACTS_DIR) -and (Get-ChildItem -Path $paths.CONTRACTS_DIR -ErrorAction SilentlyContinue | Select-Object -First 1)) {
  37. $docs += 'contracts/'
  38. }
  39. if (Test-Path $paths.QUICKSTART) { $docs += 'quickstart.md' }
  40. # Resolve tasks template through override stack
  41. $tasksTemplate = Resolve-Template -TemplateName 'tasks-template' -RepoRoot $paths.REPO_ROOT
  42. if (-not $tasksTemplate -or -not (Test-Path -LiteralPath $tasksTemplate -PathType Leaf)) {
  43. $expectedCoreTemplate = Join-Path $paths.REPO_ROOT '.specify/templates/tasks-template.md'
  44. [Console]::Error.WriteLine("ERROR: Tasks template not found for repository root: $($paths.REPO_ROOT)`nTemplate resolution order: overrides -> presets -> extensions -> core.`nExpected shared/core template location: $expectedCoreTemplate`nTo continue, verify whether 'tasks-template.md' is available in '.specify/templates/overrides/', preset templates, extension templates, or restore the shared/core templates (for example by re-running 'specify init') so that '.specify/templates/tasks-template.md' exists.")
  45. exit 1
  46. }
  47. $tasksTemplate = (Resolve-Path -LiteralPath $tasksTemplate).Path
  48. # Output results
  49. if ($Json) {
  50. [PSCustomObject]@{
  51. FEATURE_DIR = $paths.FEATURE_DIR
  52. AVAILABLE_DOCS = $docs
  53. TASKS_TEMPLATE = $tasksTemplate
  54. } | ConvertTo-Json -Compress
  55. } else {
  56. Write-Output "FEATURE_DIR: $($paths.FEATURE_DIR)"
  57. Write-Output "TASKS_TEMPLATE: $(if ($tasksTemplate) { $tasksTemplate } else { 'not found' })"
  58. Write-Output "AVAILABLE_DOCS:"
  59. Test-FileExists -Path $paths.RESEARCH -Description 'research.md' | Out-Null
  60. Test-FileExists -Path $paths.DATA_MODEL -Description 'data-model.md' | Out-Null
  61. Test-DirHasFiles -Path $paths.CONTRACTS_DIR -Description 'contracts/' | Out-Null
  62. Test-FileExists -Path $paths.QUICKSTART -Description 'quickstart.md' | Out-Null
  63. }