@@ -12,6 +12,9 @@ var nodeShellExec = cli.nodeShellExec; | |||
var chalk = require('chalk'); | |||
const homedir = require('os').homedir(); | |||
var ENV = Object.assign({}, process.env); // Shallow clone it. | |||
// singleton one time lazy | |||
var getCredentials = function(){ | |||
@@ -19,6 +22,7 @@ var getCredentials = function(){ | |||
var creds = fs.readFileSync(path.normalize(`${homedir}/.elxrcredentials`), { encoding: 'utf8' }); | |||
var creds = creds.split('\n').map( c => c.trim() && new URL(c)); | |||
console.log(creds); | |||
creds.forEach(cred => {console.log( cred.hostname ); console.log( cred.username );} ); | |||
// Subsequent calls | |||
getCredentials = ()=>{ return creds }; | |||
@@ -103,8 +107,6 @@ console.dir(processedArgs); | |||
require('glob').sync; | |||
var ENV = Object.assign({}, process.env); // Shallow clone it. | |||
const { readdir } = require("fs").promises; | |||
// Directory shallow walk and do perform on each dir. | |||
@@ -1301,8 +1303,10 @@ var op = { | |||
return any(tasks).then(() => { | |||
gitRepos.push('chess-server-lib/server'); | |||
gitRepos.push({ repo : 'chess-server-lib/server'}); | |||
gitRepos = gitRepos.concat(elevatedRunasRepos); | |||
// console.dir(gitRepos) | |||
// throw "" | |||
// gitRepos = [ | |||
// // 'bbhverse', 'serververse', 'elixir-server', | |||
@@ -1345,7 +1349,7 @@ var op = { | |||
} | |||
}); | |||
// NODE_ENV=development DEBUG=loopback:connector:mssql node --tls-min-v1.0 --inspect elixir/server.js | |||
// PB : NOTE -- npm i for client does not complete when NODE_ENV=production | |||
// therefore bower doesn't get installed !!! which then fails installing the bower dependenciew !!! | |||
// We work around this by running npm i for client without any NODE_ENV which probably defualts to development. | |||
@@ -1366,8 +1370,9 @@ var op = { | |||
// }) | |||
var bowerRepos = [{ repo : 'client'}]; | |||
var bowertasks = []; | |||
bowerRepos.forEach(repodef => { | |||
repotasks.push(() => { | |||
bowertasks.push(() => { | |||
console.log(instanceroot + '/' + repodef.repo + '/node_modules/bower/bin/bower'); | |||
// var p = nodeShellExec('node_modules/bower/bin/bower', ['install'], { | |||
var p = nodeShellExec(`"${gitbash}"`, ['-c', '"node_modules/bower/bin/bower i"'], { | |||
@@ -1381,7 +1386,7 @@ var op = { | |||
}); | |||
}); | |||
// console.log('rmtasks.length : ' + rmtasks.length) | |||
return Promise.all(rmtasks).then(() => any(repotasks)); | |||
return Promise.all(rmtasks).then(() => any(repotasks)).then(()=>any(bowertasks)); | |||
}).catch(e => { | |||
console.error(e); | |||
}).finally(statuslog.finally) | |||
@@ -1523,9 +1528,9 @@ var op = { | |||
var promise = new Promise((resolve, reject)=>{ | |||
existslink('config', function(err, data){ | |||
if(data) { | |||
var p = nodeShellExec('rmdir', ['config'], { inherit: true, shell: true, env: process.env } | |||
).catch((err) => { console.log('Ignoring benign error : ' + err); return true; }); | |||
return resolve(p); | |||
nodeShellExec('rmdir', ['config'], { inherit: true, shell: true, env: process.env }) | |||
.then(()=>{resolve(true);}) | |||
.catch((err) => { console.log('Ignoring benign error : ' + err); return resolve(true); }); | |||
} | |||
else resolve(false); | |||
}); | |||
@@ -1536,9 +1541,9 @@ var op = { | |||
var promise = new Promise((resolve, reject)=>{ | |||
existslink('data', function(err, data){ | |||
if(data) { | |||
var p = nodeShellExec('rmdir', ['data'], { inherit: true, shell: true, env: process.env } | |||
).catch((err) => { console.log('Ignoring benign error : ' + err); return true; }); | |||
return resolve(p); | |||
nodeShellExec('rmdir', ['data'], { inherit: true, shell: true, env: process.env }) | |||
.then(()=>{resolve(true);}) | |||
.catch((err) => { console.log('Ignoring benign error : ' + err); return resolve(true); }); | |||
} | |||
else resolve(false); | |||
}); | |||
@@ -1686,7 +1691,9 @@ var op = { | |||
tasks = tasks.concat( | |||
[ | |||
() => { | |||
var p = nodeShellExec('mklink', ['/J', 'data', runconfig.use + '-data'], { | |||
var dataToLink = runconfig.use + '-data' + '-' + process.env.NODE_ENV; | |||
if(!existsSync(dataToLink)) dataToLink = runconfig.use + '-data'; | |||
var p = nodeShellExec('mklink', ['/J', 'data', dataToLink], { | |||
inherit: true, shell: true | |||
, cwd : instanceroot | |||
, env: process.env | |||
@@ -1893,7 +1900,7 @@ var cmds = { | |||
var elxrcmd = (function(){ | |||
__cmdprototype = function(){}; | |||
var __cmdprototype = function(){}; | |||
function subcommandlabelFor(cmd, sub){ return (`${cmd} ${sub || ''}`).trim() } | |||
var __cmd = { | |||
@@ -2308,12 +2315,13 @@ var instanceData = (function(){ | |||
return { | |||
clusterNodeInstance(selected) { var clusternodename = 'node01'; | |||
return __acquireData(selected, selected.username, clusternodename | |||
, selected.instanceName + '-config-' + selected.node_env + `-${clusternodename}` | |||
, selected.instanceName + '-data-' + selected.node_env + `-${clusternodename}` | |||
, function(e){ console.info('Customized node level config not found. This is not an Error. Will attempt with owner level config.'); | |||
return e; } | |||
) | |||
} | |||
, ownerInstnace(selected) { return __acquireData(selected, selected.username, null, null | |||
, ownerInstnace(selected) { return __acquireData(selected, selected.username, null | |||
, selected.instanceName + '-data-' + selected.node_env | |||
, function(e){ console.info('Customized user level config not found. This is not an Error. Will attempt global common instance config.'); | |||
return e } | |||
) | |||
@@ -2397,7 +2405,8 @@ var __acquireConfig = function (selected, owner, clusternodename, configrepo, er | |||
var successHandler = () => { | |||
var manifestpath = path.normalize(selected.root + '/' + selected.instanceName + '-config-' + selected.node_env + '/repo-manifest'); | |||
selectedinstance = require(manifestpath)( null, selectedinstance); | |||
utils.assign_strict(selectedinstance, require(manifestpath)( null, selectedinstance)); | |||
console.dir(selectedinstance.repos); | |||
// Config from server always override merges into selection except for the current selection. | |||
// PB : TODO -- utils.assign Array merges are non-distinct... | |||
if(!selectedinstance.repos[0].repo) { | |||
@@ -2427,7 +2436,7 @@ var __acquireConfig = function (selected, owner, clusternodename, configrepo, er | |||
var __acquireData = function (selected, owner, clusternodename, datarepo, errHandler) { | |||
datarepo = datarepo || selected.instanceName + '-config-' + selected.node_env; | |||
datarepo = datarepo || selected.instanceName + '-data'; | |||
var errorHandler = (e) => { | |||
if(e.messages.join(' ').match(new RegExp (`fatal: unable to access '${selectedinstance.reposerver}/${owner}/${datarepo}.git/': Failed to connect to .*? port .*? after .*? ms: Timed out`))){ | |||
@@ -2447,8 +2456,8 @@ var __acquireData = function (selected, owner, clusternodename, datarepo, errHan | |||
if(e.messages.join(' ').match(new RegExp (`fatal: repository '${selectedinstance.reposerver}/${owner}/${datarepo}.git/' not found`))){ | |||
var choices = { | |||
t : `install a new temporary local instance with this name ( will not persist ). | |||
Use your own username for additional options. You can request for a username at chess@bbh.org.in )` | |||
t : `install a temporary local data folder. | |||
For more options. Request and use a personal username at chess@bbh.org.in )` | |||
, e : 'exit' }; | |||
if(selectedinstance.username !== 'guest' && selectedinstance.username !== 'demo') { | |||
@@ -3460,6 +3469,65 @@ const GIT = (function(){ | |||
return GIT | |||
})(); | |||
function createInstanceData(target, source) { | |||
var sourceinstance = source || target; | |||
console.dir(sourceinstance); | |||
var args = { | |||
remotebase : sourceinstance.reposerver + '/chess/' | |||
, sourcerepo : sourceinstance.repo || 'chess-data' | |||
, targetrepo : `${target.instanceName}-data-${target.instanceType}${target.nodeName ? ('-' + target.nodeName) : ''}` | |||
}; | |||
if(sourceinstance.local) { | |||
var options = { | |||
inherit: true, shell: true, | |||
env: process.env | |||
, cwd : instanceroot | |||
, runas: processedArgs.runas | |||
}; | |||
var cmdseq = [ | |||
['git', ['clone', `${args.remotebase}${args.sourcerepo}`, `${args.targetrepo}`], options] | |||
]; | |||
return any(cmdseq.map(getshelltask)).then(() => { return true }) | |||
} | |||
else { | |||
// http://try.gitea.io/api/v1/org/{org}/repos | |||
if(source.reposerver !== target.reposerver && source.username !== target.username) { | |||
throw 'createInstanceData is possible only within the same repository server.' | |||
} | |||
var server = new URL(target.reposerver); | |||
return GITEA.repository.fork( { hostname : server.host, protocol : server.protocol | |||
, username : target.username, password : target.password | |||
} | |||
// , { repo : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}`} | |||
, { repo : `${args.sourcerepo}`, owner : `${target.username}` }, {}, function( repository ){ | |||
return GITEA.repository.updateattributes( { | |||
hostname : server.host, protocol : server.protocol | |||
, username : target.username, password : target.password | |||
} | |||
, { repo : `${args.sourcerepo}`, owner : `${target.username}` } | |||
, { name : `${args.targetrepo}`} | |||
) | |||
} | |||
) | |||
} | |||
// GITEA.repository.updateattributes( { | |||
// hostname : server.host, protocol : server.protocol | |||
// , username : selectedinstance.username, password : selectedinstance.password | |||
// } | |||
// , { repo : `chess-config`, owner : selectedinstance.username } | |||
// , { name : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}${selectedinstance.nodeName ? '-' + selectedinstance.nodeName : ''}`} | |||
// ) | |||
// return selectedinstance | |||
} | |||
function createInstance(target, source) { | |||
var sourceinstance = source || target; |
@@ -1,4 +1,4 @@ | |||
/* Version: 1.0.0 - December 2, 2021 21:12:33 */ | |||
/* Version: 1.0.0 - December 3, 2021 11:58:46 */ | |||
'use strict'; | |||
var path$1 = require('path'); | |||
@@ -25205,7 +25205,7 @@ var getCredentials = function(){ | |||
}; | |||
const __ALIAS__STAMP__ = '9e7bebe0-1f57-11ec-8f88-778ffeea9d1b'; | |||
const BUILD_VERSION = 'Version: 1.0.0 - built on December 2, 2021 21:12:33'; | |||
const BUILD_VERSION = 'Version: 1.0.0 - built on December 3, 2021 11:58:46'; | |||
const runtimestamp = (new Date()).getTime(); | |||
function getVersion() { return BUILD_VERSION; } | |||
console.log(getVersion()); | |||
@@ -27072,7 +27072,7 @@ var cmds = { | |||
var elxrcmd = (function(){ | |||
__cmdprototype = function(){}; | |||
var __cmdprototype = function(){}; | |||
function subcommandlabelFor(cmd, sub){ return (`${cmd} ${sub || ''}`).trim() } | |||
var __cmd = { |
@@ -10,6 +10,21 @@ var nodeShellExec = cli.nodeShellExec; | |||
var chalk = require('chalk') | |||
const homedir = require('os').homedir(); | |||
var ENV = Object.assign({}, process.env); // Shallow clone it. | |||
function sysAddPathVar(path){ | |||
// Object.assign({ | |||
// inherit: true, shell: true, env: ENV, title: `${command} ${args}` | |||
// }, options) | |||
var newpath = path.split(';'); | |||
newpath = Array.from(new Set(newpath.push(path))).join(';') | |||
// path.split(';').forEach(pel => { var kv = pel.split('='); kv[0] === key ? null : newpath.push(pel); } ) | |||
return nodeShellExec('setx', ['/m', 'PATH', newpath ]); | |||
} | |||
// singleton one time lazy | |||
var getCredentials = function(){ | |||
@@ -102,8 +117,6 @@ console.dir(processedArgs) | |||
var globSync = require('glob').sync; | |||
var ENV = Object.assign({}, process.env); // Shallow clone it. | |||
const { readdir } = require("fs").promises | |||
// Directory shallow walk and do perform on each dir. | |||
@@ -1308,8 +1321,10 @@ var op = { | |||
return any(tasks).then(() => { | |||
gitRepos.push('chess-server-lib/server'); | |||
gitRepos.push({ repo : 'chess-server-lib/server'}); | |||
gitRepos = gitRepos.concat(elevatedRunasRepos); | |||
// console.dir(gitRepos) | |||
// throw "" | |||
// gitRepos = [ | |||
// // 'bbhverse', 'serververse', 'elixir-server', | |||
@@ -1352,7 +1367,7 @@ var op = { | |||
} | |||
}) | |||
// NODE_ENV=development DEBUG=loopback:connector:mssql node --tls-min-v1.0 --inspect elixir/server.js | |||
// PB : NOTE -- npm i for client does not complete when NODE_ENV=production | |||
// therefore bower doesn't get installed !!! which then fails installing the bower dependenciew !!! | |||
// We work around this by running npm i for client without any NODE_ENV which probably defualts to development. | |||
@@ -1373,8 +1388,9 @@ var op = { | |||
// }) | |||
var bowerRepos = [{ repo : 'client'}] | |||
var bowertasks = [] | |||
bowerRepos.forEach(repodef => { | |||
repotasks.push(() => { | |||
bowertasks.push(() => { | |||
console.log(instanceroot + '/' + repodef.repo + '/node_modules/bower/bin/bower') | |||
// var p = nodeShellExec('node_modules/bower/bin/bower', ['install'], { | |||
var p = nodeShellExec(`"${gitbash}"`, ['-c', '"node_modules/bower/bin/bower i"'], { | |||
@@ -1388,7 +1404,7 @@ var op = { | |||
}) | |||
}) | |||
// console.log('rmtasks.length : ' + rmtasks.length) | |||
return Promise.all(rmtasks).then(() => any(repotasks)); | |||
return Promise.all(rmtasks).then(() => any(repotasks)).then(()=>any(bowertasks)); | |||
}).catch(e => { | |||
console.error(e) | |||
}).finally(statuslog.finally) | |||
@@ -1530,9 +1546,9 @@ var op = { | |||
var promise = new Promise((resolve, reject)=>{ | |||
existslink('config', function(err, data){ | |||
if(data) { | |||
var p = nodeShellExec('rmdir', ['config'], { inherit: true, shell: true, env: process.env } | |||
).catch((err) => { console.log('Ignoring benign error : ' + err); return true; }) | |||
return resolve(p); | |||
var p = nodeShellExec('rmdir', ['config'], { inherit: true, shell: true, env: process.env }) | |||
.then(()=>{resolve(true)}) | |||
.catch((err) => { console.log('Ignoring benign error : ' + err); return resolve(true); }) | |||
} | |||
else resolve(false) | |||
}) | |||
@@ -1543,9 +1559,9 @@ var op = { | |||
var promise = new Promise((resolve, reject)=>{ | |||
existslink('data', function(err, data){ | |||
if(data) { | |||
var p = nodeShellExec('rmdir', ['data'], { inherit: true, shell: true, env: process.env } | |||
).catch((err) => { console.log('Ignoring benign error : ' + err); return true; }) | |||
return resolve(p); | |||
var p = nodeShellExec('rmdir', ['data'], { inherit: true, shell: true, env: process.env }) | |||
.then(()=>{resolve(true)}) | |||
.catch((err) => { console.log('Ignoring benign error : ' + err); return resolve(true); }) | |||
} | |||
else resolve(false) | |||
}) | |||
@@ -1710,7 +1726,9 @@ var op = { | |||
tasks = tasks.concat( | |||
[ | |||
() => { | |||
var p = nodeShellExec('mklink', ['/J', 'data', runconfig.use + '-data'], { | |||
var dataToLink = runconfig.use + '-data' + '-' + process.env.NODE_ENV | |||
if(!existsSync(dataToLink)) dataToLink = runconfig.use + '-data'; | |||
var p = nodeShellExec('mklink', ['/J', 'data', dataToLink], { | |||
inherit: true, shell: true | |||
, cwd : instanceroot | |||
, env: process.env | |||
@@ -1945,7 +1963,7 @@ var cmds = { | |||
var elxrcmd = (function(){ | |||
__cmdprototype = function(){} | |||
var __cmdprototype = function(){} | |||
function subcommandlabelFor(cmd, sub){ return (`${cmd} ${sub || ''}`).trim() } | |||
var __cmd = { | |||
@@ -2366,12 +2384,13 @@ var instanceData = (function(){ | |||
return { | |||
clusterNodeInstance(selected) { var clusternodename = 'node01' | |||
return __acquireData(selected, selected.username, clusternodename | |||
, selected.instanceName + '-config-' + selected.node_env + `-${clusternodename}` | |||
, selected.instanceName + '-data-' + selected.node_env + `-${clusternodename}` | |||
, function(e){ console.info('Customized node level config not found. This is not an Error. Will attempt with owner level config.'); | |||
return e; } | |||
) | |||
} | |||
, ownerInstnace(selected) { return __acquireData(selected, selected.username, null, null | |||
, ownerInstnace(selected) { return __acquireData(selected, selected.username, null | |||
, selected.instanceName + '-data-' + selected.node_env | |||
, function(e){ console.info('Customized user level config not found. This is not an Error. Will attempt global common instance config.'); | |||
return e } | |||
) | |||
@@ -2455,7 +2474,8 @@ var __acquireConfig = function (selected, owner, clusternodename, configrepo, er | |||
var successHandler = () => { | |||
var manifestpath = path.normalize(selected.root + '/' + selected.instanceName + '-config-' + selected.node_env + '/repo-manifest'); | |||
selectedinstance = require(manifestpath)( null, selectedinstance) | |||
utils.assign_strict(selectedinstance, require(manifestpath)( null, selectedinstance)) | |||
console.dir(selectedinstance.repos) | |||
// Config from server always override merges into selection except for the current selection. | |||
// PB : TODO -- utils.assign Array merges are non-distinct... | |||
if(!selectedinstance.repos[0].repo) { | |||
@@ -2485,7 +2505,7 @@ var __acquireConfig = function (selected, owner, clusternodename, configrepo, er | |||
var __acquireData = function (selected, owner, clusternodename, datarepo, errHandler) { | |||
datarepo = datarepo || selected.instanceName + '-config-' + selected.node_env; | |||
datarepo = datarepo || selected.instanceName + '-data'; | |||
var errorHandler = (e) => { | |||
if(e.messages.join(' ').match(new RegExp (`fatal: unable to access '${selectedinstance.reposerver}/${owner}/${datarepo}.git/': Failed to connect to .*? port .*? after .*? ms: Timed out`))){ | |||
@@ -2505,8 +2525,8 @@ var __acquireData = function (selected, owner, clusternodename, datarepo, errHan | |||
if(e.messages.join(' ').match(new RegExp (`fatal: repository '${selectedinstance.reposerver}/${owner}/${datarepo}.git/' not found`))){ | |||
var choices = { | |||
t : `install a new temporary local instance with this name ( will not persist ). | |||
Use your own username for additional options. You can request for a username at chess@bbh.org.in )` | |||
t : `install a temporary local data folder. | |||
For more options. Request and use a personal username at chess@bbh.org.in )` | |||
, e : 'exit' } | |||
if(selectedinstance.username !== 'guest' && selectedinstance.username !== 'demo') { | |||
@@ -3518,6 +3538,65 @@ const GIT = (function(){ | |||
return GIT | |||
})(); | |||
function createInstanceData(target, source) { | |||
var sourceinstance = source || target; | |||
console.dir(sourceinstance) | |||
var args = { | |||
remotebase : sourceinstance.reposerver + '/chess/' | |||
, sourcerepo : sourceinstance.repo || 'chess-data' | |||
, targetrepo : `${target.instanceName}-data-${target.instanceType}${target.nodeName ? ('-' + target.nodeName) : ''}` | |||
} | |||
if(sourceinstance.local) { | |||
var options = { | |||
inherit: true, shell: true, | |||
env: process.env | |||
, cwd : instanceroot | |||
, runas: processedArgs.runas | |||
} | |||
var cmdseq = [ | |||
['git', ['clone', `${args.remotebase}${args.sourcerepo}`, `${args.targetrepo}`], options] | |||
] | |||
return any(cmdseq.map(getshelltask)).then(() => { return true }) | |||
} | |||
else { | |||
// http://try.gitea.io/api/v1/org/{org}/repos | |||
if(source.reposerver !== target.reposerver && source.username !== target.username) { | |||
throw 'createInstanceData is possible only within the same repository server.' | |||
} | |||
var server = new URL(target.reposerver); | |||
return GITEA.repository.fork( { hostname : server.host, protocol : server.protocol | |||
, username : target.username, password : target.password | |||
} | |||
// , { repo : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}`} | |||
, { repo : `${args.sourcerepo}`, owner : `${target.username}` }, {}, function( repository ){ | |||
return GITEA.repository.updateattributes( { | |||
hostname : server.host, protocol : server.protocol | |||
, username : target.username, password : target.password | |||
} | |||
, { repo : `${args.sourcerepo}`, owner : `${target.username}` } | |||
, { name : `${args.targetrepo}`} | |||
) | |||
} | |||
) | |||
} | |||
// GITEA.repository.updateattributes( { | |||
// hostname : server.host, protocol : server.protocol | |||
// , username : selectedinstance.username, password : selectedinstance.password | |||
// } | |||
// , { repo : `chess-config`, owner : selectedinstance.username } | |||
// , { name : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}${selectedinstance.nodeName ? '-' + selectedinstance.nodeName : ''}`} | |||
// ) | |||
// return selectedinstance | |||
} | |||
function createInstance(target, source) { | |||
var sourceinstance = source || target; |