-
Notifications
You must be signed in to change notification settings - Fork 66
/
backup.js
executable file
·68 lines (57 loc) · 1.54 KB
/
backup.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var async = require('async'),
fs = require('graceful-fs'),
_ = require('lodash');
git = require('./git');
module.exports = function(args, callback){
var config = this.config.backup,
log = this.log,
backupers = this.extend.deployer.list(),
self = this;
if (!config){
var help = '';
help += 'You should configure backupment settings in _config.yml first!\n\n';
help += 'Available Types:\n';
help += ' ' + Object.keys(backupers).join(', ') + '\n\n';
help += 'For more help, you can check the online docs: ' + 'http://hexo.io/'.underline;
console.log(help);
return callback();
}
if (!Array.isArray(config)) config = [config];
var onBackupStarted = function() {
/**
* Fired before backupment.
*
* @event backupBefore
* @for Hexo
*/
self.emit('backupBefore');
};
var onBackupFinished = function(err) {
/**
* Fired after backupment.
*
* @event backupAfter
* @param {Error} err
* @for Hexo
*/
self.emit('backupAfter', err);
callback(err);
};
onBackupStarted();
// console.log(item);
// console.log(args);
async.eachSeries(config, function(item, next){
var type = item.type;
if (type != "git"){
log.e('backuper not found: ' + type);
// return next();
} else {
log.i('Start backup: ' + type);
}
git(_.extend({}, item, args), self,function(err){
if (err) return next(err);
log.i('Backup done: ' + type);
next();
});
}, onBackupFinished);
};