You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.2 KiB

# bail on failures
set -e
# go to root of repository
cd $(git rev-parse --show-toplevel)
# get commit id
ORIG_COMMIT="$(git rev-parse HEAD)"
# extract package name and version from package.json, remove scripts.prepare
ORIG_PKG="$(cat package.json)"
read PKG_NAME PKG_VERSION < <(node -e '
5 years ago
const fs = require("fs");
const pkg = JSON.parse(fs.readFileSync("package.json"));
if (pkg.scripts && pkg.scripts.prepare) {
delete pkg.scripts.prepare;
fs.writeFileSync("package.json", JSON.stringify(pkg, null, "\t") + "\n");
console.log( + " " + pkg.version);
# determine current branch name, and create new temporary branch
ORIG_BRANCH=$(git symbolic-ref --short HEAD)
git checkout --orphan=${TEMP_BRANCH}
5 years ago
git rm --cached -rf .
5 years ago
# track the files that should be included in the published package
npm pack
git add -f $(tar tf ${PKG_NAME}-${PKG_VERSION}.tgz | cut -c 9-)
5 years ago
# commit and tag
git commit -m "v${PKG_VERSION} @ ${ORIG_COMMIT}"
5 years ago
git tag v${PKG_VERSION} -am "v${PKG_VERSION} @ ${ORIG_COMMIT}"
# return to original state
git reset ${ORIG_BRANCH}
git checkout ${ORIG_BRANCH}
cat <<< "${ORIG_PKG}" > package.json
git branch -D ${TEMP_BRANCH}