Last active
November 18, 2021 23:31
-
-
Save mmende/2c10dd6161bc75120dbf153098caa48d to your computer and use it in GitHub Desktop.
Install app from an npm registry
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
#!/bin/bash | |
# Installs an app from a npm registry into a specific directory | |
APP=$1 | |
TARGET=$2 | |
# Assure we have both parameters | |
if [ -z $APP ] || [ -z $TARGET ]; then | |
echo "Usage: $0 my-node-app /some/install/path/my-node-app" | |
fi | |
# Resolve stuff like ../ | |
TARGET=$(realpath $TARGET) | |
echo "Installing $APP at $TARGET..." | |
# Whereas npm v6 returns the fetched tarball name, | |
# npm v7+ won't do that, therefore we use a custom directory | |
# with wildcard pattern to extract the app | |
rm -rf /tmp/__install_app | |
mkdir -p /tmp/__install_app | |
cd /tmp/__install_app | |
npm pack $APP | |
tar xvf *.tgz | |
mv package $TARGET | |
cd $TARGET | |
rm -rf /tmp/__install_app | |
# Install | |
NODE_ENV=production npm install --production |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage
To e.g. install some-package to
package-installation
under the current directory:bash <(curl -sL https://gist.githubusercontent.com/mmende/2c10dd6161bc75120dbf153098caa48d/raw/installNodeApp.sh) some-package ./package-installation