1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | 'use strict'
|
15 |
|
16 | const argx = require('argx')
|
17 | const path = require('path')
|
18 | const colorprint = require('colorprint')
|
19 | const co = require('co')
|
20 | const gitHelper = require('./helpers/git_helper')
|
21 | const fsHelper = require('./helpers/fs_helper')
|
22 |
|
23 |
|
24 | function deployWiki (src, url, options) {
|
25 | let args = argx(arguments)
|
26 | src = args.shift('string')
|
27 | url = args.shift('string')
|
28 | if (args.pop('function')) {
|
29 | throw new Error('[ape-deploying] Callback is no longer supported. Use promise instead.')
|
30 | }
|
31 | options = args.pop('object') || {}
|
32 |
|
33 | let clean = !!options.clean
|
34 | let commitMsg = options.commitMsg || 'Update wiki.'
|
35 | let tmpDir = options.tmpDir || 'tmp'
|
36 |
|
37 | let localRepo = path.resolve(tmpDir, `deploy-wiki-${new Date().getTime()}`)
|
38 | return co(function * () {
|
39 | let exists = yield fsHelper.existsAsync(src)
|
40 | if (!exists) {
|
41 | throw new Error(`Directory not exists: ${src}`)
|
42 | }
|
43 |
|
44 | yield gitHelper.cloneTo(url, localRepo)
|
45 |
|
46 | if (clean) {
|
47 | yield fsHelper.cleanDir(localRepo, {
|
48 | ignore: '.git'
|
49 | })
|
50 | }
|
51 |
|
52 | yield fsHelper.copyDir(src, localRepo)
|
53 | let changed = yield gitHelper.hasChange(localRepo)
|
54 | if (changed) {
|
55 | yield gitHelper.pushGit(localRepo, commitMsg)
|
56 | } else {
|
57 | colorprint.warn('Nothing to push.')
|
58 | }
|
59 | yield fsHelper.rimrafAsync(localRepo)
|
60 | })
|
61 | }
|
62 |
|
63 | module.exports = deployWiki
|