Created
April 10, 2024 13:44
-
-
Save cybrown/ad355a999f1f04c2b35858b4885ad360 to your computer and use it in GitHub Desktop.
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/bash | |
ROOT=~/.nmlnk | |
NODE_MODULES_REPOSITORY="$ROOT/repository" | |
# check package-lock.json file is present | |
if [ ! -f "package-lock.json" ]; then | |
echo "File package-lock.json not found!" | |
exit 1 | |
fi | |
# create node_modules repository if necessary | |
if [ ! -d "$NODE_MODULES_REPOSITORY" ]; then | |
mkdir -p "$NODE_MODULES_REPOSITORY" | |
fi | |
# if node_modules exists and is a directory, remove it | |
if [ -d "node_modules" ]; then | |
rm -rf node_modules | |
fi | |
# get md5 of package-lock.json file | |
FILE_MD5=$(md5sum package-lock.json | cut -d ' ' -f 1) | |
# log the date, current directory and md5 to log file | |
echo "$(date -Iminutes) - $(pwd) - $FILE_MD5" >> "$ROOT/log.txt" | |
# if directory does not exists, create it | |
if [ ! -d "$NODE_MODULES_REPOSITORY/$FILE_MD5" ]; then | |
rm -rf node_modules | |
npm ci | |
mkdir -p "$NODE_MODULES_REPOSITORY/$FILE_MD5" | |
mv node_modules "$NODE_MODULES_REPOSITORY/$FILE_MD5/node_modules" | |
fi | |
# remove directory if it already exists | |
rm -f node_modules | |
# link directory to current directory | |
ln -s "$NODE_MODULES_REPOSITORY/$FILE_MD5/node_modules" node_modules |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment