From 49d68da6639724f7d58939220e9cac1a7264360b Mon Sep 17 00:00:00 2001 From: Yassine Gherbi Date: Thu, 3 Apr 2025 12:44:44 +0200 Subject: [PATCH 01/10] feat: add dependency checks in deckdebug.sh --- scripts/deckdebug.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) mode change 100644 => 100755 scripts/deckdebug.sh diff --git a/scripts/deckdebug.sh b/scripts/deckdebug.sh old mode 100644 new mode 100755 index c6aa63bf..b571543f --- a/scripts/deckdebug.sh +++ b/scripts/deckdebug.sh @@ -2,6 +2,16 @@ # Usage: deckdebug.sh DECKIP:8081 # Dependencies: websocat jq curl chromium +required_dependencies=(lalala 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 + # 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 @@ -41,4 +51,4 @@ while :; do fi sleep 5 -done \ No newline at end of file +done From fcb1f2610045671ac330975d3878bd154a417063 Mon Sep 17 00:00:00 2001 From: Yassine Gherbi Date: Thu, 3 Apr 2025 12:45:39 +0200 Subject: [PATCH 02/10] feat: add argument validation to deckdebug.sh --- scripts/deckdebug.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/deckdebug.sh b/scripts/deckdebug.sh index b571543f..715017f6 100755 --- a/scripts/deckdebug.sh +++ b/scripts/deckdebug.sh @@ -2,6 +2,12 @@ # 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 + required_dependencies=(lalala websocat jq curl chromium) # Check if the dependencies are installed From 1a02354430d53938d508ebb783fd4e29e9ead4c7 Mon Sep 17 00:00:00 2001 From: Yassine Gherbi Date: Thu, 3 Apr 2025 12:46:11 +0200 Subject: [PATCH 03/10] feat: remove unnecessary (testing) dependency from deckdebug.sh --- scripts/deckdebug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/deckdebug.sh b/scripts/deckdebug.sh index 715017f6..c3c4e083 100755 --- a/scripts/deckdebug.sh +++ b/scripts/deckdebug.sh @@ -8,7 +8,7 @@ if [ "$#" -ne 1 ]; then exit 1 fi -required_dependencies=(lalala websocat jq curl chromium) +required_dependencies=(websocat jq curl chromium) # Check if the dependencies are installed for cmd in "${required_dependencies[@]}"; do From ac784375f447d1e0b3e498e5a03518e71d1b44a0 Mon Sep 17 00:00:00 2001 From: Yassine Gherbi Date: Thu, 3 Apr 2025 12:52:39 +0200 Subject: [PATCH 04/10] . --- scripts/plugin-info.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/plugin-info.sh diff --git a/scripts/plugin-info.sh b/scripts/plugin-info.sh old mode 100644 new mode 100755 From 51f9573a858efe68e25bb4745cde57bd4ff138dc Mon Sep 17 00:00:00 2001 From: Yassine Gherbi Date: Thu, 3 Apr 2025 13:25:19 +0200 Subject: [PATCH 05/10] feat: add script to run VSCode tasks with dependency handling --- scripts/tasks.sh | 110 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100755 scripts/tasks.sh diff --git a/scripts/tasks.sh b/scripts/tasks.sh new file mode 100755 index 00000000..deca3de0 --- /dev/null +++ b/scripts/tasks.sh @@ -0,0 +1,110 @@ +#!/usr/bin/env bash +# run_task.sh: Run a VSCode task from tasks.json including its dependencies. +# +# Usage: run_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 + +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" From 7de9d5179822bf951ea15efff3a9f6d2ec1d55a5 Mon Sep 17 00:00:00 2001 From: Yassine Gherbi Date: Thu, 3 Apr 2025 13:29:06 +0200 Subject: [PATCH 06/10] fix: update script usage instructions in tasks.sh --- scripts/tasks.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/tasks.sh b/scripts/tasks.sh index deca3de0..195e678d 100755 --- a/scripts/tasks.sh +++ b/scripts/tasks.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -# run_task.sh: Run a VSCode task from tasks.json including its dependencies. +# ./script/task.sh: Run a VSCode task from tasks.json including its dependencies. # -# Usage: run_task.sh TASK_LABEL +# Usage: ./script/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. From 3df501070b5893d005f67e8ffc56ac25fb936604 Mon Sep 17 00:00:00 2001 From: Yassine Gherbi Date: Thu, 3 Apr 2025 13:59:27 +0200 Subject: [PATCH 07/10] fix: dependency check after checking for nix --- scripts/deckdebug.sh | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/scripts/deckdebug.sh b/scripts/deckdebug.sh index c3c4e083..89d59e18 100755 --- a/scripts/deckdebug.sh +++ b/scripts/deckdebug.sh @@ -8,15 +8,6 @@ if [ "$#" -ne 1 ]; then exit 1 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 # https://jackson.dev/post/a-portable-nix-shell-shebang/ if [ -z "$INSIDE_NIX_RANDOMSTRING" ] && command -v nix &> /dev/null; then @@ -29,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 From d22612c207b1f0996f2a1dbc4bd7ad392b12e49c Mon Sep 17 00:00:00 2001 From: Yassine Gherbi Date: Thu, 3 Apr 2025 14:00:35 +0200 Subject: [PATCH 08/10] feat: add nix shell support in tasks.sh --- scripts/tasks.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/tasks.sh b/scripts/tasks.sh index 195e678d..9e8f3091 100755 --- a/scripts/tasks.sh +++ b/scripts/tasks.sh @@ -10,6 +10,17 @@ # # 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#websocat \ + nixpkgs#jq \ + nixpkgs#curl \ + --command "$0" "$@" + exit $? +fi + required_dependencies=(jq sed) # Check if the dependencies are installed From 885414ad98ef8d2ca0848102ee08bd95767bd101 Mon Sep 17 00:00:00 2001 From: Yassine Gherbi Date: Thu, 17 Apr 2025 17:55:54 +0200 Subject: [PATCH 09/10] fix: match the dependencies Resolve: https://github.com/SteamDeckHomebrew/decky-loader/pull/763/files/d22612c207b1f0996f2a1dbc4bd7ad392b12e49c#r2039722788 --- scripts/tasks.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/tasks.sh b/scripts/tasks.sh index 9e8f3091..a6d09953 100755 --- a/scripts/tasks.sh +++ b/scripts/tasks.sh @@ -14,9 +14,8 @@ 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#websocat \ nixpkgs#jq \ - nixpkgs#curl \ + nixpkgs#gnused \ --command "$0" "$@" exit $? fi From f69794791481cce785bebc2b1a0c592bc663d59d Mon Sep 17 00:00:00 2001 From: AAGaming Date: Wed, 23 Apr 2025 08:07:15 -0400 Subject: [PATCH 10/10] fix incorrect path in usage --- scripts/tasks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tasks.sh b/scripts/tasks.sh index a6d09953..a8c194c1 100755 --- a/scripts/tasks.sh +++ b/scripts/tasks.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # ./script/task.sh: Run a VSCode task from tasks.json including its dependencies. # -# Usage: ./script/task.sh TASK_LABEL +# 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.