From d76eaa1976feb52ba3f62aa106ac2f0991b1e7b8 Mon Sep 17 00:00:00 2001 From: Sune Simonsen Date: Tue, 30 Oct 2018 19:57:43 +0100 Subject: [PATCH 1/3] Replace deploy-site with gh-pages --- bin/deploy-site | 31 +++++++++++++++++++++++++++++++ bin/deploy-site.sh | 34 ---------------------------------- package.json | 1 + 3 files changed, 32 insertions(+), 34 deletions(-) create mode 100755 bin/deploy-site delete mode 100755 bin/deploy-site.sh diff --git a/bin/deploy-site b/bin/deploy-site new file mode 100755 index 0000000..dce2de6 --- /dev/null +++ b/bin/deploy-site @@ -0,0 +1,31 @@ +#!/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 = JSON.parse(fs.readFileSync(packageJson, 'utf-8')).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 f2b2369..58bea2c 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "autoprefixer": "6.7.7", "debug": "2.6.4", "ejs": "2.5.6", + "gh-pages": "2.0.1", "glob": "7.1.1", "lodash": "4.17.4", "metalsmith": "1.7.0", From 28359e6720ea82b4510d048962b7bcfdf0e3096b Mon Sep 17 00:00:00 2001 From: Sune Simonsen Date: Tue, 30 Oct 2018 20:00:34 +0100 Subject: [PATCH 2/3] Added an npmrc file --- .npmrc | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .npmrc diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..caa445c --- /dev/null +++ b/.npmrc @@ -0,0 +1,2 @@ +save-prefix='' +package-lock=false From 5fd784f8761e214eda707219d0be4d6214ecee28 Mon Sep 17 00:00:00 2001 From: Sune Simonsen Date: Tue, 30 Oct 2018 21:14:53 +0100 Subject: [PATCH 3/3] Address feedback --- .npmrc | 2 +- bin/deploy-site | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.npmrc b/.npmrc index caa445c..4fef437 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1,2 @@ -save-prefix='' +save-exact=true package-lock=false diff --git a/bin/deploy-site b/bin/deploy-site index dce2de6..be00bea 100755 --- a/bin/deploy-site +++ b/bin/deploy-site @@ -1,7 +1,7 @@ #!/usr/bin/env node const ghPages = require('gh-pages'); const path = require('path'); -const fs = require("fs"); +const fs = require('fs'); const childProcess = require('child_process'); const packageJson = path.join(process.cwd(), 'package.json'); @@ -11,14 +11,13 @@ if (!fs.existsSync(packageJson)) { process.exit(1); } -const scripts = JSON.parse(fs.readFileSync(packageJson, 'utf-8')).scripts +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) {