diff --git a/bin/sass b/bin/sass new file mode 100755 index 00000000..3c937b52 --- /dev/null +++ b/bin/sass @@ -0,0 +1,62 @@ +#!/bin/bash -e + +dir="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)" +if [ "$(basename "$dir")" == bin ]; then + # Global executables are installed in .../bin/, and global libraries + # (including their dependencies) in .../lib/node_modules. + node_modules="$(dirname "$dir")/lib/node_modules" +elif [ "$(basename "$dir")" == .bin ]; then + # Local dependency executables are installed in ./node_modules/.bin, and + # and their libraries in ./node_modules. + node_modules="$(dirname "$dir")" +else + # If all else fails, try to find node_modules in a parent directory. We + # might execute this, for example, if someone runs the script from source. + while [ "$dir" != "/" ]; do + dir="$(dirname "$dir")" + if [ -d "$dir/node_modules" ]; then + node_modules="$dir/node_modules" + break + fi + done + echo "Could not find node_modules above ${BASH_SOURCE[0]}!" >&2 + exit 1 +fi + +case "$(uname -s)" in + Linux*) + if [ ! -z "$ANDROID_ROOT" -a ! -z "$ANDROID_DATA" ]; then + os=android + else + os=linux + fi;; + Darwin*) + os=darwin;; + CYGWIN*|MINGW*|MSYS_NT*) + os=win32;; + *) + echo "Unknown operating system $(uname -s)!" >&2 + exit 1 +esac + +musl= +if [ "$os" == linux ] && grep -q /ld-musl- /bin/bash; then musl=-musl; fi + +case "$(uname -m)" in + aarch64*) arch=arm64;; + arm*) arch=arm;; + x86_64) arch=x64;; + i386|i486|i586|i686) arch=ia32;; + *) + echo "Unknown architecture $(uname -m)!" >&2 + exit 1 +esac + +shared="$node_modules/sass-embedded-$os$musl-$arch" +specific="$node_modules/sass-embedded/node_modules/sass-embedded-$os$musl-$arch" +if [ -d "$specific" ]; then + exec "$specific/dart-sass/sass" "$@" +else + exec "$shared/dart-sass/sass" "$@" +fi + diff --git a/package.json b/package.json index e9125b74..7e0881a6 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "engines": { "node": ">=16.0.0" }, + "bin": {"sass": "bin/sass"}, "scripts": { "init": "ts-node ./tool/init.ts", "check": "npm-run-all check:gts check:tsc",