Преглед изворни кода

Merge branch 'master' of //172.16.0.27/repos/elxr

production
Pradeep Bhaskaran пре 4 година
родитељ
комит
cd69b19355
2 измењених фајлова са 100 додато и 4 уклоњено
  1. 98
    3
      index.js
  2. 2
    1
      package.json

+ 98
- 3
index.js Прегледај датотеку

@@ -17,8 +17,10 @@ const { spawn, spawnSync } = require('child_process');
const cliargs = require('../elxr/cliargs'); // Use minimist...
const processedArgs = cliargs(process.argv.slice(2));
console.dir(processedArgs)
var globSync = require('glob').sync;

var path = require('path')
var path = require('path');
const { isMaster } = require('cluster');
// Serialize a set of functions that will execute to return a promises one after the other.
// Will stop when any one fails.
function any(iterable, continueOnFailure) {
@@ -533,6 +535,12 @@ var __runcmd = function(label){
kill(serverPid)
}
, 'use' : ()=>{
// use a certain named instance.
// Eg :
// 1) elxr use elixir
// 2) elxr use cihsr
// If environment is not specified defaults to development.
// 1) NODE=test elxr use elixir

var runconfig = { NODE_ENV : process.env.NODE_ENV }
try { runconfig = Object.assign(runconfig, require('../run.js')) } catch(e) { }
@@ -561,7 +569,7 @@ var __runcmd = function(label){
return p;
}
else return Promise.resolve(true);
}
},
];
runconfig.NODE_ENV = process.env.NODE_ENV = process.env.NODE_ENV || runconfig.NODE_ENV || 'development';
if(processedArgs._[1] && runconfig.use !== processedArgs._[1]) runconfig.use = processedArgs._[1];
@@ -569,6 +577,37 @@ var __runcmd = function(label){
// console.log(process.env.cwd)
fs.writeFileSync('./run.js', 'module.exports = ' + JSON.stringify(runconfig))
var checkoutMap = {
'development' : 'master',
}

// 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], {
inherit : true, shell: true,
cwd : repo
}).catch((e)=>{ console.error(e) })
}

var mergeSources = {
'development' : null,
'test' : 'master',
'production' : 'test'
}
var exludeMergeRepos = {
'elixir-config-development' : true, 'elixir-config-test': true, 'elixir-config-production' : true
}

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], {
inherit : true, shell: true,
cwd : repo
}).catch((e)=>{ console.error(e) })
}
if(runconfig.NODE_ENV === 'development') performMerge = ()=>{}

any(tasks).then(()=>{
if(!processedArgs.runas) return op['runas']()

@@ -595,7 +634,63 @@ var __runcmd = function(label){
]
)
}
return any(tasks).then(()=>{

return any(tasks.concat([
any(gitRepos.map((repo)=>performCheckout(repo))),
any(elevatedRunasRepos.map((repo)=>performCheckout(repo))),
any(gitRepos.map((repo)=>performMerge(repo))),
any(elevatedRunasRepos.map((repo)=>performMerge(repo))),
, () => {
// 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)
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) })
)
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) })
})
})
}
}
])
).then(()=>{
fs.writeFileSync('run.done', 'success')
}).catch(()=>{
fs.writeFileSync('run.done', 'error')

+ 2
- 1
package.json Прегледај датотеку

@@ -10,6 +10,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"tree-kill": "^1.2.2"
"tree-kill": "^1.2.2",
"glob": "^7.1.2"
}
}

Loading…
Откажи
Сачувај