Skip to content

Instantly share code, notes, and snippets.

@jdelibas

jdelibas/README.md

Last active May 28, 2019
Embed
What would you like to do?
local-npm-cache

Local npm cache installer

Local npm registry that caches all calls to npm.

Comes with a built in UI, once its finished syncing you should see the results.

https://github.com/local-npm/local-npm

Install

$ curl -s https://gist.githubusercontent.com/jdelibas/8e602bcd9063a2cf24ca5f879e2990bc/raw/npm.sh | bash 

Uninstall

$ docker stop local-npm && docker rm local-npm
$ rm -rf ~/.npm-cache
$ npm set registry https://registry.npmjs.org
#!/bin/bash
# v0.1.0
# Description
# Deploy local npm registry
# Exit on any failed command
set -e
echo "🏍 Local npm cache installer v0.1.0"
echo -n "🤔 Did you read the source or are you blindly trusting the internet?"
sleep 5
###
### Dependency checks
###
checkDependencies() {
for CMD in $@
do
command -v $CMD >/dev/null 2>&1 || { echo >&2 "🚨 $CMD required but not installed. Aborting."; exit 1; }
done
}
# Check if deps are present on system, if not fail build
checkDependencies docker npm
# Set local machine cache path
LOCAL_NPM_PATH=~/.npm-cache
# Start local npm container with mounted volumes
echo -en "\r\033[2K"
echo -n "🐳 Starting container, might take a minute or two"
sleep 2;
docker run -d \
-p 5080:5080 \
--restart=always \
--name local-npm \
-v $LOCAL_NPM_PATH/storage:/data \
orlandohohmeier/local-npm:latest &> /dev/null
# Set global npm registry to local instance
echo -en "\r\033[2K"
echo -n "🔨 npm settings configured"
sleep 2
npm set registry http://0.0.0.0:5080/
URL=http://localhost:5080/_browse
if which xdg-open > /dev/null
then
xdg-open $URL 2>/dev/null
elif which gnome-open > /dev/null
then
gnome-open $URL 2>/dev/null
elif which open > /dev/null
then
open $URL 2>/dev/null
fi
echo -en "\r\033[2K"
echo -n "🚀 All done! npm install all the things!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment