Browse Source

fix elxr use and npmi

pull/4/head
chess 3 years ago
parent
commit
a4012ea4e9
2 changed files with 268 additions and 60 deletions
  1. 157
    37
      i.js
  2. 111
    23
      index.js

+ 157
- 37
i.js View File

/* Version: 1.0.0 - May 8, 2021 11:38:39 */
/* Version: 1.0.0 - May 11, 2021 23:29:35 */
'use strict'; 'use strict';


var path$1 = require('path'); var path$1 = require('path');
return hooks; return hooks;


}))); })));
}, "/$$rollup_base$$/node_modules/moment");
}, "E:/elixir/production_A/bbhverse/node_modules/moment");


let array8 = arrayUntyped, let array8 = arrayUntyped,
array16 = arrayUntyped, array16 = arrayUntyped,






const BUILD_VERSION = 'Version: 1.0.0 - built on May 8, 2021 11:38:39';
const BUILD_VERSION = 'Version: 1.0.0 - built on May 11, 2021 23:29:35';
function getVersion() { return BUILD_VERSION; } function getVersion() { return BUILD_VERSION; }
console.log(getVersion()); console.log(getVersion());


console.log('result : ' + JSON.stringify(r)); console.log('result : ' + JSON.stringify(r));
Object.keys(processedArgs).forEach((v) => { v != '_' ? namedArgs.push('--' + v + '=' + processedArgs[v]) : null; }); Object.keys(processedArgs).forEach((v) => { v != '_' ? namedArgs.push('--' + v + '=' + processedArgs[v]) : null; });
// PB : TODO -- Convert all the cli args back to string. // PB : TODO -- Convert all the cli args back to string.
var args = [__dirname + '/windowselevate.hta'].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self');
var args = [__dirname + '/.run/windowselevate.hta'].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self');
args.push('--nodepath=' + r[r.length - 1]); args.push('--nodepath=' + r[r.length - 1]);
if (!processedArgs.node_env) args.push('--node_env=' + ENV.NODE_ENV); if (!processedArgs.node_env) args.push('--node_env=' + ENV.NODE_ENV);
if (processedArgs.debug) args.push('--debug=true'); // Enable to debug elevated.. if (processedArgs.debug) args.push('--debug=true'); // Enable to debug elevated..
// console.dir(env) // console.dir(env)
console.log('Running exlr pull : ' + path__default['default'].dirname(__dirname)); console.log('Running exlr pull : ' + path__default['default'].dirname(__dirname));


