Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper package checks in make_style.sh #335

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.`,
);
}
Loading