Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jrf0110 committed May 6, 2023
1 parent be40273 commit 5f74382
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# asdf-dart-sass-embedded [![Build](https://github.com/jrf0110/asdf-dart-sass-embedded/actions/workflows/build.yml/badge.svg)](https://github.com/jrf0110/asdf-dart-sass-embedded/actions/workflows/build.yml) [![Lint](https://github.com/jrf0110/asdf-dart-sass-embedded/actions/workflows/lint.yml/badge.svg)](https://github.com/jrf0110/asdf-dart-sass-embedded/actions/workflows/lint.yml)


[dart-sass-embedded](https://github.com/jrf0110/dart-sass-embedded) plugin for the [asdf version manager](https://asdf-vm.com).

</div>
Expand All @@ -14,13 +13,6 @@
- [Contributing](#contributing)
- [License](#license)

# Dependencies

**TODO: adapt this section**

- `bash`, `curl`, `tar`: generic POSIX utilities.
- `SOME_ENV_VAR`: set this environment variable in your shell config to load the correct version of tool x.

# Install

Plugin:
Expand Down
1 change: 0 additions & 1 deletion bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ source "${plugin_dir}/lib/utils.bash"

mkdir -p "$ASDF_DOWNLOAD_PATH"

# TODO: Adapt this to proper extension and adapt extracting strategy.
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION.tar.gz"

# Download tar.gz file to the download directory
Expand Down
44 changes: 37 additions & 7 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

set -euo pipefail

# TODO: Ensure this is the correct GitHub homepage where releases can be downloaded for dart-sass-embedded.
GH_REPO="https://github.com/jrf0110/dart-sass-embedded"
GH_REPO="https://github.com/sass/dart-sass-embedded"
TOOL_NAME="dart-sass-embedded"
TOOL_TEST="dart-sass-embedded --version"

Expand All @@ -19,6 +18,37 @@ if [ -n "${GITHUB_API_TOKEN:-}" ]; then
curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN")
fi

get_platform() {
local platform

case "$(uname | tr '[:upper:]' '[:lower:]')" in
darwin) platform="macos" ;;
linux) platform="linux" ;;
windows) platform="windows" ;;
*)
fail "Platform '$(uname)' not supported!"
;;
esac

echo -n $platform
}

get_arch() {
local arch

case "$(uname -m)" in
x86_64 | amd64) arch="x64" ;;
i686 | i386) arch="ia32" ;;
armv6l | armv7l) arch="arm" ;;
aarch64 | arm64) arch="arm64" ;;
*)
fail "Arch '$(uname -m)' not supported!"
;;
esac

echo -n $arch
}

sort_versions() {
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' |
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
Expand All @@ -31,18 +61,19 @@ list_github_tags() {
}

list_all_versions() {
# TODO: Adapt this. By default we simply list the tag names from GitHub releases.
# Change this function if dart-sass-embedded has other means of determining installable versions.
list_github_tags
}

download_release() {
local version filename url
version="$1"
filename="$2"
arch="$(get_arch)"
platform="$(get_platform)"

# TODO: Adapt the release URL convention for dart-sass-embedded
url="$GH_REPO/archive/v${version}.tar.gz"
# Example:
# https://github.com/sass/dart-sass-embedded/releases/download/1.62.1/sass_embedded-1.62.1-linux-x64.tar.gz
url="$GH_REPO/releases/download/${version}/sass_embedded-${version}-${platform}-${arch}.tar.gz"

echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
Expand All @@ -61,7 +92,6 @@ install_version() {
mkdir -p "$install_path"
cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path"

# TODO: Assert dart-sass-embedded executable exists.
local tool_cmd
tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)"
test -x "$install_path/$tool_cmd" || fail "Expected $install_path/$tool_cmd to be executable."
Expand Down

0 comments on commit 5f74382

Please sign in to comment.