Skip to content

Instantly share code, notes, and snippets.

@arjun-kava
Created March 4, 2019 13:31
Show Gist options
  • Save arjun-kava/f3899d8bd28e5791e4ef7aca9c7dc35f to your computer and use it in GitHub Desktop.
Save arjun-kava/f3899d8bd28e5791e4ef7aca9c7dc35f to your computer and use it in GitHub Desktop.
Script for publishing package on github
# 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