Last active
June 3, 2022 15:34
-
-
Save gausnes/70cd36df472bfc8d1775f675409a4d67 to your computer and use it in GitHub Desktop.
NPM Local Publishing Tool
This file contains hidden or 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
#!/bin/sh | |
if [ "$1" != "install" ]; then | |
echo "Invalid argument ($1), example usage: npm-local install @privaterepo/package ../path/to/package/root" | |
exit -1 | |
elif [ -z "$2" ]; then | |
echo "Invalid argument ($2), example usage: npm-local install @privaterepo/package ../path/to/package/root" | |
exit -1 | |
elif [ -z "$3" ]; then | |
echo "Invalid argument ($3), example usage: npm-local install @privaterepo/package ../path/to/package/root" | |
exit -1 | |
fi | |
PROJECT_NAME=$2 | |
LIBRARY_ROOT=$3 | |
if [ ! -f $LIBRARY_ROOT/package.json ]; then | |
echo "`$LIBRARY_ROOT` doesn't appear to be a valid NPM project" | |
exit -1 | |
fi | |
(cd $LIBRARY_ROOT && npm ci) | |
PACKAGE_NAME=$(cd $LIBRARY_ROOT && npm pack) | |
npm uninstall $PROJECT_NAME | |
[[ -d $HOME/.npm-local ]] || mkdir $HOME/.npm-local | |
mv $LIBRARY_ROOT/$PACKAGE_NAME $HOME/.npm-local/$PACKAGE_NAME | |
echo $PROJECT_NAME@$HOME/.npm-local/$PACKAGE_NAME | |
npm install $PROJECT_NAME@$HOME/.npm-local/$PACKAGE_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment