Skip to content

Instantly share code, notes, and snippets.

@fand
Last active May 20, 2019 05:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fand/2eada69b54e05ea79913 to your computer and use it in GitHub Desktop.
Save fand/2eada69b54e05ea79913 to your computer and use it in GitHub Desktop.
npmenv
#!/bin/bash
# .npmを作成
if [ ! -e .npm ]; then
mkdir .npm
fi
# npm本体をインストール
NPM_VERSION=$(echo $1 || cat .npm-version || npm -v)
if [ ! NPM_VERSION = $(npm -v) ]; then
npm install -g npm@$NPM_VERSION
fi
# 依存パッケージの準備
rm -rf node_modules
if [ -e ".npm/$NPM_VERSION" ]; then
# 既にインストールされていればコピーする
echo 'Copying installed node_modules...'
cp -r .npm/$NPM_VERSION node_modules
else
# なければインストールする
echo 'Installing deps to node_modules...'
npm install
cp -r node_modules .npm/$NPM_VERSION
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment