Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772
  1. var scripthostName = 'node'
  2. var __Promise = {};
  3. var promises = [];
  4. function startPromises(){
  5. promises.forEach(function(p){
  6. // console.log(p.chain)
  7. p ? p() : null;
  8. // promises.splice(0,1)
  9. })
  10. }
  11. function isWin(){ return /^win/.test(process.platform) }
  12. var stampedFilePfx = function(date) {
  13. return date.getFullYear() +
  14. ('0' + (date.getMonth() + 1)).slice(-2) +
  15. ('0' + date.getDate()).slice(-2) +
  16. ('0' + date.getHours()).slice(-2) +
  17. ('0' + date.getMinutes()).slice(-2) +
  18. ('0' + date.getSeconds()).slice(-2);
  19. }
  20. var runtimestamp = (new Date()).getTime();
  21. try {
  22. console.log("detected node")
  23. // var WScript = console || WScript // Dummy
  24. // console.Echo = console.log
  25. __Promise = Promise
  26. var __require = require
  27. var map = Array.map
  28. function startPromises(){
  29. promises.forEach(function(p){
  30. // console.log(p.chain)
  31. p ? Promise.resolve(p) === p ? p : p() : null;
  32. // promises.splice(0,1)
  33. })
  34. }
  35. // --------------------------------------------
  36. // Node Exists. Lets launch ourselves in Node itself
  37. WScript = function(){}
  38. WScript.Echo = function(m){
  39. console.log('Invalid Wscript')
  40. throw "Failed in Node Run."
  41. }
  42. var wait = function(ms, cb) {any
  43. return new __Promise(function(resolve){ setTimeout(resolve, ms) } ).then(function(){ cb() });
  44. }
  45. var fs = require('fs')
  46. var existsSync = require('fs').existsSync;
  47. var existsSyncFolder = existsSync
  48. var path = require('path');
  49. console.log('before cliverse')
  50. var cli = require('./cliverse')
  51. var nodeShellExec = cli.nodeShellExec;
  52. console.log('before bbhverse')
  53. var utils = require('bbhverse');
  54. var any = utils.any;
  55. var wait = setTimeout
  56. // --------------------------------------------
  57. // PB : TODO -- This should be parent dir if elxr is already installed.
  58. var selectedinstance = { root : path.resolve(".") }
  59. __main(selectedinstance)
  60. }
  61. catch(e) {
  62. WScript.Echo('detected wsh')
  63. scripthostName = 'wsh'
  64. WScript.Echo(WScript.FullName)
  65. // WScript.Echo('--' + WScript.Arguments(0) + '--')
  66. // WScript.Echo('------------ALL-----------')
  67. // var argEnumerator = new Enumerator(WScript.Arguments)
  68. // for(; !argEnumerator.atEnd(); argEnumerator.moveNext()){
  69. // WScript.Echo('-arg-' + argEnumerator.item() + '-arg-')
  70. // }
  71. // // Unnamed
  72. // WScript.Echo('------------UNNAMED-----------')
  73. // argEnumerator = new Enumerator(WScript.Arguments.Unnamed)
  74. // for(; !argEnumerator.atEnd(); argEnumerator.moveNext()){
  75. // WScript.Echo('-arg-' + argEnumerator.item() + '-arg-') // Value
  76. // }
  77. // // Named
  78. // WScript.Echo('------------NAMED-----------')
  79. // argEnumerator = new Enumerator(WScript.Arguments.Named)
  80. // for(; !argEnumerator.atEnd(); argEnumerator.moveNext()){
  81. // // WScript.Echo('-arg-' + argEnumerator.item(argEnumerator) + '-arg-') // Key
  82. // WScript.Echo('-key-' + argEnumerator.item() + '-key-') // Key
  83. // WScript.Echo('-val=' + WScript.Arguments.Named(argEnumerator.item()) + '=val-') // Value
  84. // }
  85. // cscript elxr/i.win.js /all:true
  86. var all = WScript.Arguments.Named('all');
  87. trim = function(str) { return str.replace(/^\s+|\s+$/g, ''); };
  88. var fs = new ActiveXObject('Scripting.FileSystemObject');
  89. var WshShell = WScript.CreateObject("WScript.Shell")
  90. var ENV = WshShell.Environment("Process")
  91. var sfn = WScript.ScriptFullName
  92. // WScript.Echo(sfn)
  93. var cd = fs.GetAbsolutePathName(".")
  94. var cfn = cd + '\\i.win.js'
  95. // WScript.Echo(cfn)
  96. var waslaunchedwithenv = trim(ENV.Item('LAUNCHEDWITHENV'));
  97. // for(e=new Enumerator(ENV); !e.atEnd(); e.moveNext()) WScript.echo(e.item(e));
  98. if(waslaunchedwithenv !== "YES"){
  99. var a = fs.CreateTextFile("launchwithenv.bat", true)
  100. a.WriteLine("@echo off")
  101. a.WriteLine("echo %PATH%")
  102. var gitpath = "C:\\Program Files\\Git\\cmd"
  103. var nodepath = "C:\\Program Files\\nodejs\\"
  104. var codepath = "C:\\Users\\Pradeep\\AppData\\Local\\Programs\\Microsoft VS Code\\bin"
  105. var python2path = "C:\\Python27" // Python installer doesnt write to PATH!!!
  106. a.WriteLine("set PATH=%PATH%;" + gitpath )
  107. a.WriteLine("set PATH=%PATH%;" + nodepath )
  108. a.WriteLine("set PATH=%PATH%;" + codepath )
  109. a.WriteLine("set PATH=%PATH%;" + python2path )
  110. // a.WriteLine("set LAUNCHEDWITHENV=YES" )
  111. var __ALIAS__STAMP__ = '9e7bebe0-1f57-11ec-8f88-778ffeea9d1b'
  112. var currentIsExlr = function() {
  113. if(fs.FileExists('./' + __ALIAS__STAMP__)) return true
  114. }
  115. var runningInExlr = currentIsExlr()
  116. if(cfn === sfn && runningInExlr) {
  117. a.WriteLine("cd ..");
  118. a.WriteLine("SET LAUNCHEDWITHENV=YES && cscript "+cfn+" /all:true") // PB : TODO -- Retain all script args...
  119. }
  120. else {
  121. var guesselxr = fs.FileExists(cd + './elxr/' + __ALIAS__STAMP__)
  122. if(guesselxr) {
  123. a.WriteLine("SET LAUNCHEDWITHENV=YES && cscript "+cd + './elxr/' + 'i.win.js' +" /all:true")
  124. }
  125. else a.WriteLine("SET LAUNCHEDWITHENV=YES && cscript "+sfn+" /all:true")
  126. }
  127. // a.WriteLine("powershell.exe ^")
  128. // a.WriteLine("[Environment]::GetEnvironmentVariable('Path')" )
  129. a.Close()
  130. WshShell.run("cmd /k launchwithenv.bat")
  131. WScript.Quit()
  132. // WshShell.run("powershell -noexit [Environment]::GetEnvironmentVariable(\"\"Path\"\"\) ")
  133. // WshShell.run("powershell -noexit [Environment]::SetEnvironmentVariable(\"\"Path\"\", $env:Path + \"\";C:\\tttt\"\", \"\"Machine\"\"\) ")
  134. }
  135. console = {
  136. log : function(m) { WScript.Echo(m)}
  137. , error : function(m) {WScript.Echo(m) }
  138. , dir : function(o) {
  139. for(var i in o){ console.log(i + ' : ' + o[i])}
  140. }
  141. }
  142. // if(!String.prototype.trim) String.prototype.trim = function(){
  143. // return this.replace(/^\s+|\s+$/g, '');
  144. // };
  145. // var ovrrides = {
  146. // resolve : function(v){
  147. // if(v && v.then) return v;
  148. // var p = new Promise(function(resolve, reject){ resolve(v) });
  149. // return p;
  150. // }
  151. // };
  152. // // --------------------------------------------
  153. // // Cscript
  154. var wsh = true;
  155. function isWin(){ return true; }
  156. // If UCase( Right( WScript.FullName, 12 ) ) = "\CSCRIPT.EXE" Then
  157. var clii = {
  158. question : function(q, answercb){
  159. WScript.Echo(q)
  160. // console.log('WScript.StdIn : ' + WScript.StdIn.ReadLine() + ' ==== ')
  161. var answer = WScript.StdIn.ReadLine()
  162. answercb(answer)
  163. }
  164. }
  165. var prompter = {
  166. ask : function(q){
  167. // Needs to be serialized. Parallel asks are not possible.
  168. // const clii = readline.createInterface({ input: process.stdin, output: process.stdout });
  169. return new Promise(function(resolve, reject){
  170. clii.question(q, function(answer){
  171. // clii.close();
  172. // console.log("resolve is being called");
  173. resolve(answer)
  174. })
  175. })
  176. }
  177. }
  178. var cli = {
  179. prompt : function(choices, label, defaultchoice){
  180. var options = [];
  181. // console.dir(choices)
  182. choices.forEach = forEach
  183. choices.forEach(function(choice, i, a){
  184. // console.log(choice)
  185. // console.log('------------------------')
  186. // console.log( ((+i) + 1) + ' ' + choice )
  187. options.push( ((+i) + 1) + ' ' + choice )
  188. // console.log('------------------------')
  189. })
  190. // console.log(options)
  191. return prompter.ask( label + '\n' + options.join('\n') + '\n default ( <= ' + (defaultchoice || choices[0]) + ' ) : '
  192. ).then( function(choice){
  193. if(!choice) return defaultchoice || choices[0];
  194. if(choice && isNaN(+choice)) return choice;
  195. return choices[(+choice) - 1];
  196. })
  197. }
  198. }
  199. var any = function(iterable, continueOnFailure) {
  200. // var cancelsignal = Symbol()
  201. if(!iterable.reduce) iterable.reduce = reduce
  202. // console.log('iterable.reduce ' + iterable.reduce)
  203. var cancelsignal = "cancelme{mangledrunid}"
  204. return iterable.reduce(
  205. function(p, tasq, i ,a) {
  206. // console.dir(a)
  207. // console.log('Entered')
  208. var handleError = function(err, pVal){
  209. if(err !== cancelsignal) {
  210. // Cancel only once on first failure.
  211. console.warn('Possible failure for task with result : ' )
  212. console.log('Failed : ' + err.message + ' ')
  213. console.dir(pVal)
  214. console.dir(p)
  215. if(i>0 && a[i-1].info) console.dir(a[i-1].info)
  216. console.error('Error : ' + err.stack)
  217. console.error(a[i-1])
  218. a[i-1] ? console.log("tasq : " + a[i-1].toString()) : null;
  219. if(!continueOnFailure) {console.log("Cancelling remaining on any one failure ..."); throw cancelsignal}
  220. else return pVal;
  221. // tasq ? console.log("tasq : " + tasq.toString()) : null; // Previous task is what failed not the one we are going to run.
  222. }
  223. }
  224. if(Promise.resolve(p) === p ) {
  225. if(i>0 && a[i-1].info) p.info = a[i-1].info;
  226. console.dir(' p.then is ' + p.then)
  227. return p.then( function(pVal){
  228. // Falsy values are no longer treated as task failure exceptions. Specially for Promises.
  229. // Even tasq function wrappers are required to return promises that eventually either resolve or reject..
  230. // Failures are known for promises on reject.
  231. // In future if we support direct sync function execution with a result examination for failure
  232. // we could examine the result of the function as falsy's... or a result evaluator handler needs to be passed in...
  233. // if(!pVal) handleError({ error : true, message : 'Failed without result' }, pVal)
  234. // Truthy values are failures if obj has error=true.
  235. if(pVal && pVal.error) handleError(pVal, pVal)
  236. var trycall = function(tasq){
  237. try {
  238. var result = tasq() // PB : TODO -- Handle scope for call
  239. if(tasq.resultHandler) return tasq.resultHandler(result)
  240. // else (Promise.resolve(result) === result ) ? result.start() : null
  241. return result
  242. } catch (error) {
  243. console.error(error);
  244. console.error('Error : ' + error ? error.stack : 'No stack')
  245. if(!continueOnFailure) throw error; // PB : TODO -- Support array of results for any with or without continueonfailure.
  246. }
  247. }
  248. var handleNext = function(){
  249. // console.log('Task finished with result : ')
  250. // console.dir(pVal)
  251. if(i>0 && a[i-1].info) console.dir(a[i-1].info)
  252. if(!tasq && !continueOnFailure) { console.log('Error : No task specified.'); throw false;}
  253. else if(!tasq) { console.log('Error : No task specified.'); return false;}
  254. return (Promise.resolve(tasq) === tasq ) ? tasq /*.start()*/ : trycall(tasq) ;
  255. }
  256. if(Promise.resolve(pVal) === pVal) {
  257. // Passed in function retured a promise. We still need to wait for it.
  258. pVal.then(function(pVal){ return handleNext(); })
  259. }
  260. else return handleNext()
  261. })['catch'](function(error) {
  262. if(error !== cancelsignal) {
  263. console.log('E3 : i = ' + i);
  264. if(error.result) console.error(error.result)
  265. console.error('Error : ' + (error.message || error.messages))
  266. console.error('Error : ' + error.stack)
  267. tasq ? console.log("tasq : " + tasq.toString()) : null;
  268. console.log('debugData 3-------------------------');
  269. // handleError()
  270. throw error
  271. }
  272. else throw cancelsignal;
  273. })
  274. }
  275. else if(!p) {
  276. handleError({ error : true, message : 'Failed without result' }, pVal)
  277. console.log("Bypass remaining on prior failure");
  278. return false; // All remaining tasks will return false in the any results even if they are promisies still running or functions not initiated.
  279. }
  280. else return p; // A truthy value
  281. }
  282. , Promise.resolve(true)
  283. );
  284. }
  285. // __Promise = ovrrides
  286. // PB : TODO -- iterators are messed up in cscript without enumerables...
  287. function forEach(eachFn, o){
  288. // console.dir(this)
  289. // console.log('------------------------------------')
  290. // console.log(''+ {})
  291. // console.log('------------------------------------')
  292. if('' + this === '[object Object]') {
  293. // console.log('' + this)
  294. // console.dir(this)
  295. // var o = this
  296. // for(var i in o){ console.log(i + ' : ' + o[i])}
  297. for(var i in this){
  298. if(i === 'forEach') continue; // Enumerable in cscript not supported ???
  299. // console.log(i)
  300. eachFn(this[i], i, this)
  301. }
  302. }
  303. else {
  304. for(var i=0; i<this.length; i++) eachFn(this[i], i, this)
  305. }
  306. }
  307. function reduce(reducnFn, iv){
  308. var acc = iv
  309. for(var i=0; i<this.length; i++) {acc = reducnFn(acc, this[i], i, this) }
  310. return acc;
  311. }
  312. function map(eachFn){
  313. var mapped = []
  314. for(var i=0; i<this.length; i++) mapped.push(eachFn(this[i]))
  315. return mapped
  316. }
  317. var wait = function(cb, ms) { WScript.Sleep(ms); cb() }
  318. var fso = new ActiveXObject('Scripting.FileSystemObject');
  319. var existsSync = function(filepath){ return fso.FileExists(filepath) }
  320. var fs = {
  321. writeFileSync : function(filepath, text) {
  322. // console.log('------------------writeFileSync----------------------')
  323. // console.log(filepath)
  324. // console.log('------------------writeFileSync----------------------')
  325. var fh = fso.CreateTextFile(filepath, true);
  326. fh.WriteLine(text);
  327. fh.Close();
  328. }
  329. , mkdirSync : function(path) {
  330. fso.CreateFolder(path)
  331. }
  332. , readFileSync : function(filepath){
  333. var objFileToRead = fso.OpenTextFile(filepath,1)
  334. var strFileText = objFileToRead.ReadAll()
  335. objFileToRead.Close()
  336. return strFileText
  337. }
  338. , unlinkSync : function(filepath){ fso.DeleteFile(filepath) }
  339. }
  340. var path = {
  341. resolve : function(path){ return fso.GetAbsolutePathName(path) }
  342. , dirname : function(filepath) {
  343. var normalized = this.normalize(filepath)
  344. var li = normalized.lastIndexOf("\\")
  345. if( li > -1) {
  346. return normalized.substring(0, li)
  347. }
  348. }
  349. , normalize : function(path){
  350. return path.replace(/\//g,'\\');
  351. }
  352. }
  353. // Detect or specify install directory.
  354. var selectedinstance = { root : path.resolve(".") }
  355. var existsSyncFolder = function(path){
  356. return fso.FolderExists(path)
  357. }
  358. var shell = new ActiveXObject('shell.application');
  359. promises.forEach = forEach
  360. function startPromises(){
  361. promises.forEach(function(p){
  362. // console.log(p.chain)
  363. p.start();
  364. // promises.splice(0,1)
  365. })
  366. }
  367. function batchshellescape(str) {
  368. return str.replace('=', '^=')
  369. }
  370. function nodeShellExec(command, cargs, options){
  371. // for(var arg=0; arg < cargs.length; arg++) {
  372. // // cargs[arg] = '"' + batchshellescape(cargs[arg]) +'"';
  373. // cargs[arg] = '"' + cargs[arg] +'"';
  374. // }
  375. var elevatedshellexecute = function(cmd, argstr){
  376. shell.ShellExecute(cmd, argstr , "", "", 1);
  377. }
  378. var shellExec = function(cmd, argstr){
  379. var objShell = WScript.createobject("wscript.shell")
  380. // console.log(argstr.join( ' '))
  381. console.log(cmd + ' ' + argstr.join(' '))
  382. var oExec = objShell.Exec(cmd + ' ' + argstr.join(' '))
  383. var result = {}
  384. var shellresult = { shell : objShell, result : result }
  385. var WshRunning = 0
  386. var WshFinished = 1
  387. var WshFailed = 2
  388. while(oExec.Status === WshRunning){
  389. WScript.StdOut.write('s.')
  390. WScript.Sleep(500)
  391. }
  392. var strOutput = '\n'
  393. switch(oExec.Status) {
  394. case WshFinished :
  395. strOutput = oExec.StdOut.ReadAll()
  396. result.success = true;
  397. result.code = 0
  398. break;
  399. case WshFailed :
  400. strOutput = oExec.StdErr.ReadAll()
  401. result.success = false;
  402. result.code = WshFailed
  403. break;
  404. default : strOutput = 'failed'
  405. break;
  406. }
  407. result.result = command + ' ' + cargs + ' exited with code ' + result.code
  408. result.messages = [strOutput]
  409. // console.log(strOutput)
  410. // WScript.Echo(oExec.Status)
  411. // WScript.Echo(oExec.ProcessID)
  412. // WScript.Echo(oExec.ExitCode)
  413. // console.log(objShell.StdOut.ReadAll)
  414. // console.log(objShell.StdErr.ReadAll)
  415. // objShell = WScript.createobject("wscript.shell")
  416. objShell = null;
  417. return shellresult;
  418. }
  419. var p = null;
  420. var pworker = function(resolve, reject){
  421. // console.dir(p)
  422. var pfx = selectedinstance.root + '\\.elxr\\run-' + runtimestamp + '\\' + stampedFilePfx(new Date())
  423. // console.log('p.chain.length ================ ' + p.chain.length)
  424. options = options || {
  425. runFile : path.normalize( pfx + "out.txt")
  426. // runFile : null
  427. }
  428. var runFile = null;
  429. var runFile = options.runFile || pfx + command + cargs + "out.txt";
  430. // console.log(runFile)
  431. var args = cargs.concat()
  432. // runFile ? (args.push(">"), args.push(runFile)) : cargs
  433. // console.log(command + ' ' + args.join(' '))
  434. // command = 'cmd'
  435. // args = ['/c', 'start',
  436. // '/WAIT', selectedinstance.root + '/Downloads' + '/' + 'Git-2.33.0.2-64-bit.exe'
  437. // , '/VERYSILENT'
  438. // // , '/MERGETASKS=!runcode' // This is required only for vscode...
  439. // ]
  440. var runbat = path.normalize(pfx + "run.bat")
  441. // console.log('runbat : ' + runbat)
  442. fs.writeFileSync(runbat,
  443. '@echo off \r\n' +
  444. (options.cwd ? 'cd ' + options.cwd + ' \r\n' : '') +
  445. // ' cmd /k notepad.exe \r\n' +
  446. command + ' ' + args.join(' ') + ' \r\n' +
  447. 'cmd /c echo done >> ' + runFile + ' \r\n' +
  448. 'echo done'
  449. )
  450. // fs.writeFileSync(runFile, 'started')
  451. // WScript.Quit()
  452. // elevatedshellexecute(runFile)
  453. // while(!existsSync(runbat)) { wait(function(){
  454. // console.log('awiting batch : ' + runbat)
  455. // // shellExec( 'start', ['/W', '/b', runbat])
  456. // // shellExec( 'cmd', ['/k', '/b', runbat])
  457. // shellExec( command, args)
  458. // // cmd /b /c
  459. // }, 500) }
  460. console.log(options.waitmsg || ('awaiting ' + command + ' ' + args.join(' ')))
  461. var shellresult = shellExec( 'cmd', [ '/c', runbat])
  462. // var shellresult = shellExec( 'cmd', ['/c', runbat])
  463. // var shellresult = shellExec( command, args)
  464. var wrapup = function(result) {
  465. // console.log('Wrapping up')
  466. try {
  467. // console.log('resolving.....................');
  468. // console.log('--------------P' + result.messages.join(' ').trim() +'P--------------')
  469. // if(result.messages.join().trim()) resolve(result)
  470. // else reject(result)
  471. resolve(result)
  472. }
  473. catch(e){
  474. // console.dir(e)
  475. if(e.message === 'Input past end of file') {
  476. // console.log('---------------------------------------')
  477. // console.dir(result)
  478. resolve(result)
  479. }
  480. else {
  481. // console.dir(e)
  482. reject(e)
  483. }
  484. }
  485. }
  486. // if(runFile){
  487. // var waitr = function(){
  488. // WScript.StdOut.write('w.')
  489. // if(existsSync(runFile)) {
  490. // var strOutput = fs.readFileSync(runFile)
  491. // shellresult.result.messages = [strOutput]
  492. // wrapup(shellresult.result)
  493. // fs.unlinkSync(runFile)
  494. // }
  495. // // console.dir(shellresult.result)
  496. // wait( waitr, 500)
  497. // }
  498. // // console.log(wait)
  499. // wait( waitr, 500)
  500. // }
  501. // else {
  502. // console.log('There is no runfile.')
  503. console.log(shellresult.strOutput)
  504. wrapup(shellresult.result)
  505. // }
  506. }
  507. p = new Promise(pworker)
  508. // promises.push(p)
  509. // // Promise tThens don't get hooked up... we need to postpone promise starting until all the thens are registered...
  510. // wait(function(){
  511. // console.log('p.chain.length' + p.chain.length)
  512. // p.start() } , 5000) // Bind and setTImeout is not supported by JScript
  513. return p;
  514. }
  515. createPromiseClass(/*ovrrides*/)
  516. __main( selectedinstance )
  517. function createPromiseClass(overrides) {
  518. function reject(e){
  519. var p = this;
  520. console.log('Promise Rejection : ' + p.fn)
  521. console.dir(e)
  522. // throw e;f
  523. if(p.state !== PromiseClass.PENDING) { console.error ('Error : Promise Rejection can only be called once')}
  524. var __i = 0;
  525. var __e = e;
  526. do {
  527. for(var i = __i; i < p.chain.length; i++, __i = i) if(p.chain[i].isCatch) break;
  528. try {
  529. for(var i = __i; i < p.chain.length; i++, __i = i) if(p.chain[i].isCatch) { p.chain[i](__e); break; }
  530. __i++;
  531. __e = null;
  532. }
  533. catch(e){ __i++; __e = e}
  534. } while(__e)
  535. do {
  536. try { for(var i = __i; i < p.chain.length; i++, __i = i) if(!p.chain[i].isCatch) { p.result = p.chain[i](p.result); } }
  537. catch(e){
  538. __i ++;
  539. do {
  540. try {
  541. for(var i = __i; i < p.chain.length; i++, __i = i) if(p.chain[i].isCatch) { p.chain[i](__e); break; }
  542. __i ++;
  543. __e = null;
  544. }
  545. catch(e){ __i++; __e = e}
  546. } while(__e)
  547. }
  548. } while ( __i < p.chain.length )
  549. p.state = PromiseClass.REJECTED;
  550. }
  551. function resolve(result){
  552. var p = this;
  553. // console.log(result + ' resolve was called with chain length ' + p.chain.length )
  554. if(p.state !== PromiseClass.PENDING) { console.error ('Error : Promise Resolve can only be called once')}
  555. p.result = result;
  556. if(PromiseClass.resolve(p.result) === p.result) {
  557. // console.log( 'result is still a promise waiting for result and promisechain' )
  558. waitForResult(p.result, function(r){ p.processchain(r) })
  559. }
  560. else {
  561. // console.log( 'result is value waiting for promisechain' )
  562. // console.dir(result)
  563. return p.processchain(result)
  564. }
  565. };
  566. function processchain(r){
  567. var __i = 0;
  568. var i = __i;
  569. var __e = null;
  570. p = this;
  571. // console.log('processchain chain.length : ' + p.chain.length)
  572. function __processchain(r){
  573. function waitForThen(p){
  574. if(i < p.chain.length) {
  575. if(!p.chain[i].isCatch) {
  576. // console.log('chain idx : ' + i + ' Executing : then ' + p.result + ' ' + p.chain[i])
  577. try {
  578. p.result = p.chain[i](p.result)
  579. if(PromiseClass.resolve(p.result) === p.result) {
  580. // console.log('chain idx : ' + i + ' result is still a promise starting it ')
  581. // console.dir(p.result.chain)
  582. // console.log('p.result.start : ' + p.result.start + ' ------------------ ')
  583. p.result.start()
  584. // console.log(p.result.fn + ' ------------------ ')
  585. waitForResult(p.result, function(r){
  586. // console.log('we waited')
  587. // WScript.write('.')
  588. p.result = r; i++; __i = i;
  589. waitForThen(p)
  590. })
  591. }
  592. else {
  593. i++; __i = i;
  594. waitForThen(p)
  595. }
  596. }
  597. catch(e) {
  598. i++; __i = i;
  599. __e = e;
  600. console.log('failed on index ' + __i + p.chain[__i-1] )
  601. console.dir(e)
  602. waitForCatch(p);
  603. }
  604. }
  605. else {
  606. // console.log(i + ' Skipping catch : ' + p.result + ' ' + p.chain[i])
  607. i++; __i = i;
  608. waitForThen(p)
  609. }
  610. }
  611. else return p.state = PromiseClass.FULFILLED;
  612. }
  613. function waitForCatch(p) {
  614. if(i < p.chain.length) {
  615. if(p.chain[i].isCatch) {
  616. console.log('chain idx : ' + i + ' Executing : catch : ' + p.result + ' ' + p.chain[i])
  617. try {
  618. p.result = p.chain[i](__e);
  619. if(PromiseClass.resolve(p.result) === p.result) {
  620. p.result.start()
  621. waitForResult(p.result, function(r){
  622. p.result = r; i++; __i = i;
  623. })
  624. waitForThen(p)
  625. }
  626. else {
  627. p.result = r; i++; __i = i;
  628. waitForThen(p)
  629. }
  630. }
  631. catch(e){ i++; __i = i;; __e = e; waitForCatch(p) }
  632. }
  633. else {
  634. i++; __i = i;
  635. waitForCatch(p)
  636. }
  637. }
  638. else return p.state = PromiseClass.REJECTED
  639. }
  640. waitForThen(p);
  641. }
  642. __processchain(r)
  643. }
  644. var create = function(fn){
  645. var p = {
  646. then : function(thenfn){
  647. // console.log('Adding then')
  648. thenfn.isThen = true
  649. // if(Object.prototype.toString.call(p.chain) !== '[object Array]') console.dir(p.chain)
  650. p.chain.push(thenfn)
  651. return p;
  652. }
  653. , 'catch' : function(catchfn) {
  654. catchfn.isCatch = true
  655. p.chain.push(catchfn)
  656. return p;
  657. }
  658. , start : function(){
  659. if(this.started) {
  660. console.error('Cannot start more than once...')
  661. return p
  662. };
  663. this.started = true;
  664. this.fn = fn;
  665. try { fn( function(r){
  666. // console.log('calling presolve in starter ')
  667. p.resolve(r) } , function(r){ p.reject(r) } ) }
  668. catch(e){
  669. // console.log('start catch : ' + e)
  670. // console.log('p.chain.length : ' + p.chain.length)
  671. // // console.dir(p)
  672. // console.dir(e)
  673. // console.log(fn)
  674. p.reject(e)
  675. }
  676. return p
  677. }
  678. , state : PromiseClass.PENDING
  679. , chain : []
  680. , reject : reject
  681. , resolve : resolve
  682. , processchain : processchain
  683. }
  684. p.chain.forEach = forEach;
  685. return p;
  686. }
  687. var PromiseClass = function(fn /*, donotstart */){
  688. var p = create(fn)
  689. // if(!donotstart) {
  690. // wait(function(){
  691. // console.log('p.chain.length' + p.chain.length)
  692. // p.start() } , 500) // Bind and setTImeout is not supported by JScript
  693. // }
  694. return p
  695. }
  696. PromiseClass.PENDING = 1
  697. PromiseClass.FULFILLED = 2
  698. PromiseClass.REJECTED = 3
  699. // PromiseClass.STARTED = 4
  700. PromiseClass.isSETTLED = function(p){ p.state === PromiseClass.FULFILLED || p.state === PromiseClass.REJECTED }
  701. PromiseClass.resolve = function(v){
  702. if(v && v.then) return v;
  703. var p = create(function(resolve, reject){
  704. resolve(v)
  705. });
  706. // console.log('p.chain in resolve. length ' + p.chain.length)
  707. // p.result = v;
  708. // wait(function(){ p.processchain(v) }, 0)
  709. return p;
  710. }
  711. function waitForResult(p, cb){
  712. if(!p) return cb(p)
  713. if(p.state !== PromiseClass.PENDING) cb(p.result)
  714. // console.log(p.state + ' Waiting for ..... ' + p.runFile)
  715. if(p.runFile && false) {
  716. while(!existsSync(p.runFile) && p.state === PromiseClass.PENDING) {
  717. console.log('Waiting for ResultFle'); wait(cb, 500)
  718. }
  719. cb(p.result)
  720. }
  721. else {
  722. // while(p.state === PromiseClass.PENDING) {
  723. // console.log('Waiting for Result')
  724. function waiter(){
  725. // console.log(p.result)
  726. if(p.state === PromiseClass.PENDING) wait(waiter, 500);
  727. else return cb(p.result)
  728. }
  729. wait(waiter, 500)
  730. // }
  731. }
  732. }
  733. PromiseClass.all = any; // Serialized...
  734. PromiseClass.__all = function(arr){
  735. arr.forEach = forEach;
  736. var resultPs = [];
  737. var results = [];
  738. console.log('All : ' + arr.length)
  739. var pAll = new PromiseClass(function(resolve, reject){
  740. console.log('All started : ' + pAll)
  741. // console.dir(pAll)
  742. arr.forEach(function(p){
  743. if(!p.then) { var pfn = p;
  744. p = new PromiseClass(function(resolve, reject){
  745. try{
  746. resolve(pfn())
  747. }
  748. catch(e){
  749. reject(e)
  750. }
  751. })
  752. p.start()
  753. }
  754. else {
  755. // !p.start ? p.start = function(){return p} : null
  756. // p.start()
  757. // .then( function(){ waitForResult(p, function(r){ results.push(r) }) })
  758. }
  759. resultPs.push(p)
  760. // waitForResult(p, function(r){ results.push(r) })
  761. })
  762. // PB : TODO -- This is the same as processchain!!!
  763. var allwaitr = function(){
  764. var allResolved = true
  765. console.log('resultPs : ' + resultPs.length)
  766. for(var rIdx =0; rIdx < resultPs.length; rIdx++ ){
  767. if(resultPs[rIdx]) {
  768. allResolved = false
  769. waitForResult(resultPs[rIdx], function(r){
  770. if(Promise.resolve(r) !== r) results[rIdx] = r; resultPs[rIdx] = null;
  771. })
  772. break;
  773. }
  774. }
  775. if(allResolved) {
  776. // console.log('All Reseloved')
  777. // console.dir(results)
  778. resolve(results)
  779. }
  780. else wait(allwaitr, 500)
  781. }
  782. wait(allwaitr, 500)
  783. })
  784. // pAll.chain = arr;
  785. return pAll
  786. }
  787. // PromiseClass.resolve = overrides.resolve;
  788. Promise = PromiseClass;
  789. return PromiseClass;
  790. }
  791. }
  792. function __main( selectedinstance ){
  793. var downloadsdir = path.dirname(selectedinstance.root) + '\\Downloads';
  794. var callsheltask = function(args) {
  795. // console.log('callsheltask : ' + args)
  796. return function() { return nodeShellExec.apply(null, args) } }
  797. var instanceName = 'elixir'
  798. var reposerver = 'https://git.bbh.org.in';
  799. var gitUser = 'guest';
  800. var gitpassword = 'guest';
  801. var gitEmail = 'guest@bbh.org.in';
  802. var gitPreinstalled = true;
  803. var BUILD_VERSION = '[VI]Version: {version} - built on {date}[/VI]';
  804. function getVersion() { return BUILD_VERSION; }
  805. console.log(getVersion())
  806. function ensureDirectoryExistence(filePath) {
  807. var dirname = path.dirname(filePath);
  808. if (existsSyncFolder(dirname)) {
  809. return filePath;
  810. }
  811. ensureDirectoryExistence(dirname);
  812. fs.mkdirSync(dirname);
  813. return filePath;
  814. }
  815. var getTaskCheckExists = function(command, options) {
  816. options = options || {}
  817. return function() {
  818. var runFile = path.normalize(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/' + stampedFilePfx(new Date()) + 'where' + command + "out.txt");
  819. var p = nodeShellExec.apply(null, ['cmd', ['/c', 'where', command], { runFile : runFile } ])
  820. p.runFile = runFile;
  821. if (options.ignorefailures) {
  822. return p.then(function(v) {
  823. // WScript.Echo('firstThen ' + v);
  824. return v })['catch']( function(e) {
  825. console.error(e);
  826. // Ignore. Not a major error if where command fails !!!
  827. throw e;
  828. })
  829. }
  830. else return p.then(function() {
  831. // WScript.Echo('firstThen ddd');
  832. return v });
  833. }
  834. }
  835. function verifyAndInstallPrerequisites() {
  836. fs.writeFileSync(ensureDirectoryExistence(downloadsdir + '/readme.txt'), getVersion() + ' Your local downloads for this instance');
  837. var downloadbatch =
  838. "::************************************************************************** \r\n \
  839. :Download_ <url> <File> \r\n \
  840. Powershell.exe ^\r\n \
  841. $AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'; ^\r\n \
  842. [System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols; ^\r\n \
  843. (New-Object System.Net.WebClient).DownloadFile('%1','%2') \r\n \
  844. exit /b \r\n \
  845. ::**************************************************************************";
  846. ensureDirectoryExistence(path.normalize(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/readme.txt'))
  847. fs.writeFileSync(path.normalize(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat'), downloadbatch);
  848. var downloadtasks = [];
  849. var installtasks = [];
  850. // var prereqfilter = ['nvm']
  851. var prereqfilter = ['*']
  852. prerequisites.forEach(function(preq) {
  853. // WScript.Echo('FFFFFFFFFFFFF : ' + preq.shellcmd)
  854. for(var p=0; p < prereqfilter.length; p++) {
  855. if( preq.shellcmd === prereqfilter[p] || prereqfilter[p] === '*' ) {
  856. WScript.Echo(all)
  857. if(!all && preq.optional) return
  858. var p = preq.exists().then(function(exists) {
  859. if (exists && !preq.forceinstall) console.log( preq.shellcmd + ' exists');
  860. else {
  861. console.log('----------------------------')
  862. console.log(exists) // PB : ??? Boolean true becomes -1 ???
  863. console.log('----------------------------')
  864. if(!exists) console.log(preq.shellcmd + ' is not installed');
  865. else console.log(preq.shellcmd + ' is installed but forceinstall was specifed so re-installing');
  866. return preq.preinstallsteps().then(function(){
  867. // console.log(' task.install : ' + preq.install)
  868. installtasks.push( function(){ return preq.install() } );
  869. })
  870. }
  871. })
  872. // .then(function(res){ console.log( 'preinstallsteps ' + res)});
  873. downloadtasks.push( p )
  874. }
  875. }
  876. });
  877. // console.log('downloadtasks')
  878. // console.dir(downloadtasks[0])
  879. var p = Promise.all(downloadtasks).then(function(){
  880. // console.log('calling install tasks : ' + installtasks.length)
  881. return any(installtasks) })
  882. // console.log('Promise.all.chain : ' + p.chain)
  883. return p
  884. }
  885. // var choiceHandler = function(choices, choice) {
  886. // console.log('chosen : ' + choice)
  887. // var decision = choices['d'];
  888. // if (choice && choice === 'd' || !choice) {
  889. // decision = choices['d']
  890. // }
  891. // else if (isNaN((+choice))) {
  892. // decision = choice
  893. // }
  894. // else decision = choices[choice-1]
  895. // if(!decision) throw 'Invalid selection : ' + decision
  896. // return decision
  897. // }
  898. // prereq definition helpers. We can't do proper inheritance in cscript. So fallback to global functions.
  899. function exists(next){
  900. var self = this;
  901. console.log('checking existence of ' + self.shellcmd)
  902. return getTaskCheckExists(self.shellcmd, { ignorefailures: true })().then(function(exists) {
  903. // console.log('-------------exists=======================')
  904. // console.dir(exists)
  905. // console.log(self.shellcmd)
  906. // console.log(exists.messages.join(' ').toLowerCase().indexOf(self.shellcmd.toLowerCase()))
  907. if(exists && (exists.messages.join(' ').toLowerCase().indexOf(self.shellcmd.toLowerCase()) > -1) ) {
  908. console.log(' ' + self.shellcmd + ' exists')
  909. return true;
  910. }
  911. else {
  912. console.log(' ' + self.shellcmd + ' doesnt exist')
  913. return false
  914. }
  915. })['catch'](function(e){
  916. // console.log('-------------exists catch=======================')
  917. console.dir(e)
  918. return false;
  919. })
  920. }
  921. function install() {
  922. var self = this;
  923. var ifns = [self.installcmd]
  924. if(!ifns.map) ifns.map = map;
  925. console.log('Installing')
  926. return any(ifns.map(callsheltask))['catch'](function(e){
  927. if(e.code === 1602) {
  928. console.warn("Installation was probably cancelled.")
  929. }
  930. else throw e
  931. }).then(function(){
  932. return self.postinstallsteps && self.postinstallsteps()
  933. })
  934. }
  935. function unique(arr) {
  936. var hash = {}, result = [];
  937. for ( var i = 0, l = arr.length; i < l; ++i ) {
  938. if ( !hash.hasOwnProperty(arr[i]) ) { //it works with objects! in FF, at least
  939. hash[ arr[i] ] = true;
  940. result.push(arr[i]);
  941. }
  942. }
  943. return result;
  944. }
  945. // var ENV = Object.assign({}, process.env); // Shallow clone it.
  946. // WScript.echo( ENV("Path") )
  947. function sysAddPathVar(path){
  948. return true; // PB : TODO -- Not yet enabled. Remove sys path from path before saving.
  949. // Object.assign({
  950. // inherit: true, shell: true, env: ENV, title: `${command} ${args}`
  951. // }, options)
  952. // var newpath = ENV("Path").split(';');
  953. // newpath = Array.from(new Set(newpath.push(path))).join(';')
  954. var newpath = [];
  955. newpath.push(path)
  956. newpath = unique(newpath).join(';')
  957. // path.split(';').forEach(pel => { var kv = pel.split('='); kv[0] === key ? null : newpath.push(pel); } )
  958. return any([nodeShellExec('setx', [/*'/m',*/ 'PATH', '"%PATH%;' + newpath + '"' ])
  959. // , nodeShellExec('set', [/*'/m',*/ 'PATH', '"%PATH%;' + newpath + '"' ])
  960. ] );
  961. }
  962. var getCmdString = function(args){ return args[0] + ' ' + args[1].join(' ') }
  963. var getgitshelltask = function(args, onEachError) { return function(){
  964. console.log('----------getgitshelltask--------------called')
  965. return nodeShellExec( "cmd", ['/c', getCmdString(args)], args[2])
  966. // .catch( onEachError || function(e){ console.error(e) })
  967. }
  968. }
  969. var createTasq = function(args, shellT, onEachError) {
  970. var tasq = shellT ? shellT(args) : ( function(){
  971. return any([nodeShellExec.apply(null, args)])
  972. // .catch( onEachError || function(e){ console.error(e) } )
  973. })
  974. tasq.toString = function(){ return JSON.stringify(args)}
  975. return tasq;
  976. }
  977. var execserial = function(tasklist, task, shellT, onEachError){
  978. var exec = function(taskArgs){
  979. console.log('executing ' + task)
  980. var thistask = task.concat();
  981. thistask[1] = thistask[1].concat()
  982. thistask[1].push.apply(thistask[1], taskArgs)
  983. return createTasq(thistask, shellT)
  984. }
  985. tasklist.map = map
  986. console.log('execlist ' + tasklist.map(exec))
  987. return any(tasklist.map(exec))
  988. }
  989. function resetgitconfig(){
  990. // https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage
  991. // Git Credential storage...
  992. // git config --global credential.helper 'store --file ~/.gitcredentials'
  993. // git credential-store --file ~/.gitcredentials store
  994. // // notepad C:/Program Files/Git/etc/gitconfig
  995. // git config --global --unset credential
  996. // git config --edit --system
  997. // git config --global credential.helper "store --file ~/gitcredentials"
  998. // git credential fill
  999. // git credential-store --file ~/git.store store
  1000. // Find system git config
  1001. // git config --global --edit
  1002. // git config --list --show-origin
  1003. // git config --list --show-origin --show-scope
  1004. // https://stackoverflow.com/questions/35942754/how-can-i-save-username-and-password-in-git
  1005. // Recipie
  1006. // git config --global --unset credentials.helper
  1007. // cd /path/to/my/repo
  1008. // git config --unset credential.helper
  1009. // git config --global credential.helper "store --file ~/.elxrcredentials"
  1010. // git config credential.helper 'store --file ~/.elxrcredentials'
  1011. //-- git config credential.*.username my_user_name
  1012. //-- git config credential.https://gitlab.com.username my_user_name
  1013. // git credential fill
  1014. // git config --global credential.modalprompt false // doesnst work.
  1015. // core askpass = ;;; https://stackoverflow.com/questions/37182847/how-do-i-disable-git-credential-manager-for-windows
  1016. var options = {
  1017. inherit: true, shell: true //, env: process.env
  1018. , cwd: selectedinstance.root
  1019. // , runas: processedArgs.runas
  1020. }
  1021. var task = ['git', ['config'], options]
  1022. var tasklist = [
  1023. // ['--global', '--unset credentials.helper']
  1024. // ['--unset', 'credentials.helper']
  1025. // ,
  1026. // ['credential.helper', `'store --file git_repo_credentials'`]
  1027. ['--global', 'credential.helper', '"store --file ~/.elxrcredentials"']
  1028. , ['--global', '--replace-all', 'user.name', gitUser]
  1029. , ['--global', '--replace-all', 'user.email', gitEmail]
  1030. // , ['--list']
  1031. // , ['credential', 'fill']
  1032. ]
  1033. console.log(tasklist)
  1034. var onEachError = function(e) { console.error( e.messages.join('\n') + e.result + '\n' + util.inspect(e) + '\n') }
  1035. var shellT = function(args) {
  1036. return getgitshelltask(args, onEachError)
  1037. // .catch(e => console.error( e.messages.join('\n') + e.result + '\n' + util.inspect(e) + '\n' + tasq.toString()) )
  1038. }
  1039. return execserial(tasklist, task, shellT, onEachError ).then(function(){
  1040. // git credential-store --file ./.elxrcredentials store
  1041. console.log('gathering git credentials')
  1042. var userhome = '~'
  1043. if(isWin()) userhome = '%userprofile%'
  1044. var host = reposerver.replace('https://','').replace('http://','')
  1045. var protocol = reposerver.replace('https://','') === host ? 'https' : 'http'
  1046. fs.writeFileSync('ic.txt', 'host='+host+'\r\nprotocol='+protocol+'\r\nusername='+gitUser+'\r\npassword='+gitpassword)
  1047. return nodeShellExec('git', ['credential-store', '--file', userhome + '/.elxrcredentials', 'store', '<', 'ic.txt'], options)
  1048. })
  1049. }
  1050. var gitpostinstallsteps = function(){
  1051. try {
  1052. // Load just in case someone was smart enough to fill in before install.
  1053. var icf = fs.readFileSync( 'installchoices.js')
  1054. icf = icf.replace('module.exports = ', 'icf = ')
  1055. console.log(icf)
  1056. icf = eval(icf)
  1057. // console.log(icf.reposerver)
  1058. instanceName = icf.instanceName
  1059. reposerver = icf.reposerver;
  1060. gitUser = icf.gitUser;
  1061. gitEmail = icf.gitEmail
  1062. }
  1063. catch(e) {
  1064. console.error(e)
  1065. }
  1066. // gitpassword = icf.??? ; we do not store password it should already be cached in the credential store.
  1067. // PB : TODO -- Detect failure or cancellation before attenpting postinstall steps...
  1068. var steps = [];
  1069. steps.push(
  1070. function(){
  1071. var choices = { 0 : 'elixir' }
  1072. return cli.prompt(choices, 'instanceName', instanceName).then(function(choice){ instanceName = choice } )
  1073. }
  1074. )
  1075. steps.push(
  1076. function(){
  1077. var choices = { 0 : 'https://git.bbh.org.in' }
  1078. return cli.prompt(choices, 'reposerver', reposerver).then(function(choice){ reposerver = choice } )
  1079. }
  1080. )
  1081. steps.push(
  1082. function(){
  1083. var choices = { 0 : 'guest', 1 : 'chessdemo' }
  1084. return cli.prompt(choices, 'git user name', gitUser).then(function(choice){ gitUser = choice } )
  1085. }
  1086. )
  1087. steps.push(
  1088. function(){
  1089. var choices = { }
  1090. return cli.prompt(choices, 'git password', gitpassword).then(function(choice){ gitpassword = choice } )
  1091. }
  1092. )
  1093. steps.push(
  1094. function(){
  1095. var choices = { 0 : 'guest@bbh.org.in', 1 : 'chessdemo@bbh.org.in' }
  1096. return cli.prompt(choices, 'git user email', gitEmail).then(function(choice){ gitEmail = choice })
  1097. }
  1098. )
  1099. return any(steps).then(function(){
  1100. // Save values to add credentials later in index.js...
  1101. // console.log('module.exports = { instanceName : "'+ instanceName +'", reposerver: "'+reposerver+'", gitUser: "'+gitUser+'", gitEmail:"'+gitEmail+'" }')
  1102. fs.writeFileSync( 'installchoices.js', 'module.exports = { instanceName : "'+ instanceName +'", reposerver: "'+reposerver+'", gitUser: "'+gitUser+'", gitEmail:"'+gitEmail+'" }' )
  1103. var steps = [
  1104. // ['git', ['config', '--global', '--add', 'user.name', gitUser]]
  1105. // , ['git', ['config', '--global', '--add', 'user.email', gitEmail]]
  1106. ]
  1107. if(!steps.map) steps.map = map;
  1108. return any(steps.map(callsheltask)).then(function(){
  1109. })
  1110. });
  1111. }
  1112. var prerequisites = [
  1113. {
  1114. shellcmd: 'git',
  1115. url: 'https://github.com/git-for-windows/git/releases/download/v2.33.0.windows.2/Git-2.33.0.2-64-bit.exe'
  1116. , installer: 'Git-2.33.0.2-64-bit.exe'
  1117. , installcmd: ['cmd', ['/c', 'start',
  1118. '/WAIT', downloadsdir + '/' + 'Git-2.33.0.2-64-bit.exe'
  1119. , '/VERYSILENT'
  1120. // , '/MERGETASKS=!runcode' // This is required only for vscode...
  1121. ]]
  1122. , preinstallsteps: function() {
  1123. var self = this;
  1124. console.log('Git preinstall steps')
  1125. var steps = [];
  1126. // steps.push(
  1127. // function(){
  1128. // // console.log('cli prompt steps')
  1129. // var choices = { 0 : 'guest', 1 : 'chessdemo' }
  1130. // return cli.prompt(choices, 'git user name', gitUser).then(function(choice){ gitUser = choice } )
  1131. // }
  1132. // )
  1133. // steps.push(
  1134. // function(){
  1135. // var choices = { 0 : 'guest@bbh.org.in', 1 : 'chessdemo@bbh.org.in' }
  1136. // return cli.prompt(choices, 'git user email', gitEmail).then(function(choice){ gitEmail = choice })
  1137. // }
  1138. // )
  1139. steps.push(
  1140. function(){
  1141. if (!existsSync(downloadsdir + '/' + self.installer)) {
  1142. return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', [self.url, downloadsdir + '/' + self.installer])
  1143. }
  1144. else {
  1145. console.log(self.installer + ' Already exits Download skipped.')
  1146. return Promise.resolve(true)
  1147. }
  1148. }
  1149. )
  1150. return any(steps)
  1151. // return any([any(steps), any(prompts)])
  1152. }
  1153. , installsteps: function () {
  1154. var self = this;
  1155. console.log('Git Installsteps called')
  1156. var ifns = [self.installcmd]
  1157. if(!ifns.map) ifns.map = map;
  1158. return any(ifns.map(callsheltask))['catch'](function(e){
  1159. if(e.code === 1602) {
  1160. console.warn("Installation was probably cancelled.")
  1161. }
  1162. else throw e
  1163. })
  1164. }
  1165. , postinstallsteps: gitpostinstallsteps
  1166. , install: function () {
  1167. gitPreinstalled = false;
  1168. var self = this;
  1169. console.log('Git Install called')
  1170. return any([ /*self.preinstallsteps,*/
  1171. function(){ return self.installsteps() }
  1172. , function() { return resetgitconfig() }
  1173. , function(){ return self.postinstallsteps() }
  1174. ])
  1175. }
  1176. // , verifyAndInstall : function(){
  1177. // var self = this;
  1178. // return self.exists().then( function(exits) {
  1179. // if(exists) return self.getUser(null, function(){ return self.postinstallsteps() } )
  1180. // else return self.install();
  1181. // })
  1182. // }
  1183. , exists : exists
  1184. , getUser : function(repo, onNoResult){
  1185. onNoResult = onNoResult || function(){return false}
  1186. var globalOrLocal = '--global';
  1187. if(!repo) globalOrLocal = '--global';
  1188. else globalOrLocal = '--local'
  1189. var fns = [['git', ['config', globalOrLocal, '--get-all', 'user.name']]]
  1190. if(!ifns.map) ifns.map = map;
  1191. return any(fns.map(callsheltask)).then(function(result){
  1192. // not yet configured.
  1193. if(!result.success) return onNoResult()
  1194. else {
  1195. var users = result.messages[0].trim().split('\n');
  1196. if(users.length === 0 ||
  1197. users.length === 1 && users[0] === 'guest') {
  1198. return onNoResult()
  1199. }
  1200. else return users[0]; // PB : TODO == We should probably prompt with all the users available for selection !
  1201. }
  1202. })
  1203. ['catch'](function(e){
  1204. console.log(e)
  1205. return onNoResult()
  1206. })
  1207. }
  1208. }
  1209. ,
  1210. {
  1211. shellcmd: 'node',
  1212. url: 'https://nodejs.org/dist/v14.17.6/node-v14.17.6-x64.msi'
  1213. , installer: 'node-v14.17.3-x64.msi'
  1214. , installcmd: ['MSIEXEC.exe', ['/i'
  1215. , path.normalize(downloadsdir + '/' + 'node-v14.17.3-x64.msi')
  1216. , 'ACCEPT=YES', '/passive']]
  1217. , install : install
  1218. , exists : exists
  1219. , preinstallsteps: function() {
  1220. var self = this;
  1221. console.log('Node preinstall steps')
  1222. // console.log(this.installcmd)
  1223. // console.log(path.normalize(downloadsdir + '/' + 'node-v14.17.3-x64.msi'))
  1224. var steps = [];
  1225. steps.push(
  1226. function(){
  1227. if (!existsSync(downloadsdir + '/' + self.installer)) {
  1228. return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', ['"' + self.url + '"', downloadsdir + '/' + self.installer]
  1229. , { waitmsg : 'downloading '+ self.shellcmd +' please wait' })
  1230. }
  1231. else {
  1232. console.log(self.installer + ' Already exits Download skipped.')
  1233. return Promise.resolve(true)
  1234. }
  1235. }
  1236. )
  1237. return any(steps)
  1238. // return any([any(steps), any(prompts)])
  1239. }
  1240. }
  1241. , {
  1242. shellcmd: 'nvm',
  1243. url: 'https://github.com/coreybutler/nvm-windows/releases/download/1.1.11/nvm-setup.exe'
  1244. , installer: 'nvm-setup.exe'
  1245. , installcmd: ['cmd', ['/c', 'start',
  1246. '/WAIT', downloadsdir + '/' + 'nvm-setup.exe'
  1247. , '/VERYSILENT'
  1248. // , '/MERGETASKS=!runcode' // This is required only for vscode...
  1249. ]]
  1250. , install : install
  1251. , exists : exists
  1252. , preinstallsteps: function() {
  1253. var self = this;
  1254. console.log('Node preinstall steps')
  1255. // console.log(this.installcmd)
  1256. // console.log(path.normalize(downloadsdir + '/' + 'node-v14.17.3-x64.msi'))
  1257. var steps = [];
  1258. steps.push(
  1259. function(){
  1260. if (!existsSync(downloadsdir + '/' + self.installer)) {
  1261. return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', ['"' + self.url + '"', downloadsdir + '/' + self.installer]
  1262. , { waitmsg : 'downloading '+ self.shellcmd +' please wait' })
  1263. }
  1264. else {
  1265. console.log(self.installer + ' Already exits Download skipped.')
  1266. return Promise.resolve(true)
  1267. }
  1268. }
  1269. )
  1270. return any(steps)
  1271. // return any([any(steps), any(prompts)])
  1272. }
  1273. }
  1274. , {
  1275. shellcmd: 'python'
  1276. , optional : true
  1277. , url: 'https://www.python.org/ftp/python/2.7.18/python-2.7.18.amd64.msi'
  1278. , installer: 'python-2.7.18.amd64.msi'
  1279. , installcmd: ['MSIEXEC.exe', ['/i'
  1280. , path.normalize(downloadsdir + '/' + 'python-2.7.18.amd64.msi')
  1281. , 'ACCEPT=YES', '/passive']]
  1282. , preinstallsteps: function() {
  1283. var self = this;
  1284. console.log(self.shellcmd + ' preinstall steps')
  1285. var steps = [];
  1286. steps.push(
  1287. function(){
  1288. if (!existsSync(downloadsdir + '/' + self.installer)) {
  1289. return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', [self.url, downloadsdir + '/' + self.installer]
  1290. , { waitmsg : 'downloading '+ self.shellcmd +' please wait' })
  1291. }
  1292. else {
  1293. console.log(self.installer + ' Already exits Download skipped.')
  1294. return Promise.resolve(true)
  1295. }
  1296. }
  1297. )
  1298. return any(steps)
  1299. // return any([any(steps), any(prompts)])
  1300. }
  1301. , install : install
  1302. , postinstallsteps : function() { return sysAddPathVar('%USERPROFILE%\\AppData/Local\\Microsoft\\WindowsApps') }
  1303. , exists : exists
  1304. }
  1305. , {
  1306. shellcmd: 'code'
  1307. , optional : true
  1308. , url: 'https://code.visualstudio.com/sha/download?build=stable&os=win32-x64-user'
  1309. , installer: 'VSCodeUserSetup-x64-1.65.2.exe'
  1310. , installcmd: ['cmd /c', ['start /WAIT ' + downloadsdir + '/' + 'VSCodeUserSetup-x64-1.65.2.exe /VERYSILENT'
  1311. // , '/MERGETASKS=!runcode' // This is required only for vscode...
  1312. ]]
  1313. , preinstallsteps: function() {
  1314. var self = this;
  1315. console.log(self.shellcmd + ' preinstall steps')
  1316. var steps = [];
  1317. steps.push(
  1318. function(){
  1319. if (!existsSync(downloadsdir + '/' + self.installer)) {
  1320. console.log(self.url)
  1321. return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', ['"' + self.url + '"', downloadsdir + '/' + self.installer]
  1322. , { waitmsg : 'downloading '+ self.shellcmd +' please wait' })
  1323. }
  1324. else {
  1325. console.log(self.installer + ' Already exits Download skipped.')
  1326. return Promise.resolve(true)
  1327. }
  1328. }
  1329. )
  1330. return any(steps)
  1331. // return any([any(steps), any(prompts)])
  1332. }
  1333. , install : install
  1334. , postinstallsteps : function() { return sysAddPathVar('%USERPROFILE%\\AppData/Local\\Microsoft\\WindowsApps') }
  1335. , exists : exists
  1336. }
  1337. , {
  1338. // C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\Ssms.exe
  1339. // SQL Management studio 2018
  1340. shellcmd: 'sqlcmd.exe', // 'Ssms.exe',
  1341. url: 'https://aka.ms/ssmsfullsetup'
  1342. , installer: 'SSMS-Setup-ENU.exe'
  1343. , installcmd: ['cmd', ['/c', 'start',
  1344. '/WAIT', downloadsdir + '/' + 'SSMS-Setup-ENU.exe'
  1345. , '/IAcceptSQLServerLicenseTerms'
  1346. //, 'SSMSInstallRoot=%systemdrive%\\Program Files (x86)\\Microsoft SQL Server\\140\\Tools\\Binn\\ManagementStudio'
  1347. ]]
  1348. , install : install
  1349. , exists : exists
  1350. , preinstallsteps: function() {
  1351. var self = this;
  1352. console.log('smss 2018 preinstall steps')
  1353. var steps = [];
  1354. steps.push(
  1355. function(){
  1356. if (!existsSync(downloadsdir + '/' + self.installer)) {
  1357. console.log(self.url)
  1358. return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', ['"' + self.url + '"', downloadsdir + '/' + self.installer]
  1359. , { waitmsg : 'downloading '+ self.shellcmd +' please wait' })
  1360. }
  1361. else {
  1362. console.log(self.installer + ' Already exits Download skipped.')
  1363. return Promise.resolve(true)
  1364. }
  1365. }
  1366. )
  1367. return any(steps)
  1368. // return any([any(steps), any(prompts)])
  1369. }
  1370. }
  1371. , {
  1372. shellcmd: 'sqlservr.exe',
  1373. url: 'https://go.microsoft.com/fwlink/?linkid=866658'
  1374. , installer: 'SQL2019-SSEI-Expr.exe'
  1375. , installcmd: ['cmd', ['/c', 'start',
  1376. '/WAIT', downloadsdir + '/' + 'SQL2019-SSEI-Expr.exe'
  1377. , ''
  1378. //, 'SSMSInstallRoot=%systemdrive%\\Program Files (x86)\\Microsoft SQL Server\\140\\Tools\\Binn\\ManagementStudio'
  1379. ]]
  1380. , install : install
  1381. , exists : function(){
  1382. var self = this;
  1383. var installedpath = 'C:\\Program Files\\Microsoft SQL Server\\MSSQL15.SQLEXPRESS\\MSSQL\\Binn\\sqlservr.exe'
  1384. console.log('checking existence of ' + installedpath)
  1385. return Promise.resolve(existsSync(installedpath))
  1386. }
  1387. , preinstallsteps: function() {
  1388. var self = this;
  1389. console.log('sqlexpress preinstall steps')
  1390. var steps = [];
  1391. steps.push(
  1392. function(){
  1393. if (!existsSync(downloadsdir + '/' + self.installer)) {
  1394. console.log(self.url)
  1395. return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', ['"' + self.url + '"', downloadsdir + '/' + self.installer]
  1396. , { waitmsg : 'downloading '+ self.shellcmd +' please wait' })
  1397. }
  1398. else {
  1399. console.log(self.installer + ' Already exits Download skipped.')
  1400. return Promise.resolve(true)
  1401. }
  1402. }
  1403. )
  1404. return any(steps)
  1405. // return any([any(steps), any(prompts)])
  1406. }
  1407. }
  1408. , {
  1409. shellcmd: 'mysql',
  1410. 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'
  1411. , installer: 'mysql-installer-community-8.0.30.0.msi'
  1412. , installcmd: ['MSIEXEC.exe', ['/i'
  1413. , path.normalize(downloadsdir + '/' + 'mysql-installer-community-8.0.30.0.msi')
  1414. //, 'ACCEPT=YES', '/passive'
  1415. ]]
  1416. , install : install
  1417. , exists : function(){
  1418. var self = this;
  1419. var mysqldpath = 'C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysqld.exe'
  1420. console.log('checking existence of ' + mysqldpath)
  1421. return Promise.resolve(existsSync(mysqldpath))
  1422. }
  1423. , preinstallsteps: function() {
  1424. var self = this;
  1425. console.log('mysql preinstall steps')
  1426. var steps = [];
  1427. steps.push(
  1428. function(){
  1429. if (!existsSync(downloadsdir + '/' + self.installer)) {
  1430. console.log(self.url)
  1431. return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', [self.url, downloadsdir + '/' + self.installer]
  1432. , { waitmsg : 'downloading '+ self.shellcmd +' please wait' })
  1433. }
  1434. else {
  1435. console.log(self.installer + ' Already exits Download skipped.')
  1436. return Promise.resolve(true)
  1437. }
  1438. }
  1439. )
  1440. return any(steps)
  1441. // return any([any(steps), any(prompts)])
  1442. }
  1443. }
  1444. ,
  1445. {
  1446. shellcmd: 'elxr'
  1447. , forceinstall : true
  1448. , installcmd: [ isWin() ? 'npm.cmd' : 'npm' , ['link'], { cwd : selectedinstance.root + '\\elxr' /* cwd should be the cloned dir*/}]
  1449. , preinstallsteps: function() {
  1450. var self = this;
  1451. console.log('Elxr preinstall steps')
  1452. var steps = [];
  1453. steps.push(
  1454. )
  1455. return any([any(steps)])
  1456. }
  1457. , installsteps: function () {
  1458. var self = this;
  1459. console.log('GIt config reconfirm called ' + gitPreinstalled)
  1460. var installIfNotExists = function(){
  1461. var steps = [];
  1462. if(gitPreinstalled) {
  1463. console.log('-------------------------------------')
  1464. console.log('Git was already preinstalled - reconfirming installchoices')
  1465. // Load from previous run and confirm.
  1466. // var reposerver = 'https://git.bbh.org.in';
  1467. // var gitUser = 'guest';
  1468. // var gitEmail = 'guest@bbh.org.in';
  1469. try {
  1470. var icf = fs.readFileSync( 'installchoices.js')
  1471. icf = icf.replace('module.exports = ', 'icf = ')
  1472. console.log(icf)
  1473. icf = eval(icf)
  1474. // console.log(icf.reposerver)
  1475. instanceName = icf.instanceName
  1476. reposerver = icf.reposerver;
  1477. gitUser = icf.gitUser;
  1478. gitEmail = icf.gitEmail
  1479. }
  1480. catch(e) {
  1481. console.error(e)
  1482. }
  1483. console.log('-------------------------------------')
  1484. console.dir(icf)
  1485. // var p = gitpostinstallsteps()
  1486. steps.push(gitpostinstallsteps)
  1487. // steps.push(
  1488. // function(){
  1489. // console.log('cli prompt steps')
  1490. // var choices = { 0 : 'http://git.bbh', 1 : 'https://git.bbh.org.in' }
  1491. // // console.dir(choices)
  1492. // return cli.prompt(choices, 'git repository : ', reposerver).then(function(choice){ reposerver = choice } )
  1493. // }
  1494. // )
  1495. }
  1496. else{
  1497. // var p = Promise.resolve(true)
  1498. steps.push(
  1499. function(){
  1500. var choices = { }
  1501. return cli.prompt(choices, 'git password', gitpassword).then(function(choice){ gitpassword = choice } )
  1502. }
  1503. )
  1504. }
  1505. // resetgitconfig requires the password to be loaded from credential store. Currently just prompt for it.
  1506. return any(steps).then( function(){
  1507. console.log('calling resetgitconfig')
  1508. return resetgitconfig().then(function(){
  1509. console.log('cloning elxr now')
  1510. var ifns = [
  1511. ['git', ['clone', reposerver + '/chess/elxr'] ]
  1512. ]
  1513. if(existsSyncFolder( selectedinstance.root + '\\elxr')) {
  1514. if(existsSyncFolder( selectedinstance.root + '\\elxr\\.git')) {
  1515. // PB : TODO -- use a elxr guid signature to detect more reliably folders named the same that is not us.
  1516. ifns = [ ['git', ['pull'], { cwd : selectedinstance.root + '\\elxr' } ] ]
  1517. }
  1518. else {
  1519. throw 'elxr subfolder not recognized as a git repository. Please cleanup and continue.'
  1520. }
  1521. }
  1522. else console.log(selectedinstance.root + '\\elxr' + ' NOT FOUND ')
  1523. if(!ifns.map) ifns.map = map;
  1524. return any(ifns.map(callsheltask)).then(function(){
  1525. var pkgjson = selectedinstance.root + '\\elxr\\package.json'
  1526. var pkgcontents = fs.readFileSync(pkgjson)
  1527. // PB : TODO -- Remove hardcode use proper replacement url..
  1528. fs.writeFileSync( pkgjson, pkgcontents.replace(/http\:\/\/git\.bbh/g, reposerver));
  1529. return callsheltask(['npm', ['i'], { cwd : '.\\elxr' } ])
  1530. })['catch'](function(e){
  1531. if(e.code === 1602) {
  1532. console.warn("Installation was probably cancelled.")
  1533. }
  1534. else throw e
  1535. })
  1536. })
  1537. } )
  1538. }
  1539. var ifns = [ self.installcmd ]
  1540. if(!ifns.map) ifns.map = map;
  1541. return installIfNotExists().then(function(){
  1542. return any(ifns.map(callsheltask))['catch'](function(e){
  1543. if(e.code === 1602) {
  1544. console.warn("Installation was probably cancelled.")
  1545. }
  1546. else throw e
  1547. })
  1548. })
  1549. }
  1550. , install: function () {
  1551. var self = this;
  1552. console.log('Elxr Install called')
  1553. // PB : TODO -- detect external or internal and change elxr package.json dependencies to point to proper location.
  1554. fs.writeFileSync(selectedinstance.root + '\\ei.bat', 'cmd /c node ' + selectedinstance.root + '\\elxr\\index.js i ' + instanceName)
  1555. return any([ self.preinstallsteps, function(){ return self.installsteps() }
  1556. , nodeShellExec('start', ['/WAIT', '""', '"' + selectedinstance.root + '\\ei.bat' + '"'])
  1557. // , nodeShellExec('start', ['/WAIT', '""', '"C:\\Program Files\\Git\\bin\\sh.exe"', '-c', '"node ' + (selectedinstance.root + '\\elxr\\index.js').replace(/\\/g, '/') + ' i elixir"'])
  1558. // , nodeShellExec('node', [selectedinstance.root + 'elxr\\index.js'])
  1559. ])
  1560. // return any([ /*self.preinstallsteps,*/ function(){ return self.installsteps() }
  1561. // , nodeShellExec('node', [selectedinstance.root + '\\elxr\\index.js', 'init'])
  1562. // // , nodeShellExec('node', [selectedinstance.root + 'elxr\\index.js'])
  1563. // ])
  1564. }
  1565. // , exists : function(){
  1566. // console.log('Elxr PreInstallsteps called')
  1567. // var ifns = [ ['git', ['clone', 'http://git.bbh/chess\\elxr'] ] ]
  1568. // if(existsSyncFolder( selectedinstance.root + '\\elxr')) {
  1569. // if(existsSyncFolder( selectedinstance.root + '\\elxr\\.git')) {
  1570. // // PB : TODO -- use a elxr guid signature to detect more reliably folders named the same that is not us.
  1571. // ifns = [ ['git', ['pull'], { cwd : selectedinstance.root + '\\elxr' } ] ]
  1572. // }
  1573. // else {
  1574. // throw 'elxr subfolder not recognized as a git repository. Please cleanup and continue.'
  1575. // }
  1576. // }
  1577. // else console.log(selectedinstance.root + '\\elxr' + ' NOT FOUND ')
  1578. // if(!ifns.map) ifns.map = map;
  1579. // return any(ifns.map(callsheltask))['catch'](function(e){
  1580. // if(e.code === 1602) {
  1581. // console.warn("Installation was probably cancelled.")
  1582. // }
  1583. // else throw e
  1584. // })
  1585. // }
  1586. , exists : exists
  1587. }
  1588. ]
  1589. if(!prerequisites.forEach) prerequisites.forEach = forEach;
  1590. // nodeShellExec(selectedinstance.root + '/.elxr/run-' + '1629889572461' + '/download.bat'
  1591. // , ['https://github.com/git-for-windows/git/releases/download/v2.31.0.windows.1/Git-2.32.0.2-64-bit.exe'
  1592. // , downloadsdir + '/' + 'Git-2.32.0.2-64-bit.exe']).start()
  1593. promises.push(verifyAndInstallPrerequisites())
  1594. startPromises();
  1595. }
  1596. // Open JDK
  1597. // https://objects.githubusercontent.com/github-production-release-asset-2e65be/602574963/cd0ac1ad-740d-4616-aa96-157ac2e79a60?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVCODYLSA53PQK4ZA%2F20240117%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240117T055737Z&X-Amz-Expires=300&X-Amz-Signature=4c0ce9303027a065fed291a107ff0a5f7d7782a828f077873bd5111c8e6fa0f0&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=602574963&response-content-disposition=attachment%3B%20filename%3DOpenJDK21U-jdk_x64_windows_hotspot_21.0.1_12.msi&response-content-type=application%2Foctet-stream
  1598. // JRE for runtime
  1599. // https://my.visualstudio.com/Downloads?q=Visual%20Studio%202022