-
-
Save automation-stack/86acfa8018e7eac10b572a425e1fb532 to your computer and use it in GitHub Desktop.
NPM install for low RAM machins. And "npm install ... killed" problem
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 | |
| # | |
| # Author: SuperPaintman <SuperPaintmanDeveloper@gmail.com> | |
| # | |
| ### | |
| # Constants | |
| ### | |
| RETVAL=0 | |
| CCYAN="\033[0;36m" | |
| CGREEN="\033[0;32m" | |
| CBLUE="\033[0;34m" | |
| CGRAY="\033[1;30m" | |
| CNC="\033[0m" | |
| MODULES_DIR="node_modules" | |
| ### | |
| # Packages | |
| ### | |
| node_script_dependencies=$(cat <<EOF | |
| 'use strict'; | |
| var p = require('./package.json'); | |
| var deps = []; | |
| for (var packageName in p.dependencies) { | |
| var packageV = p.dependencies[packageName]; | |
| deps.push(packageName + '@' + packageV); | |
| } | |
| console.log(deps.join(';')); | |
| EOF | |
| ) | |
| node_script_devDependencies=$(cat <<EOF | |
| 'use strict'; | |
| var p = require('./package.json'); | |
| var deps = []; | |
| for (var packageName in p.devDependencies) { | |
| var packageV = p.devDependencies[packageName]; | |
| deps.push(packageName + '@' + packageV); | |
| } | |
| console.log(deps.join(';')); | |
| EOF | |
| ) | |
| # npm install --only=production | |
| node_dependencies_str=$(node -e "$node_script_dependencies") | |
| # npm install --only=dev | |
| node_devDependencies_str=$(node -e "$node_script_devDependencies") | |
| ### | |
| # LazyInstall | |
| # | |
| # params: | |
| # $1 {String} - array of packages joined with ";" | |
| ### | |
| npm_f3_install () { | |
| dependencies=$1 | |
| array=(${dependencies//;/ }) | |
| for element in "${array[@]}" | |
| do | |
| echo -e " ${CBLUE}Package${CNC}: $element" | |
| npm install --verbose "$element" | |
| done | |
| } | |
| case "$1" in | |
| production) | |
| echo -e "${CCYAN}Start installing production dependencie${CNC}" | |
| npm install --only=production || npm_f3_install ${node_dependencies_str} | |
| ;; | |
| development) | |
| echo -e "${CCYAN}Start installing development dependencie${CNC}" | |
| npm install --only=dev || npm_f3_install ${node_devDependencies_str} | |
| ;; | |
| all|"") | |
| echo -e "${CCYAN}Start installing all dependencie${CNC}" | |
| # production | |
| npm install --only=production || npm_f3_install ${node_dependencies_str} | |
| # development | |
| npm install --only=dev || npm_f3_install ${node_devDependencies_str} | |
| ;; | |
| *) | |
| echo -e "${CCYAN}Usage${CNC}: $0 {development|production|all} (or null)" | |
| echo -e "${CCYAN}Example${CNC}:" | |
| echo -e " ${CGREEN}$0${CNC} production ${CGRAY}# install npm production dependencies${CNC}" | |
| echo -e " ${CGREEN}$0${CNC} development ${CGRAY}# install npm development dependencies${CNC}" | |
| echo -e " ${CGREEN}$0${CNC} all ${CGRAY}# install npm all dependencies${CNC}" | |
| echo -e " ${CGREEN}$0${CNC} ${CGRAY}# install npm all dependencies${CNC}" | |
| exit 1 | |
| ;; | |
| esac | |
| exit $RETVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment