Browse Source

Fixes

master
Pradeep Bhaskaran 4 years ago
parent
commit
5a877ab4ff
1 changed files with 74 additions and 50 deletions
  1. 74
    50
      index.js

+ 74
- 50
index.js View File

@@ -34,6 +34,18 @@ function any(iterable, continueOnFailure) {
if(Promise.resolve(p) === p ) {
return p.then((pVal) => {



// Falsy values are task failure.
if(!pVal) {
console.warn('Possible failure for result : ' + pVal)
console.warn(a[i-1])
fn ? console.error("Fn : " + fn.toString()) : null;
}

// Truthy values are failures if obj has error=true.
if(pVal && pVal.error) { console.error('Failed : ' + pVal.message + ' ' + pVal) }

if(Promise.resolve(pVal) === pVal) {
// Passed in function retured a promise. We still need to wait for it.
pVal.then((pVal)=>{
@@ -577,11 +589,23 @@ var __runcmd = function(label){

// cant use git checkout -b it fails with branch already exists.
var performCheckout = (repo)=>{
return nodeShellExec('git', ['checkout', checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], {
if(excludeCheckouts[repo]) return Promise.resolve({ 'skipped' : true })
return nodeShellExec('git', ['switch', '-m', '-C', checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], {
inherit : true, shell: true,
cwd : repo
, runas : processedArgs.runas
}).catch((e)=>{ console.error(e) })
, title : `git switch -C -m ${checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV} for ${repo}`
}).catch((e)=>{ console.error(e); return { error : true, message : repo} })
}

var performPullAll = (repo)=>{
if(excludeCheckouts[repo]) return Promise.resolve({ 'skipped' : true })
return nodeShellExec('git', ['pull', '--all'], {
inherit : true, shell: true,
cwd : repo
, runas : processedArgs.runas
, title : `git switch -C -m ${checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV} for ${repo}`
}).catch((e)=>{ console.error(e); return { error : true, message : repo} })
}

var mergeSources = {
@@ -592,6 +616,8 @@ var __runcmd = function(label){
var exludeMergeRepos = {
'elixir-config-development' : true, 'elixir-config-test': true, 'elixir-config-production' : true
}
var excludeCheckouts = Object.assign(exludeMergeRepos)
delete excludeCheckouts[`elixir-config-${runconfig.NODE_ENV}`]

var mergeSource = mergeSources[checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV]
var performMerge = (repo)=>{
@@ -602,7 +628,7 @@ var __runcmd = function(label){
, runas : processedArgs.runas
}).catch((e)=>{ console.error(e) })
}
if(runconfig.NODE_ENV === 'development') performMerge = ()=>{ return Promise.resolve(true) }
if(runconfig.NODE_ENV === 'development') performMerge = ()=>{ return Promise.resolve(true) }

any(tasks).then(()=>{
if(!processedArgs.runas) return op['runas']()
@@ -631,12 +657,15 @@ var __runcmd = function(label){
)
}

return any(tasks.concat([
any(gitRepos.map((repo)=>performCheckout(repo))),
any(elevatedRunasRepos.map((repo)=>performCheckout(repo))),
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)})
, () => {
return any(tasks)
.then(
() => any([ any(gitRepos.map((repo)=>performPullAll(repo))), any(elevatedRunasRepos.map((repo)=>performPullAll(repo)))]) )
.then(
() => any([ any(gitRepos.map((repo)=>performCheckout(repo))), any(elevatedRunasRepos.map((repo)=>performCheckout(repo)))]) )
.then(
() => 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';
@@ -645,48 +674,43 @@ var __runcmd = function(label){
var testcfgdir = path.dirname(__dirname) + '/' + testcfgreponame + '/'
var devcfgdir = path.dirname(__dirname) + '/' + devcfgreponame + '/' //eg (elxr/../elixir-config.development)
var promises = [];
promises.push(
nodeShellExec('git', ['checkout', 'test'], {
inherit : true, shell: true,
cwd : testcfgdir
// , env: process.env
, runas : processedArgs.runas
, title : `git checkout ${testcfgreponame}`
}).catch((e)=>{ console.error(e) })
)
promises.push(
nodeShellExec('git', ['checkout', 'master'], {
inherit : true, shell: true,
cwd : devcfgdir
// , env: process.env
, runas : processedArgs.runas
, title : `git checkout ${devcfgreponame}`
}).catch((e)=>{ console.error(e) })
)
return Promise.all(promises).then(()=> {
globSync( '**/*.test.js', {cwd : devcfgdir}).map((filename) => {
console.log('File found : ' + devcfgdir + filename)
fs.copyFileSync(devcfgdir + filename, testcfgdir+ filename);
nodeShellExec('git', ['checkout', 'test'], {
inherit : true, shell: true,
cwd : devcfgdir
// , env: process.env
, runas : processedArgs.runas
, title : `git checkout ${devcfgreponame}`
}).catch((e)=>{ console.error(e) })
})
})
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) })
}
])
}
}
])
).then(()=>{
else return Promise.resolve(true)
})
.then(()=>{
fs.writeFileSync('run.done', 'success')
}).catch(()=>{
fs.writeFileSync('run.done', 'error')

Loading…
Cancel
Save