52 changed files with 736 additions and 451 deletions
@ -0,0 +1,82 @@ |
|||||
|
#!/usr/bin/env node |
||||
|
|
||||
|
const inquirer = require('inquirer'); |
||||
|
const program = require('commander'); |
||||
|
const util = require('../util') |
||||
|
const git_util = require('../git_util.js'); |
||||
|
program |
||||
|
.version(require('../package.json').version, '-v, --version') // 定义版本信息 |
||||
|
.usage('<command> [options]'); // 定义命令用法 |
||||
|
|
||||
|
program |
||||
|
.command('check <command> [options]', { |
||||
|
noHelp: false, |
||||
|
isDefault: true |
||||
|
}) |
||||
|
.description('检查状态') // 给rm命令添加描述信息,获取命令帮助信息的时候会显示 |
||||
|
.option('--rb', '查看远程分支') |
||||
|
.action(async (options, cmd) => { // 对应命令的处理函数 |
||||
|
let currentPath = process.cwd(); |
||||
|
|
||||
|
let isClean = await util._isClean(); |
||||
|
console.log('当前节点是否干净?', isClean); |
||||
|
let branch = await util._getBranch(); |
||||
|
console.log('当前所在分支:', branch); |
||||
|
let remote = await util._getAllRemote(); |
||||
|
console.log('所有远程源:', remote); |
||||
|
if (cmd.rb) { |
||||
|
console.log('所有分支'); |
||||
|
let info = await util.exec('git branch -a'); |
||||
|
console.log(info); |
||||
|
} |
||||
|
// let info = await util.exec('git status'); |
||||
|
}); |
||||
|
|
||||
|
program |
||||
|
.command('sync') |
||||
|
.description('提交所有源') |
||||
|
.action(async (options, cmd) => { // 对应命令的处理函数 |
||||
|
// let currentPath = process.cwd(); |
||||
|
let remote = await util._getAllRemote(); |
||||
|
if (remote.length > 0) { |
||||
|
console.log('所有远程源:', remote); |
||||
|
inquirer.prompt([{ |
||||
|
type: 'confirm', // 问题类型,包括input,number,confirm,list,rawlist,password |
||||
|
name: 'all', |
||||
|
message: '是否提交所有源', // 问题 |
||||
|
default: true // 默认值 |
||||
|
}]).then(async answers => { |
||||
|
if (answers.all) { |
||||
|
// 所有源提交 |
||||
|
inquirer.prompt([{ |
||||
|
type: 'input', |
||||
|
name: 'msg', |
||||
|
message: '请输入需要提交的消息', // 问题 |
||||
|
default: '', // 默认值 |
||||
|
validate: (input) => { |
||||
|
if (input.length == 0) { // |
||||
|
return '消息不能为空' |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
}]).then(async answers => { |
||||
|
let msg = answers.msg; |
||||
|
let branch = await util._getBranch();; //当前分支 |
||||
|
for (let i = 0; i < remote.length; i++) { |
||||
|
const o = remote[i]; |
||||
|
let isclean = await util._isClean(); |
||||
|
if (!isclean) { |
||||
|
await git_util.all(msg, o, branch); |
||||
|
} else { |
||||
|
await git_util.push(o, branch); |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
}) |
||||
|
} else { |
||||
|
console.log('请添加源'); |
||||
|
} |
||||
|
// let info = await util.exec('git status'); |
||||
|
}); |
||||
|
program.parse(process.argv); // commander的入口欧,传入命令行参数执行解析 |
@ -1,3 +1,6 @@ |
|||||
## 自用的 请勿下载 |
## 自用的 请勿下载 |
||||
|
|
||||
自用GIT一键多源提交 |
自用的 请勿下载, GIT一键多源提交 |
||||
|
|
||||
|
V 1.0.* |
||||
|
项目雏形,逐步完善,不升到版本2以上表示不能使用 |
@ -0,0 +1,59 @@ |
|||||
|
const exec = require('child_process').exec; |
||||
|
module.exports = { |
||||
|
exec(command) { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
exec(command, function (error, stdout, stderr) { |
||||
|
if (error) { |
||||
|
reject(error); |
||||
|
} else resolve(stdout); |
||||
|
}) |
||||
|
}) |
||||
|
}, |
||||
|
_isClean() { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
exec('git status', function (error, stdout, stderr) { |
||||
|
if (error) { |
||||
|
console.log(error); |
||||
|
reject(error); |
||||
|
return; |
||||
|
} |
||||
|
let str = stdout.replace(/( |\\n)/g, ''); |
||||
|
// console.log(str);
|
||||
|
let isClean = str.indexOf('clean') != -1; |
||||
|
resolve(isClean); |
||||
|
}) |
||||
|
}) |
||||
|
}, |
||||
|
_getBranch() { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
exec('git branch', function (error, stdout, stderr) { |
||||
|
if (error) { |
||||
|
reject(error); |
||||
|
return; |
||||
|
} |
||||
|
let branches = stdout.split('\n').slice(0, stdout.split('\n').length - 1); |
||||
|
branches = branches.filter(v => { |
||||
|
if (v.indexOf('*') != -1) { |
||||
|
return true; |
||||
|
} else { |
||||
|
return false; |
||||
|
} |
||||
|
}) |
||||
|
let currentBranch = branches[0].slice(2); |
||||
|
resolve(currentBranch); |
||||
|
}); |
||||
|
}) |
||||
|
}, |
||||
|
_getAllRemote() { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
exec('git remote', function (error, stdout, stderr) { |
||||
|
if (error) { |
||||
|
reject(error); |
||||
|
return; |
||||
|
} |
||||
|
let origin = stdout.split('\n').slice(0, stdout.split('\n').length - 1); |
||||
|
resolve(origin) |
||||
|
}) |
||||
|
}) |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue