浏览代码

enhanced remove and add

production
Pradeep Bhaskaran 4 年前
父节点
当前提交
2dce1afa85
共有 1 个文件被更改,包括 96 次插入0 次删除
  1. 96
    0
      index.js

+ 96
- 0
index.js 查看文件

, 'is-git-repo' : (dir)=>{ , 'is-git-repo' : (dir)=>{
return nodeShellExec('git', ['-C', dir.name, 'rev-parse'], { stdio : 'ignore'}) return nodeShellExec('git', ['-C', dir.name, 'rev-parse'], { stdio : 'ignore'})
} }
, 'add' : (remotename, url) => {
remotename = remotename || processedArgs._[1]
url = url || processedArgs._[2]
var branch = 'master';
var serial_perform_git_add = (repo)=>{
var options = { cwd : repo }
// console.log(repo)
return [
['git', ['remote', 'add', remotename, url + '/' + repo], { cwd : repo }]
, ['git', ['pull', remotename, branch], { cwd : repo }]
, ['git', ['branch', `--set-upstream-to=${remotename}/${branch}`, branch], { cwd : repo }]
]
}
var x = (args)=>{
return ()=>{
// console.log(args)
return nodeShellExec.apply(null, args)
}
// return Promise.resolve(true)
}
var perform_git_add = (dir)=>{
op['is-git-repo'](dir).then((code)=>{
// console.log(code)
if(code) {
nodeShellExec('git',['remote', 'get-url', remotename], { cwd : dir.name, stdio : 'ignore' }).then(()=>{
console.log('skipped : ' + dir.name + ', reason : No remote named origin')
})
.catch((e)=>{
any( serial_perform_git_add(dir.name).map(x) )
})
}
// else console.log('Skipped : Not a Git Repo : ' + dir.name)
}).catch((e)=>{
// console.log('Failed : ' + dir.name)
})
}

const { readdir } = require("fs").promises

const dirs = async (perform, path) => {
for (const dir of await readdir(path || process.cwd(), { withFileTypes: true })) {
if (dir.isDirectory()) perform(dir)
}
}

dirs(perform_git_add)
}
, 'remove' : (remotename) => {
remotename = remotename || processedArgs._[1]
var serial_perform_git_remove = (repo)=>{
var options = { cwd : repo }
// console.log(repo)
return [
['git', ['remote', 'remove', remotename], { cwd : repo }]
]
}
var x = (args)=>{
return ()=>{
// console.log(args)
return nodeShellExec.apply(null, args)
}
// return Promise.resolve(true)
}
var perform_git_remove = (dir)=>{
op['is-git-repo'](dir).then((code)=>{
// console.log(code)
if(code) {
nodeShellExec('git',['remote', 'get-url', remotename], { cwd : dir.name, stdio : 'ignore' }).then(()=>{
any( serial_perform_git_remove(dir.name).map(x) )
})
.catch((e)=>{
console.log('skipped : ' + dir.name + ', reason : No remote named origin')
})
}
// else console.log('Skipped : Not a Git Repo : ' + dir.name)
}).catch((e)=>{
// console.log('Failed : ' + dir.name)
})
}

const { readdir } = require("fs").promises

const dirs = async (perform, path) => {
for (const dir of await readdir(path || process.cwd(), { withFileTypes: true })) {
if (dir.isDirectory()) perform(dir)
}
}

dirs(perform_git_remove)
}
, 'init-gitea' : (user) => { , 'init-gitea' : (user) => {
user = user || processedArgs._[1] user = user || processedArgs._[1]
if(!user) throw 'User name required' if(!user) throw 'User name required'
} }
) )
} }
, 'isInstalled' : ()=>{
return nodeShellExec('where', [processedArgs._[1]], { inherit : true} ).then(()=>{
console.log(processedArgs._[1] + ' exists.')
return true;
});
}
, 'npmi' : ()=>{ , 'npmi' : ()=>{
var tasks = []; var tasks = [];
gitRepos.forEach(repo => { gitRepos.forEach(repo => {

正在加载...
取消
保存