You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.8 KiB
82 lines
2.8 KiB
#!/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的入口欧,传入命令行参数执行解析
|