123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- const { exec, execSync } = require('child_process');
- const readline = require('readline').createInterface({
- //引入模块以便在命令行获取输入内容
- input: process.stdin,
- output: process.stdout,
- });
- /**
- * 上传git
- */
- function execFun() {
- // try {
- // execSync('git pull');
- // execSync('git add .');
- // execSync('git commit -m "提交"');
- // execSync('git push');
- // console.log('上传git---完成');
- // } catch (e) {
- // console.log('上传git---失败');
- // console.error(e);
- // }
- execSync('git pull');
- exec('git status', (err, stream) => {
- if (err) return console.err(err);
- // 获取当前已修改文件列表
- const list = stream.split('\n') || [];
- let haveAdd = false;
- for (let i = 0; i < list.length; i++) {
- const v = list[i];
- haveAdd = /Changes not staged for commit:/.test(v);
- if (haveAdd) break;
- }
- readline.question('请输入提交内容:', Input => {
- execSync('git add .');
- exec(`git commit -m ${Input || '提交'}`, err => {
- if (err)
- return console.log(`git commit -m ${Input || '提交'} 报错:`, err);
- exec(`git push`, err => {
- if (err) return console.log(err);
- readline.close(); //关闭对话
- });
- });
- });
- });
- }
- execFun();
|