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.

41 lines
1.1 KiB

5 years ago
# git ready
set -e
cd "$(git rev-parse --show-toplevel)"
ORIG_HEAD="$(git symbolic-ref HEAD)"
ORIG_COMMIT="$(git rev-parse HEAD)"
# extract version from package.json, and remove scripts.prepare
5 years ago
cp package.json package.json.bak
PKG_VERSION="$(node -e '
5 years ago
const fs = require("fs");
const pkg = JSON.parse(fs.readFileSync("package.json"));
pkg.scripts && delete pkg.scripts.prepare;
5 years ago
fs.writeFileSync("package.json", JSON.stringify(pkg));
# create new temporary branch
5 years ago
git checkout --orphan="$TEMP_BRANCH"
5 years ago
git rm --cached -rf .
# commit the files that should be included in the published package
PKG_TAR="$(npm pack | tail -n 1)"
5 years ago
tar tf "$PKG_TAR" | cut -c 9- | xargs -d '\n' git add -f
git commit -m "v$PKG_VERSION @ $ORIG_COMMIT"
# return to original state
5 years ago
rm "$PKG_TAR"
mv -f package.json.bak package.json
git symbolic-ref HEAD "$ORIG_HEAD"
git reset
# tag commit
git tag "v$PKG_VERSION-src"
5 years ago
# delete temporary branch
5 years ago
git branch -D "$TEMP_BRANCH"