pb пре 2 година
родитељ
комит
87d54b25de
3 измењених фајлова са 220 додато и 94 уклоњено
  1. 1
    0
      9e7bebe0-1f57-11ec-8f88-778ffeea9d1b.js
  2. 214
    92
      i.win.js
  3. 5
    2
      readme.md

+ 1
- 0
9e7bebe0-1f57-11ec-8f88-778ffeea9d1b.js Прегледај датотеку

@@ -0,0 +1 @@
9e7bebe0-1f57-11ec-8f88-778ffeea9d1b

+ 214
- 92
i.win.js Прегледај датотеку

@@ -1,4 +1,3 @@

var scripthostName = 'node'
var __Promise = {};
var promises = [];
@@ -41,7 +40,12 @@ try {
// --------------------------------------------
// Node Exists. Lets launch ourselves in Node itself
WScript = function(){}
WScript.Echo = function(m){
console.log('Invalid Wscript')
throw "Failed in Node Run."
}
var wait = function(ms, cb) {any
return new __Promise(function(resolve){ setTimeout(resolve, ms) } ).then(function(){ cb() });
}
@@ -49,13 +53,15 @@ try {
var existsSync = require('fs').existsSync;
var existsSyncFolder = existsSync
var path = require('path');
console.log('before cliverse')
var cli = require('./cliverse')
var nodeShellExec = cli.nodeShellExec;
console.log('before bbhverse')
var utils = require('bbhverse');
var any = utils.any;
var wait = setTimeout


var any = utils.any;
var wait = setTimeout

// --------------------------------------------

@@ -97,7 +103,59 @@ catch(e) {

// cscript elxr/i.win.js /all:true
var all = WScript.Arguments.Named('all');

trim = function(str) { return str.replace(/^\s+|\s+$/g, ''); };

var fs = new ActiveXObject('Scripting.FileSystemObject');
var WshShell = WScript.CreateObject("WScript.Shell")
var ENV = WshShell.Environment("Process")
var sfn = WScript.ScriptFullName
// WScript.Echo(sfn)
var cd = fs.GetAbsolutePathName(".")
var cfn = cd + '\\i.win.js'
// WScript.Echo(cfn)
var waslaunchedwithenv = trim(ENV.Item('LAUNCHEDWITHENV'));

// for(e=new Enumerator(ENV); !e.atEnd(); e.moveNext()) WScript.echo(e.item(e));
if(waslaunchedwithenv !== "YES"){

var a = fs.CreateTextFile("launchwithenv.bat", true)
a.WriteLine("@echo off")
a.WriteLine("echo %PATH%")
var gitpath = "C:\\Program Files\\Git\\cmd"
var nodepath = "C:\\Program Files\\nodejs\\"
var codepath = "C:\\Users\\Pradeep\\AppData\\Local\\Programs\\Microsoft VS Code\\bin"
a.WriteLine("set PATH=%PATH%;" + gitpath )
a.WriteLine("set PATH=%PATH%;" + nodepath )
a.WriteLine("set PATH=%PATH%;" + codepath )
// a.WriteLine("set LAUNCHEDWITHENV=YES" )
var __ALIAS__STAMP__ = '9e7bebe0-1f57-11ec-8f88-778ffeea9d1b'
var currentIsExlr = function() {
if(fs.FileExists('./' + __ALIAS__STAMP__)) return true
}
var runningInExlr = currentIsExlr()
if(cfn === sfn && runningInExlr) {
a.WriteLine("cd ..");
a.WriteLine("SET LAUNCHEDWITHENV=YES && cscript "+cfn+" /all:true") // PB : TODO -- Retain all script args...
}
else {
var guesselxr = fs.FileExists(cd + './elxr/' + __ALIAS__STAMP__)
if(guesselxr) {
a.WriteLine("SET LAUNCHEDWITHENV=YES && cscript "+cd + './elxr/' + 'i.win.js' +" /all:true")
}
else a.WriteLine("SET LAUNCHEDWITHENV=YES && cscript "+sfn+" /all:true")
}
// a.WriteLine("powershell.exe ^")
// a.WriteLine("[Environment]::GetEnvironmentVariable('Path')" )
a.Close()
WshShell.run("cmd /k launchwithenv.bat")
WScript.Quit()
// WshShell.run("powershell -noexit [Environment]::GetEnvironmentVariable(\"\"Path\"\"\) ")
// WshShell.run("powershell -noexit [Environment]::SetEnvironmentVariable(\"\"Path\"\", $env:Path + \"\";C:\\tttt\"\", \"\"Machine\"\"\) ")
}
console = {
log : function(m) { WScript.Echo(m)}
, error : function(m) {WScript.Echo(m) }
@@ -328,9 +386,18 @@ catch(e) {
// promises.splice(0,1)
})
}
function batchshellescape(str) {
return str.replace('=', '^=')
}
function nodeShellExec(command, cargs, options){
// for(var arg=0; arg < cargs.length; arg++) {
// // cargs[arg] = '"' + batchshellescape(cargs[arg]) +'"';
// cargs[arg] = '"' + cargs[arg] +'"';
// }

var elevatedshellexecute = function(cmd, argstr){
shell.ShellExecute(cmd, argstr , "", "", 1);
}
@@ -339,6 +406,7 @@ catch(e) {
var objShell = WScript.createobject("wscript.shell")
// console.log(argstr.join( ' '))
console.log(cmd + ' ' + argstr.join(' '))
var oExec = objShell.Exec(cmd + ' ' + argstr.join(' '))
var result = {}
var shellresult = { shell : objShell, result : result }
@@ -473,7 +541,7 @@ catch(e) {
// }
// else {
// console.log('There is no runfile.')
// console.log(shellresult.strOutput)
console.log(shellresult.strOutput)
wrapup(shellresult.result)
// }
@@ -793,8 +861,7 @@ function __main( selectedinstance ){

var callsheltask = function(args) {
// console.log('callsheltask : ' + args)
return function() {
return nodeShellExec.apply(null, args) } }
return function() { return nodeShellExec.apply(null, args) } }
var gitUser = 'guest';
var gitEmail = 'guest@bbh.org.in';

@@ -853,7 +920,7 @@ function __main( selectedinstance ){
WScript.Echo(all)
if(!all && preq.optional) return
var p = preq.exists().then(function(exists) {
if (exists) console.log( preq.shellcmd + ' exists');
if (exists && !preq.forceinstall) console.log( preq.shellcmd + ' exists');
else {
console.log(exists)
console.log(preq.shellcmd + ' is not installed');
@@ -909,6 +976,21 @@ function __main( selectedinstance ){
})
}

function install() {
var self = this;
var ifns = [self.installcmd]
if(!ifns.map) ifns.map = map;
console.log('Installing')
return any(ifns.map(callsheltask))['catch'](function(e){
if(e.code === 1602) {
console.warn("Installation was probably cancelled.")
}
else throw e
}).then(function(){
return self.postinstallsteps && self.postinstallsteps()
})
}

function unique(arr) {
var hash = {}, result = [];
for ( var i = 0, l = arr.length; i < l; ++i ) {
@@ -921,8 +1003,6 @@ function __main( selectedinstance ){
}

// var ENV = Object.assign({}, process.env); // Shallow clone it.
var WshShell = WScript.CreateObject("WScript.Shell")
var ENV = WshShell.Environment("Process")
// WScript.echo( ENV("Path") )
function sysAddPathVar(path){

@@ -1173,18 +1253,7 @@ function __main( selectedinstance ){
, installcmd: ['MSIEXEC.exe', ['/i'
, path.normalize(downloadsdir + '/' + 'node-v14.17.3-x64.msi')
, 'ACCEPT=YES', '/passive']]
, install : function() {
var self = this;
var ifns = [self.installcmd]
if(!ifns.map) ifns.map = map;
return any(ifns.map(callsheltask))['catch'](function(e){
if(e.code === 1602) {
console.warn("Installation was probably cancelled.")
}
else throw e
})
}
, install : install
, exists : exists
, preinstallsteps: function() {
var self = this;
@@ -1194,8 +1263,8 @@ function __main( selectedinstance ){
steps.push(
function(){
if (!existsSync(downloadsdir + '/' + self.installer)) {
return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', [self.url, downloadsdir + '/' + self.installer]
, { waitmsg : 'downloading node please wait' })
return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', ['"' + self.url + '"', downloadsdir + '/' + self.installer]
, { waitmsg : 'downloading '+ self.shellcmd +' please wait' })
}
else {
console.log(self.installer + ' Already exits Download skipped.')
@@ -1209,78 +1278,115 @@ function __main( selectedinstance ){
}
}
, {
shellcmd: 'python2'
shellcmd: 'python'
, optional : true
, url: 'https://www.python.org/ftp/python/2.7.18/python-2.7.18.amd64.msi'
, installer: 'python-2.7.18.amd64.msi'
, installcmd: ['MSIEXEC.exe', ['/i'
, path.normalize(downloadsdir + '/' + 'python-2.7.18.amd64.msi')
, 'ACCEPT=YES', '/passive']]
, preinstallsteps : function() { return Promise.resolve(true) }
, install : function() {
var self = this;
var ifns = [self.installcmd]
if(!ifns.map) ifns.map = map;
console.log('Installing')
return any(ifns.map(callsheltask))['catch'](function(e){
if(e.code === 1602) {
console.warn("Installation was probably cancelled.")
, preinstallsteps: function() {
var self = this;
console.log(self.shellcmd + ' preinstall steps')

var steps = [];
steps.push(
function(){
if (!existsSync(downloadsdir + '/' + self.installer)) {
return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', [self.url, downloadsdir + '/' + self.installer]
, { waitmsg : 'downloading '+ self.shellcmd +' please wait' })
}
else throw e
}).then(function(){
return self.postinstallsteps()
})
}
, postinstallsteps : function() { return sysAddPathVar('%USERPROFILE%\\AppData/Local\\Microsoft\\WindowsApps') }
, exists : exists
else {
console.log(self.installer + ' Already exits Download skipped.')
return Promise.resolve(true)
}
}
)
return any(steps)
// return any([any(steps), any(prompts)])
}
, install : install
, postinstallsteps : function() { return sysAddPathVar('%USERPROFILE%\\AppData/Local\\Microsoft\\WindowsApps') }
, exists : exists
}
, {
shellcmd: 'code'
, optional : true
, url: 'https://code.visualstudio.com/sha/download?build=stable&os=win32-x64-user'
, installer: 'VSCodeUserSetup-x64-1.65.2.exe'
, installcmd: ['cmd', ['/c', 'start',
'/WAIT', downloadsdir + '/' + 'VSCodeUserSetup-x64-1.65.2.exe'
, '/VERYSILENT'
, installcmd: ['cmd /c', ['start /WAIT ' + downloadsdir + '/' + 'VSCodeUserSetup-x64-1.65.2.exe /VERYSILENT'
// , '/MERGETASKS=!runcode' // This is required only for vscode...
]]
, preinstallsteps : function() { return Promise.resolve(true) }
, install : function() {
var self = this;
var ifns = [self.installcmd]
if(!ifns.map) ifns.map = map;
console.log('Installing')
return any(ifns.map(callsheltask))['catch'](function(e){
if(e.code === 1602) {
console.warn("Installation was probably cancelled.")
, preinstallsteps: function() {
var self = this;
console.log(self.shellcmd + ' preinstall steps')

var steps = [];
steps.push(
function(){
if (!existsSync(downloadsdir + '/' + self.installer)) {
console.log(self.url)
return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', ['"' + self.url + '"', downloadsdir + '/' + self.installer]
, { waitmsg : 'downloading '+ self.shellcmd +' please wait' })
}
else {
console.log(self.installer + ' Already exits Download skipped.')
return Promise.resolve(true)
}
}
else throw e
}).then(function(){
return self.postinstallsteps()
})
)
return any(steps)
// return any([any(steps), any(prompts)])
}
, install : install
, postinstallsteps : function() { return sysAddPathVar('%USERPROFILE%\\AppData/Local\\Microsoft\\WindowsApps') }
, exists : exists
}
, {
shellcmd: 'mysql',
url: 'https://dev.mysql.com/get/Downloads/MySQLInstaller/mysql-installer-community-8.0.29.0.msi'
, installer: 'mysql-installer-community-8.0.29.0.msi'
, installcmd: ['MSIEXEC.exe', ['/i'
, path.normalize(downloadsdir + '/' + 'mysql-installer-community-8.0.29.0.msi')
, 'ACCEPT=YES', '/passive']]
, install : function() {
var self = this;
var ifns = [self.installcmd]
if(!ifns.map) ifns.map = map;
return any(ifns.map(callsheltask))['catch'](function(e){
if(e.code === 1602) {
console.warn("Installation was probably cancelled.")
shellcmd: 'Ssms.exe',
url: 'https://go.microsoft.com/fwlink/?linkid=2043154&clcid=0x409'
, installer: 'SSMS-Setup-ENU.exe'
, installcmd: ['cmd', ['/c', 'start',
'/WAIT', downloadsdir + '/' + 'SSMS-Setup-ENU.exe'
, '/Quiet'
//, 'SSMSInstallRoot=%systemdrive%\\Program Files (x86)\\Microsoft SQL Server\\140\\Tools\\Binn\\ManagementStudio'
]]
, install : install
, exists : exists
, preinstallsteps: function() {
var self = this;
console.log('smss preinstall steps')

var steps = [];
steps.push(
function(){
if (!existsSync(downloadsdir + '/' + self.installer)) {
console.log(self.url)
return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', ['"' + self.url + '"', downloadsdir + '/' + self.installer]
, { waitmsg : 'downloading '+ self.shellcmd +' please wait' })
}
else {
console.log(self.installer + ' Already exits Download skipped.')
return Promise.resolve(true)
}
}
else throw e
})
)
return any(steps)
// return any([any(steps), any(prompts)])
}
}
, {
shellcmd: 'mysql',
url: 'https://dev.mysql.com/get/Downloads/MySQLInstaller/mysql-installer-community-8.0.30.0.msi' //'https://dev.mysql.com/get/Downloads/MySQLInstaller/mysql-installer-community-8.0.29.0.msi'
, installer: 'mysql-installer-community-8.0.30.0.msi'
, installcmd: ['MSIEXEC.exe', ['/i'
, path.normalize(downloadsdir + '/' + 'mysql-installer-community-8.0.30.0.msi')
//, 'ACCEPT=YES', '/passive'
]]
, install : install
, exists : exists
, preinstallsteps: function() {
var self = this;
@@ -1290,8 +1396,9 @@ function __main( selectedinstance ){
steps.push(
function(){
if (!existsSync(downloadsdir + '/' + self.installer)) {
console.log(self.url)
return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', [self.url, downloadsdir + '/' + self.installer]
, { waitmsg : 'downloading mysql please wait' })
, { waitmsg : 'downloading '+ self.shellcmd +' please wait' })
}
else {
console.log(self.installer + ' Already exits Download skipped.')
@@ -1306,6 +1413,7 @@ function __main( selectedinstance ){
}
, {
shellcmd: 'elxr'
, forceinstall : true
, installcmd: [ isWin() ? 'npm.cmd' : 'npm' , ['link'], { cwd : selectedinstance.root + '\\elxr' /* cwd should be the cloned dir*/}]
, preinstallsteps: function() {
var self = this;
@@ -1322,23 +1430,37 @@ function __main( selectedinstance ){
console.log('Elxr Installsteps called')
var installIfNotExists = function(){
console.log('Elxr PreInstallsteps called')
var ifns = [ ['git', ['clone', 'http://git.bbh/chess/elxr'] ] ]
if(existsSyncFolder( selectedinstance.root + '\\elxr')) {
if(existsSyncFolder( selectedinstance.root + '\\elxr\\.git')) {
// PB : TODO -- use a elxr guid signature to detect more reliably folders named the same that is not us.
ifns = [ ['git', ['pull'], { cwd : selectedinstance.root + '\\elxr' } ] ]
}
else {
throw 'elxr subfolder not recognized as a git repository. Please cleanup and continue.'
var steps = [];
var chessRepo = 'https://git.bbh.org.in'
steps.push(
function(){
// console.log('cli prompt steps')
var choices = { 0 : 'http://git.bbh', 1 : 'https://git.bbh.org.in' }
return cli.prompt(choices, 'git repository : ', chessRepo).then(function(choice){ chessRepo = choice } )
}
}
else console.log(selectedinstance.root + '\\elxr' + ' NOT FOUND ')
if(!ifns.map) ifns.map = map;
return any(ifns.map(callsheltask))['catch'](function(e){
if(e.code === 1602) {
console.warn("Installation was probably cancelled.")
)
return any(steps).then(function(chessRepo){
var ifns = [
['git', ['clone', chessRepo + '/chess/elxr'] ]
]
if(existsSyncFolder( selectedinstance.root + '\\elxr')) {
if(existsSyncFolder( selectedinstance.root + '\\elxr\\.git')) {
// PB : TODO -- use a elxr guid signature to detect more reliably folders named the same that is not us.
ifns = [ ['git', ['pull'], { cwd : selectedinstance.root + '\\elxr' } ] ]
}
else {
throw 'elxr subfolder not recognized as a git repository. Please cleanup and continue.'
}
}
else throw e
else console.log(selectedinstance.root + '\\elxr' + ' NOT FOUND ')
ifns.push(['npm', ['i'], { cwd : '.\\elxr' } ])
if(!ifns.map) ifns.map = map;
return any(ifns.map(callsheltask))['catch'](function(e){
if(e.code === 1602) {
console.warn("Installation was probably cancelled.")
}
else throw e
})
})
}
var ifns = [ self.installcmd ]
@@ -1355,8 +1477,8 @@ function __main( selectedinstance ){
, install: function () {
var self = this;
console.log('Elxr Install called')
return any([ /*self.preinstallsteps,*/ function(){ return self.installsteps() }
, nodeShellExec('node', [selectedinstance.root + '\\elxr\\index.js', 'init'])
return any([ self.preinstallsteps, function(){ return self.installsteps() }
, nodeShellExec('start', ['""', '"C:\\Program Files\\Git\\bin\\sh.exe"', '-c', '"node ' + (selectedinstance.root + '\\elxr\\index.js').replace(/\\/g, '/') + ' i elixir"'])
// , nodeShellExec('node', [selectedinstance.root + 'elxr\\index.js'])
])
}

+ 5
- 2
readme.md Прегледај датотеку

@@ -51,9 +51,12 @@ elxr npm i

# Installing Elixir in Windows

1) On the target drive ( D: ) preferably. Create a folder D:\chess\dev
2) For production create D:\chess\ProductionA, D:\chess\ProductionB

### **AUTOMATED INSTALL**
save https://git.bbh.org.in/chess/elxr/src/branch/master/i.win.sh to folder.
cscript i.win.sh
save https://git.bbh.org.in/chess/elxr/src/branch/master/i.win.js to folder.
cscript i.win.js

Addtional steps For Production


Loading…
Откажи
Сачувај