LoginSignup
3
4

More than 5 years have passed since last update.

Node.js と NPM セットアップの冪等な自動化

Last updated at Posted at 2014-06-17

Node.js 環境の整備は ndenv で。想定は OS X 環境。

  • nenv から ndenv に乗り換えました。
CWD=$(pwd)

NDENV="${HOME}/.ndenv"
NDVER='v4.1.1'

if ! which ndenv &> /dev/null
then
    if [ ! -d ${NDENV} ]
    then
        git clone git://github.com/riywo/ndenv.git ${NDENV}
        git clone git://github.com/riywo/node-build.git ${NDENV}/plugins/node-build
    fi
    export PATH="${NDENV}/bin:${PATH}"
    eval "$(ndenv init -)"
else
    cd ${NDENV}
    git pull
    cd ${NDENV}/plugins/node-build
    git pull
    cd ${CWD}
fi

if ! ndenv versions | grep ${NDVER} &> /dev/null
then
    ndenv install ${NDVER}
fi

ndenv global ${NDVER}
ndenv rehash

unset NDENV NDVER

if which npm &> /dev/null
then
    NPMS=(
        'LiveScript'
        'coffee-script'
        'coffeelint'
        'csslint'
        'eslint'
        'generator-hubot'
        'grunt-cli'
        'gulp'
        'js-yaml'
        'jsonlint'
        'mocha'
        'pulp'
        'wzrd'
        'yo'
    )

    for NPM in "${NPMS[@]}"
    do
        if ! npm list -g | grep ${NPM} &> /dev/null
        then
            npm install -g ${NPM}
        else
            npm update -g ${NPM}
        fi
    done

    ndenv rehash

    unset NPMS NPM
fi

unset CWD

インストール後 ${HOME}/.bash_profile とかに下記行を追記の事:

export PATH="${HOME}/.ndenv/bin:${PATH}"
eval "$(ndenv init -)"
[ -f "${HOME}/.ndenv/completions/ndenv.bash" ] && source "${HOME}/.ndenv/completions/ndenv.bash"
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4