Skip to content

Commit b15392b

Browse files
feat: VSCode Tasks Runner and deckdebug.sh Enhancements (#763)
* feat: add dependency checks in deckdebug.sh * feat: add argument validation to deckdebug.sh * feat: remove unnecessary (testing) dependency from deckdebug.sh * . * feat: add script to run VSCode tasks with dependency handling * fix: update script usage instructions in tasks.sh * fix: dependency check after checking for nix * feat: add nix shell support in tasks.sh * fix: match the dependencies Resolve: https://github.com/SteamDeckHomebrew/decky-loader/pull/763/files/d22612c207b1f0996f2a1dbc4bd7ad392b12e49c#r2039722788 * fix incorrect path in usage --------- Co-authored-by: AAGaming <aagaming00@protonmail.com>
1 parent e646168 commit b15392b

File tree

3 files changed

+138
-1
lines changed

3 files changed

+138
-1
lines changed

scripts/deckdebug.sh

100644100755
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
# Usage: deckdebug.sh DECKIP:8081
33
# Dependencies: websocat jq curl chromium
44

5+
if [ "$#" -ne 1 ]; then
6+
echo "Error: Missing or incorrect argument." >&2
7+
echo "Usage: deckdebug.sh DECKIP:8081" >&2
8+
exit 1
9+
fi
10+
11+
512
# https://jackson.dev/post/a-portable-nix-shell-shebang/
613
if [ -z "$INSIDE_NIX_RANDOMSTRING" ] && command -v nix &> /dev/null; then
714
# If the user has nix, relaunch in nix shell with dependencies added
@@ -13,6 +20,16 @@ if [ -z "$INSIDE_NIX_RANDOMSTRING" ] && command -v nix &> /dev/null; then
1320
exit $?
1421
fi
1522

23+
required_dependencies=(websocat jq curl chromium)
24+
25+
# Check if the dependencies are installed
26+
for cmd in "${required_dependencies[@]}"; do
27+
if ! command -v "$cmd" &> /dev/null; then
28+
echo "Error: '$cmd' is not installed. Please install it and try again." >&2
29+
exit 1
30+
fi
31+
done
32+
1633
chromium --remote-debugging-port=9222 &
1734
sleep 2
1835

@@ -41,4 +58,4 @@ while :; do
4158
fi
4259

4360
sleep 5
44-
done
61+
done

scripts/plugin-info.sh

100644100755
File mode changed.

scripts/tasks.sh

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/usr/bin/env bash
2+
# ./script/task.sh: Run a VSCode task from tasks.json including its dependencies.
3+
#
4+
# Usage: ./scripts/task.sh TASK_LABEL
5+
#
6+
# This script looks for .vscode/tasks.json in your workspace folder (or current directory)
7+
# and executes the command associated with the given task label.
8+
#
9+
# It also handles the "dependsOn" field recursively.
10+
#
11+
# Requirements: jq sed
12+
13+
# https://jackson.dev/post/a-portable-nix-shell-shebang/
14+
if [ -z "$INSIDE_NIX_RANDOMSTRING" ] && command -v nix &> /dev/null; then
15+
# If the user has nix, relaunch in nix shell with dependencies added
16+
INSIDE_NIX_RANDOMSTRING=1 nix shell \
17+
nixpkgs#jq \
18+
nixpkgs#gnused \
19+
--command "$0" "$@"
20+
exit $?
21+
fi
22+
23+
required_dependencies=(jq sed)
24+
25+
# Check if the dependencies are installed
26+
for cmd in "${required_dependencies[@]}"; do
27+
if ! command -v "$cmd" &> /dev/null; then
28+
echo "Error: '$cmd' is not installed. Please install it and try again." >&2
29+
exit 1
30+
fi
31+
done
32+
33+
34+
set -euo pipefail
35+
36+
# Use WORKSPACE_FOLDER if set; otherwise, assume current directory.
37+
WORKSPACE_FOLDER="${WORKSPACE_FOLDER:-$(pwd)}"
38+
TASKS_FILE="$WORKSPACE_FOLDER/.vscode/tasks.json"
39+
40+
if [ ! -f "$TASKS_FILE" ]; then
41+
echo "Error: tasks.json not found at $TASKS_FILE" >&2
42+
exit 1
43+
fi
44+
45+
if [ $# -lt 1 ]; then
46+
echo "Usage: $0 TASK_LABEL" >&2
47+
exit 1
48+
fi
49+
50+
# Remove comment lines (lines starting with //) from the tasks file to be compliant with the JSON format.
51+
TASKS_JSON=$(sed '/^[[:space:]]*\/\//d' "$TASKS_FILE")
52+
53+
TASK_LABEL="$1"
54+
shift
55+
56+
# run_task recursively looks up the task by label,
57+
# runs any dependencies first, then executes its command.
58+
run_task() {
59+
local label="$1"
60+
echo "Looking up task: $label"
61+
62+
# Get the task object from the cleaned JSON.
63+
local task
64+
task=$(echo "$TASKS_JSON" | jq --arg label "$label" -r '.tasks[] | select(.label == $label)')
65+
if [ -z "$task" ]; then
66+
echo "Error: Task with label '$label' not found in $TASKS_FILE" >&2
67+
exit 1
68+
fi
69+
70+
# If the task has dependencies, run them first.
71+
local depends
72+
depends=$(echo "$task" | jq -r '.dependsOn? // empty')
73+
if [ -n "$depends" ] && [ "$depends" != "null" ]; then
74+
# "dependsOn" can be an array or a string.
75+
if echo "$depends" | jq -e 'if type=="array" then . else empty end' >/dev/null; then
76+
for dep in $(echo "$depends" | jq -r '.[]'); do
77+
run_task "$dep"
78+
done
79+
else
80+
run_task "$depends"
81+
fi
82+
fi
83+
84+
# Check if the task has either a command or script.
85+
local has_command has_script
86+
has_command=$(echo "$task" | jq -r 'has("command")')
87+
has_script=$(echo "$task" | jq -r 'has("script")')
88+
if [[ "$has_command" != "true" && "$has_script" != "true" ]]; then
89+
echo "Task '$label' has no command or script; skipping execution."
90+
return
91+
fi
92+
93+
# Determine the command to run:
94+
local cmd=""
95+
if echo "$task" | jq 'has("command")' | grep -q "true"; then
96+
cmd=$(echo "$task" | jq -r '.command')
97+
elif echo "$task" | jq 'has("script")' | grep -q "true"; then
98+
local script
99+
script=$(echo "$task" | jq -r '.script')
100+
local path
101+
path=$(echo "$task" | jq -r '.path // empty')
102+
if [ -n "$path" ]; then
103+
cmd="cd $path && npm run $script"
104+
else
105+
cmd="npm run $script"
106+
fi
107+
else
108+
echo "Error: Task '$label' does not have a command or script." >&2
109+
exit 1
110+
fi
111+
112+
# Substitute ${workspaceFolder} with the actual folder path.
113+
cmd="${cmd//\$\{workspaceFolder\}/$WORKSPACE_FOLDER}"
114+
115+
echo "Running task '$label': $cmd"
116+
# Run the task in a subshell so that directory changes don't persist.
117+
( eval "$cmd" )
118+
}
119+
120+
run_task "$TASK_LABEL"

0 commit comments

Comments
 (0)