Skip to content

Instantly share code, notes, and snippets.

@hougasian
Created August 29, 2024 12:45
Show Gist options
  • Save hougasian/a786e28a4f9bed6cee2557ba2d8bd6dd to your computer and use it in GitHub Desktop.
Save hougasian/a786e28a4f9bed6cee2557ba2d8bd6dd to your computer and use it in GitHub Desktop.
#!/bin/sh
# Increase semver, build latest, publish to npm
cyan="\033[1;36m"
yellow="\033[1;33m"
nc="\033[0m"
v=$(perl -ne 'if (/"version": "(.*)"/) { print $1 . "\n" }' package.json)
n=$(perl -ne 'if (/"name": "(.*)"/) { print $1 . "\n" }' package.json)
PS3="What would you like to do: "
options=("Update Version & Publish" "Publish" "Quit")
select choice in "${options[@]}"; do
case $choice in
"Update Version & Publish")
echo "${cyan}You are about to increment version ${yellow}$v${cyan} of ${yellow}$n${cyan} and publish to npm."
read -r -p "😳 Is your local copy up to date? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
echo ""
read -r -p "😳 Is your local copy up to date? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
read -r -p "🀘 Ready to publish? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
PS3="What type of release are you publishing? "
releases=("major" "minor" "patch" "Quit")
select type in "${releases[@]}"; do
case $type in
"major")
echo "Creating a $type release..."
npm version $type
;;
"minor")
echo "Creating a $type release..."
npm version $type
;;
"patch")
echo "Creating a $type release..."
npm version $type
break
;;
"Quit")
echo "${yellow}Need more help on releases${nc} πŸ‘‰ https://semver.org/"
exit
;;
*) echo "invalid option $REPLY";;
esac
done
nv=$(perl -ne 'if (/"version": "(.*)"/) { print $1 . "\n" }' package.json)
echo "πŸš€ ${cyan}Building a fresh copy for ${yellow}$nv${cyan}...${nc}"
npm run build || exit $?
echo "πŸ‘‰ ${cyan}Publishing ${yellow}$nv${cyan} to npm...${nc}"
npm publish --access public || exit $?
echo "${cyan}Well done!${nc} πŸ₯ƒ"
else
echo "${yellow}Well, you tried.${nc} πŸ˜”"
fi
else
echo "${yellow}Do a${nc} fetch${yellow} and ${nc}rebase ${yellow}before you try again.${nc} πŸ˜”"
echo ""
fi
fi
;;
"Publish")
nv=$(perl -ne 'if (/"version": "(.*)"/) { print $1 . "\n" }' package.json)
echo "πŸš€ ${cyan}Building a fresh copy for ${yellow}$nv${cyan}...${nc}"
npm run build || exit $?
echo "πŸ‘‰ ${cyan}Publishing ${yellow}$nv${cyan} to npm...${nc}"
npm publish --access public || exit $?
echo "${cyan}Well done!${nc} πŸ₯ƒ"
break
;;
"Quit")
exit
;;
*) echo "invalid option $REPLY";;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment