-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish-docs
34 lines (29 loc) · 1.15 KB
/
publish-docs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const execSync = require('child_process').execSync
const spawnSync = require('child_process').spawnSync
const exit = require('process').exit
const resolve = require('path').resolve
const fs = require('fs-promise')
const docsPath = resolve('docs')
const docsGit = resolve('docs/.git')
const version = require('./package.json').version
const repository = require('./package.json').repository.url
const executeCommand = (command, args) => {
const result = spawnSync(command, args, { cwd: docsPath, encoding: 'utf8' })
if (result.status === 0) {
console.log(result.stdout)
} else {
console.log(result.stderr)
exit(result.status)
}
}
fs.removeSync(docsPath)
fs.mkdir(docsPath)
executeCommand('git', ['init'])
executeCommand('git', ['remote', 'add', 'origin', repository + '.git'])
executeCommand('git', ['checkout', '-b', 'gh-pages'])
executeCommand('git', ['pull', 'origin', 'gh-pages'])
execSync('npm run docs', {encoding: 'utf8'})
executeCommand('git', ['add', '.'])
executeCommand('git', ['commit', '-m', 'chore(docs): release docs for v' + version + ''])
executeCommand('git', ['push', 'origin', 'gh-pages'])
fs.removeSync(docsGit)