diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 125c21b..94de165 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,4 +30,4 @@ jobs: - name: plugin-test uses: asdf-vm/actions/plugin-test@v2 with: - command: node_modules/.bin/markdownlint-cli2 _version + command: markdownlint-cli2 _version diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3a14953..73805e6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -70,7 +70,7 @@ Also, for testing locally use: # it from failing while trying to lint an inexisting file, while allowing it to self-test # Replace with your GitHub user name # Replace with the branch you pushed -asdf plugin test markdownlint-cli2 https://github.com//asdf-markdownlint-cli2.git "node_modules/.bin/markdownlint-cli2 _version" --asdf-plugin-gitref +asdf plugin test markdownlint-cli2 https://github.com//asdf-markdownlint-cli2.git "markdownlint-cli2 _version" --asdf-plugin-gitref ``` diff --git a/lib/utils.bash b/lib/utils.bash index 06b3eaf..4b1b610 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -4,7 +4,7 @@ set -euo pipefail GH_REPO="https://github.com/DavidAnson/markdownlint-cli2" TOOL_NAME="markdownlint-cli2" -BASE_TOOL="node_modules/.bin/markdownlint-cli2" +BASE_TOOL="markdownlint-cli2" TOOL_TEST="$BASE_TOOL _version" fail() { @@ -33,12 +33,32 @@ list_all_versions() { list_github_tags } +ensure() { + local check=$1 + local msg=$2 + local res + + eval "$check" >/dev/null + res=$? + [ "$res" == "0" ] || fail "$msg (${check} == $res)" +} + +ensure_node() { + ensure "which node" "it appears node is not available" +} + +ensure_npm() { + ensure "which npm" "it appears npm is not available" +} + download_release() { local version destination version="$1" destination="$2" printf "* Downloading %s release %s...\n" "$TOOL_NAME" "$version" + ensure_node + ensure_npm npm pack --silent "${TOOL_NAME}@${version}" --pack-destination "$destination" >/dev/null } @@ -52,14 +72,19 @@ install_version() { fi ( - mkdir -p "$install_path" - cd "$install_path" + mkdir -p "$install_path/bin" cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path" - npm --silent install markdownlint-cli2 --save-dev >/dev/null + ensure_node + ensure_npm + npm --silent install --prefix "$install_path" markdownlint-cli2 --save-dev >/dev/null local tool_cmd - tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)" + tool_cmd="bin/$(echo "$TOOL_TEST" | cut -d' ' -f1)" + + ln -s "$install_path/node_modules/.bin/$BASE_TOOL" "$install_path/$tool_cmd" + chmod +x "$install_path/$tool_cmd" + test -x "$install_path/$tool_cmd" || fail "Expected $install_path/$tool_cmd to be executable." echo "$TOOL_NAME $version installation was successful!"