From d49cf85acb8e51f125d37e274af06f421178995b Mon Sep 17 00:00:00 2001 From: DuCanhGH <75556609+DuCanhGH@users.noreply.github.com> Date: Mon, 2 Oct 2023 20:22:33 +0700 Subject: [PATCH 1/2] Proper package check in make_style.sh --- make_style.sh | 17 ++--------------- scripts/check-package-installed.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 scripts/check-package-installed.js diff --git a/make_style.sh b/make_style.sh index b79ab2572..8fc67119f 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 || 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.`, + ); +} From 8123d1a258c9efa4424995b108f9a89dd7334064 Mon Sep 17 00:00:00 2001 From: DuCanhGH <75556609+DuCanhGH@users.noreply.github.com> Date: Mon, 2 Oct 2023 22:00:49 +0700 Subject: [PATCH 2/2] add autoprefixer --- make_style.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make_style.sh b/make_style.sh index 8fc67119f..764298298 100755 --- a/make_style.sh +++ b/make_style.sh @@ -1,7 +1,7 @@ #!/bin/bash cd "$(dirname "$0")" || exit -node scripts/check-package-installed.js postcss sass || exit +node scripts/check-package-installed.js postcss sass autoprefixer || exit build_style() { echo "Creating $1 style..."