|
|
|
|
|
|
|
|
|
|
|
|
|
|
var getshelltask = (args) => { |
|
|
var getshelltask = (args) => { |
|
|
return args[0] === 'rm' ? getgitbashtask(args) : () => { |
|
|
return args[0] === 'rm' ? getgitbashtask(args) : () => { |
|
|
return nodeShellExec.apply(null, args).catch(function(e){ e.benign = args[2].benign; if(!e.benign) {console.error(e); throw e} }) |
|
|
|
|
|
|
|
|
return nodeShellExec.apply(null, args).catch(function(e){ |
|
|
|
|
|
e.benign = args[2].benign; |
|
|
|
|
|
if(!e.benign) { console.error(e); } |
|
|
|
|
|
throw e |
|
|
|
|
|
}) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
var getgitbashtask = (args, onEachError) => { return () => { |
|
|
var getgitbashtask = (args, onEachError) => { return () => { |
|
|
return nodeShellExec( `"${gitbash}"`, ['-c', getCmdString(args)], args[2]).catch( onEachError || function(e){ console.error(e) }) } |
|
|
return nodeShellExec( `"${gitbash}"`, ['-c', getCmdString(args)], args[2]).catch( onEachError || function(e){ console.error(e) }) } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var getnodeshellexectask = (args) => { return () => { return nodeShellExec.apply(null, args) }} |
|
|
|
|
|
var perform = function( serailtasks, taskvector ){ return any( serailtasks(taskvector).map(getnodeshellexectask)) } |
|
|
|
|
|
|
|
|
var getTaskCheckExists = shell_verse.getTaskCheckExists |
|
|
var getTaskCheckExists = shell_verse.getTaskCheckExists |
|
|
// var getTaskWithElevation = function(tasdef){ return shell_verse.getElevatedTask( tasdef.elevatedpulltasks ) } |
|
|
// var getTaskWithElevation = function(tasdef){ return shell_verse.getElevatedTask( tasdef.elevatedpulltasks ) } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elevatedBatch = elevatedBatch || []; |
|
|
elevatedBatch = elevatedBatch || []; |
|
|
regularBatch = regularBatch || []; |
|
|
regularBatch = regularBatch || []; |
|
|
try{ |
|
|
try{ |
|
|
|
|
|
// PB : TODO -- local repo folder named the same as the remote repository name is not enough to establish existence. |
|
|
|
|
|
// This remote repo and branch may have been or may need to be added as a local tracking branch |
|
|
|
|
|
// to any other local repo folder (with a different name) |
|
|
var exists = existsSync(instanceroot + '/' + repo) |
|
|
var exists = existsSync(instanceroot + '/' + repo) |
|
|
} |
|
|
} |
|
|
catch(e){ |
|
|
catch(e){ |
|
|
|
|
|
|
|
|
etask.selectedinstance = selectedinstance |
|
|
etask.selectedinstance = selectedinstance |
|
|
etask.runtimestamp = runtimestamp |
|
|
etask.runtimestamp = runtimestamp |
|
|
etask.ENV = ENV |
|
|
etask.ENV = ENV |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function initElevatedBatch(){ |
|
|
elevatedBatch.info = { repo } |
|
|
elevatedBatch.info = { repo } |
|
|
elevatedBatch.errHandler = errHandler |
|
|
elevatedBatch.errHandler = errHandler |
|
|
elevatedBatch.statuslog = statuslog |
|
|
elevatedBatch.statuslog = statuslog |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (exists) { |
|
|
if (exists) { |
|
|
|
|
|
|
|
|
// Add the remotes |
|
|
|
|
|
var tasks = [] |
|
|
|
|
|
var selectedremotes = Array.from( new Set(selectedinstance.selectedremotes.concat(Object.keys(repodef.remotes || {})))); |
|
|
|
|
|
var repoRemotes = Object.assign( {}, selectedinstance.remotes, repodef.remotes ); |
|
|
|
|
|
selectedremotes.forEach((remotename)=>{ |
|
|
|
|
|
var ai_RemoteAddNeeded = (info)=>{ return true }; // ai prefix for all apis that require an answer if choice is needed. |
|
|
|
|
|
tasks.push( |
|
|
|
|
|
()=>{ |
|
|
|
|
|
|
|
|
|
|
|
return op['remote exists']({ |
|
|
|
|
|
remotename, repo, benign : true, ignorefailures : true |
|
|
|
|
|
, url : repoRemotes[remotename].url || processedArgs._[3] |
|
|
|
|
|
, branch : processedArgs._[4] |
|
|
|
|
|
}).then( (r) => { |
|
|
|
|
|
if(!r[1]) return false; // PB : TODO -- Not accessible skip for now probably should remove. |
|
|
|
|
|
else if(r[0]) return true; // Already added nothing to do |
|
|
|
|
|
else if(ai_RemoteAddNeeded()) return op['remote add']( { remotename, |
|
|
|
|
|
'set-upstream' : remotename === selectedinstance['upstream-remote'] //remote.upstream ??? when url accessible... in order of highest priority |
|
|
|
|
|
, url : remote.url, branch : checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV |
|
|
|
|
|
}) |
|
|
|
|
|
// else skipped as remote is not relevant for this repo... |
|
|
|
|
|
|
|
|
var tasks = []; |
|
|
|
|
|
return (()=>{ |
|
|
|
|
|
// PB : TODO -- We need a non cacheable set of properties that need to default to something but then need to escplicitly specified in each run. |
|
|
|
|
|
if(selectedinstance.addremotes) { |
|
|
|
|
|
return op['get-remotes']({repo}).then(( remotes )=>{ |
|
|
|
|
|
return op['get-upstream']({repo, remotes}).then(( upstream ) => { |
|
|
|
|
|
return __addremotesandpull({ upstream, remotes}) |
|
|
}) |
|
|
}) |
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
var branchprint = branch ? ' branch :' + branch : ''; |
|
|
|
|
|
var task = ()=>{ |
|
|
|
|
|
console.log('pulling ' + instanceroot + '/' + repo + branchprint ) |
|
|
|
|
|
return any(tasks).then( ()=>{ |
|
|
|
|
|
return nodeShellExec.apply(null, getPullCmd(repodef, branch)).then(() => { |
|
|
|
|
|
return true; |
|
|
|
|
|
}) |
|
|
}) |
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
initTask(task) |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
else return __pull(); |
|
|
|
|
|
})() |
|
|
|
|
|
|
|
|
if(repodef.requiresElevation) { |
|
|
|
|
|
elevatedBatch.push(shell_verse.getElevatedTaskInBatch( task )); |
|
|
|
|
|
if(elevatedBatch.length === 1) { initTask(elevatedBatch[0]) } // PB : TDOO -- Make sure first task also has run context. May need to be moved to win_verse |
|
|
|
|
|
return elevatedBatch[elevatedBatch.length-1] |
|
|
|
|
|
|
|
|
function __pull(){ |
|
|
|
|
|
var branchprint = branch ? ' branch :' + branch : ''; |
|
|
|
|
|
var task = ()=>{ |
|
|
|
|
|
console.log('pulling ' + instanceroot + '/' + repo + branchprint ) |
|
|
|
|
|
return any(tasks).then( ()=>{ |
|
|
|
|
|
return nodeShellExec.apply(null, getPullCmd(repodef, branch)).then(() => { |
|
|
|
|
|
return true; |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
initTask(task) |
|
|
|
|
|
|
|
|
|
|
|
if(repodef.requiresElevation) { |
|
|
|
|
|
elevatedBatch.push(shell_verse.getElevatedTaskInBatch( task )); |
|
|
|
|
|
if(elevatedBatch.length === 1) { initElevatedBatch(); initTask(elevatedBatch[0]) } // PB : TDOO -- Make sure first task also has run context. May need to be moved to win_verse |
|
|
|
|
|
else initTask(elevatedBatch[elevatedBatch.length-1]) |
|
|
|
|
|
return elevatedBatch[elevatedBatch.length-1] |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
regularBatch.push(shell_verse.getNonElevatedTask( task )) |
|
|
|
|
|
return regularBatch[regularBatch.length-1] |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
else { |
|
|
|
|
|
regularBatch.push(shell_verse.getNonElevatedTask( task )) |
|
|
|
|
|
return regularBatch[regularBatch.length-1] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function __addremotesandpull(options){ |
|
|
|
|
|
// Add the remotes |
|
|
|
|
|
var tasks = [] |
|
|
|
|
|
|
|
|
|
|
|
// selectedinstance.selectedremotes are optional and need not be enforced to be chosen. The selection for hte selected remotes |
|
|
|
|
|
// could also be derived from a crossfilter of remote-type selected for this run and the current chosen and operating reposervers. |
|
|
|
|
|
var selectedremotes = Array.from( new Set(selectedinstance.selectedremotes.concat(Object.keys(repodef.remotes || {})))); |
|
|
|
|
|
if(selectedremotes.length > 0) var selectedremoteFilter = function(rs) { return selectedremotes.find( rs.server ) } |
|
|
|
|
|
else var selectedremoteFilter = function(){ return true } |
|
|
|
|
|
|
|
|
|
|
|
var repoRemotes = Object.assign( {}, selectedinstance.remotes, options.remotes, options.upstream, repodef.remotes ); |
|
|
|
|
|
|
|
|
|
|
|
// We need a most permissive filtered list to use as an efficient starting point to further reduce to whats actually needed. |
|
|
|
|
|
// However if such a cached list is not available we need to build it by scaning and apply all the filters anyway on the whole world. |
|
|
|
|
|
|
|
|
|
|
|
Object.keys(repoRemotes).forEach((remotename)=>{ |
|
|
|
|
|
// PB : TODO -- ai prefix for all apis that require an answer amongst many choices. |
|
|
|
|
|
var ai_RemoteAddNeeded = (r)=>{ |
|
|
|
|
|
if(r.server === reposerver && selectedremoteFilter() && r.accessibility.find( selectedinstance[ 'remote-type' ] )){ // currently chosen remotetype... |
|
|
|
|
|
var exists = false; |
|
|
|
|
|
if(exists = (options.remotes[r.remotename] || Object.keys(options.remotes).find( lrn => { |
|
|
|
|
|
var exists = options.remotes[lrn].server === r.server && !options.remotes[r.remotename] |
|
|
|
|
|
if(exists) console.warn('Found duplicate remote with a different name for the same server...') |
|
|
|
|
|
return exists |
|
|
|
|
|
} )) ) { |
|
|
|
|
|
return false // Already a remote not required. |
|
|
|
|
|
} |
|
|
|
|
|
return true // PB : TODO -- Sort and display highest priority target.remotes.sort( ) |
|
|
|
|
|
} |
|
|
|
|
|
return false |
|
|
|
|
|
}; |
|
|
|
|
|
tasks.push( |
|
|
|
|
|
()=>{ |
|
|
|
|
|
return op['remote exists']({ |
|
|
|
|
|
remotename, repo, benign : true, ignorefailures : true |
|
|
|
|
|
, url : repoRemotes[remotename].url + repo |
|
|
|
|
|
, branch : checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV |
|
|
|
|
|
}).then( (r) => { |
|
|
|
|
|
if(!r[1]) return false; // PB : TODO -- Not accessible skip for now probably should remove. |
|
|
|
|
|
else if(r[0]) return true; // Already added nothing to do |
|
|
|
|
|
else if(ai_RemoteAddNeeded( repoRemotes[remotename] )) return op['remote add']( { remotename, |
|
|
|
|
|
'set-upstream' : remotename === selectedinstance['upstream-remote'] //remote.upstream ??? when url accessible... in order of highest priority |
|
|
|
|
|
, repo |
|
|
|
|
|
, url : repoRemotes[remotename].url , branch : checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV |
|
|
|
|
|
}) |
|
|
|
|
|
// else skipped as remote is not relevant for this repo... |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
__pull() |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
|
|
|
// PB : TODO -- detect if a clonable repo exists within the context of currentGitAuthUser on remote reposerver... |
|
|
console.log('cloning ' + repo) |
|
|
console.log('cloning ' + repo) |
|
|
// PB : TODO -- detect if a clonable repo exists in currentGitAuthUser |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// PB : TODO -- add additional remotes after cloning and pull again... |
|
|
|
|
|
|
|
|
var task = ()=>{ |
|
|
var task = ()=>{ |
|
|
return nodeShellExec('git', ['clone', '-c', 'core.symlinks=true', selectedinstance.reposerver + `/${repoowner || defaultRepoOwner}/` + repo + '.git'], |
|
|
return nodeShellExec('git', ['clone', '-c', 'core.symlinks=true', selectedinstance.reposerver + `/${repoowner || defaultRepoOwner}/` + repo + '.git'], |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
return regularBatch[regularBatch.length-1] |
|
|
return regularBatch[regularBatch.length-1] |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
initTask(task) |
|
|
initTask(task) |
|
|
if(repodef.requiresElevation) { |
|
|
if(repodef.requiresElevation) { |
|
|
|
|
|
|
|
|
var gitRepos = null |
|
|
var gitRepos = null |
|
|
|
|
|
|
|
|
// grep -qxF 'alias elxr="node elxr/index.js"' ~/.bash_profile || echo 'alias elxr="node elxr/index.js"' >> ~/.bash_profile |
|
|
// grep -qxF 'alias elxr="node elxr/index.js"' ~/.bash_profile || echo 'alias elxr="node elxr/index.js"' >> ~/.bash_profile |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// nodeShellExec('echo', ['elxr'], { inherit : true}) //, {stdio: "inherit"} |
|
|
// nodeShellExec('echo', ['elxr'], { inherit : true}) //, {stdio: "inherit"} |
|
|
|
|
|
|
|
|
var dbForLabel = function (label) { |
|
|
var dbForLabel = function (label) { |
|
|
|
|
|
|
|
|
, { |
|
|
, { |
|
|
benign : args.benign, ignorefailures : args.ignorefailures, |
|
|
benign : args.benign, ignorefailures : args.ignorefailures, |
|
|
evaluateResult : function(err, result){ |
|
|
evaluateResult : function(err, result){ |
|
|
// var found = result.messages.find( (r)=> { return r.includes( __args.remotename ) }) |
|
|
|
|
|
console.log(__args.remotename) |
|
|
|
|
|
var remotes = [] |
|
|
|
|
|
var found = false; |
|
|
|
|
|
if(+result.code === 0) found = true; |
|
|
|
|
|
// console.dir(result.messages) |
|
|
|
|
|
// console.log(result + '---------------') |
|
|
|
|
|
// result.messages.forEach( (line)=> { |
|
|
|
|
|
// console.log(line + '$$$$$$$$$$$$$$$$$$$$') |
|
|
|
|
|
// var matches = line.match(/(.*)?\s\s([^\(]*)?\s?\(?([^\)]*)\)?/); |
|
|
|
|
|
// if(matches) { |
|
|
|
|
|
// var remote = {}; |
|
|
|
|
|
// remote[matches[1]] = matches[2]; |
|
|
|
|
|
// if( (!matches[3].trim() || matches[3].trim() === 'fetch') && matches[1].trim() === remotename.trim()) { |
|
|
|
|
|
// found = true; |
|
|
|
|
|
// result.url = remote[remotename]; |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// }) |
|
|
|
|
|
console.dir(remotes) |
|
|
|
|
|
return [ |
|
|
return [ |
|
|
found |
|
|
|
|
|
|
|
|
+result.code === 0 |
|
|
, result |
|
|
, result |
|
|
] |
|
|
] |
|
|
} |
|
|
} |
|
|
} , options) ] |
|
|
|
|
|
, function(prevserialtaskresult) { |
|
|
|
|
|
if(!prevserialtaskresult) return [[ false, null], [ false, null]] |
|
|
|
|
|
|
|
|
|
|
|
if(!prevserialtaskresult) return [[ false, null], [ false, null]] |
|
|
|
|
|
console.log('================================') |
|
|
|
|
|
var url = __args || prevserialtaskresult.url; |
|
|
|
|
|
console.dir(prevserialtaskresult) |
|
|
|
|
|
return getshelltask(['git', ['ls-remote', url], utils.assign_core( { arraymergetype : utils.assign_core.DISTINCT_UNION } |
|
|
|
|
|
, { |
|
|
|
|
|
benign : args.benign, |
|
|
|
|
|
evaluateResult : function(err, result){ |
|
|
|
|
|
// fatal: unable to access '${__args.url}/': Failed to connect to git.bbh port 80 after 21025 ms: Timed out |
|
|
|
|
|
// `fatal: repository '${__args.url}/' not found` |
|
|
|
|
|
var hasfailed = /^fatal: .*/.test(result.messages.join(' ')) |
|
|
|
|
|
return [ |
|
|
|
|
|
!hasfailed, result |
|
|
|
|
|
] |
|
|
|
|
|
} |
|
|
|
|
|
} , options) ])().catch( e => { |
|
|
|
|
|
console.error(e) |
|
|
|
|
|
return [[ false, null], [ false, null]] |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} , options) ] |
|
|
] |
|
|
] |
|
|
var mapped = commands.map(callshelltask) //.map( p => p.catch(e => e)) // Handle errors later. |
|
|
|
|
|
return any(mapped, true).then( allresolved =>{ |
|
|
|
|
|
|
|
|
var mapped = commands.map(getshelltask) //.map( p => p.catch(e => e)) // Handle errors later. |
|
|
|
|
|
mapped.push( function(prevserialtaskresult) { |
|
|
|
|
|
var pt = [false , null] |
|
|
|
|
|
if(prevserialtaskresult.error) { |
|
|
|
|
|
// Previous task has failed. |
|
|
|
|
|
pt[1] = prevserialtaskresult.error[1] |
|
|
|
|
|
} |
|
|
|
|
|
else pt = prevserialtaskresult; |
|
|
|
|
|
|
|
|
|
|
|
console.dir(prevserialtaskresult) |
|
|
|
|
|
return getshelltask(['git', ['ls-remote', `${__args.url}`], utils.assign_core( { arraymergetype : utils.assign_core.DISTINCT_UNION } |
|
|
|
|
|
, { |
|
|
|
|
|
benign : args.benign, ignorefailures : args.ignorefailures, |
|
|
|
|
|
evaluateResult : function(err, result){ |
|
|
|
|
|
if(+result.code !== 0) return [pt, [ false, result]] |
|
|
|
|
|
// var hasfailed = /^fatal: .*/.test(result.messages.join(' ')) |
|
|
|
|
|
return [pt, [true, result] ] |
|
|
|
|
|
} |
|
|
|
|
|
} , options) ])().catch( e => { |
|
|
|
|
|
console.error(e) |
|
|
|
|
|
return [pt, [ false, null]] |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
return any(mapped, true, false, { accumulatedresults : [] }).then( allresolved => { |
|
|
|
|
|
|
|
|
console.dir(allresolved) |
|
|
console.dir(allresolved) |
|
|
!allresolved[0][0] && !allresolved[1][0] ? console.log('was not added as a remote and url is currently inaccessible.') |
|
|
!allresolved[0][0] && !allresolved[1][0] ? console.log('was not added as a remote and url is currently inaccessible.') |
|
|
|
|
|
|
|
|
var repo = dir.name |
|
|
var repo = dir.name |
|
|
var dscoverbranchcmd = gitops.getdiscoverbranchcmd(repo) |
|
|
var dscoverbranchcmd = gitops.getdiscoverbranchcmd(repo) |
|
|
try { |
|
|
try { |
|
|
var remotes = require(`${selectedinstance.root}/${dir.name}/repo-manifest.js`)( null, selectedinstance).remotes || []; |
|
|
|
|
|
|
|
|
var remotes = require(`${selectedinstance.root}/${dir.name}/repo-manifest.js`)( null |
|
|
|
|
|
, { utils, username : selectedinstance.username, instanceName : selectedinstance.instanceName |
|
|
|
|
|
, node_env : selectedinstance.node_env, reposerver : 'https://git.bbh.org.in' } // options |
|
|
|
|
|
|
|
|
|
|
|
).remotes || []; |
|
|
} |
|
|
} |
|
|
catch(e){ |
|
|
catch(e){ |
|
|
var remotes = [] |
|
|
var remotes = [] |
|
|
|
|
|
|
|
|
// args === processedArgs ? args = {} : null; |
|
|
// args === processedArgs ? args = {} : null; |
|
|
var __args = { |
|
|
var __args = { |
|
|
remotename : args.remotename|| processedArgs._[2] |
|
|
remotename : args.remotename|| processedArgs._[2] |
|
|
|
|
|
, repo : args.repo |
|
|
, url : args.url || processedArgs._[3] |
|
|
, url : args.url || processedArgs._[3] |
|
|
, branch : args.branch || processedArgs._[4] |
|
|
, branch : args.branch || processedArgs._[4] |
|
|
, 'set-upstream' : args['set-upstream'] || processedArgs._[5] |
|
|
, 'set-upstream' : args['set-upstream'] || processedArgs._[5] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var pushable = processedArgs.pushable || false; |
|
|
var pushable = processedArgs.pushable || false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var serial_perform_git_add = (repo) => { |
|
|
var serial_perform_git_add = (repo) => { |
|
|
var options = { cwd: instanceroot + '/' + repo } |
|
|
var options = { cwd: instanceroot + '/' + repo } |
|
|
// console.log(repo) |
|
|
// console.log(repo) |
|
|
|
|
|
|
|
|
] |
|
|
] |
|
|
} |
|
|
} |
|
|
if(args['set-upstream']) gacmds.push(['git', ['branch', `--set-upstream-to=${remotename}/${branch}`, branch], { cwd: instanceroot + '/' + repo }]) |
|
|
if(args['set-upstream']) gacmds.push(['git', ['branch', `--set-upstream-to=${remotename}/${branch}`, branch], { cwd: instanceroot + '/' + repo }]) |
|
|
|
|
|
return gacmds |
|
|
} |
|
|
} |
|
|
var x = (args) => { |
|
|
|
|
|
return () => { |
|
|
|
|
|
// console.log(args) |
|
|
|
|
|
return nodeShellExec.apply(null, args) |
|
|
|
|
|
} |
|
|
|
|
|
// return Promise.resolve(true) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// PB : TODO -- Accumulate using yield... and finally return a set of tasks or promises... |
|
|
var perform_git_add = (dir) => { |
|
|
var perform_git_add = (dir) => { |
|
|
op['is-git-repo'](dir).then((logEntry) => { |
|
|
op['is-git-repo'](dir).then((logEntry) => { |
|
|
// console.log(code) |
|
|
// console.log(code) |
|
|
|
|
|
|
|
|
console.log('skipped : ' + dir.name + ', reason : A remote with same name already exists.') |
|
|
console.log('skipped : ' + dir.name + ', reason : A remote with same name already exists.') |
|
|
}) |
|
|
}) |
|
|
.catch((e) => { |
|
|
.catch((e) => { |
|
|
any(serial_perform_git_add(dir.name).map(x)) |
|
|
|
|
|
|
|
|
perform( serial_perform_git_add, dir.name ) |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
// else console.log('Skipped : Not a Git Repo : ' + dir.name) |
|
|
|
|
|
|
|
|
// else console.log('Skipped : Not a Git Repo : ' + dir.name) |
|
|
}).catch((e) => { |
|
|
}).catch((e) => { |
|
|
console.log('Failed : ' + dir.name) |
|
|
console.log('Failed : ' + dir.name) |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const { readdir } = require("fs").promises |
|
|
|
|
|
|
|
|
|
|
|
dirs(perform_git_add) |
|
|
|
|
|
|
|
|
if(args.repo) { perform_git_add( { name : args.repo} ) } |
|
|
|
|
|
else return dirs(perform_git_add) |
|
|
} |
|
|
} |
|
|
, 'remote remove': (args) => { |
|
|
, 'remote remove': (args) => { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
['git', ['remote', 'remove', remotename], { cwd: instanceroot + '/' + repo }] |
|
|
['git', ['remote', 'remove', remotename], { cwd: instanceroot + '/' + repo }] |
|
|
] |
|
|
] |
|
|
} |
|
|
} |
|
|
var x = (args) => { |
|
|
|
|
|
return () => { |
|
|
|
|
|
// console.log(args) |
|
|
|
|
|
return nodeShellExec.apply(null, args) |
|
|
|
|
|
} |
|
|
|
|
|
// return Promise.resolve(true) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var perform_git_remove = (dir) => { |
|
|
var perform_git_remove = (dir) => { |
|
|
op['is-git-repo'](dir).then((logEntry) => { |
|
|
op['is-git-repo'](dir).then((logEntry) => { |
|
|
// console.log(code) |
|
|
// console.log(code) |
|
|
if (logEntry.success) { |
|
|
if (logEntry.success) { |
|
|
nodeShellExec('git', ['remote', 'get-url', remotename], { cwd: dir.name, stdio: 'ignore' }).then(() => { |
|
|
nodeShellExec('git', ['remote', 'get-url', remotename], { cwd: dir.name, stdio: 'ignore' }).then(() => { |
|
|
any(serial_perform_git_remove(dir.name).map(x)) |
|
|
|
|
|
|
|
|
any(serial_perform_git_remove(dir.name).map(getnodeshellexectask)) |
|
|
}) |
|
|
}) |
|
|
.catch((e) => { |
|
|
.catch((e) => { |
|
|
console.log('skipped : ' + dir.name + `, reason : No remote named ${remotename}`) |
|
|
console.log('skipped : ' + dir.name + `, reason : No remote named ${remotename}`) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dirs(perform_git_remove) |
|
|
dirs(perform_git_remove) |
|
|
} |
|
|
} |
|
|
|
|
|
, 'get-remotes' : (args) => { |
|
|
|
|
|
// var __args = { |
|
|
|
|
|
// repo : args?.repo || processedArgs._[1] |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
var repo = args.repo |
|
|
|
|
|
|
|
|
|
|
|
var serial_perform = (repo) => { |
|
|
|
|
|
return [ |
|
|
|
|
|
['git', ['remote', '-vvvv'], { cwd: instanceroot + '/' + repo, |
|
|
|
|
|
evaluateResult : function( issuccess, result){ |
|
|
|
|
|
if(!issuccess || +result.code !== 0) throw Object.assign( new Error('git branch -vvvv crashed'), result); |
|
|
|
|
|
|
|
|
|
|
|
var lines = result.messages.join('').split('\n') |
|
|
|
|
|
var remotes = {} |
|
|
|
|
|
lines.forEach(line => { |
|
|
|
|
|
// pattern = origin https://git.bbh.org.in/chess/elxr (fetch) |
|
|
|
|
|
var match = new RegExp(`(\\S+)\\s(\\S+)/${repo}.git\\s\\((\\S+)\\)`).exec(line) |
|
|
|
|
|
if(match) { |
|
|
|
|
|
var r = remotes[match[1]] || (remotes[match[1]] = { title : match[1] }) |
|
|
|
|
|
if(match[3] === 'push') { r.push = match[2] } |
|
|
|
|
|
else r.url = match[2] |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
return remotes |
|
|
|
|
|
}}] |
|
|
|
|
|
] |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return perform( serial_perform, repo ) |
|
|
|
|
|
} |
|
|
|
|
|
, 'get-remote' : (upstream) => { |
|
|
|
|
|
// var __args = { |
|
|
|
|
|
// repo : args?.repo || processedArgs._[1] |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
var repo = upstream.repo |
|
|
|
|
|
|
|
|
|
|
|
var serial_perform = (repo) => { |
|
|
|
|
|
return [ |
|
|
|
|
|
['git', ['remote', '-vvvv'], { cwd: instanceroot + '/' + repo, |
|
|
|
|
|
evaluateResult : function( issuccess, result){ |
|
|
|
|
|
if(!issuccess || +result.code !== 0) throw Object.assign( new Error('git branch -vvvv crashed'), result); |
|
|
|
|
|
|
|
|
|
|
|
// origin https://git.bbh.org.in/chess/elxr (fetch) |
|
|
|
|
|
var match = new RegExp(`${upstream.remotename}\\\s(\\S+)/${repo}.git\\s\\(fetch\\)`).exec(result.messages.join(' ')) |
|
|
|
|
|
if(match) { upstream.url = match[1] } |
|
|
|
|
|
else throw Object.assign( new Error('No upstream found for active branch'), result) |
|
|
|
|
|
return upstream |
|
|
|
|
|
}}] |
|
|
|
|
|
] |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return perform( serial_perform, repo ) |
|
|
|
|
|
} |
|
|
|
|
|
, 'get-upstream' : (args) => { |
|
|
|
|
|
|
|
|
|
|
|
var __args = { |
|
|
|
|
|
repo : args?.repo || processedArgs._[1] |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var repo = __args.repo |
|
|
|
|
|
|
|
|
|
|
|
var serial_perform = (repo) => { |
|
|
|
|
|
return [ |
|
|
|
|
|
['git', ['branch', '-vvvv'], { cwd: instanceroot + '/' + repo, |
|
|
|
|
|
evaluateResult : function( issuccess, result){ |
|
|
|
|
|
if(!issuccess || +result.code !== 0) throw Object.assign( new Error('git branch -vvvv crashed'), result); |
|
|
|
|
|
|
|
|
|
|
|
var match = /\*\s(\S+)\s\S+\s\[(\S+)\/(\S+).*?\].*?/.exec(result.messages.join(' ')) |
|
|
|
|
|
if(match) { var upstream = { remotename : match[2], branch : match[1], remotebranch : match[3] } } |
|
|
|
|
|
else throw Object.assign( new Error('No upstream found for active branch'), result) |
|
|
|
|
|
|
|
|
|
|
|
if(args?.remotes) { |
|
|
|
|
|
var r = args.remotes[upstream.remotename]; |
|
|
|
|
|
if(!r) return op['get-remote'](upstream) |
|
|
|
|
|
|
|
|
|
|
|
r.branch = upstream.branch |
|
|
|
|
|
r.remotebranch = upstream.remotebranch |
|
|
|
|
|
return r |
|
|
|
|
|
} |
|
|
|
|
|
return op['get-remote'](upstream) |
|
|
|
|
|
}}] |
|
|
|
|
|
] |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return perform( serial_perform, repo ) |
|
|
|
|
|
} |
|
|
, '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' |
|
|
|
|
|
|
|
|
, ['git', ['remote', 'set-url', 'userfork', `${selectedinstance.reposerver}/${user}/${repo}.git`], { cwd: instanceroot + '/' + repo }] |
|
|
, ['git', ['remote', 'set-url', 'userfork', `${selectedinstance.reposerver}/${user}/${repo}.git`], { cwd: instanceroot + '/' + repo }] |
|
|
] |
|
|
] |
|
|
} |
|
|
} |
|
|
var x = (args) => { |
|
|
|
|
|
return () => { |
|
|
|
|
|
// console.log(args) |
|
|
|
|
|
return nodeShellExec.apply(null, args) |
|
|
|
|
|
} |
|
|
|
|
|
// return Promise.resolve(true) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var perform_init_gitea = (dir) => { |
|
|
var perform_init_gitea = (dir) => { |
|
|
op['is-git-repo'](dir).then((logEntry) => { |
|
|
op['is-git-repo'](dir).then((logEntry) => { |
|
|
// console.log(code) |
|
|
// console.log(code) |
|
|
|
|
|
|
|
|
nodeShellExec('git', ['remote', 'get-url', 'chess'], { cwd: dir.name, stdio: 'ignore' }).then(() => { |
|
|
nodeShellExec('git', ['remote', 'get-url', 'chess'], { cwd: dir.name, stdio: 'ignore' }).then(() => { |
|
|
console.log('skipped : ' + dir.name + ', reason : Already has remote chess ') |
|
|
console.log('skipped : ' + dir.name + ', reason : Already has remote chess ') |
|
|
}) |
|
|
}) |
|
|
.catch((e) => { |
|
|
|
|
|
any(serial_perform_init_gitea(dir.name).map(x)) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
.catch((e) => { |
|
|
|
|
|
perform( serial_perform_init_gitea, dir.name ) |
|
|
|
|
|
}) |
|
|
} |
|
|
} |
|
|
// else console.log('Skipped : Not a Git Repo : ' + dir.name) |
|
|
// else console.log('Skipped : Not a Git Repo : ' + dir.name) |
|
|
}).catch((e) => { |
|
|
}).catch((e) => { |
|
|
|
|
|
|
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const { readdir } = require("fs").promises |
|
|
|
|
|
|
|
|
|
|
|
dirs(perform_init_gitea) |
|
|
dirs(perform_init_gitea) |
|
|
} |
|
|
} |
|
|
, 'syncmaster': (label) => { |
|
|
, 'syncmaster': (label) => { |
|
|
|
|
|
|
|
|
, cmd : 'users list' |
|
|
, cmd : 'users list' |
|
|
, noprerequisites : true |
|
|
, noprerequisites : true |
|
|
} |
|
|
} |
|
|
|
|
|
, 'get-upstream' :{ |
|
|
|
|
|
cmdFn : op['get-upstream'] // default |
|
|
|
|
|
, cmd : 'get-upstream' |
|
|
|
|
|
, noprerequisites : true |
|
|
|
|
|
, independentcmd : true |
|
|
|
|
|
, interpret() { return { cmd : 'get-upstream' } } |
|
|
|
|
|
, getPossiblePrompts(){ return {} } |
|
|
|
|
|
} |
|
|
, 'g' : { |
|
|
, 'g' : { |
|
|
cmdFn : op['g'] // default |
|
|
cmdFn : op['g'] // default |
|
|
, cmd : 'g' |
|
|
, cmd : 'g' |
|
|
|
|
|
|
|
|
// // }) |
|
|
// // }) |
|
|
// } |
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// PB : TODO -- Move this to utils assign... as an array merge option. |
|
|
var mergeObjByKey = function(arrOfObjs, keyName) { |
|
|
var mergeObjByKey = function(arrOfObjs, keyName) { |
|
|
|
|
|
|
|
|
var keyedDistinct = {} |
|
|
var keyedDistinct = {} |
|
|
|
|
|
|
|
|
var cacheWriteInstanceConfig = function(chessinstances){ |
|
|
var cacheWriteInstanceConfig = function(chessinstances){ |
|
|
var instanceName = chessinstances['current_run'].instanceName; |
|
|
var instanceName = chessinstances['current_run'].instanceName; |
|
|
var node_env = chessinstances['current_run'].node_env; |
|
|
var node_env = chessinstances['current_run'].node_env; |
|
|
chessinstances[instanceName][node_env].repos = mergeObjByKey(chessinstances[instanceName][node_env].repos, 'repo') ; |
|
|
|
|
|
chessinstances[instanceName][node_env].elevated = mergeObjByKey(chessinstances[instanceName][node_env].elevated, 'repo') ; |
|
|
|
|
|
|
|
|
// PB : TODO -- We should be able to do simply merge at a higher level using assign |
|
|
|
|
|
chessinstances[instanceName][node_env].repos = mergeObjByKey(chessinstances[instanceName][node_env].repos || [], 'repo') ; |
|
|
|
|
|
chessinstances[instanceName][node_env].elevated = mergeObjByKey(chessinstances[instanceName][node_env].elevated || [], 'repo') ; |
|
|
fs.writeFileSync(instanceroot + '/chessinstances.js', 'module.exports = ' + JSON.stringify(chessinstances, null, 2) + '', { 'flag': 'w' }) |
|
|
fs.writeFileSync(instanceroot + '/chessinstances.js', 'module.exports = ' + JSON.stringify(chessinstances, null, 2) + '', { 'flag': 'w' }) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
// PB : TODO -- Use the ORG level instance before falling back to common Instance coz common instance may not exist for certain orgs. |
|
|
// PB : TODO -- Use the ORG level instance before falling back to common Instance coz common instance may not exist for certain orgs. |
|
|
, commonInstance(selected) { return __acquireConfig(selected, { defaultRepoOwner } |
|
|
, commonInstance(selected) { return __acquireConfig(selected, { defaultRepoOwner } |
|
|
// , function(e){ console.info('This is probably an error unless the user is asking to create a new instance with this name.') } |
|
|
|
|
|
|
|
|
, undefined |
|
|
|
|
|
, function(e){ |
|
|
|
|
|
// PB : TODO -- console.info('This is probably an error unless the user is asking to create a new instance with this name.') |
|
|
|
|
|
statuslog.statuslog(e, e) |
|
|
|
|
|
var manifestpath = path.normalize(selected.root + '/' + selected.instanceName + '-config-' + selected.node_env + '/repo-manifest'); |
|
|
|
|
|
utils.assign_core( { keycase : true, arraymergetype : utils.assign_core.DISTINCT_UNION } |
|
|
|
|
|
, selectedinstance, require(manifestpath)( null, { utils, username : selectedinstance.username, instanceName : selectedinstance.instanceName |
|
|
|
|
|
, node_env : selectedinstance.node_env, reposerver : 'https://git.bbh.org.in' } )) |
|
|
|
|
|
console.dir(selectedinstance.repos) |
|
|
|
|
|
// Config from server always override merges into selection except for the current selection. |
|
|
|
|
|
// PB : TODO -- utils.assign Array merges are non-distinct... |
|
|
|
|
|
if(selectedinstance?.repos && !selectedinstance.repos[0].repo) { |
|
|
|
|
|
console.warn('repo manifest has obsolete format. Attempting upgrade.') |
|
|
|
|
|
selectedinstance.repos = selectedinstance.repos.map(function(repo){ return { repo } }) |
|
|
|
|
|
} |
|
|
|
|
|
if(selectedinstance?.elevated && !selectedinstance.elevated[0]?.repo) { |
|
|
|
|
|
console.warn('elevated repo manifest has obsolete format. Attempting upgrade.') |
|
|
|
|
|
selectedinstance.elevated = selectedinstance.elevated.map(function(repo){ return { repo } }) |
|
|
|
|
|
} |
|
|
|
|
|
chessinstances[selected.instanceName][selected.node_env] = selectedinstance = utils.assign_core( { arraymergetype : utils.assign_core.DISTINCT_UNION } |
|
|
|
|
|
, selected, selectedinstance) |
|
|
|
|
|
chessinstances[selected.instanceName][selected.node_env].reposervers = Array.from(new Set(chessinstances[selected.instanceName][selected.node_env].reposervers)) |
|
|
|
|
|
selectedinstance.reposerver = selectedinstance.reposerver || selectedinstance.reposervers[0] // PB : TODO -- Attempt first one that is available and online... |
|
|
|
|
|
cacheWriteInstanceConfig(chessinstances) |
|
|
|
|
|
// ENV.NODE_ENV = selectedinstance.node_env; |
|
|
|
|
|
throw e |
|
|
|
|
|
} |
|
|
) } |
|
|
) } |
|
|
, genericChessInstance(selected) { return __acquireConfig(selected) } |
|
|
|
|
|
|
|
|
// , genericChessInstance(selected) { return __acquireConfig(selected) } |
|
|
} |
|
|
} |
|
|
})() |
|
|
})() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clustername = clustername || `${selected.username}-CHESS-${selected.node_env}`; |
|
|
clustername = clustername || `${selected.username}-CHESS-${selected.node_env}`; |
|
|
return __acquireData(selected, { remote : 'userfork' } |
|
|
return __acquireData(selected, { remote : 'userfork' } |
|
|
, selected.instanceName + '-data-' + selected.node_env + `-${clusternodename}` |
|
|
, selected.instanceName + '-data-' + selected.node_env + `-${clusternodename}` |
|
|
, function(e){ console.info('Customized node level config not found. This is not an Error. Will attempt with owner level config.'); |
|
|
|
|
|
|
|
|
, function(e){ console.info('Customized node level data not found. This is not an Error. Will attempt with owner level config.'); |
|
|
return e; } |
|
|
return e; } |
|
|
) |
|
|
) |
|
|
} |
|
|
} |
|
|
, ownerInstnace(selected) { return __acquireData(selected, { remote : 'userfork' } |
|
|
, ownerInstnace(selected) { return __acquireData(selected, { remote : 'userfork' } |
|
|
, selected.instanceName + '-data-' + selected.node_env |
|
|
, selected.instanceName + '-data-' + selected.node_env |
|
|
, function(e){ console.info('Customized user level config not found. This is not an Error. Will attempt global common instance config.'); |
|
|
|
|
|
|
|
|
, function(e){ console.info('Customized user level data not found. This is not an Error. Will attempt global common instance config.'); |
|
|
return e } |
|
|
return e } |
|
|
) |
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var manifestpath = path.normalize(selected.root + '/' + selected.instanceName + '-config-' + selected.node_env + '/repo-manifest'); |
|
|
var manifestpath = path.normalize(selected.root + '/' + selected.instanceName + '-config-' + selected.node_env + '/repo-manifest'); |
|
|
utils.assign_core( { keycase : true, arraymergetype : utils.assign_core.DISTINCT_UNION } |
|
|
utils.assign_core( { keycase : true, arraymergetype : utils.assign_core.DISTINCT_UNION } |
|
|
, selectedinstance, require(manifestpath)( null, selectedinstance)) |
|
|
|
|
|
|
|
|
, selectedinstance, require(manifestpath)( null, { utils, username : selectedinstance.username, instanceName : selectedinstance.instanceName |
|
|
|
|
|
, node_env : selectedinstance.node_env, reposerver : 'https://git.bbh.org.in' })) |
|
|
console.dir(selectedinstance.repos) |
|
|
console.dir(selectedinstance.repos) |
|
|
// Config from server always override merges into selection except for the current selection. |
|
|
// Config from server always override merges into selection except for the current selection. |
|
|
// PB : TODO -- utils.assign Array merges are non-distinct... |
|
|
// PB : TODO -- utils.assign Array merges are non-distinct... |
|
|
|
|
|
|
|
|
ENV.NODE_ENV = selectedinstance.node_env; |
|
|
ENV.NODE_ENV = selectedinstance.node_env; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var selectedremotes = {}; |
|
|
|
|
|
if(options.remote) selectedremotes[options.remote] = selected.reposerverinstances[selected.reposerver].remotes[options.remote]; |
|
|
|
|
|
// else known remotes preselected from UI pref. |
|
|
|
|
|
return performPull({repo : configrepo, remotes : Object.assign(selectedremotes |
|
|
|
|
|
, selected.repos[configrepo]?.remotes || {} ) } |
|
|
|
|
|
|
|
|
return performPull( selected.reposindexed[configrepo] || { repo : configrepo } |
|
|
, null, selected.username || options.defaultRepoOwner, errHandler || errorHandler || ((e)=>{ throw e })).then( successHandler ) |
|
|
, null, selected.username || options.defaultRepoOwner, errHandler || errorHandler || ((e)=>{ throw e })).then( successHandler ) |
|
|
.catch( (e)=>{ |
|
|
.catch( (e)=>{ |
|
|
// if(e){ |
|
|
// if(e){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var selectedremotes = {}; |
|
|
|
|
|
if(options.remote) selectedremotes[options.remote] = selected.reposerverinstances[selected.reposerver].remotes[options.remote] |
|
|
|
|
|
// else ... |
|
|
|
|
|
return performPull({ repo : datarepo |
|
|
|
|
|
, remotes : Object.assign(selectedremotes |
|
|
|
|
|
, selected.repos[datarepo]?.remotes || {} ) } |
|
|
|
|
|
|
|
|
return performPull( selected.reposindexed[datarepo] || { repo : datarepo } |
|
|
, null, selected.username || options.defaultRepoOwner, errHandler || errorHandler || ((e)=>{ throw e })).then( successHandler ) |
|
|
, null, selected.username || options.defaultRepoOwner, errHandler || errorHandler || ((e)=>{ throw e })).then( successHandler ) |
|
|
.catch( (e)=>{ |
|
|
.catch( (e)=>{ |
|
|
// if(e){ |
|
|
// if(e){ |
|
|
|
|
|
|
|
|
, selectedchoice : target['upstream-remote'] || 'userfork' |
|
|
, selectedchoice : target['upstream-remote'] || 'userfork' |
|
|
// Just using getters resolves dependencies..., dependencies : [ ()=>{ return target['reposerver'] } ] |
|
|
// Just using getters resolves dependencies..., dependencies : [ ()=>{ return target['reposerver'] } ] |
|
|
} |
|
|
} |
|
|
|
|
|
, 'remote-type' : { label : `Enter Remote Type ( <= ${target['remote-type'] || 'public'} ) : ` |
|
|
|
|
|
, get choices() { |
|
|
|
|
|
return ['public', 'private', 'github', 'unc'] |
|
|
|
|
|
} |
|
|
|
|
|
, defaultchoice : 'public' |
|
|
|
|
|
, selectedchoice : target['remote-type'] || 'public' |
|
|
|
|
|
// Just using getters resolves dependencies..., dependencies : [ ()=>{ return target['reposerver'] } ] |
|
|
|
|
|
} |
|
|
, 'selectedremotes' : { label : `Chose Remote Names ( <= ${target['selectedremotes'] || 'chess'} ) : ` |
|
|
, 'selectedremotes' : { label : `Chose Remote Names ( <= ${target['selectedremotes'] || 'chess'} ) : ` |
|
|
, get choices() { |
|
|
, get choices() { |
|
|
var reposerver = target['reposerver'] // PB : TODO -- We need options to work with multiple selected reposervers at the same time.. |
|
|
var reposerver = target['reposerver'] // PB : TODO -- We need options to work with multiple selected reposervers at the same time.. |
|
|
var remotenames = [] |
|
|
var remotenames = [] |
|
|
Object.entries(target.remotes).forEach( ([rname, r]) => { |
|
|
Object.entries(target.remotes).forEach( ([rname, r]) => { |
|
|
if(r.server === reposerver){ |
|
|
|
|
|
|
|
|
if(r.server === reposerver && r.accessibility.find( target[ 'remote-type' ] )){ |
|
|
remotes.push(rname) |
|
|
remotes.push(rname) |
|
|
// PB : TODO -- Sort and display highest priority target.remotes.sort( ) |
|
|
// PB : TODO -- Sort and display highest priority target.remotes.sort( ) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// selectedinstance = Object.assign( __default, selectedinstance ) |
|
|
// selectedinstance = Object.assign( __default, selectedinstance ) |
|
|
// } |
|
|
// } |
|
|
|
|
|
|
|
|
if(!selectedinstance.repos[0].repo) { |
|
|
|
|
|
|
|
|
if(selectedinstance?.repos && !selectedinstance?.repos[0]?.repo) { |
|
|
console.warn('repo manifest has obsolete format. Attempting upgrade.') |
|
|
console.warn('repo manifest has obsolete format. Attempting upgrade.') |
|
|
selectedinstance.repos = selectedinstance.repos.map(function(repo){ return { repo } }) |
|
|
selectedinstance.repos = selectedinstance.repos.map(function(repo){ return { repo } }) |
|
|
} |
|
|
} |
|
|
if(selectedinstance.elevated[0] && !selectedinstance.elevated[0].repo) { |
|
|
|
|
|
|
|
|
if(selectedinstance?.elevated && !selectedinstance?.elevated[0]?.repo) { |
|
|
console.warn('elevated repo manifest has obsolete format. Attempting upgrade.') |
|
|
console.warn('elevated repo manifest has obsolete format. Attempting upgrade.') |
|
|
selectedinstance.elevated = selectedinstance.elevated.map(function(repo){ return { repo } }) |
|
|
selectedinstance.elevated = selectedinstance.elevated.map(function(repo){ return { repo } }) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
return todo |
|
|
|
|
|
|
|
|
return todo.then( ()=>{ |
|
|
|
|
|
// PB : TODO -- Embed this in the build instead of inlining it. |
|
|
|
|
|
// Also attepmt to load from ../chess-config/... |
|
|
|
|
|
var __repo_manifest = (require(path.normalize(instanceroot + '/elxr/repo-manifest.js')))( |
|
|
|
|
|
'defaultmanifest' // name |
|
|
|
|
|
, { utils, username : selectedinstance.username, instanceName : selectedinstance.instanceName |
|
|
|
|
|
, node_env : selectedinstance.node_env, reposerver : 'https://git.bbh.org.in' } // options |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
__default = Object.assign(__default, __repo_manifest, { |
|
|
|
|
|
// Common baseline repos for all chess instances. |
|
|
|
|
|
repos : (()=> { |
|
|
|
|
|
var __repos = [ |
|
|
|
|
|
{ repo : 'ember-masonry-grid' /*, branch : master*/ } // Default need not be specified. |
|
|
|
|
|
, { repo : 'bbhverse' } |
|
|
|
|
|
, { repo : 'clientverse' } |
|
|
|
|
|
, { repo : 'serververse' } |
|
|
|
|
|
, { repo : 'elxr' } |
|
|
|
|
|
, { repo : 'ember-searchable-select' } |
|
|
|
|
|
, { repo : 'loopback-component-jsonapi' } |
|
|
|
|
|
, { repo : 'loopback-jsonapi-model-serializer' } |
|
|
|
|
|
, { repo : 'loopback-connector-mysql' } |
|
|
|
|
|
, { repo : 'loopback-connector-ds' } |
|
|
|
|
|
|
|
|
|
|
|
, { repo : 'ember-service-worker' } |
|
|
|
|
|
, { repo : 'ember-service-worker-asset-cache' } |
|
|
|
|
|
, { repo : 'ember-service-worker-cache-fallback' } |
|
|
|
|
|
, { repo : 'ember-service-worker-index' } |
|
|
|
|
|
, { repo : 'ember-sw-client-route' } |
|
|
|
|
|
, { repo : 'global-this' } |
|
|
|
|
|
] |
|
|
|
|
|
Array.prototype.push.apply( __repos, __repo_manifest.repos) |
|
|
|
|
|
return __repos; |
|
|
|
|
|
})() |
|
|
|
|
|
// Requires elevation only in windows |
|
|
|
|
|
, elevated : [ { repo : 'chess-server-lib', requiresElevation : true } ] |
|
|
|
|
|
, exludeMergeRepos : { } |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
initinstances(selectedinstance) |
|
|
|
|
|
return selectedinstance |
|
|
|
|
|
}) |
|
|
} |
|
|
} |
|
|
else return Promise.resolve(true) |
|
|
else return Promise.resolve(true) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var __default = null; // PB : TODO -- Use initialized instance instead of default everywhere. |
|
|
|
|
|
|
|
|
var __default = {}; // PB : TODO -- Use initialized instance instead of default everywhere. |
|
|
// PB : TODO -- In windows if we are run from an elevated shell we never move forward and simply exits !?. |
|
|
// PB : TODO -- In windows if we are run from an elevated shell we never move forward and simply exits !?. |
|
|
// -- Currently workaround in windows is to always run from a non-elevated shell. |
|
|
// -- Currently workaround in windows is to always run from a non-elevated shell. |
|
|
shell_verse.acquireElevationState().then((elevationstate) => { |
|
|
shell_verse.acquireElevationState().then((elevationstate) => { |
|
|
return detectInstanceRoot.then(()=>{ |
|
|
return detectInstanceRoot.then(()=>{ |
|
|
|
|
|
|
|
|
// PB : TODO -- Embed this in the build instead of inlining it. |
|
|
|
|
|
// Also attepmt to load from ../chess-config/... |
|
|
|
|
|
var __repo_manifest = (require(path.normalize(instanceroot + '/elxr/repo-manifest.js')))( |
|
|
|
|
|
'__default' // name |
|
|
|
|
|
, { utils, username : 'guest', instanceName : 'chess', node_env : 'development', reposerver : 'https://git.bbh.org.in' } // options |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
__default = Object.assign(__repo_manifest, { |
|
|
|
|
|
// Common baseline repos for all chess instances. |
|
|
|
|
|
repos : (()=> { |
|
|
|
|
|
var __repos = [ |
|
|
|
|
|
{ repo : 'ember-masonry-grid' /*, branch : master*/ } // Default need not be specified. |
|
|
|
|
|
, { repo : 'bbhverse' } |
|
|
|
|
|
, { repo : 'clientverse' } |
|
|
|
|
|
, { repo : 'serververse' } |
|
|
|
|
|
, { repo : 'elxr' } |
|
|
|
|
|
, { repo : 'ember-searchable-select' } |
|
|
|
|
|
, { repo : 'loopback-component-jsonapi' } |
|
|
|
|
|
, { repo : 'loopback-jsonapi-model-serializer' } |
|
|
|
|
|
, { repo : 'loopback-connector-mysql' } |
|
|
|
|
|
, { repo : 'loopback-connector-ds' } |
|
|
|
|
|
|
|
|
|
|
|
, { repo : 'ember-service-worker' } |
|
|
|
|
|
, { repo : 'ember-service-worker-asset-cache' } |
|
|
|
|
|
, { repo : 'ember-service-worker-cache-fallback' } |
|
|
|
|
|
, { repo : 'ember-service-worker-index' } |
|
|
|
|
|
, { repo : 'ember-sw-client-route' } |
|
|
|
|
|
, { repo : 'global-this' } |
|
|
|
|
|
] |
|
|
|
|
|
Array.prototype.push.apply( __repos, __repo_manifest.repos) |
|
|
|
|
|
return __repos; |
|
|
|
|
|
})() |
|
|
|
|
|
// Requires elevation only in windows |
|
|
|
|
|
, elevated : [ { repo : 'chess-server-lib', requiresElevation : true } ] |
|
|
|
|
|
, exludeMergeRepos : { } |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var cmdobj = cmds[clioverrides.cmd] |
|
|
var cmdobj = cmds[clioverrides.cmd] |
|
|
return Promise.all((cmdobj.requires || []).map( (r) => utils.promisify(null, r) ) ).then(()=>{ |
|
|
return Promise.all((cmdobj.requires || []).map( (r) => utils.promisify(null, r) ) ).then(()=>{ |
|
|
if(cmdobj.independentcmd) { |
|
|
if(cmdobj.independentcmd) { |