diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..4fef437 --- /dev/null +++ b/.npmrc @@ -0,0 +1,2 @@ +save-exact=true +package-lock=false diff --git a/bin/deploy-site b/bin/deploy-site new file mode 100755 index 0000000..be00bea --- /dev/null +++ b/bin/deploy-site @@ -0,0 +1,30 @@ +#!/usr/bin/env node +const ghPages = require('gh-pages'); +const path = require('path'); +const fs = require('fs'); +const childProcess = require('child_process'); + +const packageJson = path.join(process.cwd(), 'package.json'); + +if (!fs.existsSync(packageJson)) { + console.error('Please run in the root directory of the package'); + process.exit(1); +} + +const scripts = require(packageJson).scripts + +if (!scripts || !scripts['generate-site']) { + console.error('Please setup a generate-site script in your package.json'); + process.exit(1); +} + +childProcess.execSync('npm run generate-site') + +ghPages.publish('site-build', function (err) { + if (err) { + console.error(err); + process.exit(1); + } else { + console.log('Published site'); + } +}); diff --git a/bin/deploy-site.sh b/bin/deploy-site.sh deleted file mode 100755 index 83ccbbd..0000000 --- a/bin/deploy-site.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh -if [ -n "$(git describe --always --dirty | grep -- -dirty)" ] -then - echo "Working tree is dirty, please commit or stash your changes, then try again" - exit 1 -fi - -TARGET_BRANCH=${1:-gh-pages} -CURRENT_BRANCH=`git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||'` -npm run generate-site - -if [ -n "$(git describe --always --dirty | grep -- -dirty)" ] -then - echo "Working tree is dirty after generating the site. Make sure that your documentation tests" - echo "are fully updated and that site-build is in .gitignore etc." - exit 1 -fi - -git fetch origin $TARGET_BRANCH -if [ `git branch --list -a origin/$TARGET_BRANCH` ]; then \ - git checkout -B $TARGET_BRANCH origin/$TARGET_BRANCH -else \ - git checkout --orphan $TARGET_BRANCH && \ - git rm -rf . -fi -rm `git ls-files | grep -v '^\.gitignore$'` -printf "node_modules\nsite-build\n" > .gitignore -cp -r site-build/* . -if [ "`git status --porcelain`" != "" ]; then \ - (git add -A . && \ - git commit -m "Updated site" && \ - git push origin +$TARGET_BRANCH:$TARGET_BRANCH) -fi -git checkout $CURRENT_BRANCH diff --git a/package.json b/package.json index 4db0511..846d5a3 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "autoprefixer": "6.7.7", "debug": "4.1.0", "ejs": "2.5.6", + "gh-pages": "2.0.1", "glob": "7.1.1", "lodash": "4.17.11", "metalsmith": "1.7.0",