Skip to content

Instantly share code, notes, and snippets.

@allex
Last active August 29, 2015 14:11
Show Gist options
  • Save allex/ea4a4cee2278d5b0fccd to your computer and use it in GitHub Desktop.
Save allex/ea4a4cee2278d5b0fccd to your computer and use it in GitHub Desktop.
#!/bin/sh
# git hook for auto upload current package to npm server
# author: Allex Wang (http://iallex.com)
# GistID: ea4a4cee2278d5b0fccd
# GistURL: http://gist.github.com/allex/ea4a4cee2278d5b0fccd
npm_server="server.npm"
npm_root="/data/npm"
name=`node -p "require('./package').name"`
[ -n "$name" ] || { echo "project name not valid, please check your package.json correctly."; exit 1; }
commit=`git log -1 --pretty=format:"%h"`
dist_name=$name-${commit}.tar.gz
dist_file=/tmp/${dist_name}
git archive -o $dist_file --prefix="${name}/" HEAD
scp ${dist_file} ${npm_server}:${npm_root} >/dev/null
ssh sandbox "ln -sf ${npm_root}/${dist_name} ${npm_root}/${name}.tar.gz" >/dev/null
rm ${dist_file} >/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment