Created
December 14, 2016 09:47
-
-
Save 321hendrik/1047d1d092e7c4cf8c48c4a277f426bb to your computer and use it in GitHub Desktop.
zip a npm project with only local dependencies
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 | |
# | |
# NPM Packer | |
# - copy script to project folder | |
# - npm install | |
# - ./packer.sh | |
# | |
# -> creates a PROJECT_NAME.zip | |
# | |
SCRIPT_ROOT=`pwd` | |
PROJECT_DIR=$SCRIPT_ROOT | |
if [ $1 ]; then | |
PROJECT_DIR+=/$1 | |
fi | |
PROJECT_NAME=`basename $PROJECT_DIR` | |
TMP_DIR=$PROJECT_DIR/pack_temp | |
# copy to subfolder | |
rsync -av --progress $PROJECT_DIR/* $TMP_DIR --exclude pack_temp --exclude node_modules --exclude .git | |
# create new node modules dir in temp dir | |
mkdir $TMP_DIR/node_modules | |
# change into temp dir | |
cd $TMP_DIR/ | |
# copy local dependencies | |
for RESULT in `cat $PROJECT_DIR/package.json | grep git+ssh` | |
do | |
if [[ $RESULT == *"\":"* ]]; then | |
SUB=$(echo $RESULT| cut -d '"' -f 2) | |
npm remove $SUB --save | |
cp -R $PROJECT_DIR/node_modules/$SUB $TMP_DIR/node_modules/$SUB | |
fi | |
done | |
# zip it up | |
zip -r ../$PROJECT_NAME.zip * | |
# go back to script root | |
cd $SCRIPT_ROOT | |
# remove temp dir | |
rm -rf $TMP_DIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment