diff --git a/package.json b/package.json index df4bca8..82bbc27 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "type": "module", "scripts": { "changeset": "./scripts/changeset.sh", + "changeset:postversion": "tsx scripts/update-version.ts", "codegen": "tsx scripts/liblab-gen.ts", "build:docs": "tsx scripts/liblab-docs.ts" }, diff --git a/scripts/changeset.sh b/scripts/changeset.sh index 676ecf9..6426474 100755 --- a/scripts/changeset.sh +++ b/scripts/changeset.sh @@ -1,27 +1,26 @@ #!/usr/bin/env bash -# make sure the script runs relative to the repo root -set -euo pipefail && cd "$(dirname "${BASH_SOURCE[0]}")/.." +# Ensure script runs relative to the repo root +set -euo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")/.." -# some helpers and error handling: -info() { printf "%s\n" "$*" >&1; } -error() { printf "%s\n" "$*" >&2; } -trap 'echo Changeset interrupted >&2; exit 2' INT TERM +# Trap signals for graceful exit +trap 'echo "Script interrupted" >&2; exit 2' INT TERM -# pass all arguments to changeset -./node_modules/.bin/changeset "$@" +# Run changeset with passed arguments +npx changeset "$@" +exitCode=$? -changeset_exit=$? -if [ ${changeset_exit} -gt 0 ]; -then - error "Changeset finished with error" - exit ${changeset_exit} +if [ $exitCode -ne 0 ]; then + echo "Changeset finished with error" >&2 + exit $exitCode fi -# if first argument was `version` also run the `update-version.ts` script -args=("$@") -info "args: ${args[@]}" -if [ $# -gt 0 ] && [ ${args[0]} = "version" ] -then - yarn tsx scripts/update-version.ts +# Handle "post" scripts if arguments are provided +if [ $# -gt 0 ]; then + command="$1" + shift # Remove the first argument from $@ + script="changeset:post${command}" + echo "Running post script: ${script}" + npm run "${script}" --if-present -- "$@" fi