Skip to content

Instantly share code, notes, and snippets.

@proustibat
Last active August 13, 2018 03:21
Show Gist options
  • Save proustibat/20b77c1e8c4ee663c2b6dd2a47a82fae to your computer and use it in GitHub Desktop.
Save proustibat/20b77c1e8c4ee663c2b6dd2a47a82fae to your computer and use it in GitHub Desktop.
NPM 5 / NPM 6 / Yarn installations
#!/usr/bin/env bash
## @file install-comparisons.sh
## @author Jennifer Proust - proustibat@gmail.com
## @section DESCRIPTION Compare installations times between NPM 5/ NPM6 and YARN
set -o errexit || true
set -o errtrace
set -o nounset
set -o pipefail
#set -o xtrace
RESULTDIR="install-results"
RESULTFILE="results.txt"
NPM5FILE=".stdout.npm5"
NPM6FILE=".stdout.npm6"
YARNFILE=".sdtout.yarn"
run() {
printf ">>> LET'S GO\n"
# gnu-time installation
brew install gnu-time
# Init files with some information
printf "> Init results files...\n"
rm -rf $RESULTDIR && mkdir $RESULTDIR
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
NVMVERSION="NVM `nvm --version`"
CURRENTDIR=${PWD##*/}
DATE=`date '+%Y-%m-%d %H:%M:%S'`
printf "************************************************\n$CURRENTDIR\n$DATE\n...\n$NVMVERSION\n************************************************\n\n" | tee -a $RESULTDIR/$RESULTFILE
# INSTALL WITH NPM 5
installPackages npm5
# INSTALL WITH NPM 6npm install npm@latest -g
installPackages npm6
# INSTALL WITH YARN
installPackages yarn
# LAST CLEAN
clean
# END
printf "\n\n>>> ALL DONE!\n" | tee -a $RESULTDIR/$RESULTFILE
open $RESULTDIR/results.txt
}
clean () {
REPEAT=${1:-0}
if [ $REPEAT != "repeat" ]
then
rm -rf yarn.lock package-lock.json
fi
rm -rf node_modules
npm cache clean --force
yarn cache clean
}
installPackages() {
clean
nvm install 9 && nvm use 9
if [ $1 = "npm5" ]
then
printf "\n================================================\nINSTALLATION WITH NPM 5\n===============================================\n" | tee -a $RESULTDIR/$RESULTFILE
npm install npm@5.6.0 -g
printf "Node version: `node -v`\n" | tee -a $RESULTDIR/$RESULTFILE
printf "NPM version: `npm -v`\n" | tee -a $RESULTDIR/$RESULTFILE
runNPMInstall
clean "repeat"
runNPMInstall
rm -rf node_modules
runNPMInstall
elif [ $1 = "npm6" ]
then
printf "\n================================================\nINSTALLATION WITH NPM 6\n================================================\n" | tee -a $RESULTDIR/$RESULTFILE
npm install npm@6.0.0 -g
printf "Node version: `node -v`\n" | tee -a $RESULTDIR/$RESULTFILE
printf "NPM version: `npm -v`\n" | tee -a $RESULTDIR/$RESULTFILE
runNPMInstall
clean "repeat"
runNPMInstall
rm -rf node_modules
runNPMInstall
elif [ $1 = "yarn" ]
then
printf "\n================================================\nINSTALLATION WITH YARN \n================================================\n" | tee -a $RESULTDIR/$RESULTFILE
brew install yarn --without-node || brew upgrade yarn
printf "Node version: `node -v`\n" | tee -a $RESULTDIR/$RESULTFILE
printf "Yarn version: `yarn --version`\n" | tee -a $RESULTDIR/$RESULTFILE
runYarnInstall
clean "repeat"
runYarnInstall
rm -rf node_modules
runYarnInstall
else
echo "Error: this kind of installation is not supported!" | tee -a $RESULTDIR/$RESULTFILE
fi
printf "> Done!\n"
}
runNPMInstall() {
gtime -f "\nREAL\t\tUSER\t\tSYS\t\n------------------------------------------------\n%E\t\t%U\t\t%S" -ao $RESULTDIR/$RESULTFILE npm install
}
runYarnInstall() {
gtime -f "\nREAL\t\tUSER\t\tSYS\t\n------------------------------------------------\n%E\t\t%U\t\t%S" -ao $RESULTDIR/$RESULTFILE yarn install
}
run
@proustibat
Copy link
Author

proustibat commented May 5, 2018

Run the line below :

git clone https://gist.github.com/20b77c1e8c4ee663c2b6dd2a47a82fae.git ic-temp && cp ic-temp/install-comparisons.sh . && rm -rf ic-temp  && bash install-comparisons.sh && rm install-comparisons.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment