2018-10-04 01:50:00 +00:00
|
|
|
# bail on failures
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# go to root of repository
|
|
|
|
cd $(git rev-parse --show-toplevel)
|
|
|
|
|
2018-10-04 10:42:59 +00:00
|
|
|
# get commit id
|
|
|
|
COMMIT_ID="$(git rev-parse HEAD)"
|
|
|
|
|
2018-10-04 14:10:37 +00:00
|
|
|
# extract package name and version from package.json, remove scripts.prepare
|
2018-10-04 09:59:04 +00:00
|
|
|
ORIG_PKG="$(cat package.json)"
|
2018-10-04 10:24:50 +00:00
|
|
|
read NAME VERSION < <(node -e '
|
2018-10-04 01:50:00 +00:00
|
|
|
const fs = require("fs");
|
|
|
|
const pkg = JSON.parse(fs.readFileSync("package.json"));
|
2018-10-04 14:10:37 +00:00
|
|
|
if (pkg.scripts && pkg.scripts.prepare) {
|
2018-10-04 01:50:00 +00:00
|
|
|
delete pkg.scripts.prepare;
|
2018-10-04 14:10:37 +00:00
|
|
|
fs.writeFileSync("package.json", JSON.stringify(pkg, null, "\t") + "\n");
|
2018-10-04 01:50:00 +00:00
|
|
|
}
|
2018-10-04 10:24:50 +00:00
|
|
|
console.log(pkg.name + " " + pkg.version);
|
|
|
|
')
|
2018-10-04 01:50:00 +00:00
|
|
|
|
|
|
|
# determine current branch name, and create new temporary branch
|
|
|
|
ORIG_BRANCH=$(git symbolic-ref --short HEAD)
|
|
|
|
TEMP_BRANCH=RELEASE_${VERSION}_$(date +'%Y%m%d%H%M%S')
|
|
|
|
git checkout -b ${TEMP_BRANCH}
|
|
|
|
|
|
|
|
# untrack all files, and track the files that should be included in the published package
|
|
|
|
git rm --cached -r .
|
|
|
|
npm pack
|
|
|
|
git add -f $(tar tf ${NAME}-${VERSION}.tgz | cut -c 9-)
|
|
|
|
rm ${NAME}-${VERSION}.tgz
|
|
|
|
|
2018-10-04 10:23:32 +00:00
|
|
|
# commit and tag
|
2018-10-04 10:42:59 +00:00
|
|
|
git commit -m "v${VERSION} @ ${COMMIT_ID}"
|
|
|
|
git tag v${VERSION} -a -m "v${VERSION} @ ${COMMIT_ID}"
|
2018-10-04 01:50:00 +00:00
|
|
|
|
|
|
|
# return to original state
|
|
|
|
git reset ${ORIG_BRANCH}
|
|
|
|
git checkout ${ORIG_BRANCH}
|
2018-10-04 10:24:50 +00:00
|
|
|
cat <<< "${ORIG_PKG}" > package.json
|
2018-10-04 01:50:00 +00:00
|
|
|
git branch -D ${TEMP_BRANCH}
|