|
|
@@ -76,19 +76,56 @@ var getTaskCheckExists = (command, options) => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var getTaskWithElevation = function(tasdef){ |
|
|
|
return ()=>{ |
|
|
|
if (__isElevated) { |
|
|
|
return tasdef.elevatedpulltasks(); |
|
|
|
} |
|
|
|
else { |
|
|
|
// PB : TODO -- Rename op['runas'] to 'elevate' |
|
|
|
return op['runas']().then(() => { return true; }) |
|
|
|
.catch((e) => { |
|
|
|
console.error(e) |
|
|
|
}) |
|
|
|
.finally(() => { |
|
|
|
if (!processedArgs.runas) { return tasdef.regularpulltasks(); } |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var getTaskWithoutElevation = function(tasdef){ |
|
|
|
return ()=>{ |
|
|
|
if(!processedArgs.runas) { return tasdef.regularpulltasks(); } |
|
|
|
else Promise.resolve(true) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var gitops = { |
|
|
|
|
|
|
|
getdiscoverbranchcmd : function(repo){ |
|
|
|
|
|
|
|
var parameters = ['-c', 'branch=`git rev-parse --abbrev-ref HEAD`;for i in `git remote`; do git pull $i $branch; done;'] |
|
|
|
var cmd = [gitbash |
|
|
|
, ['-c', 'branch=`git rev-parse --abbrev-ref HEAD`;for i in `git remote`; do git pull $i $branch; done;'] |
|
|
|
, { cwd: instanceroot + '/' + repo, title: 'pull all origins for ' + repo + ' ' + parameters.join(' ') }] |
|
|
|
return cmd |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var getPullCmd = (repo, branch) => { |
|
|
|
// console.log(useGitPull)var getPullCmd = (repo, branch) => { |
|
|
|
// console.log(useGitPull) |
|
|
|
|
|
|
|
if(branch) { |
|
|
|
var parameters = ['-c', 'for i in `git remote`; do git pull $i ' + branch + '; done;'] |
|
|
|
var pullCmd = [ gitbash |
|
|
|
, ['-c', 'for i in `git remote`; do git pull $i ' + branch + '; done;'] |
|
|
|
, { cwd: instanceroot + '/' + repo, title : 'pull all origins for ' + repo }] |
|
|
|
, { cwd: instanceroot + '/' + repo, title : 'pull all origins for ' + branch + ' ' + repo + ' ' + parameters.join(' ') }] |
|
|
|
} |
|
|
|
else { |
|
|
|
var pullCmd = [gitbash |
|
|
|
, ['-c', 'branch=`git rev-parse --abbrev-ref HEAD`;for i in `git remote`; do git pull $i $branch; done;'] |
|
|
|
, { cwd: instanceroot + '/' + repo, title: 'pull all origins for ' + repo }] |
|
|
|
console.warn('No branch was specified detecting from working client.') |
|
|
|
var pullCmd = gitops.getdiscoverbranchcmd(repo) |
|
|
|
} |
|
|
|
// var pullCmd = ['pullall', [], { cwd : repo }] |
|
|
|
if (useGitPull) pullCmd = ['git', ['pull'], { |
|
|
@@ -101,22 +138,10 @@ var getPullCmd = (repo, branch) => { |
|
|
|
return pullCmd |
|
|
|
} |
|
|
|
|
|
|
|
// var getPullCmd = (repo, branch) => { |
|
|
|
// var pullCmd = [gitbash |
|
|
|
// , ['-c', 'branch=`git rev-parse --abbrev-ref HEAD`;for i in `git remote`; do git pull $i $branch; done;'] |
|
|
|
// , { cwd: instanceroot + '/' + repo, title: 'pull all origins for ' + repo }] |
|
|
|
// // var pullCmd = ['pullall', [], { cwd : repo }] |
|
|
|
// if (useGitPull) pullCmd = ['git', ['pull'], { |
|
|
|
// inherit: true, shell: true, |
|
|
|
// cwd: instanceroot + '/' + repo |
|
|
|
// // , env: process.env |
|
|
|
// , runas: processedArgs.runas |
|
|
|
// , title: `git pull ${repo}` |
|
|
|
// }] |
|
|
|
// return pullCmd |
|
|
|
// } |
|
|
|
|
|
|
|
var performPull = (repo, branch) => { |
|
|
|
// PB : TODO -- Handle no branch passed in case. |
|
|
|
// if(!branch) { throw 'No branch specified' } |
|
|
|
|
|
|
|
if (existsSync(instanceroot + '/' + repo)) { |
|
|
|
var branchprint = branch ? ' branch :' + branch : ''; |
|
|
|
console.log('pulling ' + instanceroot + '/' + repo + branchprint ) |
|
|
@@ -127,13 +152,13 @@ var performPull = (repo, branch) => { |
|
|
|
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) |
|
|
|
}) |
|
|
|
.catch((e) => { |
|
|
|
e.repo = repo; |
|
|
|
if (__isElevated) { |
|
|
|
fs.writeFileSync('run.log', ', ' + JSON.stringify(e), { 'flag': 'a+' }) |
|
|
|
} |
|
|
|
else statuslog.statuslog(e); console.error(e) |
|
|
|
}) |
|
|
|
} |
|
|
|
else { |
|
|
|
console.log('cloning ' + repo) |
|
|
@@ -679,39 +704,11 @@ var op = { |
|
|
|
else return op['runas']() |
|
|
|
} |
|
|
|
|
|
|
|
, 'pull': (label) => { |
|
|
|
, 'pull' : (label) => { |
|
|
|
// Usage : |
|
|
|
// elxr pull -- Defaults to run config |
|
|
|
|
|
|
|
var env = Object.assign({}, process.env); // Shallow clone it. |
|
|
|
console.log('Running exlr pull : ' + path.dirname(__dirname)) |
|
|
|
|
|
|
|
var useGitPull = processedArgs.useGitPull || false; |
|
|
|
|
|
|
|
if (__isElevated) { |
|
|
|
return any(elevatedRunasRepos.map((repo) => performPull(repo))).then(() => { |
|
|
|
fs.writeFileSync('run.done', 'success') |
|
|
|
return true; |
|
|
|
}).catch(() => { |
|
|
|
fs.writeFileSync('run.done', 'error') |
|
|
|
}) |
|
|
|
} |
|
|
|
else { |
|
|
|
// PB : TODO -- Rename op['runas'] to 'elevate' |
|
|
|
return op['runas']().then(() => { return true; }) |
|
|
|
.catch((e) => { |
|
|
|
console.error(e) |
|
|
|
}) |
|
|
|
.finally(() => { |
|
|
|
if (!processedArgs.runas) { |
|
|
|
var pendingpulls = []; |
|
|
|
gitRepos.forEach((r) => { pendingpulls.push(performPull(r)) }) |
|
|
|
return Promise.all(pendingpulls).then(results => { |
|
|
|
return true; |
|
|
|
}).finally(Traq.finally) |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
return elxr.getpulltask()() |
|
|
|
} |
|
|
|
, 'isInstalled': () => { |
|
|
|
return nodeShellExec('where', [processedArgs._[1]], { inherit: true }).then(() => { |
|
|
@@ -719,10 +716,10 @@ var op = { |
|
|
|
return true; |
|
|
|
}); |
|
|
|
} |
|
|
|
, 'i': () => { |
|
|
|
, 'i' : () => { |
|
|
|
|
|
|
|
var tasks = [] |
|
|
|
tasks.push(op['pull']); |
|
|
|
// tasks.push(op['pull']); |
|
|
|
tasks.push(getShellTask.apply(null, ['rm', [instanceroot + '/run.js'], { ignorefailures: true }])) |
|
|
|
tasks.push(op['use']) |
|
|
|
if (!__isElevated) { |
|
|
@@ -763,7 +760,7 @@ var op = { |
|
|
|
}).catch((e) => { |
|
|
|
console.error('Ignoring Benign Error'); console.error(e); |
|
|
|
}).then(() => { |
|
|
|
console.log(`--------------------npm run build for ${repo}--------------------`) |
|
|
|
console.log(`--npm run build for ${repo}--------------------`) |
|
|
|
return nodeShellExec('npm', ['run build'], { |
|
|
|
inherit: true, shell: true |
|
|
|
, cwd: instanceroot + '/' + repo |
|
|
@@ -792,7 +789,7 @@ var op = { |
|
|
|
|
|
|
|
rmtasks.push( |
|
|
|
// () => { |
|
|
|
// console.log(`--------------------rm package-lock.json for ${repo}--------------------`) |
|
|
|
// console.log(`--rm package-lock.json for ${repo}--------------------`) |
|
|
|
// return nodeShellExec(`"${gitbash}"`, ['-c', '"rm package-lock.json"'], { |
|
|
|
nodeShellExec('rm', ['package-lock.json'], { |
|
|
|
inherit: true, shell: true |
|
|
@@ -801,7 +798,7 @@ var op = { |
|
|
|
, title: `rm 'package-lock.json' for ${repo}` |
|
|
|
}) |
|
|
|
.then(()=>{ |
|
|
|
console.log(`--------------------rm package-lock.json for ${repo}--------------------`) |
|
|
|
console.log(`--rm package-lock.json for ${repo}--------------------`) |
|
|
|
}).catch((e) => { console.error(e) }) |
|
|
|
// } |
|
|
|
) |
|
|
@@ -809,7 +806,7 @@ var op = { |
|
|
|
if (npmbuildrepos.indexOf(repo) < 0) { |
|
|
|
repotasks.push( |
|
|
|
() => { |
|
|
|
console.log(`--------------------npm i for ${repo}--------------------`) |
|
|
|
console.log(`--npm i for ${repo}--------------------`) |
|
|
|
var p = nodeShellExec('npm', ['i', '--force'], { |
|
|
|
inherit: true, shell: true |
|
|
|
, cwd: instanceroot + '/' + repo |
|
|
@@ -943,7 +940,7 @@ var op = { |
|
|
|
console.log(serverPid) |
|
|
|
kill(serverPid) |
|
|
|
} |
|
|
|
, 'use': () => { |
|
|
|
, 'use' : () => { |
|
|
|
// use a certain named instance. |
|
|
|
// Eg : |
|
|
|
// 1) elxr use elixir |
|
|
@@ -956,11 +953,11 @@ var op = { |
|
|
|
2) Make Links for config ({{name}}-config-{{node_env}}) and data with the NODE_ENV specified or default to dev |
|
|
|
3) Iterates all repos and pull all. 'git', ['pull', '--all']. |
|
|
|
4) Iterates all repos and checkout to the ENV specified. 'git', ['checkout', checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV] |
|
|
|
5) Iterates all repos and merge from source configured in mergeSource. 'git', ['merge', mergeSource], |
|
|
|
5) Iterates all repos and merge from source configured in mergesource. 'git', ['merge', mergesource], |
|
|
|
*/ |
|
|
|
var runconfig = { NODE_ENV: repomanifest.node_env } |
|
|
|
try { runconfig = Object.assign(runconfig, require(instanceroot + '/run.js')) } catch (e) { } |
|
|
|
if ((!processedArgs.runas || processedArgs.runas !== 'self') && |
|
|
|
if ((!processedArgs.runas || processedArgs.runas !== 'self' && !processedArgs.force) && |
|
|
|
runconfig.NODE_ENV && runconfig.NODE_ENV === (repomanifest.node_env || runconfig.NODE_ENV) && |
|
|
|
repomanifest.instanceName && runconfig.use === repomanifest.instanceName) { |
|
|
|
|
|
|
@@ -996,29 +993,65 @@ var op = { |
|
|
|
// Maps an environment to a branch. Not required if the branch is appropriately named. |
|
|
|
var checkoutMap = { 'development': 'master' } |
|
|
|
|
|
|
|
// cant use git checkout -b it fails with branch already exists. |
|
|
|
var performCheckout = (repo, branch) => { |
|
|
|
if (!branch) return Promise.resolve({ 'skipped': true }) |
|
|
|
if (excludeCheckouts[repo]) return Promise.resolve({ 'skipped': true }) |
|
|
|
return nodeShellExec('git', ['checkout', branch || checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], { |
|
|
|
// return nodeShellExec('git', ['switch', '-m', '-C', checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], { |
|
|
|
// inherit : true, shell: true, |
|
|
|
cwd: instanceroot + '/' + repo |
|
|
|
// , stdio : ignore // Use when we want to silcence output completely. |
|
|
|
, runas: processedArgs.runas |
|
|
|
, title: `git checkout ${branch || checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV} for ${repo}` |
|
|
|
}).then(()=>{ console.log( `SUCCESS : git checkout ${branch || checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV} for ${repo}` ) }).catch((e) => { console.error(e); return { error: true, message: repo } }) |
|
|
|
var branch = checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV |
|
|
|
|
|
|
|
var performPullOrCloneForBranch = (def)=>{ |
|
|
|
var promise = Promise.resolve(true) |
|
|
|
if (!branch) { |
|
|
|
var dscoverbranchcmd = gitops.getdiscoverbranchcmd(repo) |
|
|
|
|
|
|
|
promise = nodeShellExec.apply(null, dscoverbranchcmd(repo)).then(__branch=>{ branch = __branch}) |
|
|
|
.catch((e) => { console.error(e); return { error: true, message: repo } }) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return promise = promise.then(()=>{ return elxr.getpulltask(def)() }).catch(e => { console.error( 'performPullOrCloneForBranch : Failed ' + e )}) |
|
|
|
} |
|
|
|
if (runconfig.NODE_ENV === 'development') performCheckout = () => { return Promise.resolve(true) } |
|
|
|
|
|
|
|
var performPullAll = (repo) => { |
|
|
|
|
|
|
|
// cant use git checkout -b it fails when branch already exists. |
|
|
|
var performCheckout = (def) => { |
|
|
|
if (excludeCheckouts[repo]) return Promise.resolve({ 'skipped': true }) |
|
|
|
|
|
|
|
return performPullOrCloneForBranch(def)().then(()=>{ |
|
|
|
nodeShellExec('git', ['checkout', def.branch || checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], { |
|
|
|
// return nodeShellExec('git', ['switch', '-m', '-C', checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], { |
|
|
|
// inherit : true, shell: true, |
|
|
|
cwd: instanceroot + '/' + def.repo |
|
|
|
// , stdio : ignore // Use when we want to silence output completely. |
|
|
|
, runas: processedArgs.runas |
|
|
|
, title: `git checkout ${def.branch || checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV} for ${def.repo}` |
|
|
|
}).then(()=>{ console.log( `SUCCESS : git checkout ${def.branch || checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV} for ${def.repo}` ) }).catch((e) => { console.error(e); return { error: true, message: def.repo } }) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
var enqueueCheckout = function(def){ enqueue(elevatedqueue, performCheckout, def) } |
|
|
|
var enqueueMerge = function(def){ enqueue(elevatedqueue, performMerge, def) } |
|
|
|
|
|
|
|
var elevatedqueue = []; |
|
|
|
var enqueueOnce = (queue, task, def) => { |
|
|
|
var found = queue.find(element => { |
|
|
|
var keys = Object.keys( element ) |
|
|
|
for(var k=0; k < keys.length; k++) { |
|
|
|
if(element[keys[k]] !== def[k]) return false; |
|
|
|
} |
|
|
|
}) |
|
|
|
queue.push(function(){ return task(this)}.bind(def)); |
|
|
|
} |
|
|
|
var enqueue = (queue, task, def) => { |
|
|
|
queue.push(function(){ return task(def)}.bind(def)); |
|
|
|
} |
|
|
|
|
|
|
|
if (runconfig.NODE_ENV === 'development') performCheckout = (def) => { return performPullOrCloneForBranch(def) } |
|
|
|
|
|
|
|
var performPullAll = (def) => { |
|
|
|
if (excludeCheckouts[def.repo]) return Promise.resolve({ 'skipped': true }) |
|
|
|
return nodeShellExec('git', ['pull', '--all'], { |
|
|
|
// inherit : true, shell: true, |
|
|
|
cwd: instanceroot + '/' + repo |
|
|
|
cwd: instanceroot + '/' + def.repo |
|
|
|
, runas: processedArgs.runas |
|
|
|
, title: `git pull -all for ${checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV} ${repo}` |
|
|
|
}).catch((e) => { console.error(e); return { error: true, message: repo } }) |
|
|
|
, title: `git pull -all for ${checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV} ${def.repo}` |
|
|
|
}).catch((e) => { console.error(e); return { error: true, message: def.repo } }) |
|
|
|
} |
|
|
|
|
|
|
|
var mergeSources = { |
|
|
@@ -1030,116 +1063,114 @@ var op = { |
|
|
|
delete excludeCheckouts[`elixir-config-${runconfig.NODE_ENV}`] |
|
|
|
delete excludeCheckouts[`cihsr-config-${runconfig.NODE_ENV}`] |
|
|
|
|
|
|
|
var mergeSource = mergeSources[checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV] |
|
|
|
var performMerge = (repo) => { |
|
|
|
if (exludeMergeRepos[repo]) return Promise.resolve({ 'skipped': true }) |
|
|
|
return nodeShellExec('git', ['merge', mergeSource], { |
|
|
|
var mergesource = mergeSources[checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV] |
|
|
|
var performMerge = (def) => { |
|
|
|
if (exludeMergeRepos[def.repo]) return Promise.resolve({ 'skipped': true }) |
|
|
|
return nodeShellExec('git', ['merge', mergesource], { |
|
|
|
inherit: true, shell: true, |
|
|
|
cwd: instanceroot + '/' + repo |
|
|
|
cwd: instanceroot + '/' + def.repo |
|
|
|
, runas: processedArgs.runas |
|
|
|
}).catch((e) => { console.error(e) }) |
|
|
|
} |
|
|
|
if (runconfig.NODE_ENV === 'development') performMerge = () => { return Promise.resolve(true) } |
|
|
|
|
|
|
|
return any(tasks).then(() => { |
|
|
|
if (!processedArgs.runas) return op['runas']() |
|
|
|
var performRepoOperation = function(def) { |
|
|
|
elevatedRunasRepos.map((repo) => enqueueCheckout({ repo, branch: def.branch, requiresElevation : true })) |
|
|
|
return any(gitRepos.map((repo) => performCheckout({ repo, branch: def.branch}))) |
|
|
|
} |
|
|
|
|
|
|
|
tasks = [ |
|
|
|
() => { |
|
|
|
// Use junctions to avoid npm package issues |
|
|
|
var p = nodeShellExec('mklink', ['/J', 'config', runconfig.use + '-config' + '-' + process.env.NODE_ENV], { |
|
|
|
inherit: true, shell: true |
|
|
|
, cwd : instanceroot |
|
|
|
, env: process.env |
|
|
|
}).catch((e) => { console.error(e) }) |
|
|
|
return p; |
|
|
|
} |
|
|
|
]; |
|
|
|
if (processedArgs._[1]) { |
|
|
|
tasks = tasks.concat( |
|
|
|
[ |
|
|
|
return any(tasks).then(() => { |
|
|
|
var pr = Promise.resolve(true) |
|
|
|
if (!__isElevated) { |
|
|
|
pr = op['runas']() |
|
|
|
return pr.then(()=>{ |
|
|
|
|
|
|
|
//target is the env is we specify in elxr use command. Default is dev |
|
|
|
//Switch to target branch |
|
|
|
return any(gitRepos.map((repo) => performCheckout({ repo, branch}))) |
|
|
|
// pull or clone target branch |
|
|
|
.then(() => any(gitRepos.map((repo) => performPullAll({repo}))) ) |
|
|
|
// switch to source branch |
|
|
|
.then( () => { |
|
|
|
if(mergesource) return any(gitRepos.map((repo) => performCheckout({ repo, branch: mergesource}))) |
|
|
|
else return Promise.resolve(true) // Dont do anything if there is no source to merge from. |
|
|
|
}) |
|
|
|
//Pull on merge source branch |
|
|
|
.then( () => { |
|
|
|
if(!mergesource) return Promise.resolve(true) |
|
|
|
return any(gitRepos.map((repo) => performPullAll({repo}))) |
|
|
|
}) |
|
|
|
//Switch to target branch |
|
|
|
.then( () => { |
|
|
|
if(!mergesource) return Promise.resolve(true) |
|
|
|
return any(elevatedRunasRepos.map((repo) => performCheckout({ repo, branch}))) |
|
|
|
}) |
|
|
|
.then( //Merge source branch to target branch |
|
|
|
() => { |
|
|
|
var p = nodeShellExec('mklink', ['/J', 'data', runconfig.use + '-data'], { |
|
|
|
inherit: true, shell: true |
|
|
|
, cwd : instanceroot |
|
|
|
, env: process.env |
|
|
|
}).catch((e) => { console.error(e) }) |
|
|
|
return p; |
|
|
|
} |
|
|
|
] |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
return any(tasks) |
|
|
|
//target is the env is we specify in elxr use command. Default is dev |
|
|
|
.then( //Switch to target branch |
|
|
|
() => any([any(gitRepos.map((repo) => performCheckout(repo, process.env.NODE_ENV || 'development'))) |
|
|
|
, any(elevatedRunasRepos.map((repo) => performCheckout(repo, process.env.NODE_ENV || 'development')))])) |
|
|
|
.then( //PULL from target branch |
|
|
|
() => any([any(gitRepos.map((repo) => performPullAll(repo))), any(elevatedRunasRepos.map((repo) => performPullAll(repo)))])) |
|
|
|
.then( //Switch to merge source branch |
|
|
|
() => any([any(gitRepos.map((repo) => performCheckout(repo, mergeSources[process.env.NODE_ENV || 'development']))) |
|
|
|
, any(elevatedRunasRepos.map((repo) => performCheckout(repo, mergeSources[process.env.NODE_ENV || 'development'])))])) |
|
|
|
.then( //Pull on merge source branch |
|
|
|
() => any([any(gitRepos.map((repo) => performPullAll(repo))), any(elevatedRunasRepos.map((repo) => performPullAll(repo)))])) |
|
|
|
.then( //Switch to target branch |
|
|
|
() => any([any(gitRepos.map((repo) => performCheckout(repo, process.env.NODE_ENV || 'development'))) |
|
|
|
, any(elevatedRunasRepos.map((repo) => performCheckout(repo, process.env.NODE_ENV || 'development')))])) |
|
|
|
.then( //Merge source branch to target branch |
|
|
|
() => any([any(gitRepos.map((repo) => performMerge(repo))).catch(err => { console.error('error in performMerge ' + err) }), |
|
|
|
any(elevatedRunasRepos.map((repo) => performMerge(repo))).catch(err => { console.error('error in performMerge ' + err) })])) |
|
|
|
.then(() => { |
|
|
|
// Move test config from dev. |
|
|
|
// if(process.env.NODE_ENV === 'test'){ |
|
|
|
// var devcfgreponame = runconfig.use + '-config' + '-development'; |
|
|
|
// var testcfgreponame = runconfig.use + '-config' + '-test'; |
|
|
|
|
|
|
|
// var testcfgdir = path.dirname(__dirname) + '/' + testcfgreponame + '/' |
|
|
|
// var devcfgdir = path.dirname(__dirname) + '/' + devcfgreponame + '/' //eg (elxr/../elixir-config.development) |
|
|
|
|
|
|
|
// return any([ |
|
|
|
// ()=>{ |
|
|
|
// return nodeShellExec('git', ['checkout', 'test'], { |
|
|
|
// inherit : true, shell: true, |
|
|
|
// cwd : testcfgdir |
|
|
|
// // , env: process.env |
|
|
|
// , runas : processedArgs.runas |
|
|
|
// , title : `git checkout test for ${testcfgreponame}` |
|
|
|
// }).catch((e)=>{ console.error(e) }) |
|
|
|
// } |
|
|
|
// , ()=> { |
|
|
|
// return nodeShellExec('git', ['checkout', 'master'], { |
|
|
|
// inherit : true, shell: true, |
|
|
|
// cwd : devcfgdir |
|
|
|
// // , env: process.env |
|
|
|
// , runas : processedArgs.runas |
|
|
|
// , title : `git checkout master for ${devcfgreponame}` |
|
|
|
// }).catch((e)=>{ console.error(e) }) |
|
|
|
// } |
|
|
|
// , ()=> { |
|
|
|
// globSync( '**/*.test.js', {cwd : devcfgdir}).map((filename) => { |
|
|
|
// console.log('File found : ' + devcfgdir + filename) |
|
|
|
// fs.copyFileSync(devcfgdir + filename, testcfgdir+ filename); |
|
|
|
// }) |
|
|
|
// return nodeShellExec('git', ['checkout', 'test'], { |
|
|
|
// inherit : true, shell: true, |
|
|
|
// cwd : devcfgdir |
|
|
|
// // , env: process.env |
|
|
|
// , runas : processedArgs.runas |
|
|
|
// , title : `git checkout test for ${devcfgreponame}` |
|
|
|
// }).catch((e)=>{ console.error(e) }) |
|
|
|
// } |
|
|
|
// ]) |
|
|
|
// } |
|
|
|
// else { |
|
|
|
return Promise.resolve(true) |
|
|
|
// } |
|
|
|
if(!mergesource) return Promise.resolve(true) |
|
|
|
return any(gitRepos.map((repo) => performMerge({ repo }))).catch(err => { console.error('error in performMerge ' + err) }) |
|
|
|
}) |
|
|
|
}) |
|
|
|
.then(() => { |
|
|
|
fs.writeFileSync('run.done', 'success') |
|
|
|
}).catch(() => { |
|
|
|
fs.writeFileSync('run.done', 'error') |
|
|
|
} |
|
|
|
else { |
|
|
|
tasks = [ |
|
|
|
() => { |
|
|
|
// Use junctions to avoid npm package issues |
|
|
|
var p = nodeShellExec('mklink', ['/J', 'config', runconfig.use + '-config' + '-' + process.env.NODE_ENV], { |
|
|
|
inherit: true, shell: true |
|
|
|
, cwd : instanceroot |
|
|
|
, env: process.env |
|
|
|
}).catch((e) => { console.error(e) }) |
|
|
|
return p; |
|
|
|
} |
|
|
|
]; |
|
|
|
if (processedArgs._[1]) { |
|
|
|
tasks = tasks.concat( |
|
|
|
[ |
|
|
|
() => { |
|
|
|
var p = nodeShellExec('mklink', ['/J', 'data', runconfig.use + '-data'], { |
|
|
|
inherit: true, shell: true |
|
|
|
, cwd : instanceroot |
|
|
|
, env: process.env |
|
|
|
}).catch((e) => { console.error(e) }) |
|
|
|
return p; |
|
|
|
} |
|
|
|
] |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
return any(tasks).then(()=>{ |
|
|
|
return any(elevatedRunasRepos.map((repo) => performCheckout({ repo, branch}))) |
|
|
|
// pull or clone target branch |
|
|
|
.then( () => any(elevatedRunasRepos.map((repo) => performPullAll({repo}))) ) |
|
|
|
// switch to source branch |
|
|
|
.then( () => { |
|
|
|
if(mergesource) return any(elevatedRunasRepos.map((repo) => performCheckout({ repo, branch: mergesource}))) |
|
|
|
else return Promise.resolve(true) // Dont do anything if there is no source to merge from. |
|
|
|
}) |
|
|
|
//Pull on merge source branch |
|
|
|
.then( () => { |
|
|
|
if(!mergesource) return Promise.resolve(true) |
|
|
|
return any(elevatedRunasRepos.map((repo) => performPullAll({repo}))) |
|
|
|
}) |
|
|
|
//Switch to target branch |
|
|
|
.then( () => { |
|
|
|
if(!mergesource) return Promise.resolve(true) |
|
|
|
return any(elevatedRunasRepos.map((repo) => performCheckout({ repo, branch}))) |
|
|
|
}) |
|
|
|
.then( //Merge source branch to target branch |
|
|
|
() => { |
|
|
|
if(!mergesource) return Promise.resolve(true) |
|
|
|
return any(elevatedRunasRepos.map((repo) => performMerge({ repo }))).catch(err => { console.error('error in performMerge ' + err) }) |
|
|
|
}) |
|
|
|
.then(() => { |
|
|
|
fs.writeFileSync('run.done', 'success') |
|
|
|
}).catch(() => { |
|
|
|
fs.writeFileSync('run.done', 'error') |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
}).catch(() => { |
|
|
|
fs.writeFileSync('run.done', 'error') |
|
|
|
}) |
|
|
@@ -1287,12 +1318,52 @@ var elxr = { |
|
|
|
------------------------------------------------------------------------------- |
|
|
|
`) |
|
|
|
} |
|
|
|
, getpulltask(def){ |
|
|
|
|
|
|
|
console.log(`-------------------Processing pull for : ${def.repo} ${def.branch}`) |
|
|
|
console.dir(def) |
|
|
|
|
|
|
|
var env = Object.assign({}, process.env); // Shallow clone it. |
|
|
|
console.log('Running exlr pull : ' + path.dirname(__dirname)) |
|
|
|
|
|
|
|
var useGitPull = processedArgs.useGitPull || false; |
|
|
|
|
|
|
|
if(def.elevatedRepos || def.reqularRepos) { |
|
|
|
if(def.elevatedRepos) def.requiresElevation = true; |
|
|
|
else delete def.requiresElevation; |
|
|
|
} |
|
|
|
else { |
|
|
|
if(def.requiresElevation) def.elevatedRepos = [def] |
|
|
|
else def.reqularRepos = [def] |
|
|
|
} |
|
|
|
|
|
|
|
var elevatedpulltasks = null; |
|
|
|
var regularpulltasks = function(){ return Promise.resolve(true) } |
|
|
|
if(def.elevatedRepos){ |
|
|
|
elevatedpulltasks = function() { |
|
|
|
return any(def.elevatedRepos.map((def) => performPull(def.repo))).then(() => { |
|
|
|
fs.writeFileSync('run.done', 'success') |
|
|
|
return true; |
|
|
|
}).catch(() => { fs.writeFileSync('run.done', 'error') }) |
|
|
|
} |
|
|
|
} |
|
|
|
if(def.reqularRepos) { |
|
|
|
var regularpulltasks = function(){ |
|
|
|
var pendingpulls = []; |
|
|
|
def.reqularRepos.forEach((def) => { pendingpulls.push(performPull(def.repo)) }) |
|
|
|
return Promise.all(pendingpulls).finally(Traq.finally) |
|
|
|
} |
|
|
|
} |
|
|
|
if(elevatedpulltasks) return getTaskWithElevation( { elevatedpulltasks, regularpulltasks} ) |
|
|
|
else return getTaskWithoutElevation({ regularpulltasks}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// The main elxr cli process |
|
|
|
function elxrworker(hasconfig) { |
|
|
|
function elxrworker() { |
|
|
|
// Everything runs after this check is completed. Elevation occurs out of process when needed. |
|
|
|
gitRepos = repomanifest.repos |
|
|
|
// gitRepos = ['chess-server-lib']; |
|
|
|
|
|
|
|
// Repositiories that have symlinks that require elevated priviletes in windows to create symlinks |
|
|
|
elevatedRunasRepos = repomanifest.elevated |
|
|
@@ -1388,7 +1459,7 @@ We will run your choice of default or create your own at the next prompt. |
|
|
|
process.exit(); |
|
|
|
} |
|
|
|
|
|
|
|
return p1.ask(`Enter preferred repo server ( <= ${selectedinstance.reposervers[0]} ) : `).then(function (reposerver) { |
|
|
|
return p1.ask(`Enter preferred repo server ( <= ${selectedinstance.reposerver || selectedinstance.reposervers[0]} ) : `).then(function (reposerver) { |
|
|
|
p1.close() |
|
|
|
selectedinstance.reposerver = reposerver || selectedinstance.reposervers[0] || 'https://git.bbh.org.in' |
|
|
|
}) |
|
|
@@ -1408,7 +1479,7 @@ We will run your choice of default or create your own at the next prompt. |
|
|
|
processedArgs._[0] = 'pull' |
|
|
|
} |
|
|
|
else processedArgs._[0] = cmd |
|
|
|
return p1.ask(`Enter preferred repo server ( <= ${selectedinstance.reposervers[0]} ) : `).then(function (reposerver) { |
|
|
|
return p1.ask(`Enter preferred repo server ( <= ${selectedinstance.reposerver || selectedinstance.reposervers[0]} ) : `).then(function (reposerver) { |
|
|
|
selectedinstance.reposerver = reposerver || selectedinstance.reposervers[0] || 'https://git.bbh.org.in' |
|
|
|
p1.close() |
|
|
|
}) |
|
|
@@ -1427,29 +1498,25 @@ We will run your choice of default or create your own at the next prompt. |
|
|
|
var acquireConfig = function (selected, chessinstances) { |
|
|
|
|
|
|
|
var configrepo = selected.instanceName + '-config-' + selected.node_env; |
|
|
|
|
|
|
|
return (async ()=>{return await __default.reposerver})().then(()=>{ |
|
|
|
|
|
|
|
return performPull(configrepo).then(() => { |
|
|
|
var manifestpath = path.normalize(selected.root + '/' + selected.instanceName + '-config-' + selected.node_env + '/repo-manifest'); |
|
|
|
repomanifest = require(manifestpath)() |
|
|
|
chessinstances = chessinstances || {}; |
|
|
|
chessinstances[selected.instanceName] = chessinstances[selected.instanceName] || {} |
|
|
|
chessinstances[selected.instanceName][selected.node_env] = chessinstances[selected.instanceName][selected.node_env] || {} |
|
|
|
chessinstances['current_run'] = { instanceName: selected.instanceName, node_env: selected.node_env } |
|
|
|
// Config from server always override merges into selection ecept for the current selection. |
|
|
|
selectedinstance = utils.assign(chessinstances[selected.instanceName][selected.node_env], selected, repomanifest) |
|
|
|
fs.writeFileSync(instanceroot + '/chessinstances.js', 'module.exports = ' + JSON.stringify(chessinstances, null, 2) + '', { 'flag': 'w' }) |
|
|
|
// PB : TODO -- We should probably write the new server config also... |
|
|
|
selectedinstance.reposerver = selectedinstance.reposervers[0] // PB : TODO -- Attempt first one that is available and online... |
|
|
|
ENV.NODE_ENV = selectedinstance.node_env; |
|
|
|
}) |
|
|
|
.catch((e) => { |
|
|
|
console.error(e) |
|
|
|
console.error('Config acquisition failed.') |
|
|
|
}) |
|
|
|
|
|
|
|
return performPull(configrepo).then(() => { |
|
|
|
var manifestpath = path.normalize(selected.root + '/' + selected.instanceName + '-config-' + selected.node_env + '/repo-manifest'); |
|
|
|
repomanifest = require(manifestpath)() |
|
|
|
chessinstances = chessinstances || {}; |
|
|
|
chessinstances[selected.instanceName] = chessinstances[selected.instanceName] || {} |
|
|
|
chessinstances[selected.instanceName][selected.node_env] = chessinstances[selected.instanceName][selected.node_env] || {} |
|
|
|
chessinstances['current_run'] = { instanceName: selected.instanceName, node_env: selected.node_env } |
|
|
|
// Config from server always override merges into selection ecept for the current selection. |
|
|
|
selectedinstance = utils.assign(chessinstances[selected.instanceName][selected.node_env], selected, repomanifest) |
|
|
|
fs.writeFileSync(instanceroot + '/chessinstances.js', 'module.exports = ' + JSON.stringify(chessinstances, null, 2) + '', { 'flag': 'w' }) |
|
|
|
// PB : TODO -- We should probably write the new server config also... |
|
|
|
selectedinstance.reposerver = selectedinstance.reposerver || selectedinstance.reposervers[0] // PB : TODO -- Attempt first one that is available and online... |
|
|
|
ENV.NODE_ENV = selectedinstance.node_env; |
|
|
|
}) |
|
|
|
.catch((e) => { |
|
|
|
console.error(e) |
|
|
|
console.error('Config acquisition failed.') |
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var launchpath = process.cwd().replace(/\\/, '/') |