Explorar el Código

Credentials upgrade and smoother install with cached insatllargs

master
pb hace 2 años
padre
commit
fc87466d3c
Se han modificado 2 ficheros con 423 adiciones y 224 borrados
  1. 353
    186
      i.win.js
  2. 70
    38
      index.js

+ 353
- 186
i.win.js Ver fichero

@@ -213,9 +213,17 @@ catch(e) {
var cli = {
prompt : function(choices, label, defaultchoice){
var options = [];
// console.dir(choices)
choices.forEach = forEach
choices.forEach(function(choice){ options.push( ((+choice) + 1) + ' ' + choices[choice] )})
return prompter.ask( label + ' \\n ' + options.join('\n') + '\n default ( <= ' + (defaultchoice || choices[0]) + ' ) : '
choices.forEach(function(choice, i, a){
// console.log(choice)
// console.log('------------------------')
// console.log( ((+i) + 1) + ' ' + choice )
options.push( ((+i) + 1) + ' ' + choice )
// console.log('------------------------')
})
// console.log(options)
return prompter.ask( label + '\n' + options.join('\n') + '\n default ( <= ' + (defaultchoice || choices[0]) + ' ) : '
).then( function(choice){
if(!choice) return defaultchoice || choices[0];
if(choice && isNaN(+choice)) return choice;
@@ -319,8 +327,26 @@ catch(e) {
// __Promise = ovrrides
function forEach(eachFn){
for(var i=0; i<this.length; i++) eachFn(this[i])
// PB : TODO -- iterators are messed up in cscript without enumerables...
function forEach(eachFn, o){
// console.dir(this)
// console.log('------------------------------------')
// console.log(''+ {})
// console.log('------------------------------------')
if('' + this === '[object Object]') {
// console.log('' + this)
// console.dir(this)
// var o = this
// for(var i in o){ console.log(i + ' : ' + o[i])}
for(var i in this){
if(i === 'forEach') continue; // Enumerable in cscript not supported ???
// console.log(i)
eachFn(this[i], i, this)
}
}
else {
for(var i=0; i<this.length; i++) eachFn(this[i], i, this)
}
}
function reduce(reducnFn, iv){
var acc = iv
@@ -339,7 +365,10 @@ catch(e) {
var existsSync = function(filepath){ return fso.FileExists(filepath) }
var fs = {
writeFileSync : function(filepath, text) {
// console.log('------------------writeFileSync----------------------')
// console.log(filepath)
// console.log('------------------writeFileSync----------------------')
var fh = fso.CreateTextFile(filepath, true);
fh.WriteLine(text);
fh.Close();
@@ -859,13 +888,19 @@ catch(e) {
}

function __main( selectedinstance ){
var downloadsdir = selectedinstance.root + '/Downloads';
var downloadsdir = selectedinstance.root + '\\..\\Downloads';

var callsheltask = function(args) {
// console.log('callsheltask : ' + args)
return function() { return nodeShellExec.apply(null, args) } }
var instanceName = 'elixir'
var reposerver = 'https://git.bbh.org.in';
var gitUser = 'guest';
var gitpassword = 'guest';
var gitEmail = 'guest@bbh.org.in';
var gitPreinstalled = true;


var BUILD_VERSION = '[VI]Version: {version} - built on {date}[/VI]';
function getVersion() { return BUILD_VERSION; }
@@ -924,8 +959,11 @@ function __main( selectedinstance ){
var p = preq.exists().then(function(exists) {
if (exists && !preq.forceinstall) console.log( preq.shellcmd + ' exists');
else {
console.log(exists)
console.log(preq.shellcmd + ' is not installed');
console.log('----------------------------')
console.log(exists) // PB : ??? Boolean true becomes -1 ???
console.log('----------------------------')
if(!exists) console.log(preq.shellcmd + ' is not installed');
else console.log(preq.shellcmd + ' is installed but forceinstall was specifed so re-installing');
return preq.preinstallsteps().then(function(){
// console.log(' task.install : ' + preq.install)
installtasks.push( function(){ return preq.install() } );
@@ -966,8 +1004,10 @@ function __main( selectedinstance ){
return getTaskCheckExists(self.shellcmd, { ignorefailures: true })().then(function(exists) {
// console.log('-------------exists=======================')
// console.dir(exists)
// console.log(self.shellcmd)
// console.log(exists.messages.join(' ').indexOf(self.shellcmd))
// console.log(exists + ' ' + self.shellcmd + ' exists')
if(exists && exists.messages.join(' ').indexOf(self.shellcmd) > -1 ) {
if(exists && (exists.messages.join(' ').indexOf(self.shellcmd) > -1) ) {
return true;
}
else return false
@@ -1033,6 +1073,170 @@ function __main( selectedinstance ){
// .catch( onEachError || function(e){ console.error(e) })
}
}


var createTasq = function(args, shellT, onEachError) {
var tasq = shellT ? shellT(args) : ( function(){
return any([nodeShellExec.apply(null, args)])
// .catch( onEachError || function(e){ console.error(e) } )
})
tasq.toString = function(){ return JSON.stringify(args)}
return tasq;
}

var execserial = function(tasklist, task, shellT, onEachError){
var exec = function(taskArgs){
console.log('executing ' + task)
var thistask = task.concat();
thistask[1] = thistask[1].concat()
thistask[1].push.apply(thistask[1], taskArgs)
return createTasq(thistask, shellT)
}
tasklist.map = map
console.log('execlist ' + tasklist.map(exec))
return any(tasklist.map(exec))
}
function resetgitconfig(){

// https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage
// Git Credential storage...
// git config --global credential.helper 'store --file ~/.gitcredentials'
// git credential-store --file ~/.gitcredentials store
// // notepad C:/Program Files/Git/etc/gitconfig
// git config --global --unset credential
// git config --edit --system
// git config --global credential.helper "store --file ~/gitcredentials"
// git credential fill
// git credential-store --file ~/git.store store
// Find system git config
// git config --global --edit
// git config --list --show-origin
// git config --list --show-origin --show-scope
// https://stackoverflow.com/questions/35942754/how-can-i-save-username-and-password-in-git
// Recipie
// git config --global --unset credentials.helper
// cd /path/to/my/repo
// git config --unset credential.helper
// git config --global credential.helper "store --file ~/.elxrcredentials"
// git config credential.helper 'store --file ~/.elxrcredentials'
//-- git config credential.*.username my_user_name
//-- git config credential.https://gitlab.com.username my_user_name
// git credential fill

// git config --global credential.modalprompt false // doesnst work.
// core askpass = ;;; https://stackoverflow.com/questions/37182847/how-do-i-disable-git-credential-manager-for-windows
var options = {
inherit: true, shell: true //, env: process.env
, cwd: selectedinstance.root
// , runas: processedArgs.runas
}
var task = ['git', ['config'], options]
var tasklist = [
// ['--global', '--unset credentials.helper']
// ['--unset', 'credentials.helper']
// ,
// ['credential.helper', `'store --file git_repo_credentials'`]
['--global', 'credential.helper', '"store --file ~/.elxrcredentials"']
, ['--global', '--replace-all', 'user.name', gitUser]
, ['--global', '--replace-all', 'user.email', gitEmail]
// , ['--list']
// , ['credential', 'fill']
]
console.log(tasklist)
var onEachError = function(e) { console.error( e.messages.join('\n') + e.result + '\n' + util.inspect(e) + '\n') }
var shellT = function(args) {
return getgitshelltask(args, onEachError)
// .catch(e => console.error( e.messages.join('\n') + e.result + '\n' + util.inspect(e) + '\n' + tasq.toString()) )
}
return execserial(tasklist, task, shellT, onEachError ).then(function(){
// git credential-store --file ./.elxrcredentials store
console.log('gathering git credentials')
var userhome = '~'
if(isWin()) userhome = '%userprofile%'
var host = reposerver.replace('https://','').replace('http://','')
var protocol = reposerver.replace('https://','') === host ? 'https' : 'http'
fs.writeFileSync('ic.txt', 'host='+host+'\r\nprotocol='+protocol+'\r\nusername='+gitUser+'\r\npassword='+gitpassword)
return nodeShellExec('git', ['credential-store', '--file', userhome + '/.elxrcredentials', 'store', '<', 'ic.txt'], options)
})
}

var gitpostinstallsteps = function(){

// Load just in case someone was smart enough to fill in before install.
var icf = fs.readFileSync( 'installchoices.js')
icf = icf.replace('module.exports = ', 'icf = ')
console.log(icf)
try {
icf = eval(icf)
}
catch(e) {
console.error(e)
}
// console.log(icf.reposerver)
instanceName = icf.instanceName
reposerver = icf.reposerver;
gitUser = icf.gitUser;
gitEmail = icf.gitEmail
// gitpassword = icf.??? ; we do not store password it should already be cached in the credential store.

// PB : TODO -- Detect failure or cancellation before attenpting postinstall steps...
var steps = [];
steps.push(
function(){
var choices = { 0 : 'elixir' }
return cli.prompt(choices, 'instanceName', instanceName).then(function(choice){ instanceName = choice } )
}
)
steps.push(
function(){
var choices = { 0 : 'https://git.bbh.org.in' }
return cli.prompt(choices, 'reposerver', reposerver).then(function(choice){ reposerver = choice } )
}
)
steps.push(
function(){
var choices = { 0 : 'guest', 1 : 'chessdemo' }
return cli.prompt(choices, 'git user name', gitUser).then(function(choice){ gitUser = choice } )
}
)
steps.push(
function(){
var choices = { }
return cli.prompt(choices, 'git password', gitpassword).then(function(choice){ gitpassword = choice } )
}
)
steps.push(
function(){
var choices = { 0 : 'guest@bbh.org.in', 1 : 'chessdemo@bbh.org.in' }
return cli.prompt(choices, 'git user email', gitEmail).then(function(choice){ gitEmail = choice })
}
)

return any(steps).then(function(){
// Save values to add credentials later in index.js...
// console.log('module.exports = { instanceName : "'+ instanceName +'", reposerver: "'+reposerver+'", gitUser: "'+gitUser+'", gitEmail:"'+gitEmail+'" }')
fs.writeFileSync( 'installchoices.js', 'module.exports = { instanceName : "'+ instanceName +'", reposerver: "'+reposerver+'", gitUser: "'+gitUser+'", gitEmail:"'+gitEmail+'" }' )
var steps = [
// ['git', ['config', '--global', '--add', 'user.name', gitUser]]
// , ['git', ['config', '--global', '--add', 'user.email', gitEmail]]
]
if(!steps.map) steps.map = map;
return any(steps.map(callsheltask)).then(function(){
})
});
}

var prerequisites = [
{
shellcmd: 'git',
@@ -1088,136 +1292,25 @@ function __main( selectedinstance ){
else throw e
})
}
, postinstallsteps: function(){

// PB : TODO -- Detect failure or cancellation before attenpting postinstall steps...
var steps = [];
steps.push(
function(){
var choices = { 0 : 'guest', 1 : 'chessdemo' }
return cli.prompt(choices, 'git user name', gitUser).then(function(choice){ gitUser = choice } )
}
)

steps.push(
function(){
var choices = { 0 : 'guest@bbh.org.in', 1 : 'chessdemo@bbh.org.in' }
return cli.prompt(choices, 'git user email', gitEmail).then(function(choice){ gitEmail = choice })
}
)

return any(steps).then(function(){
var steps = [
['git', ['config', '--global', '--add', 'user.name', gitUser]]
, ['git', ['config', '--global', '--add', 'user.email', gitEmail]]
]
if(!steps.map) steps.map = map;
return any(steps.map(callsheltask)).then(function(){

})
});
}
, postinstallsteps: gitpostinstallsteps
, install: function () {
gitPreinstalled = false;
var self = this;
console.log('Git Install called')

var createTasq = function(args, shellT, onEachError) {
var tasq = shellT ? shellT(args) : ( function(){
console.log('sdsfdsdf ' + args)
return any([nodeShellExec.apply(null, args)])
// .catch( onEachError || function(e){ console.error(e) } )
})
tasq.toString = function(){ return JSON.stringify(args)}
return tasq;
}

var execserial = function(tasklist, task, shellT, onEachError){
var exec = function(taskArgs){
console.log('execcing ' + task)
var thistask = task.concat();
thistask[1] = thistask[1].concat()
thistask[1].push.apply(thistask[1], taskArgs)
return createTasq(thistask, shellT)
}
tasklist.map = map
console.log('execlist ' + tasklist.map(exec))
return any(tasklist.map(exec))
}
function resetgitconfig(){
// https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage
// Git Credential storage...
// git config --global credential.helper 'store --file ~/.gitcredentials'
// git credential-store --file ~/.gitcredentials store
// // notepad C:/Program Files/Git/etc/gitconfig
// git config --global --unset credential
// git config --edit --system
// git config --global credential.helper "store --file ~/gitcredentials"
// git credential fill
// git credential-store --file ~/git.store store
// Find system git config
// git config --global --edit
// git config --list --show-origin
// git config --list --show-origin --show-scope
// https://stackoverflow.com/questions/35942754/how-can-i-save-username-and-password-in-git
// Recipie
// git config --global --unset credentials.helper
// cd /path/to/my/repo
// git config --unset credential.helper
// git config credential.helper 'store --file ~/.git_repo_credentials'
// git config credential.*.username my_user_name
// git config credential.https://gitlab.com.username my_user_name
// git credential fill
// git config --global credential.modalprompt false // doesnst work.
// core askpass = ;;; https://stackoverflow.com/questions/37182847/how-do-i-disable-git-credential-manager-for-windows
var options = {
inherit: true, shell: true //, env: process.env
, cwd: selectedinstance.root
// , runas: processedArgs.runas
}
var task = ['git', ['config'], options]
var tasklist = [
// ['--global', '--unset credentials.helper']
// ['--unset', 'credentials.helper']
// ,
// ['credential.helper', `'store --file git_repo_credentials'`]
['--global', 'credential.helper', "'store --file ~/.git_repo_credentials'"]
, ['--global', '--replace-all', 'user.name', 'pb']
, ['--global', '--replace-all', 'user.email', 'pradeep@bbh.org.in']
// , ['--list']
// , ['credential', 'fill']
]
var onEachError = function(e) { console.error( e.messages.join('\n') + e.result + '\n' + util.inspect(e) + '\n') }
var shellT = function(args) {
return getgitshelltask(args, onEachError)
// .catch(e => console.error( e.messages.join('\n') + e.result + '\n' + util.inspect(e) + '\n' + tasq.toString()) )
}
execserial(tasklist, task, shellT, onEachError )
}

return any([ /*self.preinstallsteps,*/
function(){ return self.installsteps() }
, function() { resetgitconfig() }
, function() { return resetgitconfig() }
, function(){ return self.postinstallsteps() }
])
}
, verifyAndInstall : function(){
var self = this;
return self.exists().then( function(exits) {
if(exists) return self.getUser(null, function(){ return self.postinstallsteps() } )
else return self.install();
})
}
// , verifyAndInstall : function(){
// var self = this;
// return self.exists().then( function(exits) {
// if(exists) return self.getUser(null, function(){ return self.postinstallsteps() } )
// else return self.install();
// })
// }
, exists : exists
, getUser : function(repo, onNoResult){
@@ -1346,25 +1439,33 @@ function __main( selectedinstance ){
, postinstallsteps : function() { return sysAddPathVar('%USERPROFILE%\\AppData/Local\\Microsoft\\WindowsApps') }
, exists : exists
}
, {
shellcmd: 'sqlexpress',
url: 'https://go.microsoft.com/fwlink/?linkid=866658'
, installer: 'SQL2019-SSEI-Expr.exe'
, {
// C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\Ssms.exe
// SQL Management studio 2018
shellcmd: 'Ssms.exe',
url: 'https://aka.ms/ssmsfullsetup'
, installer: 'SSMS-Setup-ENU.exe'
, installcmd: ['cmd', ['/c', 'start',
'/WAIT', downloadsdir + '/' + 'SQL2019-SSEI-Expr.exe'
, ''
'/WAIT', downloadsdir + '/' + 'SSMS-Setup-ENU.exe'
, '/IAcceptSQLServerLicenseTerms'
//, 'SSMSInstallRoot=%systemdrive%\\Program Files (x86)\\Microsoft SQL Server\\140\\Tools\\Binn\\ManagementStudio'
]]
, install : install
, exists : exists
, exists : function(){
var self = this;
var installedpath = 'C:\\Program Files (x86)\\Microsoft SQL Server Management Studio 18\\Common7\\IDE\\Ssms.exe'
console.log('checking existence of ' + installedpath)
return Promise.resolve(existsSync(installedpath))
}
, preinstallsteps: function() {
var self = this;
console.log('Node preinstall steps')
console.log('smss 2018 preinstall steps')

var steps = [];
steps.push(
function(){
if (!existsSync(downloadsdir + '/' + self.installer)) {
console.log(self.url)
return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', ['"' + self.url + '"', downloadsdir + '/' + self.installer]
, { waitmsg : 'downloading '+ self.shellcmd +' please wait' })
}
@@ -1380,18 +1481,24 @@ function __main( selectedinstance ){
}
}
, {
// "C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\Ssms.exe"
// SQL Management studio 2018
shellcmd: 'C:\\Program Files (x86)\\Microsoft SQL Server Management Studio 18\\Common7\\IDE\\Ssms.exe\\Ssms.exe',
url: 'https://aka.ms/ssmsfullsetup'
, installer: 'SSMS-Setup-ENU.exe'
// C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\Ssms.exe
shellcmd: 'Ssms.exe', // SQL Mgmt Studo 2017
url: 'https://go.microsoft.com/fwlink/?linkid=2043154&clcid=0x409'
, installer: 'SSMS-Setup-ENU-2017.exe'
, installcmd: ['cmd', ['/c', 'start',
'/WAIT', downloadsdir + '/' + 'SSMS-Setup-ENU.exe'
'/WAIT', downloadsdir + '/' + 'SSMS-Setup-ENU-2017.exe'
, '/IAcceptSQLServerLicenseTerms'
//, 'SSMSInstallRoot=%systemdrive%\\Program Files (x86)\\Microsoft SQL Server\\140\\Tools\\Binn\\ManagementStudio'
]]
, install : install
, exists : exists
, exists : function(){
return Promise.resolve(false)
var self = this;
// var installedpath = 'C:\\Program Files (x86)\\Microsoft SQL Server Management Studio 18\\Common7\\IDE\\Ssms.exe'
var installedpath = 'C:\\Program Files (x86)\\Microsoft SQL Server\\140\\Tools\\Binn\\ManagementStudio\\Ssms.exe'
console.log('checking existence of ' + installedpath)
return Promise.resolve(existsSync(installedpath))
}
, preinstallsteps: function() {
var self = this;
console.log('smss preinstall steps')
@@ -1415,20 +1522,25 @@ function __main( selectedinstance ){
// return any([any(steps), any(prompts)])
}
}
, {
shellcmd: 'Ssms.exe', // SQL Mgmt Studo 2017
url: 'https://go.microsoft.com/fwlink/?linkid=2043154&clcid=0x409'
, installer: 'SSMS-Setup-ENU-2017.exe'
, {
shellcmd: 'sqlservr.exe',
url: 'https://go.microsoft.com/fwlink/?linkid=866658'
, installer: 'SQL2019-SSEI-Expr.exe'
, installcmd: ['cmd', ['/c', 'start',
'/WAIT', downloadsdir + '/' + 'SSMS-Setup-ENU.exe'
, '/Quiet'
'/WAIT', downloadsdir + '/' + 'SQL2019-SSEI-Expr.exe'
, ''
//, 'SSMSInstallRoot=%systemdrive%\\Program Files (x86)\\Microsoft SQL Server\\140\\Tools\\Binn\\ManagementStudio'
]]
, install : install
, exists : exists
, exists : function(){
var self = this;
var installedpath = 'C:\\Program Files\\Microsoft SQL Server\\MSSQL15.SQLEXPRESS\\MSSQL\\Binn\\sqlservr.exe'
console.log('checking existence of ' + installedpath)
return Promise.resolve(existsSync(installedpath))
}
, preinstallsteps: function() {
var self = this;
console.log('smss preinstall steps')
console.log('sqlexpress preinstall steps')

var steps = [];
steps.push(
@@ -1458,7 +1570,12 @@ function __main( selectedinstance ){
//, 'ACCEPT=YES', '/passive'
]]
, install : install
, exists : exists
, exists : function(){
var self = this;
var mysqldpath = 'C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysqld.exe'
console.log('checking existence of ' + mysqldpath)
return Promise.resolve(existsSync(mysqldpath))
}
, preinstallsteps: function() {
var self = this;
console.log('mysql preinstall steps')
@@ -1482,7 +1599,8 @@ function __main( selectedinstance ){
// return any([any(steps), any(prompts)])
}
}
, {
,
{
shellcmd: 'elxr'
, forceinstall : true
, installcmd: [ isWin() ? 'npm.cmd' : 'npm' , ['link'], { cwd : selectedinstance.root + '\\elxr' /* cwd should be the cloned dir*/}]
@@ -1498,43 +1616,87 @@ function __main( selectedinstance ){
}
, installsteps: function () {
var self = this;
console.log('Elxr Installsteps called')
console.log('GIt config reconfirm called ' + gitPreinstalled)
var installIfNotExists = function(){
console.log('Elxr PreInstallsteps called')
var steps = [];
var chessRepo = 'https://git.bbh.org.in'
steps.push(
function(){
// console.log('cli prompt steps')
var choices = { 0 : 'http://git.bbh', 1 : 'https://git.bbh.org.in' }
return cli.prompt(choices, 'git repository : ', chessRepo).then(function(choice){ chessRepo = choice } )
}
)
return any(steps).then(function(){
var ifns = [

['git', ['clone', chessRepo + '/chess/elxr'] ]
]
if(existsSyncFolder( selectedinstance.root + '\\elxr')) {
if(existsSyncFolder( selectedinstance.root + '\\elxr\\.git')) {
// PB : TODO -- use a elxr guid signature to detect more reliably folders named the same that is not us.
ifns = [ ['git', ['pull'], { cwd : selectedinstance.root + '\\elxr' } ] ]
if(gitPreinstalled) {
console.log('-------------------------------------')
console.log('Git was already preinstalled - reconfirming installchoices')
// Load from previous run and confirm.
// var reposerver = 'https://git.bbh.org.in';
// var gitUser = 'guest';
// var gitEmail = 'guest@bbh.org.in';
var icf = fs.readFileSync( 'installchoices.js')
icf = icf.replace('module.exports = ', 'icf = ')
console.log(icf)
try {
icf = eval(icf)
}
else {
throw 'elxr subfolder not recognized as a git repository. Please cleanup and continue.'
catch(e) {
console.error(e)
}
// console.log(icf.reposerver)
instanceName = icf.instanceName
reposerver = icf.reposerver;
gitUser = icf.gitUser;
gitEmail = icf.gitEmail
console.log('-------------------------------------')
console.dir(icf)
// var p = gitpostinstallsteps()
steps.push(gitpostinstallsteps)
// steps.push(
// function(){
// console.log('cli prompt steps')
// var choices = { 0 : 'http://git.bbh', 1 : 'https://git.bbh.org.in' }
// // console.dir(choices)
// return cli.prompt(choices, 'git repository : ', reposerver).then(function(choice){ reposerver = choice } )
// }
// )
}
else console.log(selectedinstance.root + '\\elxr' + ' NOT FOUND ')
ifns.push(['npm', ['i'], { cwd : '.\\elxr' } ])
if(!ifns.map) ifns.map = map;
return any(ifns.map(callsheltask))['catch'](function(e){
if(e.code === 1602) {
console.warn("Installation was probably cancelled.")
}
else throw e
else{
// var p = Promise.resolve(true)
steps.push(
function(){
var choices = { }
return cli.prompt(choices, 'git password', gitpassword).then(function(choice){ gitpassword = choice } )
}
)
}
// resetgitconfig requires the password to be loaded from credential store. Currently just prompt for it.
return any(steps).then( function(){
return resetgitconfig().then(function(){
var ifns = [
['git', ['clone', reposerver + '/chess/elxr'] ]
]
if(existsSyncFolder( selectedinstance.root + '\\elxr')) {
if(existsSyncFolder( selectedinstance.root + '\\elxr\\.git')) {
// PB : TODO -- use a elxr guid signature to detect more reliably folders named the same that is not us.
ifns = [ ['git', ['pull'], { cwd : selectedinstance.root + '\\elxr' } ] ]
}
else {
throw 'elxr subfolder not recognized as a git repository. Please cleanup and continue.'
}
}
else console.log(selectedinstance.root + '\\elxr' + ' NOT FOUND ')
var pkgjson = selectedinstance.root + '\\elxr\\package.json'
var pkgcontents = fs.readFileSync(pkgjson)
// PB : TODO -- Remove hardcode use proper replacement url..
fs.writeFileSync( pkgjson, pkgcontents.replace(/http\:\/\/git\.bbh/g, reposerver));
ifns.push(['npm', ['i'], { cwd : '.\\elxr' } ])
if(!ifns.map) ifns.map = map;
return any(ifns.map(callsheltask))['catch'](function(e){
if(e.code === 1602) {
console.warn("Installation was probably cancelled.")
}
else throw e
})
})
})
} )
}
var ifns = [ self.installcmd ]
if(!ifns.map) ifns.map = map;
@@ -1550,8 +1712,13 @@ function __main( selectedinstance ){
, install: function () {
var self = this;
console.log('Elxr Install called')

// PB : TODO -- detect external or internal and change elxr package.json dependencies to point to proper location.
fs.writeFileSync(selectedinstance.root + '\\ei.bat', 'cmd /c node ' + selectedinstance.root + '\\elxr\\index.js i ' + instanceName)
return any([ self.preinstallsteps, function(){ return self.installsteps() }
, nodeShellExec('start', ['""', '"C:\\Program Files\\Git\\bin\\sh.exe"', '-c', '"node ' + (selectedinstance.root + '\\elxr\\index.js').replace(/\\/g, '/') + ' i elixir"'])
, nodeShellExec('start', ['/WAIT', '""', '"' + selectedinstance.root + '\\ei.bat' + '"'])
// , nodeShellExec('start', ['/WAIT', '""', '"C:\\Program Files\\Git\\bin\\sh.exe"', '-c', '"node ' + (selectedinstance.root + '\\elxr\\index.js').replace(/\\/g, '/') + ' i elixir"'])
// , nodeShellExec('node', [selectedinstance.root + 'elxr\\index.js'])
])
// return any([ /*self.preinstallsteps,*/ function(){ return self.installsteps() }

+ 70
- 38
index.js Ver fichero

@@ -2217,10 +2217,11 @@ shell_verse.acquireElevationState().then((isElevated) => {
Object.keys(op).forEach( oper => {
if(cmds[oper]) return

cmds[oper] = {
// return a interpreted set of arguments for this cmd run context.
interpret() { return { cmd : oper, runchoice : 'c' } }
}
cmds[oper] = {}
// cmds[oper] = {
// // return a interpreted set of arguments for this cmd run context.
// interpret() { return { cmd : oper, runchoice : 'c' } }
// }
})

var elxrcmd = (function(){
@@ -2229,7 +2230,22 @@ shell_verse.acquireElevationState().then((isElevated) => {
function subcommandlabelFor(cmd, sub){ return (`${cmd} ${sub || ''}`).trim() }

var __cmd = {
interpret() { return { cmd : this.cmd } }
interpret() {
var interpreted = {}
// Non custom command has universal positiona args.
processedArgs._[1] ? interpreted.instanceName = processedArgs._[1]: null;
// return clioverrides
// cmds[cmd] = {
// interpret() {
// return Object.assign(clioverrides, { cmd, runchoice : 'c' })
// }
// , getPossiblePrompts(){ return { cmd, username : true, password : true,
// instanceName : true, instanceType : true, reposerver : true } }
// }
// ... PB : TODO -- use cmd.toArgs
interpreted.cmd = this.cmd
return interpreted
}
, getPossiblePrompts(){ return { username : true, password : true, instanceName : true, instanceType : true, reposerver : true } }
, cmdFn : ()=>{ throw "Elxr Unknown command."}
, finalized : true
@@ -2265,31 +2281,24 @@ shell_verse.acquireElevationState().then((isElevated) => {

var interpretrun = function(){
var cmd = processedArgs._[0];
return cmds[cmd] ? cmds[cmd].interpret() : (function(){
// Non custom command has universal positiona args.
processedArgs._[1] ? clioverrides.instanceName = processedArgs._[1]: null;
// return clioverrides
// cmds[cmd] = {
// interpret() {
// return Object.assign(clioverrides, { cmd, runchoice : 'c' })
// }
// , getPossiblePrompts(){ return { cmd, username : true, password : true,
// instanceName : true, instanceType : true, reposerver : true } }
// }
return cmds[cmd].interpret()
})()
return cmds[cmd].interpret()
}

var clioverrides = interpretrun()
clioverrides = utils.assign( { cmd : processedArgs._[0], node_env : ENV.NODE_ENV, root : ENV.wd, instanceType : ENV.NODE_ENV }
, clioverrides, cmds[clioverrides.cmd].toArgs(processedArgs), { root : ENV.wd } )
function acquirelocalinstances(selected){
// utils.assign is used to cleanup duplicates... assuming chessinstances.js is probably not clean.
// PB : TODO -- if require(path.normalize(selected.root + '/chessinstances.js')) fails decipher instanceName from findlocalinstances using the root...
// utils.assign is used to cleanup duplicates... assuming it is probably not clean.
// PB : TODO -- if require fails decipher instanceName from findlocalinstances using the root...

try { var existinglocalinstances = require(path.normalize(selected.root + '/chessinstances.js'))}
catch(e){
console.warn( 'Local instances not found.' ) // This is not an error. A new fresh instance is probably being setup.
var existinglocalinstances = { current_run : {}, error : true }
}

var chessinstances = utils.assign_core( { arraymergetype : utils.assign_core.DISTINCT_UNION }
, require(path.normalize(selected.root + '/chessinstances.js')));
var chessinstances = utils.assign_core( { arraymergetype : utils.assign_core.DISTINCT_UNION }, existinglocalinstances);
// console.dir(chessinstances)
return chessinstances
}

@@ -2301,6 +2310,7 @@ shell_verse.acquireElevationState().then((isElevated) => {
if(existsSync( localinstancesPath )) {
try {
var chessinstances = acquirelocalinstances( `${instanceroot}/${p}` )
if(chessinstances.error) delete chessinstances.error
return Object.keys(chessinstances).earlyreduce( ( reduced, instanceName) => {
return Object.keys(chessinstances[instanceName]).earlyreduce( (reduced, instanceType) => {
if( path.normalize(chessinstances[instanceName][instanceType].root) === path.normalize( instanceroot) ) {
@@ -2338,9 +2348,11 @@ shell_verse.acquireElevationState().then((isElevated) => {
return distinctArrOfObjs;
}

var cacheWriteInstanceConfig = function(chessinstances, instanceroot){
var instanceName = chessinstances['current_run'].instanceName;
var node_env = chessinstances['current_run'].node_env;
var cacheWriteInstanceConfig = function(chessinstances, instanceroot, selectedinstance){
var instanceName = selectedinstance.instanceName ;
var node_env = selectedinstance.node_env;
// PB : TODO -- handle current_run switch...
// console.dir(chessinstances)
// PB : TODO -- We should be able to do simply merge at a higher level using assign
chessinstances[instanceName][node_env].repos = mergeObjByKey(chessinstances[instanceName][node_env].repos || [], 'repo') ;
chessinstances[instanceName][node_env].elevated = mergeObjByKey(chessinstances[instanceName][node_env].elevated || [], 'repo') ;
@@ -2364,11 +2376,27 @@ shell_verse.acquireElevationState().then((isElevated) => {
// PB : TODO -- Override cli prefs and call with undefined selectedinstance only if there is no cli overide or selection.
var chessinstances = acquirelocalinstances( { root : ENV.wd } )
if(chessinstances.error) {
delete chessinstances.error
// use installchoices only when we don't find chessinstances.
try { var installchoices = require(path.normalize(ENV.wd + '/installchoices.js'))
chessinstances[installchoices.instanceName] = chessinstances[installchoices.instanceName] || {}
chessinstances[installchoices.instanceName][installchoices.node_env || clioverrides.node_env] = installchoices
}
catch(e){
console.warn( 'Install choices not found. WIll prompt for choices' ) // This is not an error. A new fresh instance is probably being setup.
throw 'PROMPT FOR INSTLL CHOICES TO BE IMPLEMENTED'
chessinstances[installchoices.instanceName] = chessinstances[installchoices.instanceName] || {}
chessinstances[installchoices.instanceName][installchoices.node_env || clioverrides.node_env] = installchoices
}
}
// PB : chessinstances.js update if we are switching repo servers, username etc... Myabe always refresh on each run.
// root location for instance swithc ?? should not be allowd...
var instance = chessinstances[clioverrides.instanceName || chessinstances.current_run.instanceName][clioverrides.node_env
|| (selectedinstance && selectedinstance.node_env) || [chessinstances.current_run.node_env] ]
// PB : TODO -- Handle instance not found cases.
var selectedInstanceName = chessinstances[clioverrides.instanceName || chessinstances.current_run.instanceName];
var instance = selectedInstanceName ? selectedInstanceName[clioverrides.node_env || (selectedinstance && selectedinstance.node_env) || [chessinstances.current_run.node_env] ]
: clioverrides
// PB : TODO -- Handle instance not found cases. and prompt cases..

// PB : TODO -- Embed defaults in the build instead of inlining here...
var __default = {
@@ -2403,11 +2431,20 @@ shell_verse.acquireElevationState().then((isElevated) => {
, { utils, username : instance.username /** ??? TODO */ , instanceName : instance.instanceName /** ??? TODO */
, node_env : clioverrides.node_env, reposerver : instance.instanceName /** ??? TODO */ } // options
)

if(__repo_manifest_elxr.error) console.log(__repo_manifest_elxr.e.message)
var instance_specific_config_manifest = loadmanifest( instance.root + `/${instance.instanceName}-config-${clioverrides.node_env}`
, { utils, username : instance.username /** ??? TODO */ , instanceName : instance.instanceName /** ??? TODO */
, node_env : clioverrides.node_env, reposerver : instance.instanceName /** ??? TODO */ } // options
)
if(instance_specific_config_manifest.error) console.log(instance_specific_config_manifest.e.message)
delete __repo_manifest_elxr.error
delete __repo_manifest_elxr.e
delete __repo_manifest_elxr.utils
delete instance_specific_config_manifest.error
delete instance_specific_config_manifest.e
delete instance_specific_config_manifest.utils

// selectedinstance is not complete until we load in the following order of priority...
// 1) inline defaults
@@ -2423,13 +2460,7 @@ shell_verse.acquireElevationState().then((isElevated) => {
, { root : ENV.wd, node_env : ENV.NODE_ENV
, get instanceName() {
// FInalize to prevent subsequent overrides...
return (()=>{
/** ??? TODO */
// Find from last run or identify current roots instance name. If all fails prompt options
var __instanceName = clioverrides.instanceName || instance.instanceName
Object.defineProperty(this, 'instanceName', { value: __instanceName, writable: false });
return __instanceName;
})
return instance.instanceName
}
}
, instance_specific_config_manifest
@@ -2467,8 +2498,9 @@ shell_verse.acquireElevationState().then((isElevated) => {
}
)
chessinstances[__pub.instanceName] = chessinstances[__pub.instanceName] || {}
chessinstances[__pub.instanceName][__pub.instanceType] = __pub
cacheWriteInstanceConfig(chessinstances, __pub.root )
cacheWriteInstanceConfig(chessinstances, __pub.root, __pub )

Object.defineProperty(__g, 'selectedinstance', {
get(){ return __pub}

Cargando…
Cancelar
Guardar