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.

44 lines
1.2 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 str = fs.readFileSync("package.json").toString();
const m = str.match(/\n([\t ]+)/);
const indent = m ? m[1] : "\t";
const pkg = JSON.parse(str);
pkg.scripts && delete pkg.scripts.prepare;
fs.writeFileSync("package.json", JSON.stringify(pkg, null, indent) + (str.endsWith("\n") ? "\n" : ""));
# 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"