Created
March 4, 2019 13:31
-
-
Save arjun-kava/f3899d8bd28e5791e4ef7aca9c7dc35f to your computer and use it in GitHub Desktop.
Script for publishing package on github
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# script used to publish package to npm and push new tag | |
# step 1 - change version from package json | |
# step 2 - run ./scripts/publish-npm.sh $version i.e ./scripts/publish-npm.sh 0.0.3 | |
set -e | |
if [ $# -eq 0 ] | |
then | |
echo "Please specify version." | |
exit | |
fi | |
PACKAGE_NAME="package-name-js" | |
# if you forget to commit | |
PORCELAIN=`git status --porcelain` | |
if [ -n "$PORCELAIN" ]; then | |
echo "Please commit changes first."; | |
echo $PORCELAIN | |
exit; | |
fi | |
BRANCH=`git rev-parse --abbrev-ref HEAD` | |
ORIGIN=`git config --get remote.origin.url` | |
if [ "$BRANCH" != "master" ]; then | |
echo "Error: Switch to the master branch before publishing." | |
exit | |
fi | |
if ! [[ "$ORIGIN" =~ $PACKAGE_NAME ]]; then | |
echo "Error: Switch to the main repo ($PACKAGE_NAME) before publishing." | |
exit | |
fi | |
# Build CPU: | |
npm pack | |
npm publish | |
echo "⌛ ⌛ Published ${PACKAGE_NAME} a new package to npm." | |
# Revert GPU changes: | |
git checkout . | |
if [ $# -ne 0 ] | |
then | |
git pull | |
git push # verify everthing on cloud before creting tag | |
git tag $1 | |
git push --tags | |
rm -rf $PACKAGE_NAME-*.tgz | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment