|
|
@@ -8,7 +8,20 @@ Tasq.addlistener(statuslog.statuslog) |
|
|
|
var cli = require('./cliverse') |
|
|
|
var nodeShellExec = cli.nodeShellExec; |
|
|
|
var chalk = require('chalk') |
|
|
|
const homedir = require('os').homedir(); |
|
|
|
|
|
|
|
// singleton one time lazy |
|
|
|
var getCredentials = function(){ |
|
|
|
|
|
|
|
// First call |
|
|
|
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); |
|
|
|
|
|
|
|
// Subsequent calls |
|
|
|
getCredentials = ()=>{ return creds } |
|
|
|
return getCredentials(); |
|
|
|
} |
|
|
|
|
|
|
|
const __ALIAS__STAMP__ = '9e7bebe0-1f57-11ec-8f88-778ffeea9d1b' |
|
|
|
const BUILD_VERSION = '[VI]Version: {version} - built on {date}[/VI]'; |
|
|
@@ -50,6 +63,23 @@ console.log(getVersion()); |
|
|
|
}()); |
|
|
|
|
|
|
|
const { existsSync } = require('fs'); |
|
|
|
const existslink = function(name, cb){ |
|
|
|
fs.lstat(name, (error, stats) => { |
|
|
|
if (error) { |
|
|
|
console.log(error); |
|
|
|
cb(error) |
|
|
|
} |
|
|
|
else { |
|
|
|
console.log("Stats object for: example_directory.txt"); |
|
|
|
console.log(stats); |
|
|
|
|
|
|
|
// Using methods of the Stats object |
|
|
|
console.log("Path is file:", stats.isFile()); |
|
|
|
console.log("Path is directory:", stats.isDirectory()); |
|
|
|
cb(null, true) |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
const existsFolderSync = existsSync; |
|
|
|
const fs = require('fs') |
|
|
|
|
|
|
@@ -65,71 +95,8 @@ console.dir(processedArgs) |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// elxr cli operations |
|
|
|
var noprerequisites = { |
|
|
|
add : true, 'set-url' : true, 'repo-relocate' : true |
|
|
|
, remote : true, 'c' : true, 'h' : true |
|
|
|
, httpget : true, getuser : true |
|
|
|
, 'switch user' : true |
|
|
|
, 'switch' : true |
|
|
|
// , 'undefined' : true |
|
|
|
} |
|
|
|
|
|
|
|
var reconfirmcmds = { create : true } |
|
|
|
|
|
|
|
var subcommandlabels = { |
|
|
|
remote : (`remote ${processedArgs._[1] || ''}`).trim() |
|
|
|
, switch : (`switch ${processedArgs._[1] || ''}`).trim() |
|
|
|
} |
|
|
|
|
|
|
|
var cmds = { |
|
|
|
remote : { |
|
|
|
// return a interpreted set of arguments for this comd run context. |
|
|
|
interpret() { |
|
|
|
return { cmd : subcommandlabels['remote'], runchoice : 'c' } |
|
|
|
} |
|
|
|
} |
|
|
|
, switch : { |
|
|
|
interpret() { |
|
|
|
return { cmd : subcommandlabels['switch'], runchoice : 'c', username : processedArgs._[2] |
|
|
|
, reposerver : __default.reposerver |
|
|
|
} |
|
|
|
} |
|
|
|
, getPossiblePrompts(){ return { username : true, reposerver : 'http://git.bbh' } } // Requires only one argument... |
|
|
|
} |
|
|
|
, 'switch user' : { |
|
|
|
interpret() { |
|
|
|
return { cmd : subcommandlabels['switch'], runchoice : 'c', username : processedArgs._[2] } |
|
|
|
} |
|
|
|
, getPossiblePrompts(){ return { username : true } } // Requires only one argument... |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var interpretrun = function(){ |
|
|
|
|
|
|
|
var cmd = processedArgs._[0]; |
|
|
|
var clioverrides = { cmd } |
|
|
|
processedArgs.node_env ? clioverrides.node_env = 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; |
|
|
|
|
|
|
|
|
|
|
|
return cmds[cmd] ? cmds[cmd].interpret() : (function(){ |
|
|
|
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() |
|
|
|
})() |
|
|
|
} |
|
|
|
|
|
|
|
var clioverrides = interpretrun() |
|
|
|
console.dir(clioverrides) |
|
|
|
|
|
|
|
// Object.keys(clioverrides).forEach( prop => { }) |
|
|
|
|
|
|
@@ -320,7 +287,7 @@ var performPull = (repo, branch, repoowner, errHandler) => { |
|
|
|
env: process.env |
|
|
|
, cwd: instanceroot + '/' + repo |
|
|
|
, runas: processedArgs.runas |
|
|
|
, title: `'git', ${['config', '--replace-all', 'user.name', selectedinstance.username].join(' ')}` |
|
|
|
, title: `'git', ${['config', '--replace-all', 'core.symlinks', selectedinstance.username].join(' ')}` |
|
|
|
}) |
|
|
|
.then(() => { |
|
|
|
if (__isElevated) { |
|
|
@@ -1560,20 +1527,30 @@ var op = { |
|
|
|
|
|
|
|
var tasks = [ |
|
|
|
() => { |
|
|
|
if (existsSync('config')) { |
|
|
|
var p = nodeShellExec('rmdir', ['config'], { inherit: true, shell: true, env: process.env } |
|
|
|
).catch((err) => { console.log('Ignoring benign error : ' + err); return true; }) |
|
|
|
return p; |
|
|
|
} |
|
|
|
else return Promise.resolve(true); |
|
|
|
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); |
|
|
|
} |
|
|
|
else resolve(false) |
|
|
|
}) |
|
|
|
}) |
|
|
|
return promise; |
|
|
|
}, |
|
|
|
() => { |
|
|
|
if (existsSync('data')) { |
|
|
|
var p = nodeShellExec('rmdir', ['data'], { inherit: true, shell: true, env: process.env } |
|
|
|
).catch((err) => { console.log('Ignoring benign error : ' + err); return true; }) |
|
|
|
return p; |
|
|
|
} |
|
|
|
else return Promise.resolve(true); |
|
|
|
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); |
|
|
|
} |
|
|
|
else resolve(false) |
|
|
|
}) |
|
|
|
}) |
|
|
|
return promise; |
|
|
|
}, |
|
|
|
]; |
|
|
|
runconfig.NODE_ENV = process.env.NODE_ENV = process.env.NODE_ENV || runconfig.NODE_ENV || 'development'; |
|
|
@@ -1894,9 +1871,8 @@ var op = { |
|
|
|
|
|
|
|
g[processedArgs._[1]](); |
|
|
|
} |
|
|
|
|
|
|
|
, 'create' : () => { |
|
|
|
return createInstance(selectedinstance) } |
|
|
|
|
|
|
|
, 'create' : () => { return createInstance(selectedinstance) } |
|
|
|
|
|
|
|
, 'httpget' : () => { |
|
|
|
// RESTAPI.get({ |
|
|
@@ -1909,15 +1885,125 @@ var op = { |
|
|
|
return createInstance(selectedinstance) |
|
|
|
} |
|
|
|
|
|
|
|
, 'getuser' : ()=>{ |
|
|
|
return prerequisites.git.getuser().then(u=>{ console.log(u)}) |
|
|
|
, 'getuser' : ()=>{ return prerequisites.git.getuser().then(u=>{ console.log(u)}) } |
|
|
|
, 'switch user' : (tousername)=>{ return GIT['switch user'](tousername) } |
|
|
|
} |
|
|
|
|
|
|
|
// elxr cli operations |
|
|
|
var noprerequisites = { |
|
|
|
add : true, 'set-url' : true, 'repo-relocate' : true |
|
|
|
, remote : true, 'c' : true, 'h' : true |
|
|
|
, httpget : true, getuser : true |
|
|
|
, 'switch user' : true |
|
|
|
, 'switch' : true |
|
|
|
// , 'undefined' : true |
|
|
|
} |
|
|
|
|
|
|
|
var reconfirmcmds = { create : true } |
|
|
|
|
|
|
|
var subcommandlabels = { |
|
|
|
remote : (`remote ${processedArgs._[1] || ''}`).trim() |
|
|
|
, switch : (`switch ${processedArgs._[1] || ''}`).trim() |
|
|
|
} |
|
|
|
|
|
|
|
var cmds = { |
|
|
|
remote : { |
|
|
|
// return a interpreted set of arguments for this comd run context. |
|
|
|
interpret() { |
|
|
|
return { cmd : subcommandlabels['remote'], runchoice : 'c' } |
|
|
|
} |
|
|
|
} |
|
|
|
, switch : { |
|
|
|
interpret() { |
|
|
|
return { cmd : subcommandlabels['switch'], runchoice : 'c', username : processedArgs._[2] |
|
|
|
, reposerver : __default.reposerver |
|
|
|
} |
|
|
|
} |
|
|
|
, getPossiblePrompts(){ return { username : true, reposerver : 'http://git.bbh' } } // Requires only one argument... |
|
|
|
} |
|
|
|
, 'switch user' : { |
|
|
|
interpret() { |
|
|
|
return { cmd : subcommandlabels['switch'], runchoice : 'c', username : processedArgs._[2] } |
|
|
|
} |
|
|
|
, getPossiblePrompts(){ return { username : true } } // Requires only one argument... |
|
|
|
} |
|
|
|
|
|
|
|
// Flat linear structure. Every subcommand should have a top level 'label' |
|
|
|
, 'users' : { |
|
|
|
// default to the users list |
|
|
|
subcommands : { list : {} } |
|
|
|
, cmdFn : ()=>getCredentials() // default |
|
|
|
, cmd : 'users' |
|
|
|
, noprerequisites : true |
|
|
|
} |
|
|
|
, 'users list' : { |
|
|
|
cmdFn : ()=>getCredentials() |
|
|
|
, cmd : 'users list' |
|
|
|
, noprerequisites : true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var elxrcmd = (function(){ |
|
|
|
|
|
|
|
, 'switch user' : (tousername)=>{ |
|
|
|
return GIT['switch user'](tousername) |
|
|
|
__cmdprototype = function(){} |
|
|
|
function subcommandlabelFor(cmd, sub){ return (`${cmd} ${sub || ''}`).trim() } |
|
|
|
|
|
|
|
var __cmd = { |
|
|
|
interpret() { return { cmd : this.cmd } } |
|
|
|
, getPossiblePrompts(){ return {} } // Requires only one argument... |
|
|
|
, cmdFn : ()=>{ throw "Elxr Unknown command."} |
|
|
|
, finalized : true |
|
|
|
} |
|
|
|
|
|
|
|
function __createO(o){ |
|
|
|
if(o.finalized) return o; |
|
|
|
var subs = Object.keys(cmds[o.cmd].subcommands || {}) |
|
|
|
console.log(subs) |
|
|
|
console.log(o) |
|
|
|
subs.forEach(sub=>elxrcmd.create( cmds[subcommandlabelFor(o.cmd, sub)] )) |
|
|
|
|
|
|
|
var created = utils.assign_strict({}, __cmd, cmds[o.cmd], o) |
|
|
|
cmds[o.cmd] = created; |
|
|
|
op[o.cmd] = created.cmdFn; |
|
|
|
noprerequisites[o.cmd] = created.noprerequisites |
|
|
|
return created.cmdFn; |
|
|
|
} |
|
|
|
|
|
|
|
function create(o){ return __createO(o) } |
|
|
|
|
|
|
|
__cmdprototype.create = create; |
|
|
|
|
|
|
|
return __cmdprototype; |
|
|
|
})() |
|
|
|
|
|
|
|
elxrcmd.create(cmds['users']) |
|
|
|
|
|
|
|
var interpretrun = function(){ |
|
|
|
|
|
|
|
var cmd = processedArgs._[0]; |
|
|
|
var clioverrides = { cmd } |
|
|
|
processedArgs.node_env ? clioverrides.node_env = 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; |
|
|
|
|
|
|
|
|
|
|
|
return cmds[cmd] ? cmds[cmd].interpret() : (function(){ |
|
|
|
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() |
|
|
|
})() |
|
|
|
} |
|
|
|
|
|
|
|
var clioverrides = interpretrun() |
|
|
|
console.dir(clioverrides) |
|
|
|
|
|
|
|
var util = require('util'); |
|
|
|
var cliname = 'elxr'; |
|
|
|
var ver = '1.1'; |
|
|
@@ -2268,11 +2354,48 @@ var eNotImplemented = function(){ |
|
|
|
process.exit() |
|
|
|
} |
|
|
|
|
|
|
|
// PB : TODO -- accept additional arg - an array specifying custom configPriority. |
|
|
|
var acquireConfig = function(slections){ |
|
|
|
var configPriority = [ 'clusterNodeInstance', 'ownerInstnace', 'commonInstance', 'genericChessInstance' ] |
|
|
|
return any(configPriority.map(cfg => { return function() { return configs[cfg](slections) } } ), true, true) |
|
|
|
var configPriority = [ 'clusterNodeInstance', 'ownerInstnace', 'commonInstance' /*, 'genericChessInstance'*/ ] |
|
|
|
return any(configPriority.map(cfg => { return function() { return configs[cfg](slections) } } ), true, true).then(()=>{ |
|
|
|
return acquireData(slections) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
var instanceData = (function(){ |
|
|
|
return { |
|
|
|
clusterNodeInstance(selected) { var clusternodename = 'node01' |
|
|
|
return __acquireData(selected, selected.username, clusternodename |
|
|
|
, selected.instanceName + '-config-' + 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 |
|
|
|
, function(e){ console.info('Customized user level config not found. This is not an Error. Will attempt global common instance config.'); |
|
|
|
return e } |
|
|
|
) |
|
|
|
} |
|
|
|
// PB : TODO -- Use the ORG level instance before falling back to common Instance coz common instance may not exist for certain orgs. |
|
|
|
, commonInstance(selected) { return __acquireData(selected, defaultRepoOwner |
|
|
|
// , function(e){ console.info('This is probably an error unless the user is asking to create a new instance with this name.') } |
|
|
|
) } |
|
|
|
, genericChessInstance(selected) { return __acquireData(selected) } |
|
|
|
} |
|
|
|
})() |
|
|
|
|
|
|
|
var acquireData = function(slections){ |
|
|
|
var configPriority = [ 'clusterNodeInstance', 'ownerInstnace', 'commonInstance' /*, 'genericChessInstance'*/ ] |
|
|
|
return any(configPriority.map(cfg => { return function() { return instanceData[cfg](slections) } } ), true, true) |
|
|
|
} |
|
|
|
|
|
|
|
// Git Credential storage... |
|
|
|
// 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 |
|
|
|
var __acquireConfig = function (selected, owner, clusternodename, configrepo, errHandler) { |
|
|
|
|
|
|
|
configrepo = configrepo || selected.instanceName + '-config-' + selected.node_env; |
|
|
@@ -2312,7 +2435,9 @@ var __acquireConfig = function (selected, owner, clusternodename, configrepo, er |
|
|
|
return cli.prompt( choices |
|
|
|
, 'Config for instance not found. Would you like to ', 'e' ).then(propValue => { |
|
|
|
|
|
|
|
if(propValue === 't') return createInstance() |
|
|
|
if(propValue === 't') { |
|
|
|
selectedinstance.local = true; return createInstance(selectedinstance) |
|
|
|
} |
|
|
|
if(propValue === 'i') return eNotImplemented() |
|
|
|
if(propValue === 'f') return eNotImplemented() |
|
|
|
if(propValue === 'o') return eNotImplemented() |
|
|
@@ -2358,6 +2483,76 @@ var __acquireConfig = function (selected, owner, clusternodename, configrepo, er |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
var __acquireData = function (selected, owner, clusternodename, datarepo, errHandler) { |
|
|
|
|
|
|
|
datarepo = datarepo || selected.instanceName + '-config-' + selected.node_env; |
|
|
|
|
|
|
|
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`))){ |
|
|
|
// console.error('Could not connect to repo server. Timed Out') |
|
|
|
return cli.prompt( ['(y)es', '(n)o', '(r)etry'], 'Could not connect to repo server. Timed Out. Would you like to switch server ? (y/n) ', 'y' ).then(propValue => { |
|
|
|
|
|
|
|
if(propValue === 'y') { |
|
|
|
reconfirm = getReconfirmAll() |
|
|
|
return startElxr() |
|
|
|
} |
|
|
|
else if(propValue === 'r'){ |
|
|
|
return acquireConfig(selected) |
|
|
|
} |
|
|
|
else process.exit() |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
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 )` |
|
|
|
, e : 'exit' } |
|
|
|
|
|
|
|
if(selectedinstance.username !== 'guest' && selectedinstance.username !== 'demo') { |
|
|
|
choices = utils.assign({ |
|
|
|
i : 'create a new instance with this name => will fork the default config under your username' |
|
|
|
, f : 'fork a new instance with this name for yourself for this node from another instance' |
|
|
|
, o : 'fork a new instance with this name for your organization from another instance' // prompt organization name... |
|
|
|
, c : 'create a custom config for yourself for this node' // prompt hostname as nodename |
|
|
|
, p : 'create a custom config for yourself ' |
|
|
|
}, choices) |
|
|
|
} |
|
|
|
|
|
|
|
return cli.prompt( choices |
|
|
|
, 'Data repo for instance not found. Would you like to ', 'e' ).then(propValue => { |
|
|
|
|
|
|
|
if(propValue === 't') { |
|
|
|
selectedinstance.local = true; return createInstanceData(selectedinstance) |
|
|
|
} |
|
|
|
if(propValue === 'i') return eNotImplemented() |
|
|
|
if(propValue === 'f') return eNotImplemented() |
|
|
|
if(propValue === 'o') return eNotImplemented() |
|
|
|
if(propValue === 'c') return eNotImplemented() // return createLocalChessInsance(selectedinstance) |
|
|
|
if(propValue === 'p') return eNotImplemented() // return createChessInstance(selectedinstance) |
|
|
|
// if(propValue === 'o') createChessInstance(selectedinstance, orgname) |
|
|
|
else process.exit() |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
console.warn(e) |
|
|
|
throw e; //('Config acquisition failed.') |
|
|
|
} |
|
|
|
|
|
|
|
var successHandler = () => { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return performPull(datarepo, null, owner, errHandler || errorHandler || ((e)=>{ throw e })).then( successHandler ) |
|
|
|
.catch( (e)=>{ |
|
|
|
// if(e){ |
|
|
|
if(Promise.resolve(e) === e) return e; |
|
|
|
console.error(e) |
|
|
|
throw e; // Not a hard error but we need this for bcontinueonfailure |
|
|
|
// } |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
var launchpath = path.normalize(process.cwd()) |
|
|
|
var thisscriptdir = path.normalize(__dirname); // PB : TODO -- Thisscriptdir could be dislocated when run as a standalone file... We need to detect this where and how we were run. |
|
|
|
// The easisest would be to ask for a target directory and default to current dir.... |
|
|
@@ -2380,16 +2575,31 @@ var __default = ((name, options)=>{ |
|
|
|
// User can always add more branches and remotes as needed. Mainifest only occupies |
|
|
|
// well defined namespaces |
|
|
|
var remotes = { |
|
|
|
// these are both fetch and push remotes. Use push - remotes to override push. |
|
|
|
'chess' : { path : `/chess/`, push : 'no-pushing' } |
|
|
|
|
|
|
|
// these are both fetch and push remotes. Use push - remotes to override push. |
|
|
|
'chess' : { |
|
|
|
server : `${options.reposerver}`, user : 'chess', path : ``, get url(){ return `${this.server}/${this.user}/${this.path}`} // fetch |
|
|
|
, push : 'no-pushing' } |
|
|
|
, 'baptistdev-public' : { |
|
|
|
server : `https://github.com`, user : 'baptistdev', path : ``, get url(){ return `${this.server}/${this.user}/${this.path}`} // fetch |
|
|
|
, push : 'no-pushing' } |
|
|
|
|
|
|
|
|
|
|
|
// Multiple urls dont tell us the current origin which may be |
|
|
|
// different based on currently available/accessible based on device and client. |
|
|
|
// We just treat them as different remotes and merge as needed. |
|
|
|
// |
|
|
|
, 'origin' : { path : `/${options.username}/` } |
|
|
|
, 'origin-public' : { path : `/${options.username}/` } |
|
|
|
, 'origin-unc' : { path : `/${options.username}/` } |
|
|
|
, 'origin' : { |
|
|
|
server : `${options.reposerver}`, user : '${options.username}', path : ``, get url(){ return `${this.server}/${this.user}/${this.path}`} // fetch |
|
|
|
} |
|
|
|
, 'origin-public' : { |
|
|
|
server : `https://git.bbh.org.in`, user : 'chess', path : ``, get url(){ return `${this.server}/${this.user}/${this.path}`} // fetch |
|
|
|
, push : { |
|
|
|
server : `${options.reposerver}`, user : `${options.username}`, path : ``, get url(){ return `${this.server}/${this.user}/${this.path}`} |
|
|
|
} |
|
|
|
} |
|
|
|
, 'origin-unc' : { |
|
|
|
server : `//172.16.0.27/repos`, user : '${options.username}', path : ``, get url(){ return `${this.server}/${this.user}/${this.path}`} // fetch |
|
|
|
} |
|
|
|
// , { `${options.username}` : `https://git.bbh.org.in/${options.username}/elxr.git` } |
|
|
|
} |
|
|
|
|
|
|
@@ -2410,21 +2620,24 @@ var __default = ((name, options)=>{ |
|
|
|
, 'https://git.bbh.org.in' : { users, remotes, external : true } |
|
|
|
, '//172.16.0.27/repos' : { users, remotes } |
|
|
|
, 'https://github.com' : { |
|
|
|
// We host a miniaml set of repositories in github. |
|
|
|
get users() { return [{ username : `${this.username}` }]}, username : `baptistdev` |
|
|
|
, remotes : { get 'baptistdev-public'() { return {path : `/${this.username}/`, push : 'no-pushing'} } |
|
|
|
// , Add other remotes here. |
|
|
|
} |
|
|
|
, external : true, public : true |
|
|
|
// We host a miniaml set of repositories in github. |
|
|
|
get users() { return [{ username : `${this.username}` }]}, username : `baptistdev` |
|
|
|
, remotes : { |
|
|
|
'baptistdev-public' : { |
|
|
|
server : `https://github.com`, user : 'baptistdev', path : ``, get url(){ return `${this.server}/${this.user}/${this.path}`} // fetch |
|
|
|
, push : 'no-pushing' } |
|
|
|
// , Add other remotes here. |
|
|
|
} |
|
|
|
, external : true, public : true |
|
|
|
} |
|
|
|
} |
|
|
|
return { |
|
|
|
reposervers : Object.keys(reposerverinstances) |
|
|
|
, reposerverinstances |
|
|
|
reposervers : Object.keys(reposerverinstances) |
|
|
|
, reposerverinstances |
|
|
|
|
|
|
|
// Common baseline repos for all chess instances. |
|
|
|
, repos : [ |
|
|
|
{ repo : 'ember-masonry-grid' /*, branch : master*/ } // Default need not be specified. |
|
|
|
// Common baseline repos for all chess instances. |
|
|
|
, repos : [ |
|
|
|
{ repo : 'ember-masonry-grid' /*, branch : master*/ } // Default need not be specified. |
|
|
|
, { repo : 'bbhverse' } |
|
|
|
, { repo : 'clientverse' } |
|
|
|
, { repo : 'serververse' } |
|
|
@@ -2443,20 +2656,6 @@ var __default = ((name, options)=>{ |
|
|
|
, { repo : 'global-this' } |
|
|
|
] |
|
|
|
|
|
|
|
// PB : TODO -- lighter defaults for lite new instance creation.. |
|
|
|
, repos: [ |
|
|
|
{ repo : 'setup' } |
|
|
|
, { repo : 'elxr' } |
|
|
|
, { repo : 'loopback-connector-mysql' } |
|
|
|
, { repo : 'loopback-jsonapi-model-serializer' } |
|
|
|
, { repo : 'loopback-component-jsonapi' } |
|
|
|
, { repo : 'ember-service-worker' } |
|
|
|
, { repo : 'ember-service-worker-asset-cache' } |
|
|
|
, { repo : 'ember-service-worker-cache-fallback' } |
|
|
|
, { repo : 'ember-service-worker-index' } |
|
|
|
, { repo : 'ember-sw-client-route' } |
|
|
|
] |
|
|
|
|
|
|
|
, elevated : [ ] |
|
|
|
, exludeMergeRepos : { } |
|
|
|
} |
|
|
@@ -2716,12 +2915,14 @@ var __interactive_prompts = function( target, choices, promptsfilter ){ |
|
|
|
, choices : choices['instanceType'], defaultchoice : 'development'} |
|
|
|
, reposerver : { label : `Enter Repo Url ( <= ${target.reposerver || 'https://git.bbh.org.in'} ) : ` |
|
|
|
, choices : choices['reposerver'], defaultchoice : 'https://git.bbh.org.in'} |
|
|
|
, username : { label : `Enter User Id for ${target.reposerver} ( <= ${target.username || 'chess'} ) : ` |
|
|
|
, choices : choices['username'], defaultchoice : 'chess'} |
|
|
|
, password : { label : `Enter Password for ${target.username} @ ${target.reposerver} ( <= ${target.password || ''} ) : ` |
|
|
|
, choices : choices['password'], defaultchoice : '***'} |
|
|
|
, email : { label : `Enter Email for ${target.username} @ ${target.reposerver} ( <= ${target.email || ''} ) : ` |
|
|
|
, choices : choices['email'], defaultchoice : 'guest@bbh.org.in'} |
|
|
|
|
|
|
|
, get username() { return { label : `Enter User Id for ${target.reposerver} ( <= ${target.username || 'chess'} ) : ` |
|
|
|
, choices : choices['username'], defaultchoice : 'chess'} } |
|
|
|
, get password() { return { label : `Enter Password for ${target.username} @ ${target.reposerver} ( <= ${target.password || ''} ) : ` |
|
|
|
, choices : choices['password'], defaultchoice : '***'} } |
|
|
|
, get email() { return { label : `Enter Email for ${target.username} @ ${target.reposerver} ( <= ${target.email || ''} ) : ` |
|
|
|
, choices : choices['email'], defaultchoice : 'guest@bbh.org.in'} } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@@ -2948,6 +3149,8 @@ function verifyAndInstallPrerequisites() { |
|
|
|
var shell = new ActiveXObject('shell.application'); |
|
|
|
// alert('launching node privilged. ' + processedArgs['nodepath']) |
|
|
|
// shell.ShellExecute('where', 'node', '', '', 10); |
|
|
|
// shell.ShellExecute('cmd.exe', '/k notepad.exe', '', 'runas', 1); |
|
|
|
// shell.ShellExecute('cmd.exe ', '/k node "' + cargs + '"', '', 'runas', 1); |
|
|
|
shell.ShellExecute('node', cargs, '', 'runas', 1); |
|
|
|
// shell.ShellExecute(processedArgs['nodepath'], cargs, '', 'runas', 1); |
|
|
|
var fso = new ActiveXObject('Scripting.FileSystemObject'); |
|
|
@@ -3138,7 +3341,8 @@ var detection_state = { |
|
|
|
} |
|
|
|
|
|
|
|
const https = require('https') |
|
|
|
const http = require('http') |
|
|
|
const http = require('http'); |
|
|
|
const { resolve } = require('path'); |
|
|
|
const RESTAPI = (function(){ |
|
|
|
|
|
|
|
// Singleton |
|
|
@@ -3314,38 +3518,48 @@ const GIT = (function(){ |
|
|
|
return GIT |
|
|
|
})(); |
|
|
|
|
|
|
|
function createInstance(selectedinstance) { |
|
|
|
function createInstance(target, source) { |
|
|
|
|
|
|
|
console.dir(selectedinstance) |
|
|
|
if(selectedinstance.local) { |
|
|
|
selectedinstance |
|
|
|
var args = { |
|
|
|
remotebase : selectedinstance.reposerver + '/chess/' |
|
|
|
, sourcerepo : 'chess-config' |
|
|
|
, targetrepo : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}` |
|
|
|
} |
|
|
|
var sourceinstance = source || target; |
|
|
|
console.dir(sourceinstance) |
|
|
|
var args = { |
|
|
|
remotebase : sourceinstance.reposerver + '/chess/' |
|
|
|
, sourcerepo : sourceinstance.repo || 'chess-config' |
|
|
|
, targetrepo : `${target.instanceName}-config-${target.instanceType}${target.nodeName ? ('-' + target.nodeName) : ''}` |
|
|
|
} |
|
|
|
|
|
|
|
cmdseq = ['git', ['clone', `${args.remotebase}${args.sourcerepo}`, `${args.targetrepo}`], options] |
|
|
|
if(sourceinstance.local) { |
|
|
|
|
|
|
|
return any(cmdseq.map(getshelltask)).then(() => { |
|
|
|
return true |
|
|
|
}) |
|
|
|
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 |
|
|
|
|
|
|
|
var server = new URL(selectedinstance.reposerver); |
|
|
|
if(source.reposerver !== target.reposerver && source.username !== target.username) { |
|
|
|
throw 'createInstance 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 : selectedinstance.username, password : selectedinstance.password |
|
|
|
, username : target.username, password : target.password |
|
|
|
} |
|
|
|
// , { repo : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}`} |
|
|
|
, { repo : `chess-config`, owner : 'chess' }, {}, function( repository ){ |
|
|
|
, { repo : `${args.sourcerepo}`, owner : `${target.username}` }, {}, function( repository ){ |
|
|
|
return GITEA.repository.updateattributes( { |
|
|
|
hostname : server.host, protocol : server.protocol |
|
|
|
, username : selectedinstance.username, password : selectedinstance.password |
|
|
|
, username : target.username, password : target.password |
|
|
|
} |
|
|
|
, { repo : `chess-config`, owner : selectedinstance.username } |
|
|
|
, { name : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}${selectedinstance.nodeName ? '-' + selectedinstance.nodeName : ''}`} |
|
|
|
, { repo : `${args.sourcerepo}`, owner : `${target.username}` } |
|
|
|
, { name : `${args.targetrepo}`} |
|
|
|
) |
|
|
|
} |
|
|
|
) |
|
|
@@ -3454,14 +3668,29 @@ var maintask = () => { |
|
|
|
var e = { message : 'verifyAndInstall', success : true} |
|
|
|
var inittasks = [] |
|
|
|
if(!detection_state.localInstanceDetected) { |
|
|
|
inittasks.push(createInstance(selectedinstance).then(() => { preworkerconfig(); return elxrworker(true) })) |
|
|
|
var specifictask = ()=>{ return createInstance(selectedinstance) } |
|
|
|
var commantask = () => { preworkerconfig(); return elxrworker(true) } |
|
|
|
if(!__isElevated) { |
|
|
|
} |
|
|
|
else { |
|
|
|
specifictask = ()=>{ Promise.resolve(true) } |
|
|
|
} |
|
|
|
inittasks.push(specifictask().then( commantask )) |
|
|
|
} |
|
|
|
else { |
|
|
|
inittasks.push(acquireConfig(selectedinstance).catch((err) => { |
|
|
|
var specifictask = ()=>{ return acquireConfig(selectedinstance) } |
|
|
|
var commantask = () => { preworkerconfig(); return elxrworker(true) } |
|
|
|
if(!__isElevated) { |
|
|
|
} |
|
|
|
else { |
|
|
|
specifictask = ()=>{ return Promise.resolve(true) } |
|
|
|
} |
|
|
|
|
|
|
|
inittasks.push( specifictask().catch((err) => { |
|
|
|
e = err; |
|
|
|
console.error('Chosen cofiguraton failed or not found. Fix config and rerun or chose another.') |
|
|
|
console.error(err) |
|
|
|
}).then(() => { preworkerconfig(); return elxrworker(true) }) |
|
|
|
}).then( commantask ) |
|
|
|
// .finally(()=>{ |
|
|
|
// fs.writeFileSync('run.log', ', ' + JSON.stringify({ error: e.message }), { 'flag': 'a+' }) |
|
|
|
// if(!e.success) fs.writeFileSync('run.done', 'error'); |