Skip to content

Commit

Permalink
Proper package checks in make_style.sh (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
DuCanhGH authored Oct 3, 2023
1 parent a463faa commit 019edcf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
17 changes: 2 additions & 15 deletions make_style.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
28 changes: 28 additions & 0 deletions scripts/check-package-installed.js
Original file line number Diff line number Diff line change
@@ -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.`,
);
}

0 comments on commit 019edcf

Please sign in to comment.