Skip to content

Instantly share code, notes, and snippets.

@lukekarrys
Last active December 21, 2017 10:38
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukekarrys/57480999ea32deafa3e2 to your computer and use it in GitHub Desktop.
Save lukekarrys/57480999ea32deafa3e2 to your computer and use it in GitHub Desktop.
Deploy a subdirectory in your NodeJS Git project to GitHub pages.

Deploy a subdirectory in your NodeJS Git project to GitHub pages.

  1. Make sure node build outputs some static files to _built.
  2. npm run deploy.

This eventually became this blog post and this module

{
"scripts": {
"build": "node build",
"commit-built": "git add _built -A && git commit -m \"_built files at `date`\" -n > /dev/null 2>&1; exit 0",
"ghpages": "git subtree split --prefix _built/ -b gh-pages && git push -f origin gh-pages:gh-pages && git branch -D gh-pages",
"deploy": "npm run build && npm run commit-built && npm run ghpages"
}
}
@kumar303
Copy link

kumar303 commented Oct 7, 2016

This is so simple, thanks! I also wanted to give myself a reminder that all outstanding changes need to be committed (duh) so mine looks like this in a shell script:

#!/bin/bash
if [[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]; then
    git status
    echo "---------------------------------------------------------"
    echo "You need to commit all changes first"
    echo "---------------------------------------------------------"
    exit 1
fi
git subtree split --prefix www/ -b gh-pages && git push origin gh-pages:gh-pages && git branch -D gh-pages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment