-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdeploy.js
37 lines (33 loc) · 1.09 KB
/
deploy.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
'use strict';
const path = require('path');
const chalk = require('chalk');
const { execSync } = require('child_process');
const rootDir = path.join('.');
const ERROR_CODE = 255;
/**
* 提交代码到分支
*
* @param {String} branch 分支名
*/
function push(branch) {
const execOptions = {
cwd: rootDir,
};
console.log('Start to push code to github.');
try {
execSync(`git pull origin ${branch}`, execOptions);
execSync('git add .', execOptions);
execSync(`git commit -m "yuque auto update"`, execOptions);
execSync(`git push -u [email protected]:txd-team/monthly.git HEAD:${branch}`, execOptions);
} catch(error) {
console.log(chalk.yellow(error.message));
console.log(chalk.yellow('There are some exceptions during push code to github, please manually check it.'));
if (error.message.startsWith('Command failed: git commit -m')) {
console.log(chalk.yellow('Almost it is caused by that there isn\'t any changes of repository'));
return process.exit(0);
}
process.exit(ERROR_CODE);
}
console.log('Push code to github done!');
}
push('master');