2026-05-02 02:18:19 +05:00
#!/usr/bin/env pwsh
[ CmdletBinding ()]
param (
[ switch ] $Json ,
2026-07-21 18:40:15 +02:00
[ switch ] $Help ,
[ Parameter ( ValueFromRemainingArguments = $true )]
[ string[] ] $RemainingArgs
2026-05-02 02:18:19 +05:00
)
$ErrorActionPreference = 'Stop'
2026-07-21 18:40:15 +02:00
# Help wins over unknown-argument validation to match the Bash/Python
# variants, which stop at --help and exit 0.
2026-05-02 02:18:19 +05:00
if ( $Help ) {
Write-Output "Usage: setup-tasks.ps1 [-Json] [-Help]"
exit 0
}
2026-07-21 18:40:15 +02:00
if ( $RemainingArgs . Count -gt 0 ) {
[ Console ]:: Error . WriteLine ( "ERROR: Unknown option ' $( $RemainingArgs [ 0 ]) '" )
exit 1
}
2026-05-02 02:18:19 +05:00
# Source common functions
. " $PSScriptRoot /common.ps1"
2026-06-09 06:13:07 -05:00
# Get feature paths
2026-07-21 18:40:15 +02:00
$paths = Get-FeaturePathsEnv -ReturnNullOnError
if ( -not $paths ) {
[ Console ]:: Error . WriteLine ( "ERROR: Failed to resolve feature paths" )
exit 1
}
2026-05-02 02:18:19 +05:00
if ( -not ( Test-Path $paths . IMPL_PLAN -PathType Leaf )) {
[ Console ]:: Error . WriteLine ( "ERROR: plan.md not found in $( $paths . FEATURE_DIR ) " )
2026-06-03 23:24:13 +02:00
$planCommand = Format-SpecKitCommand -CommandName 'plan' -RepoRoot $paths . REPO_ROOT
[ Console ]:: Error . WriteLine ( "Run $planCommand first to create the implementation plan." )
2026-05-02 02:18:19 +05:00
exit 1
}
if ( -not ( Test-Path $paths . FEATURE_SPEC -PathType Leaf )) {
[ Console ]:: Error . WriteLine ( "ERROR: spec.md not found in $( $paths . FEATURE_DIR ) " )
2026-06-03 23:24:13 +02:00
$specifyCommand = Format-SpecKitCommand -CommandName 'specify' -RepoRoot $paths . REPO_ROOT
[ Console ]:: Error . WriteLine ( "Run $specifyCommand first to create the feature structure." )
2026-05-02 02:18:19 +05:00
exit 1
}
# Build available docs list
$docs = @ ()
if ( Test-Path $paths . RESEARCH ) { $docs += 'research.md' }
if ( Test-Path $paths . DATA_MODEL ) { $docs += 'data-model.md' }
if (( Test-Path $paths . CONTRACTS_DIR ) -and ( Get-ChildItem -Path $paths . CONTRACTS_DIR -ErrorAction SilentlyContinue | Select-Object -First 1 )) {
$docs += 'contracts/'
}
if ( Test-Path $paths . QUICKSTART ) { $docs += 'quickstart.md' }
# Resolve tasks template through override stack
$tasksTemplate = Resolve-Template -TemplateName 'tasks-template' -RepoRoot $paths . REPO_ROOT
2026-08-10 10:22:31 -05:00
$tasksTemplateContent = Resolve-TemplateContent -TemplateName 'tasks-template' -RepoRoot $paths . REPO_ROOT
if ( $null -eq $tasksTemplateContent ) {
2026-07-21 18:40:15 +02:00
[ Console ]:: Error . WriteLine ( "ERROR: Could not resolve required tasks-template from the template override stack for $( $paths . REPO_ROOT ) " )
[ Console ]:: Error . WriteLine ( "Template 'tasks-template' was not found in any supported location (overrides, presets, extensions, or shared core). Add an override at .specify/templates/overrides/tasks-template.md, or run 'specify init' / reinstall shared infra to restore the core .specify/templates/tasks-template.md template." )
2026-05-02 02:18:19 +05:00
exit 1
}
2026-08-10 10:22:31 -05:00
if ( $tasksTemplate -and ( Test-Path -LiteralPath $tasksTemplate -PathType Leaf )) {
$tasksTemplate = ( Resolve-Path -LiteralPath $tasksTemplate ). Path
} else {
$tasksTemplate = ''
}
2026-05-02 02:18:19 +05:00
# Output results
if ( $Json ) {
[ PSCustomObject ] @ {
FEATURE_DIR = $paths . FEATURE_DIR
AVAILABLE_DOCS = $docs
TASKS_TEMPLATE = $tasksTemplate
2026-08-10 10:22:31 -05:00
TASKS_TEMPLATE_CONTENT = $tasksTemplateContent
2026-05-02 02:18:19 +05:00
} | ConvertTo-Json -Compress
} else {
Write-Output "FEATURE_DIR: $( $paths . FEATURE_DIR ) "
Write-Output "TASKS_TEMPLATE: $( if ( $tasksTemplate ) { $tasksTemplate } else { 'not found' }) "
Write-Output "AVAILABLE_DOCS:"
Test-FileExists -Path $paths . RESEARCH -Description 'research.md' | Out-Null
Test-FileExists -Path $paths . DATA_MODEL -Description 'data-model.md' | Out-Null
Test-DirHasFiles -Path $paths . CONTRACTS_DIR -Description 'contracts/' | Out-Null
Test-FileExists -Path $paths . QUICKSTART -Description 'quickstart.md' | Out-Null
}