Browse Source

Fixed multiple performpulls and logging

pull/4/head
pb 3 years ago
parent
commit
244e9e603b
1 changed files with 49 additions and 94 deletions
  1. 49
    94
      index.js

+ 49
- 94
index.js View File

var path = require('path'); var path = require('path');
const { isMaster } = require('cluster'); const { isMaster } = require('cluster');


var getCmd = (command, args, options)=>{
return [command, args, Object.assign({
inherit : true, shell: true, title : `${command} `
}, options)
]
}


var getPullCmd = (repo)=>{ var getPullCmd = (repo)=>{
// console.log(useGitPull) // console.log(useGitPull)


var pullCmd = [ gitInstallDir var pullCmd = [ gitInstallDir
, ['-c', 'for i in `git remote`; do git pull $i master; done;']
, ['-c', 'branch=`git rev-parse --abbrev-ref HEAD`;for i in `git remote`; do git pull $i $branch; done;']
, { cwd : repo, title : 'pull all origins for ' + repo }] , { cwd : repo, title : 'pull all origins for ' + repo }]
// var pullCmd = ['pullall', [], { cwd : repo }] // var pullCmd = ['pullall', [], { cwd : repo }]
if(useGitPull) pullCmd = ['git', ['pull'], { if(useGitPull) pullCmd = ['git', ['pull'], {
return pullCmd return pullCmd
} }


var getCmd = (command, args, options)=>{
return [command, args, Object.assign({
inherit : true, shell: true, title : `${command} `
}, options)
]
}

var performPull = (repo) => {

if(exludeMergeRepos[repo]) return Promise.resolve({ 'skipped' : true })


var performPull = (repo) => {
if(existsSync(repo)) { if(existsSync(repo)) {
console.log('pulling ' + repo) console.log('pulling ' + repo)
return nodeShellExec.apply(null, getPullCmd(repo)).catch((e)=>{ console.error(e) })
return nodeShellExec.apply(null, getPullCmd(repo)).then(()=>{
if(__isElevated) {
fs.writeFileSync('run.log', ', ' + JSON.stringify({ repo, success:true}), {'flag':'a+'} )
}
else statuslog.statuslog(null, repo)
return true;
})
.catch((e)=>{
e.repo = repo;
if(__isElevated) {
fs.writeFileSync('run.log', ', ' + JSON.stringify(e), {'flag':'a+'} )
}
else statuslog.statuslog(e); console.error(e)
})
} }
else { else {
console.log('cloning ' + repo) console.log('cloning ' + repo)
inherit : true, shell: true, inherit : true, shell: true,
env: process.env env: process.env
, runas : processedArgs.runas , runas : processedArgs.runas
}).catch((e)=>{ console.error(e) }).then(()=>{
}).catch((e)=>{
throw e;
}).then(()=>{


return nodeShellExec('git', ['config', '--replace-all' , 'core.symlinks', true], return nodeShellExec('git', ['config', '--replace-all' , 'core.symlinks', true],
{ {
, runas : processedArgs.runas , runas : processedArgs.runas
, title : `git core.symlinks --replace-all true for ${defaultRepoServer + `/${defaultRepoOwner}/` + repo + '.git'}` , title : `git core.symlinks --replace-all true for ${defaultRepoServer + `/${defaultRepoOwner}/` + repo + '.git'}`
}) })
.then(()=>{
if(__isElevated) {
fs.writeFileSync('run.log', ', ' + JSON.stringify({ repo, success:true}), {'flag':'a+'} )
}
else statuslog.statuslog(null, repo)
})
.catch((e)=>{
e.repo = repo;
if(__isElevated) {
fs.writeFileSync('run.log', ', ' + JSON.stringify(e), {'flag':'a+'} )
}
else statuslog.statuslog(e);
})
})
.catch(e=>{
e.repo = repo;
if(__isElevated) {
fs.writeFileSync('run.log', ', ' + JSON.stringify(e), {'flag':'a+'} )
}
else statuslog.statuslog(e);
}) })
} }
} }
var args = [__dirname + '/windowselevate.hta'].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self'); var args = [__dirname + '/windowselevate.hta'].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self');
args.push('--nodepath='+r[r.length-1]) args.push('--nodepath='+r[r.length-1])
args.push('--node_env='+env.NODE_ENV) args.push('--node_env='+env.NODE_ENV)
if(_.debug) args.push('--debug=true') // Enable to debug elevated..
if(processedArgs.debug) args.push('--debug=true') // Enable to debug elevated..


