diff --git a/make_style.sh b/make_style.sh index b79ab2572..764298298 100755 --- a/make_style.sh +++ b/make_style.sh @@ -1,21 +1,8 @@ #!/bin/bash -if ! [ -x "$(command -v npx sass)" ]; then - echo 'Error: sass is not installed.' >&2 - exit 1 -fi - -if ! [ -x "$(command -v npx postcss)" ]; then - echo 'Error: postcss is not installed.' >&2 - exit 1 -fi - -if ! [ -x "$(command -v npx autoprefixer)" ]; then - echo 'Error: autoprefixer is not installed.' >&2 - exit 1 -fi - cd "$(dirname "$0")" || exit +node scripts/check-package-installed.js postcss sass autoprefixer || exit + build_style() { echo "Creating $1 style..." cp resources/vars-$1.scss resources/vars.scss diff --git a/scripts/check-package-installed.js b/scripts/check-package-installed.js new file mode 100644 index 000000000..7bfbe8ab5 --- /dev/null +++ b/scripts/check-package-installed.js @@ -0,0 +1,28 @@ +// @ts-check +import { createRequire } from "node:module"; + +const require = createRequire(import.meta.url); + +if (process.argv.length < 3) { + throw new Error("Please specify a package/packages to check."); +} + +/** + * @type {string[]} + */ +const failedPackages = []; + +for (let i = 2; i < process.argv.length; ++i) { + const packageName = process.argv[i]; + try { + require(packageName); + } catch { + failedPackages.push(packageName); + } +} + +if (failedPackages.length !== 0) { + throw new Error( + `${failedPackages.join(", ")} ${failedPackages.length === 1 ? "is" : "are"} not installed.`, + ); +}