Browse Source

Fixes

production
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

if(Promise.resolve(p) === p ) { if(Promise.resolve(p) === p ) {
return p.then((pVal) => { 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) { if(Promise.resolve(pVal) === pVal) {
// Passed in function retured a promise. We still need to wait for it. // Passed in function retured a promise. We still need to wait for it.
pVal.then((pVal)=>{ pVal.then((pVal)=>{


// cant use git checkout -b it fails with branch already exists. // cant use git checkout -b it fails with branch already exists.
var performCheckout = (repo)=>{ 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, inherit : true, shell: true,
cwd : repo cwd : repo
, runas : processedArgs.runas , 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 = { var mergeSources = {
var exludeMergeRepos = { var exludeMergeRepos = {
'elixir-config-development' : true, 'elixir-config-test': true, 'elixir-config-production' : true '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 mergeSource = mergeSources[checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV]
var performMerge = (repo)=>{ var performMerge = (repo)=>{
, runas : processedArgs.runas , runas : processedArgs.runas
}).catch((e)=>{ console.error(e) }) }).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(()=>{ any(tasks).then(()=>{
if(!processedArgs.runas) return op['runas']() if(!processedArgs.runas) return op['runas']()
) )
} }


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. // Move test config from dev.
if(process.env.NODE_ENV === 'test'){ if(process.env.NODE_ENV === 'test'){
var devcfgreponame = runconfig.use + '-config' + '-development'; var devcfgreponame = runconfig.use + '-config' + '-development';
var testcfgdir = path.dirname(__dirname) + '/' + testcfgreponame + '/' var testcfgdir = path.dirname(__dirname) + '/' + testcfgreponame + '/'
var devcfgdir = path.dirname(__dirname) + '/' + devcfgreponame + '/' //eg (elxr/../elixir-config.development) 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') fs.writeFileSync('run.done', 'success')
}).catch(()=>{ }).catch(()=>{
fs.writeFileSync('run.done', 'error') fs.writeFileSync('run.done', 'error')

Loading…
Cancel
Save