return nodeShellExec('MSHTA', [`"${args.join('" "')}"`] return nodeShellExec('MSHTA', [`"${args.join('" "')}"`]
, { , {
console.log('Running exlr pull : ' + path.dirname(__dirname)) console.log('Running exlr pull : ' + path.dirname(__dirname))


var useGitPull = processedArgs.useGitPull || false; var useGitPull = processedArgs.useGitPull || false;
var getPullCmd = (repo)=>{
// console.log(useGitPull)

var pullCmd = [ gitInstallDir
, ['-c', 'branch=`git rev-parse --abbrev-ref HEAD`;for i in `git remote`; do git pull $i $branch; done;']
, { cwd : repo, title : 'pull all origins for ' + repo }]
// var pullCmd = ['pullall', [], { cwd : repo }]
if(useGitPull) pullCmd = ['git', ['pull'], {
inherit : true, shell: true,
cwd : repo
// , env: process.env
, runas : processedArgs.runas
, title : `git pull ${repo}`
}]
return pullCmd
}

var performPull = (repo) => {
if(existsSync(repo)) {
console.log('pulling ' + repo)
return nodeShellExec.apply(null, getPullCmd(repo)).then(()=>{
if(__isElevated) {
fs.writeFileSync('run.log', ', ' + JSON.stringify({ repo, success:true}), {'flag':'a+'} )
}
else statuslog.statuslog(null, repo)
return true;
})
.catch((e)=>{
e.repo = repo;
if(__isElevated) {
fs.writeFileSync('run.log', ', ' + JSON.stringify(e), {'flag':'a+'} )
}
else statuslog.statuslog(e); console.error(e)
})
}
else {
// PB : TODO -- detect if a clonable repo exists in currentGitAuthUser
return nodeShellExec('git', ['clone', '-c', 'core.symlinks=true', defaultRepoServer + `/${defaultRepoOwner}/` + repo + '.git'],
{
inherit : true, shell: true,
env: process.env
, runas : processedArgs.runas
}).catch((e)=>{
throw e;
}).then(()=>{

return nodeShellExec('git', ['config', '--replace-all' , 'core.symlinks', true],
{
inherit : true, shell: true,
env: process.env
, cwd : repo
, runas : processedArgs.runas
, title : `git core.symlinks --replace-all true for ${defaultRepoServer + `/${defaultRepoOwner}/` + repo + '.git'}`
})
.then(()=>{
if(__isElevated) {
fs.writeFileSync('run.log', ', ' + JSON.stringify({ repo, success:true}), {'flag':'a+'} )
}
else statuslog.statuslog(null, repo)
})
.catch((e)=>{
e.repo = repo;
if(__isElevated) {
fs.writeFileSync('run.log', ', ' + JSON.stringify(e), {'flag':'a+'} )
}
else statuslog.statuslog(e);
})
})
.catch(e=>{
e.repo = repo;
if(__isElevated) {
fs.writeFileSync('run.log', ', ' + JSON.stringify(e), {'flag':'a+'} )
}
else statuslog.statuslog(e);
})
}
}


if(__isElevated){ if(__isElevated){
return any(elevatedRunasRepos.map((repo)=>performPull(repo))).then(()=>{ return any(elevatedRunasRepos.map((repo)=>performPull(repo))).then(()=>{
else { else {
// PB : TODO -- Rename op['runas'] to 'elevate' // PB : TODO -- Rename op['runas'] to 'elevate'
return op['runas']().then(()=>{ return true; }) return op['runas']().then(()=>{ return true; })
.catch(()=>{})
.catch((e)=>{
console.error(e)
})
.finally(()=>{ .finally(()=>{
if(!processedArgs.runas) { if(!processedArgs.runas) {
var pendingpulls = []; var pendingpulls = [];

Loading…
Cancel
Save