|
|
|
|
|
|
|
|
else { |
|
|
else { |
|
|
console.log('cloning ' + repo) |
|
|
console.log('cloning ' + repo) |
|
|
// PB : TODO -- detect if a clonable repo exists in currentGitAuthUser |
|
|
// PB : TODO -- detect if a clonable repo exists in currentGitAuthUser |
|
|
return nodeShellExec('git', ['clone', '-c', 'core.symlinks=true', defaultRepoServer + `/${defaultRepoOwner}/` + repo + '.git'], |
|
|
|
|
|
|
|
|
return nodeShellExec('git', ['clone', '-c', 'core.symlinks=true', selectedinstance.reposerver + `/${defaultRepoOwner}/` + repo + '.git'], |
|
|
{ |
|
|
{ |
|
|
inherit: true, shell: true, |
|
|
inherit: true, shell: true, |
|
|
env: process.env |
|
|
env: process.env |
|
|
|
|
|
|
|
|
env: process.env |
|
|
env: process.env |
|
|
, cwd: instanceroot + '/' + repo |
|
|
, cwd: instanceroot + '/' + repo |
|
|
, runas: processedArgs.runas |
|
|
, runas: processedArgs.runas |
|
|
, title: `git core.symlinks --replace-all true for ${defaultRepoServer + `/${defaultRepoOwner}/` + repo + '.git'}` |
|
|
|
|
|
|
|
|
, title: `git core.symlinks --replace-all true for ${selectedinstance.reposerver + `/${defaultRepoOwner}/` + repo + '.git'}` |
|
|
}) |
|
|
}) |
|
|
.then(() => { |
|
|
.then(() => { |
|
|
if (__isElevated) { |
|
|
if (__isElevated) { |
|
|
|
|
|
|
|
|
var defaultRepoOwner = 'chess'; |
|
|
var defaultRepoOwner = 'chess'; |
|
|
var elevatedRunasRepos = null |
|
|
var elevatedRunasRepos = null |
|
|
var gitRepos = null |
|
|
var gitRepos = null |
|
|
var defaultRepoServer = null |
|
|
|
|
|
|
|
|
|
|
|
// grep -qxF 'alias elxr="node elxr/index.js"' ~/.bash_profile || echo 'alias elxr="node elxr/index.js"' >> ~/.bash_profile |
|
|
// grep -qxF 'alias elxr="node elxr/index.js"' ~/.bash_profile || echo 'alias elxr="node elxr/index.js"' >> ~/.bash_profile |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var sequentialTaskShellCommands = []; |
|
|
var sequentialTaskShellCommands = []; |
|
|
if (!existsSync(`Z:/${repo}.git`)) { |
|
|
if (!existsSync(`Z:/${repo}.git`)) { |
|
|
sequentialTaskShellCommands = [ |
|
|
sequentialTaskShellCommands = [ |
|
|
// ['net', ['use', 'Z:', defaultRepoServer.replace('/','\\')], { |
|
|
|
|
|
|
|
|
// ['net', ['use', 'Z:', selectedinstance.reposerver.replace('/','\\')], { |
|
|
// inherit : true, shell: true |
|
|
// inherit : true, shell: true |
|
|
// , env: process.env |
|
|
// , env: process.env |
|
|
// }] |
|
|
// }] |
|
|
|
|
|
|
|
|
, ['git', ['remote', 'rename', 'origin', 'githubclone'], { cwd: `${instanceroot + '/' + repo}` }, (err) => { |
|
|
, ['git', ['remote', 'rename', 'origin', 'githubclone'], { cwd: `${instanceroot + '/' + repo}` }, (err) => { |
|
|
console.log('Ignoring origin rename error : ' + err); return true; //return true to continue. |
|
|
console.log('Ignoring origin rename error : ' + err); return true; //return true to continue. |
|
|
}] // PB ; Todo -- new repositories created locally will not have origin. Handle this failure. |
|
|
}] // PB ; Todo -- new repositories created locally will not have origin. Handle this failure. |
|
|
, ['git', ['remote', 'add', 'origin', `${defaultRepoServer}/${repo}.git`], { cwd: `${instanceroot + '/' + repo}` }] |
|
|
|
|
|
|
|
|
, ['git', ['remote', 'add', 'origin', `${selectedinstance.reposerver}/${repo}.git`], { cwd: `${instanceroot + '/' + repo}` }] |
|
|
// PB : TODO -- If threre is a gitbubclone origin |
|
|
// PB : TODO -- If threre is a gitbubclone origin |
|
|
// Set the master to pull from the local repo. |
|
|
// Set the master to pull from the local repo. |
|
|
] |
|
|
] |
|
|
if (!existsSync(`Z:`)) { |
|
|
if (!existsSync(`Z:`)) { |
|
|
sequentialTaskShellCommands.splice(0, 0, ['net', ['use', 'Z:', defaultRepoServer.replace(/\//gm, '\\')], { |
|
|
|
|
|
|
|
|
sequentialTaskShellCommands.splice(0, 0, ['net', ['use', 'Z:', selectedinstance.reposerver.replace(/\//gm, '\\')], { |
|
|
inherit: true, shell: true |
|
|
inherit: true, shell: true |
|
|
, env: process.env |
|
|
, env: process.env |
|
|
}]) |
|
|
}]) |
|
|
|
|
|
|
|
|
var options = { cwd: instanceroot + '/' + repo } |
|
|
var options = { cwd: instanceroot + '/' + repo } |
|
|
// console.log(repo) |
|
|
// console.log(repo) |
|
|
return [ |
|
|
return [ |
|
|
['git', ['remote', 'add', 'chess', `${defaultRepoServer}/${user}/${repo}.git`], { cwd: instanceroot + '/' + repo }] |
|
|
|
|
|
|
|
|
['git', ['remote', 'add', 'chess', `${selectedinstance.reposerver}/${user}/${repo}.git`], { cwd: instanceroot + '/' + repo }] |
|
|
, ['git', ['remote', 'set-url', '--push', 'chess', 'no-pushing'], { cwd: instanceroot + '/' + repo }] |
|
|
, ['git', ['remote', 'set-url', '--push', 'chess', 'no-pushing'], { cwd: instanceroot + '/' + repo }] |
|
|
, ['git', ['remote', 'set-url', 'origin', `${defaultRepoServer}/${user}/${repo}.git`], { cwd: instanceroot + '/' + repo }] |
|
|
|
|
|
|
|
|
, ['git', ['remote', 'set-url', 'origin', `${selectedinstance.reposerver}/${user}/${repo}.git`], { cwd: instanceroot + '/' + repo }] |
|
|
] |
|
|
] |
|
|
} |
|
|
} |
|
|
var x = (args) => { |
|
|
var x = (args) => { |
|
|
|
|
|
|
|
|
We will run your choice of default or create your own at the next prompt. |
|
|
We will run your choice of default or create your own at the next prompt. |
|
|
------------------------------------------------------------------------------- |
|
|
------------------------------------------------------------------------------- |
|
|
`)) |
|
|
`)) |
|
|
var prompt = cli.prompt; |
|
|
|
|
|
|
|
|
var prompt = cli.prompter; |
|
|
return prompt.ask(`Choose an option : |
|
|
return prompt.ask(`Choose an option : |
|
|
d) Install the default chess instance. |
|
|
d) Install the default chess instance. |
|
|
=> elxr i chess node_env=development --default |
|
|
=> elxr i chess node_env=development --default |
|
|
|
|
|
|
|
|
processedArgs._[0] = 'i' |
|
|
processedArgs._[0] = 'i' |
|
|
selectedinstance.instanceName = processedArgs._[1] = processedArgs._[1] || 'chess' |
|
|
selectedinstance.instanceName = processedArgs._[1] = processedArgs._[1] || 'chess' |
|
|
selectedinstance.node_env = processedArgs.node_env = (process.env.NODE_ENV && process.env.NODE_ENV.trim()) || processedArgs.node_env || 'development' |
|
|
selectedinstance.node_env = processedArgs.node_env = (process.env.NODE_ENV && process.env.NODE_ENV.trim()) || processedArgs.node_env || 'development' |
|
|
defaultRepoServer = 'https://git.bbh.org.in' |
|
|
|
|
|
|
|
|
selectedinstance.reposerver = 'https://git.bbh.org.in' |
|
|
getManifest() // PB : TODO -- acquire the manifest directly from http url instead of clone before cloning the config. Since |
|
|
getManifest() // PB : TODO -- acquire the manifest directly from http url instead of clone before cloning the config. Since |
|
|
// This is because the manifest at any server location can redirect to the preferred server.. |
|
|
// This is because the manifest at any server location can redirect to the preferred server.. |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
console.log(elxr.help()); process.exit() |
|
|
console.log(elxr.help()); process.exit() |
|
|
} |
|
|
} |
|
|
else if (choice === 'n' || choice === 'i') { |
|
|
else if (choice === 'n' || choice === 'i') { |
|
|
var p1 = cli.prompt; |
|
|
|
|
|
|
|
|
var p1 = cli.prompter; |
|
|
return p1.ask(`Enter Instance Name ( <= ${selectedinstance.instanceName} ) : `).then(function (instanceName) { |
|
|
return p1.ask(`Enter Instance Name ( <= ${selectedinstance.instanceName} ) : `).then(function (instanceName) { |
|
|
processedArgs._[0] = 'i' |
|
|
processedArgs._[0] = 'i' |
|
|
selectedinstance.instanceName = processedArgs._[1] = instanceName || selectedinstance.instanceName; |
|
|
selectedinstance.instanceName = processedArgs._[1] = instanceName || selectedinstance.instanceName; |
|
|
return p1.ask(`Enter Environment ( <= ${selectedinstance.node_env} ) : `).then(function (node_env) { |
|
|
return p1.ask(`Enter Environment ( <= ${selectedinstance.node_env} ) : `).then(function (node_env) { |
|
|
selectedinstance.node_env = processedArgs.node_env = node_env || selectedinstance.node_env |
|
|
selectedinstance.node_env = processedArgs.node_env = node_env || selectedinstance.node_env |
|
|
if (choice === 'n') { |
|
|
if (choice === 'n') { |
|
|
defaultRepoServer = 'https://git.bbh.org.in' |
|
|
|
|
|
|
|
|
selectedinstance.reposerver = 'https://git.bbh.org.in' |
|
|
console.warn( |
|
|
console.warn( |
|
|
chalk.magenta('No Option Available. Your account may not have privileges. You can request here http://git.bbh.org.in/chess')) |
|
|
chalk.magenta('No Option Available. Your account may not have privileges. You can request here http://git.bbh.org.in/chess')) |
|
|
process.exit(); |
|
|
process.exit(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return p1.ask(`Enter preferred repo server ( <= ${selectedinstance.reposervers[0]} ) : `).then(function (reposerver) { |
|
|
return p1.ask(`Enter preferred repo server ( <= ${selectedinstance.reposervers[0]} ) : `).then(function (reposerver) { |
|
|
p1.close() |
|
|
p1.close() |
|
|
defaultRepoServer = reposerver || selectedinstance.reposervers[0] || 'https://git.bbh.org.in' |
|
|
|
|
|
|
|
|
selectedinstance.reposerver = reposerver || selectedinstance.reposervers[0] || 'https://git.bbh.org.in' |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
} else if (choice === 'c') { |
|
|
} else if (choice === 'c') { |
|
|
var p1 = cli.prompt; |
|
|
|
|
|
|
|
|
var p1 = cli.prompter; |
|
|
return p1.ask(`Enter Instance Name ( <= ${selectedinstance.instanceName} ) : `).then(function (instanceName) { |
|
|
return p1.ask(`Enter Instance Name ( <= ${selectedinstance.instanceName} ) : `).then(function (instanceName) { |
|
|
selectedinstance.instanceName = processedArgs._[1] = instanceName || selectedinstance.instanceName |
|
|
selectedinstance.instanceName = processedArgs._[1] = instanceName || selectedinstance.instanceName |
|
|
return p1.ask(`Enter Environment ( <= ${selectedinstance.node_env} ) : `).then(function (node_env) { |
|
|
return p1.ask(`Enter Environment ( <= ${selectedinstance.node_env} ) : `).then(function (node_env) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
else processedArgs._[0] = cmd |
|
|
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.reposervers[0]} ) : `).then(function (reposerver) { |
|
|
defaultRepoServer = reposerver || selectedinstance.reposervers[0] || 'https://git.bbh.org.in' |
|
|
|
|
|
|
|
|
selectedinstance.reposerver = reposerver || selectedinstance.reposervers[0] || 'https://git.bbh.org.in' |
|
|
p1.close() |
|
|
p1.close() |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
var acquireConfig = function (selected, chessinstances) { |
|
|
var acquireConfig = function (selected, chessinstances) { |
|
|
|
|
|
|
|
|
var configrepo = selected.instanceName + '-config-' + selected.node_env; |
|
|
var configrepo = selected.instanceName + '-config-' + selected.node_env; |
|
|
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) + '', { 'flag': 'w' }) |
|
|
|
|
|
// PB : TODO -- We should probably write the new server config also... |
|
|
|
|
|
defaultRepoServer = 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 (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.') |
|
|
|
|
|
}) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var launchpath = process.cwd().replace(/\\/, '/') |
|
|
var launchpath = process.cwd().replace(/\\/, '/') |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
instanceroot = root.replace(/\\/, '/'); |
|
|
instanceroot = root.replace(/\\/, '/'); |
|
|
|
|
|
|
|
|
return Object.assign({ root }, __default); |
|
|
|
|
|
|
|
|
__default.root = root; |
|
|
|
|
|
return Promise.resolve(__default); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// |
|
|
var __default = { |
|
|
var __default = { |
|
|
|
|
|
|
|
|
// Default is public server only. |
|
|
// Default is public server only. |
|
|
|
|
|
|
|
|
, node_env: 'development' |
|
|
, node_env: 'development' |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var __interactve_promts = { |
|
|
|
|
|
get reposerver(){ |
|
|
|
|
|
return cli.prompt(this.reposervers, 'git default repo').then(reposerver => { |
|
|
|
|
|
Object.defineProperty(this, 'reposerver', { |
|
|
|
|
|
value: reposerver, |
|
|
|
|
|
writable: false, |
|
|
|
|
|
configurable : true |
|
|
|
|
|
}); |
|
|
|
|
|
return reposerver |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
, set reposerver(reposerver){ |
|
|
|
|
|
Object.defineProperty(this, 'reposerver', { |
|
|
|
|
|
value: reposerver, |
|
|
|
|
|
writable: false, |
|
|
|
|
|
configurable : true |
|
|
|
|
|
}); |
|
|
|
|
|
return reposerver |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var downloadsdir = '../Downloads'; |
|
|
var downloadsdir = '../Downloads'; |
|
|
var prerequisites = [ |
|
|
var prerequisites = [ |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
// , '/MERGETASKS=!runcode' // This is required only for vscode... |
|
|
// , '/MERGETASKS=!runcode' // This is required only for vscode... |
|
|
]] |
|
|
]] |
|
|
, preinstallsteps: function() { |
|
|
, preinstallsteps: function() { |
|
|
var prompt = cli.prompt; |
|
|
|
|
|
|
|
|
var prompt = cli.prompter; |
|
|
var steps = [ |
|
|
var steps = [ |
|
|
() => { |
|
|
() => { |
|
|
if (!existsSync(downloadsdir + '/' + this.installer)) { |
|
|
if (!existsSync(downloadsdir + '/' + this.installer)) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
] |
|
|
] |
|
|
var prompts = [ |
|
|
var prompts = [ |
|
|
() => prompt.ask(`git user name : ( <= ${gitUser} )`).then((user) => { gitUser = user; }) |
|
|
|
|
|
|
|
|
() => prompt.ask(`git user name : ( <= ${gitUser} )`).then((user) => { gitUser = user; }) |
|
|
, () => prompt.ask(`git email : ( <= ${gitEmail} )`).then((email) => { gitEmail = email; }) |
|
|
, () => prompt.ask(`git email : ( <= ${gitEmail} )`).then((email) => { gitEmail = email; }) |
|
|
] |
|
|
] |
|
|
return any([any(steps), any(prompts)]).then(() => { prompt.close() }) |
|
|
return any([any(steps), any(prompts)]).then(() => { prompt.close() }) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
, postinstallsteps: function(){ |
|
|
, postinstallsteps: function(){ |
|
|
|
|
|
|
|
|
var prompt = cli.prompt; |
|
|
|
|
|
|
|
|
var prompt = cli.prompter; |
|
|
|
|
|
|
|
|
var gitUser = 'guest'; |
|
|
var gitUser = 'guest'; |
|
|
var gitEmail = 'guest@bbh.org.in'; |
|
|
var gitEmail = 'guest@bbh.org.in'; |
|
|
|
|
|
|
|
|
prompts.push( |
|
|
prompts.push( |
|
|
()=>{ |
|
|
()=>{ |
|
|
var choices = { 0 : 'guest', 1 : 'chessdemo' } |
|
|
var choices = { 0 : 'guest', 1 : 'chessdemo' } |
|
|
return prompt.ask( |
|
|
|
|
|
`git user name \n ` + Object.keys(choices).map(choice => { return ` ${(+choice) + 1}) ${choices[choice]} `}).join('\n') + `\n default ( <= ${choices[0]} ) : ` |
|
|
|
|
|
).then(choice => { |
|
|
|
|
|
if(!choice) return gitUser = choices[0]; |
|
|
|
|
|
if(choice && isNaN(+choice)) return gitUser = choice; |
|
|
|
|
|
return gitUser = choices[choice + 1]; |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
return cli.prompt(choices, 'git user name').then(gituser => gitUser = gituser) |
|
|
} |
|
|
} |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
prompts.push( |
|
|
prompts.push( |
|
|
()=>{ |
|
|
()=>{ |
|
|
var choices = { 0 : 'guest@bbh.org.in', 1 : 'chessdemo@bbh.org.in' } |
|
|
var choices = { 0 : 'guest@bbh.org.in', 1 : 'chessdemo@bbh.org.in' } |
|
|
return prompt.ask( |
|
|
|
|
|
`git user email \n ` + Object.keys(choices).map(choice => { return ` ${(+choice) + 1}) ${choices[choice]} `}).join('\n') + `\n default ( <= ${choices[0]} ) : ` |
|
|
|
|
|
).then(choice => { |
|
|
|
|
|
if(!choice) return gitEmail = choices[0]; |
|
|
|
|
|
if(choice && isNaN(+choice)) return gitEmail = choice; |
|
|
|
|
|
return gitEmail = choices[choice + 1]; |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
return cli.prompt(choices, 'git user email').then(gitemail => gitEmail = gitemail) |
|
|
} |
|
|
} |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Promise.all(downloadtasks).then(() => { return any(installtasks) }) |
|
|
return Promise.all(downloadtasks).then(() => { return any(installtasks) }) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
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) } |
|
|
|
|
|
var detectedInstance = detectInstance(); // From launch location etc. |
|
|
|
|
|
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; |
|
|
|
|
|
|
|
|
|
|
|
selectedinstance = detectedInstance = Object.assign(selectedinstance, clioverrides); |
|
|
|
|
|
var maintask = () => { |
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
// function updateselection(selected) { selectedinstance = utils.assign(selectedinstance, selected) } |
|
|
|
|
|
var selectedinstance = null; |
|
|
|
|
|
var chessinstances = { current_run : {} }; |
|
|
|
|
|
acquireElevationState().then(() => { |
|
|
|
|
|
var skipprerequisites = false; |
|
|
|
|
|
var clioverrides = { } |
|
|
|
|
|
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] || {} |
|
|
|
|
|
|
|
|
|
|
|
// Override sequence. |
|
|
|
|
|
// __default, chessinstances[current_run], instanceName-config-development, cliargs, interactve_promts |
|
|
|
|
|
selectedinstance = Object.assign( |
|
|
|
|
|
selected |
|
|
|
|
|
, chessinstances[chessinstances.current_run.instanceName][chessinstances.current_run.node_env] |
|
|
|
|
|
, clioverrides |
|
|
|
|
|
// , __interactve_promts -- Cant just override. Also need selectedinstance to be ready... |
|
|
|
|
|
); |
|
|
|
|
|
repomanifest = selectedinstance |
|
|
|
|
|
return chessinstances |
|
|
|
|
|
} |
|
|
|
|
|
function acquirelocalinstances(selected){ |
|
|
|
|
|
var chessinstances = utils.assign(require(path.normalize(selected.root + '/chessinstances.js'))); |
|
|
|
|
|
return chessinstances |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var maintask = () => { |
|
|
|
|
|
|
|
|
// Default cmd to run ! |
|
|
// Default cmd to run ! |
|
|
var chessinstances = acquirelocalinstances(selectedinstance); |
|
|
|
|
|
processedArgs._[0] === processedArgs._[0] || 'pull'; |
|
|
processedArgs._[0] === processedArgs._[0] || 'pull'; |
|
|
// defaultRepoServer = repomanifest.reposervers[0] // PB : TODO -- Attempt first one that is available and online from all that are available... |
|
|
|
|
|
return prerequisites.git.verifyAndInstall().then(()=>{ |
|
|
|
|
|
return acquireConfig(selectedinstance, chessinstances).catch((e) => { |
|
|
|
|
|
console.error('Exisitng config Failed. Fix config and rerun or chose another.') |
|
|
|
|
|
console.error(e); |
|
|
|
|
|
|
|
|
// selectedinstance.reposerver = repomanifest.reposervers[0] // PB : TODO -- Attempt first one that is available and online from all that are available... |
|
|
|
|
|
|
|
|
|
|
|
return prerequisites.git.verifyAndInstall().then(()=>{ |
|
|
|
|
|
var e = { message : 'verifyAndInstall', success : true} |
|
|
|
|
|
return acquireConfig(selectedinstance, chessinstances).catch((err) => { |
|
|
|
|
|
e = err; |
|
|
|
|
|
console.error('Chosen cofiguraton failed or not found. Fix config and rerun or chose another.') |
|
|
|
|
|
console.error(err) |
|
|
}).then(() => { return elxrworker(true) }) |
|
|
}).then(() => { return elxrworker(true) }) |
|
|
}); |
|
|
|
|
|
|
|
|
// .finally(()=>{ |
|
|
|
|
|
// fs.writeFileSync('run.log', ', ' + JSON.stringify({ error: e.message }), { 'flag': 'a+' }) |
|
|
|
|
|
// if(!e.success) fs.writeFileSync('run.done', 'error'); |
|
|
|
|
|
// // return process.exit() |
|
|
|
|
|
// }) |
|
|
|
|
|
}) |
|
|
} |
|
|
} |
|
|
catch (e) { |
|
|
|
|
|
console.error(e) |
|
|
|
|
|
// No local instances config found. We acquire user choices and proceed to reattempt. |
|
|
|
|
|
chessinstances = {} |
|
|
|
|
|
chessinstances.current_run = {} |
|
|
|
|
|
initinstances(chessinstances, selectedinstance) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return detectInstance().then((detectedInstance)=>{ |
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
|
|
|
|
selectedinstance = Object.assign(detectedInstance, clioverrides); |
|
|
var todo = Promise.resolve(true); |
|
|
var todo = Promise.resolve(true); |
|
|
if(processedArgs._[0] && selectedinstance.node_env && selectedinstance.instanceName){ |
|
|
|
|
|
// Weve been told what to do. |
|
|
|
|
|
todo = Promise.resolve(true) |
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
chessinstances = acquirelocalinstances(selectedinstance); |
|
|
|
|
|
initinstances(chessinstances, selectedinstance) |
|
|
} |
|
|
} |
|
|
else todo = acquireChoices(selectedinstance) |
|
|
|
|
|
|
|
|
catch (e) { |
|
|
|
|
|
console.error(e) |
|
|
|
|
|
// No local instances config found. We acquire user choices and proceed to reattempt. |
|
|
|
|
|
initinstances(chessinstances, selectedinstance) |
|
|
|
|
|
|
|
|
return todo.then(() => { |
|
|
|
|
|
try { |
|
|
|
|
|
var chessinstances = acquirelocalinstances(selectedinstance) |
|
|
|
|
|
} |
|
|
|
|
|
catch (e) { |
|
|
|
|
|
console.error(e) |
|
|
|
|
|
console.error('No local instances config found in current root = ' + selectedinstance.root); |
|
|
|
|
|
console.log('A config will be createed with the instance and environment chosen...') |
|
|
|
|
|
} |
|
|
|
|
|
finally { |
|
|
|
|
|
return prerequisites.git.verifyAndInstall().then(()=>{ |
|
|
|
|
|
return acquireConfig(selectedinstance, chessinstances).catch((e) => { |
|
|
|
|
|
console.error('Chosen cofiguraton failed or not found') |
|
|
|
|
|
console.error(e) |
|
|
|
|
|
}).then(() => { return elxrworker(true) }) |
|
|
|
|
|
.finally(()=>{ |
|
|
|
|
|
fs.writeFileSync('run.log', ', ' + JSON.stringify({ error: e.message }), { 'flag': 'a+' }) |
|
|
|
|
|
fs.writeFileSync('run.done', 'error'); |
|
|
|
|
|
// return process.exit() |
|
|
|
|
|
|
|
|
var prompts = []; |
|
|
|
|
|
Object.keys(__interactve_promts).forEach(k => { |
|
|
|
|
|
if(!selectedinstance[k]) { |
|
|
|
|
|
prompts.push(async ()=>{ |
|
|
|
|
|
Object.defineProperty(selectedinstance, k, Object.getOwnPropertyDescriptor(__interactve_promts, k)); |
|
|
|
|
|
return await selectedinstance[k] |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
todo = any(prompts).then(()=>{ return selectedinstance }) |
|
|
|
|
|
|
|
|
|
|
|
if(!processedArgs._[0] || !selectedinstance.node_env || !selectedinstance.instanceName){ |
|
|
|
|
|
// Weve been told what to do. |
|
|
|
|
|
todo = acquireChoices(selectedinstance) |
|
|
} |
|
|
} |
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
todo = todo.then(() => { |
|
|
|
|
|
try { |
|
|
|
|
|
chessinstances = acquirelocalinstances(selectedinstance) |
|
|
|
|
|
initinstances(chessinstances, selectedinstance) |
|
|
|
|
|
} |
|
|
|
|
|
catch (e) { |
|
|
|
|
|
console.error(e) |
|
|
|
|
|
console.log('No local instances config found in current root = ' + selectedinstance.root); |
|
|
|
|
|
console.log('A config will be createed with the instance and environment chosen...') |
|
|
|
|
|
// return (async ()=>{return await __default.reposerver})().then(()=>{ |
|
|
|
|
|
// // selectedinstance = Object.assign(detectedInstance, clioverrides); |
|
|
|
|
|
// return selectedinstance = Object.assign(__default, selectedinstance); |
|
|
|
|
|
// }) |
|
|
|
|
|
return selectedinstance |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
acquireElevationState().then(() => { |
|
|
|
|
|
var skipprerequisites = false |
|
|
|
|
|
if (!skipprerequisites && !__isElevated) mainTasks.push(verifyAndInstallPrerequisites); |
|
|
|
|
|
mainTasks.push(maintask) |
|
|
|
|
|
return any(mainTasks); |
|
|
|
|
|
|
|
|
return todo |
|
|
|
|
|
}).then(()=>{ |
|
|
|
|
|
if (!skipprerequisites && !__isElevated) mainTasks.push(verifyAndInstallPrerequisites); |
|
|
|
|
|
mainTasks.push(maintask) |
|
|
|
|
|
return any(mainTasks); |
|
|
|
|
|
}) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
// detect if alread installed -> Take no action. |
|
|
// detect if alread installed -> Take no action. |