-
Notifications
You must be signed in to change notification settings - Fork 74
/
sync_deploy_history.js
52 lines (43 loc) · 1.41 KB
/
sync_deploy_history.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
// Thanks to @Aetf
'use strict';
const pathFn = require('path');
const fs = require('fs');
const parseConfig = require('hexo-deployer-git/lib/parse_config');
const spawn = require('hexo-util/lib/spawn');
const Hexo = require('hexo');
async function sync_deploy_history() {
console.log('\nSync start...');
// Hexo context
const hexo = new Hexo(process.cwd(), { silent: true });
await hexo.init();
const deployDir = pathFn.join(hexo.base_dir, '.deploy_git');
// For git cmd
function git(...args) {
return spawn('git', args, {
verbose: true,
stdio: 'inherit'
});
}
// Get multi deployer configurations as array
let deployConfigs = hexo.config.deploy;
if (!Array.isArray(deployConfigs)) {
deployConfigs = [deployConfigs];
}
// Parse repo from configs and pull repo
deployConfigs.forEach(async deployConfig => {
if (deployConfig.type !== 'git') {
console.log(`Skip deployer: ${deployConfig.type}.`);
return;
}
const repos = parseConfig(deployConfig);
if (repos.length > 1) {
console.error(`Given too much repos: ${repos.length}.`);
throw new TypeError('Only single repo is supported!');
}
console.log(`Located a single repo: ${repos[0].url},${repos[0].branch}.`);
const result = await git('clone', '--branch', repos[0].branch, repos[0].url, deployDir);
console.log(result);
});
console.log('Sync done\n');
}
sync_deploy_history();