-
Notifications
You must be signed in to change notification settings - Fork 41
/
cmd.js
74 lines (65 loc) · 2.01 KB
/
cmd.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
69
70
71
72
73
74
var fs = require('fs');
var path = require('path');
var log = hexo.log;
var config = require('./config');
var sync = require('./sync');
var package_info = require('./package.json');
var commands = module.exports = function() {
return commands;
};
var mkcdndir = function (dirpath) {
fs.exists(dirpath, function(exists){
if (!exists) {
fs.mkdirSync(dirpath);
}
});
};
var local_dir = config.local_dir ? config.local_dir : 'cdn';
mkcdndir(local_dir);
mkcdndir(path.join(local_dir, config.image.folder));
mkcdndir(path.join(local_dir, config.js.folder));
mkcdndir(path.join(local_dir, config.css.folder));
commands.sync = function(){
if (config.access_key && config.secret_key && config.bucket) {
sync.sync();
} else {
console.log('Qiniu config is not complete.\nCan\'t Sync.'.red);
}
};
commands.sync2 = function(){
if (config.access_key && config.secret_key && config.bucket) {
sync.sync2();
} else {
console.log('Qiniu config is not complete.\nCan\'t Sync.'.red);
}
};
commands.info = function(){
console.log('Plugin name'.bold + ': ' + package_info.name);
console.log('Version'.bold + ': ' + package_info.version);
console.log('Author'.bold + ': ' + package_info.author.name);
console.log('Github'.bold + ': ' + package_info.repository.url);
console.log('Bugs'.bold + ': ' + package_info.bugs.url);
};
hexo.on('ready', sync.unsymlink);
hexo.on('exit', sync.unsymlink);
if(config.offline){
log.w('qiniu sync is offline mode');
hexo.on('generateAfter', function(){
sync.symlink(true);
});
hexo.on('server', function(){
sync.symlink(false);
});
}else{
if(config.sync){
hexo.on('generateBefore', sync.scan);
hexo.on('generateAfter', sync.scan_end);
hexo.on('server', sync.watch);
}else{
log.w('qiniu sync is off');
hexo.on('server', function(){
sync.symlink(false);
});
}
hexo.on('deployBefore',sync.unsymlink);
}