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 () => { module.exports = {
if (haveGit) { up() {
exec('git remote', function (error, stdout, stderr) { async () => {
// 获取命令执行的输出 if (haveGit) {
if (error) { exec('git remote', function (error, stdout, stderr) {
console.log(error); // 获取命令执行的输出
reject(error); if (error) {
return; 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;
} }
}]).then(async answers => { // 所有的源
exec('git remote add ' + answers.name + ' ' + answers.url, function (error, stdout, stderr) { let origin = stdout.split('\n').slice(0, stdout.split('\n').length - 1);
if (error) { console.log(origin);
console.log(error); if (origin.length == 0) {
reject(error); inquirer.prompt([{
return; type: 'input', // 问题类型,包括input,number,confirm,list,rawlist,password
} name: 'name',
console.log('添加成功'); message: '源名字', // 问题
}) default: '', // 默认值
}) validate: (input) => {
return; if (input.length == 0) {
} return '请输入源名字';
inquirer.prompt([{ }
type: 'confirm', // 问题类型,包括input,number,confirm,list,rawlist,password return true;
name: 'all', }
message: '是否提交所有源', // 问题 }, {
default: true // 默认值 type: 'input', // 问题类型,包括input,number,confirm,list,rawlist,password
}]).then(async answers => { name: 'url',
if (answers.all) { message: '源url', // 问题
// 所有源提交 default: '', // 默认值
let branch = await getBranch(); //当前分支 validate: (input) => {
for (let i = 0; i < origin.length; i++) { if (input.length == 0) {
const o = origin[i]; return '请输入源url';
let isclean = await isClean(); }
if (!isclean) { return true;
await git_util.all('sa', o, branch); }
} else { }]).then(async answers => {
await git_util.push(o, branch); 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([{ inquirer.prompt([{
type: 'checkbox', // 问题类型,包括input,number,confirm,list,rawlist,password type: 'confirm', // 问题类型,包括input,number,confirm,list,rawlist,password
choices: origin, name: 'all',
name: 'choices', message: '是否提交所有源', // 问题
message: '请选择一个源提交', // 问题
default: true // 默认值 default: true // 默认值
}]).then(async answers => { }]).then(async answers => {
console.log(answers.choices); if (answers.all) {
let ooo = answers.choices; // 所有源提交
let branch = await getBranch(); //当前分支 let branch = await getBranch(); //当前分支
for (let i = 0; i < ooo.length; i++) { for (let i = 0; i < origin.length; i++) {
const o = ooo[i]; const o = origin[i];
let isclean = await isClean(); let isclean = await isClean();
if (!isclean) { if (!isclean) {
await git_util.all('sa', o, branch); await git_util.all('sa', o, branch);
} else { } else {
await git_util.push(o, branch); 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) {
} else { // 获取命令执行的输出
exec('git init', function (error, stdout, stderr) { if (error) {
// 获取命令执行的输出 console.log(error);
if (error) { reject(error);
console.log(error); return;
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", "version": "1.0.0",
"description": "", "description": "",
"main": "app.js", "main": "app.js",
@ -7,9 +7,7 @@
"type": "git", "type": "git",
"url": "http://git.poorman.top/topuser/eyc.git" "url": "http://git.poorman.top/topuser/eyc.git"
}, },
"scripts": { "scripts": {},
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [], "keywords": [],
"author": "", "author": "",
"license": "ISC", "license": "ISC",

3
readme

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