Skip to content

Commit ffaed31

Browse files
committed
refactor(hooks): extract hook extension logic into a separate function
#345 (comment)
1 parent 8b8788a commit ffaed31

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

.github/workflows/scripts/create-release-packages.sh

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ rewrite_paths() {
3838
-e 's@(/?)hooks/@.specify/hooks/@g'
3939
}
4040

41+
get_hook_extension() {
42+
local script_variant=$1
43+
if [[ "$script_variant" == "ps" ]]; then
44+
echo ".ps1"
45+
else
46+
echo ""
47+
fi
48+
}
49+
4150
generate_commands() {
4251
local agent=$1 ext=$2 arg_format=$3 output_dir=$4 script_variant=$5
4352
mkdir -p "$output_dir"
@@ -58,11 +67,8 @@ generate_commands() {
5867
script_command="(Missing script command for $script_variant)"
5968
fi
6069

61-
# Replace {SCRIPT} placeholder with the script command and {EXT} with extension
62-
local ext=""
63-
if [[ "$script_variant" == "ps" ]]; then
64-
ext=".ps1"
65-
fi
70+
# Replace {SCRIPT} placeholder with the script command and {HOOK_EXT} with extension
71+
local ext=$(get_hook_extension "$script_variant")
6672
body=$(printf '%s\n' "$file_content" | sed "s|{SCRIPT}|${script_command}|g" | sed "s|{HOOK_EXT}|${ext}|g")
6773

6874
# Remove the scripts: section from frontmatter while preserving YAML structure
@@ -146,11 +152,8 @@ build_variant() {
146152
if [[ -n $script_command ]]; then
147153
# Always prefix with .specify/ for plan usage
148154
script_command=".specify/$script_command"
149-
# Replace {SCRIPT} placeholder with the script command, {EXT} with extension, and __AGENT__ with agent name
150-
local ext=""
151-
if [[ "$script" == "ps" ]]; then
152-
ext=".ps1"
153-
fi
155+
# Replace {SCRIPT} placeholder with the script command, {HOOK_EXT} with extension, and __AGENT__ with agent name
156+
local ext=$(get_hook_extension "$script")
154157
substituted=$(sed "s|{SCRIPT}|${script_command}|g" "$plan_tpl" | tr -d '\r' | sed "s|__AGENT__|${agent}|g" | sed "s|{HOOK_EXT}|${ext}|g")
155158
# Strip YAML frontmatter from plan template output (keep body only)
156159
stripped=$(printf '%s\n' "$substituted" | awk 'BEGIN{fm=0;dash=0} /^---$/ {dash++; if(dash==1){fm=1; next} else if(dash==2){fm=0; next}} {if(!fm) print}')

0 commit comments

Comments
 (0)