Browse Source

Old changes on Production A

pull/9/head
anishbhattacharjee 3 years ago
parent
commit
b044d3f5ad
1 changed files with 40 additions and 20 deletions
  1. 40
    20
      index.js

+ 40
- 20
index.js View File

} }
} }


var getPullCmd = (repo) => {
var getPullCmd = (repo, branch) => {
// console.log(useGitPull) // console.log(useGitPull)


var pullCmd = [gitInstallDir
, ['-c', 'branch=`git rev-parse --abbrev-ref HEAD`;for i in `git remote`; do git pull $i $branch; done;']
, { cwd: repo, title: 'pull all origins for ' + repo }]
if(branch) {
var pullCmd = [ gitInstallDir
, ['-c', 'for i in `git remote`; do git pull $i ' + branch + '; done;']
, { cwd : repo, title : 'pull all origins for ' + repo }]
}
else {
var pullCmd = [gitInstallDir
, ['-c', 'branch=`git rev-parse --abbrev-ref HEAD`;for i in `git remote`; do git pull $i $branch; done;']
, { cwd: repo, title: 'pull all origins for ' + repo }]
}
// var pullCmd = ['pullall', [], { cwd : repo }] // var pullCmd = ['pullall', [], { cwd : repo }]
if (useGitPull) pullCmd = ['git', ['pull'], { if (useGitPull) pullCmd = ['git', ['pull'], {
inherit: true, shell: true, inherit: true, shell: true,
return pullCmd return pullCmd
} }


var performPull = (repo) => {
var performPull = (repo, branch) => {
if (existsSync(instanceroot + '/' + repo)) { if (existsSync(instanceroot + '/' + repo)) {
console.log('pulling ' + instanceroot + '/' + repo)
return nodeShellExec.apply(null, getPullCmd(repo)).then(() => {
console.log('pulling ' + instanceroot + '/' + repo + 'branch ' + branch)
return nodeShellExec.apply(null, getPullCmd(repo, branch)).then(() => {
if (__isElevated) { if (__isElevated) {
fs.writeFileSync('run.log', ', ' + JSON.stringify({ repo, success: true }), { 'flag': 'a+' }) fs.writeFileSync('run.log', ', ' + JSON.stringify({ repo, success: true }), { 'flag': 'a+' })
} }
// console.dir(env) // console.dir(env)
console.log('Running exlr pull : ' + path.dirname(__dirname)) console.log('Running exlr pull : ' + path.dirname(__dirname))


if (!processedArgs.runas) gitRepos.forEach(performPull)
// SAM : TODO Exclude data repo
if (!processedArgs.runas) gitRepos.map((repo) => performPull(repo, 'master'))
if (__isElevated) { if (__isElevated) {
return any(elevatedRunasRepos.map((repo) => performPull(repo))).then(() => {
return any(elevatedRunasRepos.map((repo) => performPull(repo, 'master'))).then(() => {
fs.writeFileSync('run.done', 'success') fs.writeFileSync('run.done', 'success')
}).catch(() => { }).catch(() => {
fs.writeFileSync('run.done', 'error') fs.writeFileSync('run.done', 'error')
// --runas // --runas
if (processedArgs.runas) { if (processedArgs.runas) {
// Weve been asked to run in priviledged mode. Check if we already are privileged. // Weve been asked to run in priviledged mode. Check if we already are privileged.
__runcmd('runas')
return __runcmd('runas')
} }
else __runcmd(processedArgs.label || processedArgs._[0] || 'h');
else return __runcmd(processedArgs.label || processedArgs._[0] || 'h');
} }


var getManifest = function () { var getManifest = function () {


, elevated: [] , elevated: []
, exludeMergeRepos: {} , exludeMergeRepos: {}
, instanceName: processedArgs._[1] || 'chess'
, instanceName: 'chess'
// Runas windowshta clobbers and removes the NODE_ENV !!! We therefore pass it in. // Runas windowshta clobbers and removes the NODE_ENV !!! We therefore pass it in.
, node_env: (process.env.NODE_ENV && process.env.NODE_ENV.trim()) || processedArgs.node_env || 'development'
, node_env: 'development'
} }
return Object.assign({ root }, __default); return Object.assign({ root }, __default);
} }


return Promise.all(downloadtasks).then(() => { return any(installtasks) }) return Promise.all(downloadtasks).then(() => { return any(installtasks) })
} }


function acquirelocalinstances(selected){
var chessinstances = utils.assign(require(path.normalize(selected.root + '/chessinstances.js')));
chessinstances.current_run.instanceName = processedArgs._[1] = selected.instanceName || processedArgs._[1] || chessinstances.current_run.instanceName;
chessinstances.current_run.node_env = processedArgs.node_env = selected.node_env || processedArgs.node_env || chessinstances.current_run.node_env;
selectedinstance = Object.assign(chessinstances[chessinstances.current_run.instanceName][chessinstances.current_run.node_env], selected);
function initinstances(chessinstances, selected) {
chessinstances.current_run.instanceName = processedArgs._[1] = processedArgs._[1] || chessinstances.current_run.instanceName || selected.instanceName;
chessinstances.current_run.node_env = processedArgs.node_env = processedArgs.node_env || chessinstances.current_run.node_env || selected.node_env;
chessinstances[chessinstances.current_run.instanceName] = chessinstances[chessinstances.current_run.instanceName] || {}
selectedinstance = Object.assign(selected, chessinstances[chessinstances.current_run.instanceName][chessinstances.current_run.node_env], clioverrides);
repomanifest = selectedinstance repomanifest = selectedinstance
return chessinstances return chessinstances
} }
function acquirelocalinstances(selected){
var chessinstances = utils.assign(require(path.normalize(selected.root + '/chessinstances.js')));
return initinstances(chessinstances, selected)
}


function updateselection(selected) { selectedinstance = utils.assign(selectedinstance, selected) } function updateselection(selected) { selectedinstance = utils.assign(selectedinstance, selected) }
var detectedInstance = detectInstance(); // From launch location etc. var detectedInstance = detectInstance(); // From launch location etc.
var selectedinstance = detectedInstance var selectedinstance = detectedInstance

var clioverrides = { }
processedArgs._[1] ? clioverrides.instanceName = processedArgs._[1]: null;
processedArgs.node_env ? clioverrides.node_env = (process.env.NODE_ENV && process.env.NODE_ENV.trim()) || processedArgs.node_env
: (process.env.NODE_ENV && process.env.NODE_ENV.trim()) ? clioverrides.node_env = (process.env.NODE_ENV && process.env.NODE_ENV.trim()): null;


var maintask = () => { var maintask = () => {
try { try {
catch (e) { catch (e) {
console.error(e) console.error(e)
// No local instances config found. We acquire user choices and proceed to reattempt. // No local instances config found. We acquire user choices and proceed to reattempt.
chessinstances = {}
chessinstances.current_run = {}
initinstances(chessinstances, selectedinstance)
return acquireChoices(selectedinstance).then(() => { return acquireChoices(selectedinstance).then(() => {
try { try {
var chessinstances = acquirelocalinstances(selectedinstance) var chessinstances = acquirelocalinstances(selectedinstance)
console.log('We will create a new one with the instance and environment chosen...') console.log('We will create a new one with the instance and environment chosen...')
} }
finally { finally {
return acquireConfig(selectedinstance, chessinstances).catch((e) => { return acquireConfig(selectedinstance, chessinstances).catch((e) => {
console.error('Chosen cofiguraton failed or not found') console.error('Chosen cofiguraton failed or not found')
console.error(e) console.error(e)
.finally(()=>{ .finally(()=>{
fs.writeFileSync('run.log', ', ' + JSON.stringify({ error: e.message }), { 'flag': 'a+' }) fs.writeFileSync('run.log', ', ' + JSON.stringify({ error: e.message }), { 'flag': 'a+' })
fs.writeFileSync('run.done', 'error'); fs.writeFileSync('run.done', 'error');
return process.exit()
// return process.exit()
}) })
} }
}) })

Loading…
Cancel
Save