|
|
@@ -26,9 +26,34 @@ const cliargs = utils.cliargs; |
|
|
|
const processedArgs = cliargs(process.argv.slice(2)); |
|
|
|
|
|
|
|
const __ALIAS__STAMP__ = '9e7bebe0-1f57-11ec-8f88-778ffeea9d1b' |
|
|
|
|
|
|
|
// var shell_verse = cli.shell_verse; |
|
|
|
// const getVersion = cli.shell_verse.getVersion |
|
|
|
|
|
|
|
|
|
|
|
function isWin(){ return /^win/.test(process.platform) } |
|
|
|
try { |
|
|
|
|
|
|
|
if(isWin()) { |
|
|
|
var win_verse = require('./win_verse') |
|
|
|
var shell_verse = win_verse; |
|
|
|
} |
|
|
|
else { |
|
|
|
var lin_verse = require('./lin_verse') |
|
|
|
var shell_verse = lin_verse; |
|
|
|
} |
|
|
|
} |
|
|
|
catch(e) { |
|
|
|
console.dir(e); |
|
|
|
console.error('cli environment detection failed') |
|
|
|
} |
|
|
|
|
|
|
|
const BUILD_VERSION = '[VI]Version: {version} - built on {date}[/VI]'; |
|
|
|
shell_verse.getVersion = function getVersion() { return BUILD_VERSION; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const runtimestamp = processedArgs.runtimestamp ? (new Date(processedArgs.runtimestamp)).getTime() : (new Date()).getTime(); |
|
|
|
function getVersion() { return BUILD_VERSION; } |
|
|
|
|
|
|
|
var defaultowner = 'chess'; |
|
|
|
|
|
|
@@ -50,7 +75,7 @@ const http = require('http'); |
|
|
|
const { Console } = require('console'); |
|
|
|
const { env } = require('process'); |
|
|
|
const { validate } = require('uuid'); |
|
|
|
const PATTERNAPI = require('serververse').PATTERNAPI |
|
|
|
const PATTERNAPI = utils.PATTERNAPI |
|
|
|
// const RESTAPI = require('serververse').RESTAPI |
|
|
|
const RESTAPI = (function(){ |
|
|
|
|
|
|
@@ -407,19 +432,51 @@ const GIT = (function(){ |
|
|
|
} |
|
|
|
}()); |
|
|
|
|
|
|
|
function isWin(){ return /^win/.test(process.platform) } |
|
|
|
if(isWin()) { |
|
|
|
var win_verse = require('./win_verse') |
|
|
|
var shell_verse = win_verse; |
|
|
|
shell_verse.getVersion = getVersion |
|
|
|
} |
|
|
|
else { |
|
|
|
var lin_verse = require('./lin_verse') |
|
|
|
var shell_verse = lin_verse; |
|
|
|
} |
|
|
|
|
|
|
|
// SAM : TODO Use nodeshellexec where to detect git installation dir |
|
|
|
var gitbash = shell_verse.getbash() |
|
|
|
var gitRepos = null |
|
|
|
var callshelltask = (args) => { |
|
|
|
// console.dir(args) |
|
|
|
if( Object.prototype.toString.call(args) === '[object Function]' ) { |
|
|
|
return args; |
|
|
|
} |
|
|
|
return getshelltask(args)() |
|
|
|
} |
|
|
|
|
|
|
|
var runconfig = null; |
|
|
|
|
|
|
|
// PB : TODO -- rename as shelltask and bashtask['gitbash']... ( gitbash is a different bash... so previously named to specify that the bash distribution from git is the bash being used...) |
|
|
|
var getShellTask = (command, args, options) => { |
|
|
|
options = options || {} |
|
|
|
var callshell = command === 'rm' ? getgitbashtask : getshelltask; |
|
|
|
return () => { |
|
|
|
var p = callshell( [command, args, Object.assign({ |
|
|
|
inherit: true, shell: true, env: ENV, title: `${command} ${args}` |
|
|
|
}, options) |
|
|
|
])() |
|
|
|
if (options.ignorefailures) { |
|
|
|
return p.catch(e => { |
|
|
|
// Ignore. Not a major error. |
|
|
|
}) |
|
|
|
} |
|
|
|
else return p; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var getCmdString = function(args){ return `"${args[0]} ${args[1].join(' ')}"` } |
|
|
|
var getgitbashtask = (args, onEachError) => { return () => { |
|
|
|
return nodeShellExec( `"${gitbash}"`, ['-c', getCmdString(args)], args[2]).catch( onEachError || function(e){ console.error(e) }) } |
|
|
|
} |
|
|
|
|
|
|
|
var getshelltask = (args) => { |
|
|
|
return args[0] === 'rm' ? getgitbashtask(args) : () => { |
|
|
|
return nodeShellExec.apply(null, args).catch(function(e){ |
|
|
|
e.benign = args[2].benign; |
|
|
|
if(!e.benign) { console.error( JSON.stringify(e) ); } |
|
|
|
throw e |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// PB : TODO -- In windows if we are run from an elevated shell we never move forward and simply exits !?. |
|
|
|
// -- Currently workaround in windows is to always run from a non-elevated shell. |
|
|
@@ -435,7 +492,7 @@ shell_verse.acquireElevationState().then((isElevated) => { |
|
|
|
} |
|
|
|
else { |
|
|
|
console.log("Stats object for: example_directory.txt"); |
|
|
|
console.log(stats); |
|
|
|
console.log(util.inspect(stats)); |
|
|
|
|
|
|
|
// Using methods of the Stats object |
|
|
|
console.log("Path is file:", stats.isFile()); |
|
|
@@ -489,7 +546,7 @@ shell_verse.acquireElevationState().then((isElevated) => { |
|
|
|
// console.log('launchscriptdir : ' + path.normalize(__dirname)) |
|
|
|
console.log('----------------------------------------------------------------') |
|
|
|
console.log('BEFORE DISCOVERY') |
|
|
|
console.log('version : ' + getVersion()); |
|
|
|
console.log('version : ' + shell_verse.getVersion()); |
|
|
|
console.log('process.env.wd : ' + process.env.wd) |
|
|
|
console.log('processedArgs.root : ' + processedArgs.root) |
|
|
|
console.log('----------------------------------------------------------------') |
|
|
@@ -626,7 +683,7 @@ shell_verse.acquireElevationState().then((isElevated) => { |
|
|
|
|
|
|
|
console.log('----------------------------------------------------------------') |
|
|
|
console.log('AFTER DISCOVERY') |
|
|
|
console.log('version : ' + getVersion()); |
|
|
|
console.log('version : ' + shell_verse.getVersion()); |
|
|
|
console.log('process.env.wd : ' + process.env.wd) |
|
|
|
console.log('processedArgs.root : ' + processedArgs.root) |
|
|
|
console.log('----------------------------------------------------------------') |
|
|
@@ -647,7 +704,7 @@ shell_verse.acquireElevationState().then((isElevated) => { |
|
|
|
// console.dir(shell_verse.selectedinstance.launchscript) |
|
|
|
// throw shell_verse.selectedinstance.launchscript |
|
|
|
// Instead of waiting for the root to be establised we start working at the current locatoin and then relocate when root changes. |
|
|
|
var runlogjson = `${processedArgs.root}/.elxr/run-${runtimestamp}/run.log` |
|
|
|
var runlogjson = `${root}/.elxr/run-${runtimestamp}/run.log` |
|
|
|
ensureDirectoryExistence(runlogjson) |
|
|
|
fs.writeFileSync(runlogjson, JSON.stringify( { message : `Started ${runtimestamp}`, success:true})) // Initialize a new log file with "logrotate" for every run |
|
|
|
Tasq.addlistener((e)=>{ fs.writeFileSync(runlogjson, ', ' + JSON.stringify( e ), { 'flag': 'a+' }) }) |
|
|
@@ -1280,6 +1337,11 @@ shell_verse.acquireElevationState().then((isElevated) => { |
|
|
|
return pT() // Execute it. |
|
|
|
} |
|
|
|
|
|
|
|
var elevatedRunasRepos = null |
|
|
|
var exludeMergeRepos = []; |
|
|
|
// Maps an environment to a branch. Not required if the branch is appropriately named. |
|
|
|
var checkoutMap = { 'development': 'master' } |
|
|
|
|
|
|
|
var oplist = { |
|
|
|
'h': () => { console.log(elxr.help()); return '-h' } |
|
|
|
, 'clean' : () => { |
|
|
@@ -2492,7 +2554,7 @@ shell_verse.acquireElevationState().then((isElevated) => { |
|
|
|
, env: ENV |
|
|
|
, title: `npm i for ${repo}` |
|
|
|
}).catch((e) => { |
|
|
|
console.error('Ignoring Benign Error'); console.error(e); |
|
|
|
console.error('Ignoring Benign Error'); console.error(util.inspect(e)); |
|
|
|
}).then(() => { |
|
|
|
console.log(`--npm run build for ${repo}--------------------`) |
|
|
|
return nodeShellExec('npm', ['run build'], { |
|
|
@@ -2534,7 +2596,7 @@ shell_verse.acquireElevationState().then((isElevated) => { |
|
|
|
}]) |
|
|
|
.then(()=>{ |
|
|
|
console.log(`--rm package-lock.json for ${repodef.repo}--------------------`) |
|
|
|
}).catch((e) => { console.error(e) }) |
|
|
|
}).catch((e) => { console.error(util.inspect(e)) }) |
|
|
|
// } |
|
|
|
) |
|
|
|
|
|
|
@@ -2573,7 +2635,7 @@ shell_verse.acquireElevationState().then((isElevated) => { |
|
|
|
// }).then(Tasq.then).catch(Tasq.catch) |
|
|
|
// }) |
|
|
|
|
|
|
|
var bowerRepos = [{ repo : 'elixir-client'}]; |
|
|
|
var bowerRepos = [{ repo : 'elixir-client/client'}]; |
|
|
|
var bowertasks = [] |
|
|
|
bowerRepos.forEach(repodef => { |
|
|
|
bowertasks.push(() => { |
|
|
@@ -2938,6 +3000,12 @@ shell_verse.acquireElevationState().then((isElevated) => { |
|
|
|
var p = shell_verse.createJuntionOrLink('config', target, opts) |
|
|
|
return p; |
|
|
|
} |
|
|
|
, () => { |
|
|
|
// Use junctions to avoid npm package issues |
|
|
|
var target = runconfig.use + '-' + 'clientconfig' + '-' + ENV.NODE_ENV |
|
|
|
var p = shell_verse.createJuntionOrLink('clientconfig', target, opts) |
|
|
|
return p; |
|
|
|
} |
|
|
|
]; |
|
|
|
// if (processedArgs._[1]) { |
|
|
|
tasks = tasks.concat( [ |
|
|
@@ -3243,7 +3311,7 @@ shell_verse.acquireElevationState().then((isElevated) => { |
|
|
|
var parameters = ['-c', 'for i in `git remote`; do git pull $i ' + branch + '; done;'] |
|
|
|
var pullCmd = [ gitbash |
|
|
|
, ['-c', 'for i in `git remote`; do git pull $i ' + branch + '; done;'] |
|
|
|
, { cwd: repodef.repdir + '/' + repo, title : 'pull all remotes for ' + branch + ' ' + repo + ' ' + parameters.join(' ') }] |
|
|
|
, { cwd: repodef.repodir + '/' + repo, title : 'pull all remotes for ' + branch + ' ' + repo + ' ' + parameters.join(' ') }] |
|
|
|
} |
|
|
|
else pullCmd = ['git', ['pull'], { |
|
|
|
inherit: true, shell: true, |
|
|
@@ -3984,24 +4052,6 @@ shell_verse.acquireElevationState().then((isElevated) => { |
|
|
|
resetgitconfig() |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var getCmdString = function(args){ return `"${args[0]} ${args[1].join(' ')}"` } |
|
|
|
var getgitbashtask = (args, onEachError) => { return () => { |
|
|
|
return nodeShellExec( `"${gitbash}"`, ['-c', getCmdString(args)], args[2]).catch( onEachError || function(e){ console.error(e) }) } |
|
|
|
} |
|
|
|
|
|
|
|
var getshelltask = (args) => { |
|
|
|
return args[0] === 'rm' ? getgitbashtask(args) : () => { |
|
|
|
return nodeShellExec.apply(null, args).catch(function(e){ |
|
|
|
e.benign = args[2].benign; |
|
|
|
if(!e.benign) { console.error( JSON.stringify(e) ); } |
|
|
|
throw e |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const GITSHELL = (function(){ |
|
|
|
const GITSHELL = function(){} |
|
|
|
GITSHELL.bash = shell_verse.getbash() |
|
|
@@ -4790,32 +4840,6 @@ shell_verse.acquireElevationState().then((isElevated) => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// PB : TODO -- rename as shelltask and bashtask['gitbash']... ( gitbash is a different bash... so previously named to specify that the bash distribution from git is the bash being used...) |
|
|
|
var getShellTask = (command, args, options) => { |
|
|
|
options = options || {} |
|
|
|
var callshell = command === 'rm' ? getgitbashtask : getshelltask; |
|
|
|
return () => { |
|
|
|
var p = callshell( [command, args, Object.assign({ |
|
|
|
inherit: true, shell: true, env: ENV, title: `${command} ${args}` |
|
|
|
}, options) |
|
|
|
])() |
|
|
|
if (options.ignorefailures) { |
|
|
|
return p.catch(e => { |
|
|
|
// Ignore. Not a major error. |
|
|
|
}) |
|
|
|
} |
|
|
|
else return p; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var callshelltask = (args) => { |
|
|
|
// console.dir(args) |
|
|
|
if( Object.prototype.toString.call(args) === '[object Function]' ) { |
|
|
|
return args; |
|
|
|
} |
|
|
|
return getshelltask(args)() |
|
|
|
} |
|
|
|
|
|
|
|
var getnodeshellexectask = (args) => { return () => { return nodeShellExec.apply(null, args) }} |
|
|
|
var perform = function( serailtasks, taskvector ){ return any( serailtasks(taskvector).map(getnodeshellexectask)) } |
|
|
|
|
|
|
@@ -4831,8 +4855,7 @@ shell_verse.acquireElevationState().then((isElevated) => { |
|
|
|
|
|
|
|
var currentGitAuthUser; // nodeShellExec('git', ['config', 'user.email']) ... PB : TODO-- get the current GITEA username |
|
|
|
|
|
|
|
var elevatedRunasRepos = null |
|
|
|
var gitRepos = null |
|
|
|
|
|
|
|
|
|
|
|
// grep -qxF 'alias elxr="node elxr/index.js"' ~/.bash_profile || echo 'alias elxr="node elxr/index.js"' >> ~/.bash_profile |
|
|
|
// nodeShellExec('echo', ['elxr'], { inherit : true}) //, {stdio: "inherit"} |
|
|
@@ -4846,14 +4869,12 @@ shell_verse.acquireElevationState().then((isElevated) => { |
|
|
|
return dbsForLabel[label] || 'mysql' |
|
|
|
} |
|
|
|
|
|
|
|
// Maps an environment to a branch. Not required if the branch is appropriately named. |
|
|
|
var checkoutMap = { 'development': 'master' } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// var gitbash = "G:\\Installed\\Git\\bin\\sh.exe" |
|
|
|
// Relevant git repos |
|
|
|
var exludeMergeRepos = []; |
|
|
|
|
|
|
|
var useGitPull = processedArgs.useGitPull || false; |
|
|
|
var configPromise = null |
|
|
|
|
|
|
@@ -5498,7 +5519,6 @@ shell_verse.acquireElevationState().then((isElevated) => { |
|
|
|
} |
|
|
|
|
|
|
|
// function updateselection(selected) { selectedinstance = utils.assign(selectedinstance, selected) } |
|
|
|
var runconfig = null; |
|
|
|
|
|
|
|
var promptkeys = { |
|
|
|
cmd : processedArgs._[0] || 'pull' |