1549469775 5 years ago
parent
commit
7ec318d6e2
  1. 186
      app.js
  2. 6
      package.json
  3. 3
      readme

186
app.js

@ -55,104 +55,108 @@ function getBranch() {
})
}
(async () => {
if (haveGit) {
exec('git remote', function (error, stdout, stderr) {
// 获取命令执行的输出
if (error) {
console.log(error);
reject(error);
return;
}
// 所有的源
let origin = stdout.split('\n').slice(0, stdout.split('\n').length - 1);
console.log(origin);
if (origin.length == 0) {
inquirer.prompt([{
type: 'input', // 问题类型,包括input,number,confirm,list,rawlist,password
name: 'name',
message: '源名字', // 问题
default: '', // 默认值
validate: (input) => {
if (input.length == 0) {
return '请输入源名字';
}
return true;
}
}, {
type: 'input', // 问题类型,包括input,number,confirm,list,rawlist,password
name: 'url',
message: '源url', // 问题
default: '', // 默认值
validate: (input) => {
if (input.length == 0) {
return '请输入源url';
}
return true;
module.exports = {
up() {
async () => {
if (haveGit) {
exec('git remote', function (error, stdout, stderr) {
// 获取命令执行的输出
if (error) {
console.log(error);
reject(error);
return;
}
}]).then(async answers => {
exec('git remote add ' + answers.name + ' ' + answers.url, function (error, stdout, stderr) {
if (error) {
console.log(error);
reject(error);
return;
}
console.log('添加成功');
})
})
return;
}
inquirer.prompt([{
type: 'confirm', // 问题类型,包括input,number,confirm,list,rawlist,password
name: 'all',
message: '是否提交所有源', // 问题
default: true // 默认值
}]).then(async answers => {
if (answers.all) {
// 所有源提交
let branch = await getBranch(); //当前分支
for (let i = 0; i < origin.length; i++) {
const o = origin[i];
let isclean = await isClean();
if (!isclean) {
await git_util.all('sa', o, branch);
} else {
await git_util.push(o, branch);
}
// 所有的源
let origin = stdout.split('\n').slice(0, stdout.split('\n').length - 1);
console.log(origin);
if (origin.length == 0) {
inquirer.prompt([{
type: 'input', // 问题类型,包括input,number,confirm,list,rawlist,password
name: 'name',
message: '源名字', // 问题
default: '', // 默认值
validate: (input) => {
if (input.length == 0) {
return '请输入源名字';
}
return true;
}
}, {
type: 'input', // 问题类型,包括input,number,confirm,list,rawlist,password
name: 'url',
message: '源url', // 问题
default: '', // 默认值
validate: (input) => {
if (input.length == 0) {
return '请输入源url';
}
return true;
}
}]).then(async answers => {
exec('git remote add ' + answers.name + ' ' + answers.url, function (error, stdout, stderr) {
if (error) {
console.log(error);
reject(error);
return;
}
console.log('添加成功');
})
})
return;
}
} else {
inquirer.prompt([{
type: 'checkbox', // 问题类型,包括input,number,confirm,list,rawlist,password
choices: origin,
name: 'choices',
message: '请选择一个源提交', // 问题
type: 'confirm', // 问题类型,包括input,number,confirm,list,rawlist,password
name: 'all',
message: '是否提交所有源', // 问题
default: true // 默认值
}]).then(async answers => {
console.log(answers.choices);
let ooo = answers.choices;
let branch = await getBranch(); //当前分支
for (let i = 0; i < ooo.length; i++) {
const o = ooo[i];
let isclean = await isClean();
if (!isclean) {
await git_util.all('sa', o, branch);
} else {
await git_util.push(o, branch);
if (answers.all) {
// 所有源提交
let branch = await getBranch(); //当前分支
for (let i = 0; i < origin.length; i++) {
const o = origin[i];
let isclean = await isClean();
if (!isclean) {
await git_util.all('sa', o, branch);
} else {
await git_util.push(o, branch);
}
}
} else {
inquirer.prompt([{
type: 'checkbox', // 问题类型,包括input,number,confirm,list,rawlist,password
choices: origin,
name: 'choices',
message: '请选择一个源提交', // 问题
default: true // 默认值
}]).then(async answers => {
console.log(answers.choices);
let ooo = answers.choices;
let branch = await getBranch(); //当前分支
for (let i = 0; i < ooo.length; i++) {
const o = ooo[i];
let isclean = await isClean();
if (!isclean) {
await git_util.all('sa', o, branch);
} else {
await git_util.push(o, branch);
}
}
})
}
})
}
})
});
} else {
exec('git init', function (error, stdout, stderr) {
// 获取命令执行的输出
if (error) {
console.log(error);
reject(error);
return;
});
} else {
exec('git init', function (error, stdout, stderr) {
// 获取命令执行的输出
if (error) {
console.log(error);
reject(error);
return;
}
console.log('git项目初始化成功');
});
}
console.log('git项目初始化成功');
});
}
}
})();
}

6
package.json

@ -1,5 +1,5 @@
{
"name": "git-up",
"name": "gittttup",
"version": "1.0.0",
"description": "",
"main": "app.js",
@ -7,9 +7,7 @@
"type": "git",
"url": "http://git.poorman.top/topuser/eyc.git"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"scripts": {},
"keywords": [],
"author": "",
"license": "ISC",

3
readme

@ -0,0 +1,3 @@
## 自用的 请勿下载
自用GIT一键多源提交
Loading…
Cancel
Save