Quellcode durchsuchen

new build

pull/6/head
guest vor 3 Jahren
Ursprung
Commit
2d8af7a29e
1 geänderte Dateien mit 87 neuen und 19 gelöschten Zeilen
  1. 87
    19
      elxr.js

+ 87
- 19
elxr.js Datei anzeigen

@@ -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
@@ -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;

Laden…
Abbrechen
Speichern