-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(scripts): deploy document by travis (eggjs#325)
Use nodejs rewrite doc tools, and support auto publish gh-pages on travis. Only run publishing when commit to master branch. Closes eggjs#86
- Loading branch information
Showing
9 changed files
with
120 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const fs = require('mz/fs'); | ||
const co = require('co'); | ||
const rimraf = require('rimraf'); | ||
const runscript = require('runscript'); | ||
const ghpages = require('gh-pages'); | ||
|
||
// The branch that pushing document | ||
const BRANCH = 'gh-pages'; | ||
const DOC_PUBLISHER_NAME = 'Auto Doc Publisher'; | ||
const DOC_PUBLISHER_EMAIL = '[email protected]'; | ||
const command = process.argv[2]; | ||
|
||
co(function* () { | ||
const exists = yield fs.exists('node_modules'); | ||
if (!exists) { | ||
throw new Error('should run `npm install` first'); | ||
} | ||
|
||
console.log('Copying CONTRIBUTING.md'); | ||
yield copyFile('CONTRIBUTING.md', 'docs/source/contributing.md'); | ||
yield copyFile('CONTRIBUTING.zh-CN.md', 'docs/source/zh-cn/contributing.md'); | ||
|
||
yield rm('docs/public'); | ||
yield runscript('npminstall', { cwd: 'docs' }); | ||
|
||
switch (command) { | ||
case 'server': | ||
yield runscript('hexo --cwd docs server -l'); | ||
break; | ||
case 'build': | ||
yield runscript('hexo --cwd docs generate --force'); | ||
break; | ||
case 'deploy': | ||
yield runscript('hexo --cwd docs generate --force'); | ||
yield deploy(); | ||
break; | ||
default: | ||
} | ||
}).catch(err => { | ||
console.error(err.stack); | ||
process.exit(1); | ||
}); | ||
|
||
function* deploy() { | ||
console.log('Pushing to %s', BRANCH); | ||
let repo = yield runscript('git config remote.origin.url', { stdio: 'pipe' }); | ||
repo = repo.stdout.toString().slice(0, -1); | ||
if (/^http/.test(repo)) { | ||
repo = repo.replace('https://github.com/', '[email protected]:'); | ||
} | ||
yield publish('docs/public', { | ||
logger(message) { console.log(message); }, | ||
user: { | ||
name: DOC_PUBLISHER_NAME, | ||
email: DOC_PUBLISHER_EMAIL, | ||
}, | ||
branch: BRANCH, | ||
repo, | ||
}); | ||
} | ||
|
||
function* copyFile(src, dist) { | ||
const buf = yield fs.readFile(src); | ||
yield fs.writeFile(dist, buf); | ||
} | ||
|
||
function rm(dir) { | ||
return done => rimraf(dir, done); | ||
} | ||
|
||
function publish(basePath, options) { | ||
return done => ghpages.publish(basePath, options, done); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#! /usr/bin/env bash | ||
|
||
# https://gist.github.com/domenic/ec8b0fc8ab45f39403dd#sign-up-for-travis-and-add-your-project | ||
|
||
# Only deply on master branch | ||
SOURCE_BRANCH="master" | ||
|
||
# Pull requests and commits to other branches shouldn't try to deploy, just build to verify | ||
if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then | ||
echo "Skip deploy, TRAVIS_PULL_REQUEST=$TRAVIS_PULL_REQUEST, TRAVIS_BRANCH=$TRAVIS_BRANCH" | ||
exit 0 | ||
fi | ||
|
||
# Get the deploy key by using Travis's stored variables to decrypt deploy_key.enc | ||
ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key" | ||
ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv" | ||
ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR} | ||
ENCRYPTED_IV=${!ENCRYPTED_IV_VAR} | ||
# echo "key: $ENCRYPTED_KEY, iv: $ENCRYPTED_IV" | ||
openssl aes-256-cbc -K $ENCRYPTED_KEY -iv $ENCRYPTED_IV -in scripts/deploy_key.enc -out deploy_key -d | ||
chmod 600 deploy_key | ||
eval `ssh-agent -s` | ||
ssh-add deploy_key | ||
|
||
npm run doc-deploy |
Oops, something went wrong.