if (!processedArgs.runas) gitRepos.map((repo) => performPull(repo, 'master'));
if (!processedArgs.runas) gitRepos.map((def) => performPull(def.repo, def.branch || 'master'));
if (__isElevated) { if (__isElevated) {
return any(elevatedRunasRepos.map((repo) => performPull(repo, 'master'))).then(() => {
return any(elevatedRunasRepos.map((def) => performPull(def.repo, def.branch || 'master'))).then(() => {
fs.writeFileSync('run.done', 'success'); fs.writeFileSync('run.done', 'success');
}).catch(() => { }).catch(() => {
fs.writeFileSync('run.done', 'error'); fs.writeFileSync('run.done', 'error');
var repotasks = []; var repotasks = [];
var env = Object.assign({}, process.env); var env = Object.assign({}, process.env);
delete env.NODE_ENV; delete env.NODE_ENV;
gitRepos.forEach(repo => {
gitRepos.forEach(repodef => {


rmtasks.push( rmtasks.push(
// () => { // () => {
// console.log(`--rm package-lock.json for ${repo}--------------------`)
// console.log(`--rm package-lock.json for ${repodef.repo}--------------------`)
// return nodeShellExec(`"${gitbash}"`, ['-c', '"rm package-lock.json"'], { // return nodeShellExec(`"${gitbash}"`, ['-c', '"rm package-lock.json"'], {
nodeShellExec('rm', ['package-lock.json'], { nodeShellExec('rm', ['package-lock.json'], {
inherit: true, shell: true inherit: true, shell: true
, cwd: instanceroot + '/' + repo
, cwd: instanceroot + '/' + repodef.repo
, env: process.env , env: process.env
, title: `rm 'package-lock.json' for ${repo}`
, title: `rm 'package-lock.json' for ${repodef.repo}`
}) })
.then(()=>{ .then(()=>{
console.log(`--rm package-lock.json for ${repo}--------------------`);
console.log(`--rm package-lock.json for ${repodef.repo}--------------------`);
}).catch((e) => { console.error(e); }) }).catch((e) => { console.error(e); })
// } // }
); );


if (npmbuildrepos.indexOf(repo) < 0) {
if (npmbuildrepos.indexOf(repodef.repo) < 0) {
repotasks.push( repotasks.push(
() => { () => {
console.log(`--npm i for ${repo}--------------------`);
console.log(`--npm i for ${repodef.repo}--------------------`);
var p = nodeShellExec('npm', ['i', '--force'], { var p = nodeShellExec('npm', ['i', '--force'], {
inherit: true, shell: true inherit: true, shell: true
, cwd: instanceroot + '/' + repo
, cwd: instanceroot + '/' + repodef.repo
, env , env
, title: `npm i for ${repo}`
, title: `npm i for ${repodef.repo}`
}).then(Tasq.then).catch(Tasq.catch); }).then(Tasq.then).catch(Tasq.catch);
return p; return p;
}); });
// }).then(Tasq.then).catch(Tasq.catch) // }).then(Tasq.then).catch(Tasq.catch)
// }) // })


var bowerRepos = ['client'];
bowerRepos.forEach(repo => {
var bowerRepos = [{ repo : 'client'}];
bowerRepos.forEach(repodef => {
repotasks.push(() => { repotasks.push(() => {
console.log(instanceroot + '/' + repo + '/node_modules/bower/bin/bower');
console.log(instanceroot + '/' + repodef.repo + '/node_modules/bower/bin/bower');
// var p = nodeShellExec('node_modules/bower/bin/bower', ['install'], { // var p = nodeShellExec('node_modules/bower/bin/bower', ['install'], {
var p = nodeShellExec(`"${gitbash}"`, ['-c', '"node_modules/bower/bin/bower i"'], { var p = nodeShellExec(`"${gitbash}"`, ['-c', '"node_modules/bower/bin/bower i"'], {


inherit: true, shell: true inherit: true, shell: true
, cwd: instanceroot + '/' + repo
, cwd: instanceroot + '/' + repodef.repo
, env: process.env , env: process.env
, title: `bower i for ${repo}`
, title: `bower i for ${repodef.repo}`
}).then(Tasq.then).catch(Tasq.catch); }).then(Tasq.then).catch(Tasq.catch);
return p; return p;
}); });
console.log(serverPid); console.log(serverPid);
kill(serverPid); kill(serverPid);
} }
, 'model' : () => {
if (__isElevated) {
var tasks = [
() => {
var p = nodeShellExec('mklink', [ `${processedArgs._[2]}.json`
, `..\\..\\node_modules\\chess-server-lib\\common\\models\\${processedArgs._[2]}.json`], {
inherit: true, shell: true
, cwd : instanceroot + `/${selectedinstance.instanceName}-server/${selectedinstance.instanceName}/models`
, title: `mklink ${processedArgs._[2]}.json ..\\..\\node_modules\\chess-server-lib\\common\\models\\${processedArgs._[2]}.json`
, env: process.env
}).catch((e) => { console.error(e); });
return p;
}
];
return any(tasks).then(() => {
fs.writeFileSync('run.done', 'success');
}).catch(() => {
fs.writeFileSync('run.done', 'error');
})
}
else return op['runas']()
}
, 'use' : () => { , 'use' : () => {
// use a certain named instance. // use a certain named instance.
// Eg : // Eg :
*/ */
var runconfig = { NODE_ENV: repomanifest.node_env }; var runconfig = { NODE_ENV: repomanifest.node_env };
try { runconfig = Object.assign(runconfig, commonjsRequire(instanceroot + '/run.js',"/$$rollup_base$$")); } catch (e) { } try { runconfig = Object.assign(runconfig, commonjsRequire(instanceroot + '/run.js',"/$$rollup_base$$")); } catch (e) { }
if ((!processedArgs.runas || processedArgs.runas !== 'self' && !processedArgs.force) &&
// We no longer need to check ruans.. ??? if we were initiated from self invoked privileged shell ?
if (( /*processedArgs.runas && processedArgs.runas !== 'self' &&*/ !processedArgs.force) &&
runconfig.NODE_ENV && runconfig.NODE_ENV === (repomanifest.node_env || runconfig.NODE_ENV) && runconfig.NODE_ENV && runconfig.NODE_ENV === (repomanifest.node_env || runconfig.NODE_ENV) &&
repomanifest.instanceName && runconfig.use === repomanifest.instanceName) { repomanifest.instanceName && runconfig.use === repomanifest.instanceName) {




// cant use git checkout -b it fails when branch already exists. // cant use git checkout -b it fails when branch already exists.
var performCheckout = (def) => { var performCheckout = (def) => {
if (excludeCheckouts[repo]) return Promise.resolve({ 'skipped': true })
if (excludeCheckouts[def.repo]) return Promise.resolve({ 'skipped': true })
return performPullOrCloneForBranch(def)().then(()=>{
return performPullOrCloneForBranch(def).then(()=>{
nodeShellExec('git', ['checkout', def.branch || checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], { nodeShellExec('git', ['checkout', def.branch || checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], {
// return nodeShellExec('git', ['switch', '-m', '-C', checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], { // return nodeShellExec('git', ['switch', '-m', '-C', checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], {
// inherit : true, shell: true, // inherit : true, shell: true,
}; };
if (runconfig.NODE_ENV === 'development') performMerge = () => { return Promise.resolve(true) }; if (runconfig.NODE_ENV === 'development') performMerge = () => { return Promise.resolve(true) };


// var performRepoOperation = function(def) {
// elevatedRunasRepos.map((repo) => enqueueCheckout({ repo, branch: def.branch, requiresElevation : true }))
// return any(gitRepos.map((repo) => performCheckout({ repo, branch: def.branch})))
// }

return any(tasks).then(() => { return any(tasks).then(() => {
var pr = Promise.resolve(true); var pr = Promise.resolve(true);
if (!__isElevated) { if (!__isElevated) {


//target is the env is we specify in elxr use command. Default is dev //target is the env is we specify in elxr use command. Default is dev
//Switch to target branch //Switch to target branch
return any(gitRepos.map((repo) => performCheckout({ repo, branch})))
return any(gitRepos.map((repodef) => { return performCheckout({ repo : repodef.repo, branch}).catch(e=>{ console.log(e); }) } ))
// pull or clone target branch // pull or clone target branch
.then(() => any(gitRepos.map((repo) => performPullAll({repo}))) )
.then(() => any(gitRepos.map((repo) => performPullAll(repo))) )
// switch to source branch // switch to source branch
.then( () => { .then( () => {
if(mergesource) return any(gitRepos.map((repo) => performCheckout({ repo, branch: mergesource})))
if(mergesource) return any(gitRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch: mergesource})))
else return Promise.resolve(true) // Dont do anything if there is no source to merge from. else return Promise.resolve(true) // Dont do anything if there is no source to merge from.
}) })
//Pull on merge source branch //Pull on merge source branch
.then( () => { .then( () => {
if(!mergesource) return Promise.resolve(true) if(!mergesource) return Promise.resolve(true)
return any(gitRepos.map((repo) => performPullAll({repo})))
return any(gitRepos.map((repo) => performPullAll(repo)))
}) })
//Switch to target branch //Switch to target branch
.then( () => { .then( () => {
if(!mergesource) return Promise.resolve(true) if(!mergesource) return Promise.resolve(true)
return any(elevatedRunasRepos.map((repo) => performCheckout({ repo, branch})))
return any(elevatedRunasRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch})))
}) })
.then( //Merge source branch to target branch .then( //Merge source branch to target branch
() => { () => {
if(!mergesource) return Promise.resolve(true) if(!mergesource) return Promise.resolve(true)
return any(gitRepos.map((repo) => performMerge({ repo }))).catch(err => { console.error('error in performMerge ' + err); })
return any(gitRepos.map((repo) => performMerge( repo ))).catch(err => { console.error('error in performMerge ' + err); })
}) })
}) })
} }
} }
return any(tasks).then(()=>{ return any(tasks).then(()=>{
return any(elevatedRunasRepos.map((repo) => performCheckout({ repo, branch, requiresElevation : true})))
return any(elevatedRunasRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch, requiresElevation : true})))
// pull or clone target branch // pull or clone target branch
.then( () => any(elevatedRunasRepos.map((repo) => performPullAll({repo}))) )
.then( () => any(elevatedRunasRepos.map((repo) => performPullAll(repo))) )
// switch to source branch // switch to source branch
.then( () => { .then( () => {
if(mergesource) return any(elevatedRunasRepos.map((repo) => performCheckout({ repo, branch: mergesource, requiresElevation : true})))
if(mergesource) return any(elevatedRunasRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch: mergesource, requiresElevation : true})))
else return Promise.resolve(true) // Dont do anything if there is no source to merge from. else return Promise.resolve(true) // Dont do anything if there is no source to merge from.
}) })
//Pull on merge source branch //Pull on merge source branch
.then( () => { .then( () => {
if(!mergesource) return Promise.resolve(true) if(!mergesource) return Promise.resolve(true)
return any(elevatedRunasRepos.map((repo) => performPullAll({repo, requiresElevation : true })))
return any(elevatedRunasRepos.map((repodef) => performPullAll({repo : repodef.repo, requiresElevation : true })))
}) })
//Switch to target branch //Switch to target branch
.then( () => { .then( () => {
if(!mergesource) return Promise.resolve(true) if(!mergesource) return Promise.resolve(true)
return any(elevatedRunasRepos.map((repo) => performCheckout({ repo, branch, requiresElevation : true})))
return any(elevatedRunasRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch, requiresElevation : true})))
}) })
.then( //Merge source branch to target branch .then( //Merge source branch to target branch
() => { () => {
if(!mergesource) return Promise.resolve(true) if(!mergesource) return Promise.resolve(true)
return any(elevatedRunasRepos.map((repo) => performMerge({ repo, requiresElevation : true }))).catch(err => { console.error('error in performMerge ' + err); })
return any(elevatedRunasRepos.map((repodef) => performMerge({ repo : repodef.repo, requiresElevation : true }))).catch(err => { console.error('error in performMerge ' + err); })
}) })
.then(() => { .then(() => {
fs.writeFileSync('run.done', 'success'); fs.writeFileSync('run.done', 'success');
} }
, getpulltask(def){ , getpulltask(def){


def = def || {
requiresElevation : true,
reqularRepos : gitRepos,
elevatedRepos : elevatedRunasRepos
};
console.log(`-------------------Processing pull for : ${def.repo} ${def.branch}`); console.log(`-------------------Processing pull for : ${def.repo} ${def.branch}`);
console.dir(def); console.dir(def);


var steps = [ var steps = [
() => { () => {
if (!existsSync(downloadsdir + '/' + this.installer)) { if (!existsSync(downloadsdir + '/' + this.installer)) {
return nodeShellExec('download.bat', [this.url, downloadsdir + '/' + this.installer])
return nodeShellExec('.run/download.bat', [this.url, downloadsdir + '/' + this.installer])
} }
else return Promise.resolve(true) else return Promise.resolve(true)
} }
var mainTasks = []; var mainTasks = [];
function verifyAndInstallPrerequisites() { function verifyAndInstallPrerequisites() {
fs.writeFileSync(ensureDirectoryExistence(path__default['default'].normalize(downloadsdir + '/readme.txt')), `${getVersion()} Your local downloads for this instance`); fs.writeFileSync(ensureDirectoryExistence(path__default['default'].normalize(downloadsdir + '/readme.txt')), `${getVersion()} Your local downloads for this instance`);
// PB : TODO -- Keep only the last n runs...
ensureDirectoryExistence('.run/download.bat');

// PB : TODO include and build from files... using rollup..
var downloadbatch = var downloadbatch =
`::************************************************************************** `::**************************************************************************
:Download_ <url> <File> :Download_ <url> <File>
(New-Object System.Net.WebClient).DownloadFile('%1','%2') (New-Object System.Net.WebClient).DownloadFile('%1','%2')
exit /b exit /b
::**************************************************************************`; ::**************************************************************************`;
fs.writeFileSync('download.bat', downloadbatch);
fs.writeFileSync('.run/download.bat', downloadbatch);

var windowselevate =
`
<html><HTA:APPLICATION ID="windowselevate" icon="#"/>
<script language="vbscript">
document.title = "elxr control panel"
self.ResizeTo 200,600
Sub Window_Onload
self.MoveTo (screen.availWidth - (document.body.clientWidth + 40)),10
End Sub

Set objShell = CreateObject("WScript.Shell")
Set objENV = objShell.Environment("Process")
dim NODE_ENV
NODE_ENV = objENV("NODE_ENV")
</script>

<script language="javascript">
//WINDOWSTATE="minimize" SHOWINTASKBAR="no" SYSMENU="no" CAPTION="no"
// https://devblogs.microsoft.com/scripting/how-can-i-pass-command-line-variables-to-an-hta-when-it-starts/
// alert(windowselevate.commandLine)
var args = windowselevate.commandLine.split('"').slice(3);
// alert(args)
var processedArgs = { _ : [] }
var namedArgs = [];
for(var item in args){
if(args[item].charAt(0) === '-'){
namedArgs.push(args[item])
var split = args[item].split('=');
processedArgs[split[0].slice(2)] = split[1] || true;
}
else processedArgs._.push(args[item]);
}
// args = args.forEach(function(item){ })
// alert('processedArgs._ : ' + processedArgs._);
// alert(processedArgs.runas);
// PB : TODO -- Convert all the cli args back to string.
var cargs = (processedArgs.debug ? '--inspect-brk=9228' : '') + ' elxr ' + processedArgs._.join(' ') + ' ' + namedArgs.join(' ');
// alert(cargs)
var shell = new ActiveXObject('shell.application');
// alert('launching node privilged. ' + processedArgs['nodepath'])
// shell.ShellExecute('where', 'node', '', '', 10);
shell.ShellExecute('node', cargs, '', 'runas', 1);
// shell.ShellExecute(processedArgs['nodepath'], cargs, '', 'runas', 1);
var fso = new ActiveXObject('Scripting.FileSystemObject');
window.onload = function() {
document.body.style.backgroundColor = 'black';
document.body.style.fontFamily = 'arial';
var log = document.createElement('div');
log.innerHTML='Please Wait';
function l(msg){ log.innerHTML+= msg; };
log.style.color = 'blue';
log.style.width = '95%';
log.id = 'log';
document.body.appendChild(log);
l('<Br/>Current config : ')
l('<Br/>NODE_ENV = ' + NODE_ENV)
l('<Br/>cmd = ' + processedArgs._[0])
processedArgs._[1] === 'use' ? l('<Br/>using = ' + processedArgs._[2]) : null;
l('<Br/><Br/>')
var timer = function(){
l('.');
if(fso.FileExists("run.done")) close();
else window.setTimeout(timer, 1000);
};
window.setTimeout(timer, 3000);
};
</script>
</html>
`;
fs.writeFileSync('.run/windowselevate.hta', windowselevate);


var downloadtasks = []; var downloadtasks = [];
var installtasks = []; var installtasks = [];
prerequisites.forEach(preq => { prerequisites.forEach(preq => {
// "current_run": { "instanceName": "elixir", "node_env": "production" } // "current_run": { "instanceName": "elixir", "node_env": "production" }
// } // }


// ,([^\}^\S\r]*?\}) // Regexp to eliminate extra comma at the end of an array or an object...

var elxr_1 = { var elxr_1 = {


}; };

+ 111
- 23
index.js View File

console.log('result : ' + JSON.stringify(r)) console.log('result : ' + JSON.stringify(r))
Object.keys(processedArgs).forEach((v) => { v != '_' ? namedArgs.push('--' + v + '=' + processedArgs[v]) : null; }) Object.keys(processedArgs).forEach((v) => { v != '_' ? namedArgs.push('--' + v + '=' + processedArgs[v]) : null; })
// PB : TODO -- Convert all the cli args back to string. // PB : TODO -- Convert all the cli args back to string.
var args = [__dirname + '/windowselevate.hta'].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self');
var args = [__dirname + '/.run/windowselevate.hta'].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self');
args.push('--nodepath=' + r[r.length - 1]) args.push('--nodepath=' + r[r.length - 1])
if (!processedArgs.node_env) args.push('--node_env=' + ENV.NODE_ENV) if (!processedArgs.node_env) args.push('--node_env=' + ENV.NODE_ENV)
if (processedArgs.debug) args.push('--debug=true') // Enable to debug elevated.. if (processedArgs.debug) args.push('--debug=true') // Enable to debug elevated..


if (!processedArgs.runas) gitRepos.map((def) => performPull(def.repo, def.branch || 'master')) if (!processedArgs.runas) gitRepos.map((def) => performPull(def.repo, def.branch || 'master'))
if (__isElevated) { if (__isElevated) {
return any(elevatedRunasRepos.map((repo) => performPull(def.repo, def.branch || 'master'))).then(() => {
return any(elevatedRunasRepos.map((def) => performPull(def.repo, def.branch || 'master'))).then(() => {
fs.writeFileSync('run.done', 'success') fs.writeFileSync('run.done', 'success')
}).catch(() => { }).catch(() => {
fs.writeFileSync('run.done', 'error') fs.writeFileSync('run.done', 'error')
var repotasks = [] var repotasks = []
var env = Object.assign({}, process.env) var env = Object.assign({}, process.env)
delete env.NODE_ENV delete env.NODE_ENV
gitRepos.forEach(repo => {
gitRepos.forEach(repodef => {


rmtasks.push( rmtasks.push(
// () => { // () => {
// console.log(`--rm package-lock.json for ${repo}--------------------`)
// console.log(`--rm package-lock.json for ${repodef.repo}--------------------`)
// return nodeShellExec(`"${gitbash}"`, ['-c', '"rm package-lock.json"'], { // return nodeShellExec(`"${gitbash}"`, ['-c', '"rm package-lock.json"'], {
nodeShellExec('rm', ['package-lock.json'], { nodeShellExec('rm', ['package-lock.json'], {
inherit: true, shell: true inherit: true, shell: true
, cwd: instanceroot + '/' + repo
, cwd: instanceroot + '/' + repodef.repo
, env: process.env , env: process.env
, title: `rm 'package-lock.json' for ${repo}`
, title: `rm 'package-lock.json' for ${repodef.repo}`
}) })
.then(()=>{ .then(()=>{
console.log(`--rm package-lock.json for ${repo}--------------------`)
console.log(`--rm package-lock.json for ${repodef.repo}--------------------`)
}).catch((e) => { console.error(e) }) }).catch((e) => { console.error(e) })
// } // }
) )


if (npmbuildrepos.indexOf(repo) < 0) {
if (npmbuildrepos.indexOf(repodef.repo) < 0) {
repotasks.push( repotasks.push(
() => { () => {
console.log(`--npm i for ${repo}--------------------`)
console.log(`--npm i for ${repodef.repo}--------------------`)
var p = nodeShellExec('npm', ['i', '--force'], { var p = nodeShellExec('npm', ['i', '--force'], {
inherit: true, shell: true inherit: true, shell: true
, cwd: instanceroot + '/' + repo
, cwd: instanceroot + '/' + repodef.repo
, env , env
, title: `npm i for ${repo}`
, title: `npm i for ${repodef.repo}`
}).then(Tasq.then).catch(Tasq.catch) }).then(Tasq.then).catch(Tasq.catch)
return p; return p;
}) })
// }).then(Tasq.then).catch(Tasq.catch) // }).then(Tasq.then).catch(Tasq.catch)
// }) // })


var bowerRepos = ['client']
bowerRepos.forEach(repo => {
var bowerRepos = [{ repo : 'client'}]
bowerRepos.forEach(repodef => {
repotasks.push(() => { repotasks.push(() => {
console.log(instanceroot + '/' + repo + '/node_modules/bower/bin/bower')
console.log(instanceroot + '/' + repodef.repo + '/node_modules/bower/bin/bower')
// var p = nodeShellExec('node_modules/bower/bin/bower', ['install'], { // var p = nodeShellExec('node_modules/bower/bin/bower', ['install'], {
var p = nodeShellExec(`"${gitbash}"`, ['-c', '"node_modules/bower/bin/bower i"'], { var p = nodeShellExec(`"${gitbash}"`, ['-c', '"node_modules/bower/bin/bower i"'], {


inherit: true, shell: true inherit: true, shell: true
, cwd: instanceroot + '/' + repo
, cwd: instanceroot + '/' + repodef.repo
, env: process.env , env: process.env
, title: `bower i for ${repo}`
, title: `bower i for ${repodef.repo}`
}).then(Tasq.then).catch(Tasq.catch) }).then(Tasq.then).catch(Tasq.catch)
return p; return p;
}) })
*/ */
var runconfig = { NODE_ENV: repomanifest.node_env } var runconfig = { NODE_ENV: repomanifest.node_env }
try { runconfig = Object.assign(runconfig, require(instanceroot + '/run.js')) } catch (e) { } try { runconfig = Object.assign(runconfig, require(instanceroot + '/run.js')) } catch (e) { }
if ((!processedArgs.runas || processedArgs.runas !== 'self' && !processedArgs.force) &&
// We no longer need to check ruans.. ??? if we were initiated from self invoked privileged shell ?
if (( /*processedArgs.runas && processedArgs.runas !== 'self' &&*/ !processedArgs.force) &&
runconfig.NODE_ENV && runconfig.NODE_ENV === (repomanifest.node_env || runconfig.NODE_ENV) && runconfig.NODE_ENV && runconfig.NODE_ENV === (repomanifest.node_env || runconfig.NODE_ENV) &&
repomanifest.instanceName && runconfig.use === repomanifest.instanceName) { repomanifest.instanceName && runconfig.use === repomanifest.instanceName) {




// cant use git checkout -b it fails when branch already exists. // cant use git checkout -b it fails when branch already exists.
var performCheckout = (def) => { var performCheckout = (def) => {
if (excludeCheckouts[repo]) return Promise.resolve({ 'skipped': true })
if (excludeCheckouts[def.repo]) return Promise.resolve({ 'skipped': true })
return performPullOrCloneForBranch(def)().then(()=>{
return performPullOrCloneForBranch(def).then(()=>{
nodeShellExec('git', ['checkout', def.branch || checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], { nodeShellExec('git', ['checkout', def.branch || checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], {
// return nodeShellExec('git', ['switch', '-m', '-C', checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], { // return nodeShellExec('git', ['switch', '-m', '-C', checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], {
// inherit : true, shell: true, // inherit : true, shell: true,


//target is the env is we specify in elxr use command. Default is dev //target is the env is we specify in elxr use command. Default is dev
//Switch to target branch //Switch to target branch
return any(gitRepos.map((repodef) => performCheckout({ repo : repodef.repo, branch})))
return any(gitRepos.map((repodef) => { return performCheckout({ repo : repodef.repo, branch}).catch(e=>{ console.log(e); }) } ))
// pull or clone target branch // pull or clone target branch
.then(() => any(gitRepos.map((repo) => performPullAll(repo))) ) .then(() => any(gitRepos.map((repo) => performPullAll(repo))) )
// switch to source branch // switch to source branch
var steps = [ var steps = [
() => { () => {
if (!existsSync(downloadsdir + '/' + this.installer)) { if (!existsSync(downloadsdir + '/' + this.installer)) {
return nodeShellExec('download.bat', [this.url, downloadsdir + '/' + this.installer])
return nodeShellExec('.run/download.bat', [this.url, downloadsdir + '/' + this.installer])
} }
else return Promise.resolve(true) else return Promise.resolve(true)
} }
var mainTasks = []; var mainTasks = [];
function verifyAndInstallPrerequisites() { function verifyAndInstallPrerequisites() {
fs.writeFileSync(ensureDirectoryExistence(path.normalize(downloadsdir + '/readme.txt')), `${getVersion()} Your local downloads for this instance`) fs.writeFileSync(ensureDirectoryExistence(path.normalize(downloadsdir + '/readme.txt')), `${getVersion()} Your local downloads for this instance`)
// PB : TODO -- Keep only the last n runs...
ensureDirectoryExistence('.run/download.bat')

// PB : TODO include and build from files... using rollup..
var downloadbatch = var downloadbatch =
`::************************************************************************** `::**************************************************************************
:Download_ <url> <File> :Download_ <url> <File>
(New-Object System.Net.WebClient).DownloadFile('%1','%2') (New-Object System.Net.WebClient).DownloadFile('%1','%2')
exit /b exit /b
::**************************************************************************` ::**************************************************************************`
fs.writeFileSync('download.bat', downloadbatch)
fs.writeFileSync('.run/download.bat', downloadbatch)

var windowselevate =
`
<html><HTA:APPLICATION ID="windowselevate" icon="#"/>
<script language="vbscript">
document.title = "elxr control panel"
self.ResizeTo 200,600
Sub Window_Onload
self.MoveTo (screen.availWidth - (document.body.clientWidth + 40)),10
End Sub

Set objShell = CreateObject("WScript.Shell")
Set objENV = objShell.Environment("Process")
dim NODE_ENV
NODE_ENV = objENV("NODE_ENV")
</script>

<script language="javascript">
//WINDOWSTATE="minimize" SHOWINTASKBAR="no" SYSMENU="no" CAPTION="no"
// https://devblogs.microsoft.com/scripting/how-can-i-pass-command-line-variables-to-an-hta-when-it-starts/
// alert(windowselevate.commandLine)
var args = windowselevate.commandLine.split('"').slice(3);
// alert(args)
var processedArgs = { _ : [] }
var namedArgs = [];
for(var item in args){
if(args[item].charAt(0) === '-'){
namedArgs.push(args[item])
var split = args[item].split('=');
processedArgs[split[0].slice(2)] = split[1] || true;
}
else processedArgs._.push(args[item]);
}
// args = args.forEach(function(item){ })
// alert('processedArgs._ : ' + processedArgs._);
// alert(processedArgs.runas);
// PB : TODO -- Convert all the cli args back to string.
var cargs = (processedArgs.debug ? '--inspect-brk=9228' : '') + ' elxr ' + processedArgs._.join(' ') + ' ' + namedArgs.join(' ');
// alert(cargs)
var shell = new ActiveXObject('shell.application');
// alert('launching node privilged. ' + processedArgs['nodepath'])
// shell.ShellExecute('where', 'node', '', '', 10);
shell.ShellExecute('node', cargs, '', 'runas', 1);
// shell.ShellExecute(processedArgs['nodepath'], cargs, '', 'runas', 1);
var fso = new ActiveXObject('Scripting.FileSystemObject');
window.onload = function() {
document.body.style.backgroundColor = 'black';
document.body.style.fontFamily = 'arial';
var log = document.createElement('div');
log.innerHTML='Please Wait';
function l(msg){ log.innerHTML+= msg; };
log.style.color = 'blue';
log.style.width = '95%';
log.id = 'log';
document.body.appendChild(log);
l('<Br/>Current config : ')
l('<Br/>NODE_ENV = ' + NODE_ENV)
l('<Br/>cmd = ' + processedArgs._[0])
processedArgs._[1] === 'use' ? l('<Br/>using = ' + processedArgs._[2]) : null;
l('<Br/><Br/>')
var timer = function(){
l('.');
if(fso.FileExists("run.done")) close();
else window.setTimeout(timer, 1000);
};
window.setTimeout(timer, 3000);
};
</script>
</html>
`
fs.writeFileSync('.run/windowselevate.hta', windowselevate)


var downloadtasks = []; var downloadtasks = [];
var installtasks = []; var installtasks = [];
prerequisites.forEach(preq => { prerequisites.forEach(preq => {
// } // }
// }, // },
// "current_run": { "instanceName": "elixir", "node_env": "production" } // "current_run": { "instanceName": "elixir", "node_env": "production" }
// }
// }

// ,([^\}^\S\r]*?\}) // Regexp to eliminate extra comma at the end of an array or an object...

Loading…
Cancel
Save