summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorYassine Gherbi <y.gherbi.dev@gmail.com>2025-04-23 14:10:28 +0200
committerGitHub <noreply@github.com>2025-04-23 08:10:28 -0400
commitb15392b5f260123e75cf5606b7d507838f1fb77d (patch)
tree1182868092e9ed2af100b0b56f3db1e977c45a94 /scripts
parente646168e31fe01df4ec3c369db60ceac3527a0ed (diff)
downloaddecky-loader-b15392b5f260123e75cf5606b7d507838f1fb77d.tar.gz
decky-loader-b15392b5f260123e75cf5606b7d507838f1fb77d.zip
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>
Diffstat (limited to 'scripts')
-rwxr-xr-x[-rw-r--r--]scripts/deckdebug.sh19
-rwxr-xr-x[-rw-r--r--]scripts/plugin-info.sh0
-rwxr-xr-xscripts/tasks.sh120
3 files changed, 138 insertions, 1 deletions
diff --git a/scripts/deckdebug.sh b/scripts/deckdebug.sh
index c6aa63bf..89d59e18 100644..100755
--- a/scripts/deckdebug.sh
+++ b/scripts/deckdebug.sh
@@ -2,6 +2,13 @@
# Usage: deckdebug.sh DECKIP:8081
# Dependencies: websocat jq curl chromium
+if [ "$#" -ne 1 ]; then
+ echo "Error: Missing or incorrect argument." >&2
+ echo "Usage: deckdebug.sh DECKIP:8081" >&2
+ exit 1
+fi
+
+
# https://jackson.dev/post/a-portable-nix-shell-shebang/
if [ -z "$INSIDE_NIX_RANDOMSTRING" ] && command -v nix &> /dev/null; then
# 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
exit $?
fi
+required_dependencies=(websocat jq curl chromium)
+
+# Check if the dependencies are installed
+for cmd in "${required_dependencies[@]}"; do
+ if ! command -v "$cmd" &> /dev/null; then
+ echo "Error: '$cmd' is not installed. Please install it and try again." >&2
+ exit 1
+ fi
+done
+
chromium --remote-debugging-port=9222 &
sleep 2
@@ -41,4 +58,4 @@ while :; do
fi
sleep 5
-done \ No newline at end of file
+done
diff --git a/scripts/plugin-info.sh b/scripts/plugin-info.sh
index 2a2feadb..2a2feadb 100644..100755
--- a/scripts/plugin-info.sh
+++ b/scripts/plugin-info.sh
diff --git a/scripts/tasks.sh b/scripts/tasks.sh
new file mode 100755
index 00000000..a8c194c1
--- /dev/null
+++ b/scripts/tasks.sh
@@ -0,0 +1,120 @@
+#!/usr/bin/env bash
+# ./script/task.sh: Run a VSCode task from tasks.json including its dependencies.
+#
+# Usage: ./scripts/task.sh TASK_LABEL
+#
+# This script looks for .vscode/tasks.json in your workspace folder (or current directory)
+# and executes the command associated with the given task label.
+#
+# It also handles the "dependsOn" field recursively.
+#
+# Requirements: jq sed
+
+# https://jackson.dev/post/a-portable-nix-shell-shebang/
+if [ -z "$INSIDE_NIX_RANDOMSTRING" ] && command -v nix &> /dev/null; then
+ # If the user has nix, relaunch in nix shell with dependencies added
+ INSIDE_NIX_RANDOMSTRING=1 nix shell \
+ nixpkgs#jq \
+ nixpkgs#gnused \
+ --command "$0" "$@"
+ exit $?
+fi
+
+required_dependencies=(jq sed)
+
+# Check if the dependencies are installed
+for cmd in "${required_dependencies[@]}"; do
+ if ! command -v "$cmd" &> /dev/null; then
+ echo "Error: '$cmd' is not installed. Please install it and try again." >&2
+ exit 1
+ fi
+done
+
+
+set -euo pipefail
+
+# Use WORKSPACE_FOLDER if set; otherwise, assume current directory.
+WORKSPACE_FOLDER="${WORKSPACE_FOLDER:-$(pwd)}"
+TASKS_FILE="$WORKSPACE_FOLDER/.vscode/tasks.json"
+
+if [ ! -f "$TASKS_FILE" ]; then
+ echo "Error: tasks.json not found at $TASKS_FILE" >&2
+ exit 1
+fi
+
+if [ $# -lt 1 ]; then
+ echo "Usage: $0 TASK_LABEL" >&2
+ exit 1
+fi
+
+# Remove comment lines (lines starting with //) from the tasks file to be compliant with the JSON format.
+TASKS_JSON=$(sed '/^[[:space:]]*\/\//d' "$TASKS_FILE")
+
+TASK_LABEL="$1"
+shift
+
+# run_task recursively looks up the task by label,
+# runs any dependencies first, then executes its command.
+run_task() {
+ local label="$1"
+ echo "Looking up task: $label"
+
+ # Get the task object from the cleaned JSON.
+ local task
+ task=$(echo "$TASKS_JSON" | jq --arg label "$label" -r '.tasks[] | select(.label == $label)')
+ if [ -z "$task" ]; then
+ echo "Error: Task with label '$label' not found in $TASKS_FILE" >&2
+ exit 1
+ fi
+
+ # If the task has dependencies, run them first.
+ local depends
+ depends=$(echo "$task" | jq -r '.dependsOn? // empty')
+ if [ -n "$depends" ] && [ "$depends" != "null" ]; then
+ # "dependsOn" can be an array or a string.
+ if echo "$depends" | jq -e 'if type=="array" then . else empty end' >/dev/null; then
+ for dep in $(echo "$depends" | jq -r '.[]'); do
+ run_task "$dep"
+ done
+ else
+ run_task "$depends"
+ fi
+ fi
+
+ # Check if the task has either a command or script.
+ local has_command has_script
+ has_command=$(echo "$task" | jq -r 'has("command")')
+ has_script=$(echo "$task" | jq -r 'has("script")')
+ if [[ "$has_command" != "true" && "$has_script" != "true" ]]; then
+ echo "Task '$label' has no command or script; skipping execution."
+ return
+ fi
+
+ # Determine the command to run:
+ local cmd=""
+ if echo "$task" | jq 'has("command")' | grep -q "true"; then
+ cmd=$(echo "$task" | jq -r '.command')
+ elif echo "$task" | jq 'has("script")' | grep -q "true"; then
+ local script
+ script=$(echo "$task" | jq -r '.script')
+ local path
+ path=$(echo "$task" | jq -r '.path // empty')
+ if [ -n "$path" ]; then
+ cmd="cd $path && npm run $script"
+ else
+ cmd="npm run $script"
+ fi
+ else
+ echo "Error: Task '$label' does not have a command or script." >&2
+ exit 1
+ fi
+
+ # Substitute ${workspaceFolder} with the actual folder path.
+ cmd="${cmd//\$\{workspaceFolder\}/$WORKSPACE_FOLDER}"
+
+ echo "Running task '$label': $cmd"
+ # Run the task in a subshell so that directory changes don't persist.
+ ( eval "$cmd" )
+}
+
+run_task "$TASK_LABEL"