You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763
  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 = 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. prerequisites.forEach(function(preq) {
  851. WScript.Echo(all)
  852. if(!all && preq.optional) return
  853. var p = preq.exists().then(function(exists) {
  854. if (exists && !preq.forceinstall) console.log( preq.shellcmd + ' exists');
  855. else {
  856. console.log('----------------------------')
  857. console.log(exists) // PB : ??? Boolean true becomes -1 ???
  858. console.log('----------------------------')
  859. if(!exists) console.log(preq.shellcmd + ' is not installed');
  860. else console.log(preq.shellcmd + ' is installed but forceinstall was specifed so re-installing');
  861. return preq.preinstallsteps().then(function(){
  862. // console.log(' task.install : ' + preq.install)
  863. installtasks.push( function(){ return preq.install() } );
  864. })
  865. }
  866. })
  867. // .then(function(res){ console.log( 'preinstallsteps ' + res)});
  868. downloadtasks.push( p )
  869. });
  870. // console.log('downloadtasks')
  871. // console.dir(downloadtasks[0])
  872. var p = Promise.all(downloadtasks).then(function(){
  873. // console.log('calling install tasks : ' + installtasks.length)
  874. return any(installtasks) })
  875. // console.log('Promise.all.chain : ' + p.chain)
  876. return p
  877. }
  878. // var choiceHandler = function(choices, choice) {
  879. // console.log('chosen : ' + choice)
  880. // var decision = choices['d'];
  881. // if (choice && choice === 'd' || !choice) {
  882. // decision = choices['d']
  883. // }
  884. // else if (isNaN((+choice))) {
  885. // decision = choice
  886. // }
  887. // else decision = choices[choice-1]
  888. // if(!decision) throw 'Invalid selection : ' + decision
  889. // return decision
  890. // }
  891. // prereq definition helpers. We can't do proper inheritance in cscript. So fallback to global functions.
  892. function exists(next){
  893. var self = this;
  894. console.log('checking existence of ' + self.shellcmd)
  895. return getTaskCheckExists(self.shellcmd, { ignorefailures: true })().then(function(exists) {
  896. // console.log('-------------exists=======================')
  897. // console.dir(exists)
  898. // console.log(self.shellcmd)
  899. // console.log(exists.messages.join(' ').indexOf(self.shellcmd))
  900. // console.log(exists + ' ' + self.shellcmd + ' exists')
  901. if(exists && (exists.messages.join(' ').indexOf(self.shellcmd) > -1) ) {
  902. return true;
  903. }
  904. else return false
  905. })['catch'](function(e){
  906. // console.log('-------------exists catch=======================')
  907. console.dir(e)
  908. return false;
  909. })
  910. }
  911. function install() {
  912. var self = this;
  913. var ifns = [self.installcmd]
  914. if(!ifns.map) ifns.map = map;
  915. console.log('Installing')
  916. return any(ifns.map(callsheltask))['catch'](function(e){
  917. if(e.code === 1602) {
  918. console.warn("Installation was probably cancelled.")
  919. }
  920. else throw e
  921. }).then(function(){
  922. return self.postinstallsteps && self.postinstallsteps()
  923. })
  924. }
  925. function unique(arr) {
  926. var hash = {}, result = [];
  927. for ( var i = 0, l = arr.length; i < l; ++i ) {
  928. if ( !hash.hasOwnProperty(arr[i]) ) { //it works with objects! in FF, at least
  929. hash[ arr[i] ] = true;
  930. result.push(arr[i]);
  931. }
  932. }
  933. return result;
  934. }
  935. // var ENV = Object.assign({}, process.env); // Shallow clone it.
  936. // WScript.echo( ENV("Path") )
  937. function sysAddPathVar(path){
  938. return true; // PB : TODO -- Not yet enabled. Remove sys path from path before saving.
  939. // Object.assign({
  940. // inherit: true, shell: true, env: ENV, title: `${command} ${args}`
  941. // }, options)
  942. // var newpath = ENV("Path").split(';');
  943. // newpath = Array.from(new Set(newpath.push(path))).join(';')
  944. var newpath = [];
  945. newpath.push(path)
  946. newpath = unique(newpath).join(';')
  947. // path.split(';').forEach(pel => { var kv = pel.split('='); kv[0] === key ? null : newpath.push(pel); } )
  948. return any([nodeShellExec('setx', [/*'/m',*/ 'PATH', '"%PATH%;' + newpath + '"' ])
  949. // , nodeShellExec('set', [/*'/m',*/ 'PATH', '"%PATH%;' + newpath + '"' ])
  950. ] );
  951. }
  952. var getCmdString = function(args){ return args[0] + ' ' + args[1].join(' ') }
  953. var getgitshelltask = function(args, onEachError) { return function(){
  954. console.log('----------getgitshelltask--------------called')
  955. return nodeShellExec( "cmd", ['/c', getCmdString(args)], args[2])
  956. // .catch( onEachError || function(e){ console.error(e) })
  957. }
  958. }
  959. var createTasq = function(args, shellT, onEachError) {
  960. var tasq = shellT ? shellT(args) : ( function(){
  961. return any([nodeShellExec.apply(null, args)])
  962. // .catch( onEachError || function(e){ console.error(e) } )
  963. })
  964. tasq.toString = function(){ return JSON.stringify(args)}
  965. return tasq;
  966. }
  967. var execserial = function(tasklist, task, shellT, onEachError){
  968. var exec = function(taskArgs){
  969. console.log('executing ' + task)
  970. var thistask = task.concat();
  971. thistask[1] = thistask[1].concat()
  972. thistask[1].push.apply(thistask[1], taskArgs)
  973. return createTasq(thistask, shellT)
  974. }
  975. tasklist.map = map
  976. console.log('execlist ' + tasklist.map(exec))
  977. return any(tasklist.map(exec))
  978. }
  979. function resetgitconfig(){
  980. // https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage
  981. // Git Credential storage...
  982. // git config --global credential.helper 'store --file ~/.gitcredentials'
  983. // git credential-store --file ~/.gitcredentials store
  984. // // notepad C:/Program Files/Git/etc/gitconfig
  985. // git config --global --unset credential
  986. // git config --edit --system
  987. // git config --global credential.helper "store --file ~/gitcredentials"
  988. // git credential fill
  989. // git credential-store --file ~/git.store store
  990. // Find system git config
  991. // git config --global --edit
  992. // git config --list --show-origin
  993. // git config --list --show-origin --show-scope
  994. // https://stackoverflow.com/questions/35942754/how-can-i-save-username-and-password-in-git
  995. // Recipie
  996. // git config --global --unset credentials.helper
  997. // cd /path/to/my/repo
  998. // git config --unset credential.helper
  999. // git config --global credential.helper "store --file ~/.elxrcredentials"
  1000. // git config credential.helper 'store --file ~/.elxrcredentials'
  1001. //-- git config credential.*.username my_user_name
  1002. //-- git config credential.https://gitlab.com.username my_user_name
  1003. // git credential fill
  1004. // git config --global credential.modalprompt false // doesnst work.
  1005. // core askpass = ;;; https://stackoverflow.com/questions/37182847/how-do-i-disable-git-credential-manager-for-windows
  1006. var options = {
  1007. inherit: true, shell: true //, env: process.env
  1008. , cwd: selectedinstance.root
  1009. // , runas: processedArgs.runas
  1010. }
  1011. var task = ['git', ['config'], options]
  1012. var tasklist = [
  1013. // ['--global', '--unset credentials.helper']
  1014. // ['--unset', 'credentials.helper']
  1015. // ,
  1016. // ['credential.helper', `'store --file git_repo_credentials'`]
  1017. ['--global', 'credential.helper', '"store --file ~/.elxrcredentials"']
  1018. , ['--global', '--replace-all', 'user.name', gitUser]
  1019. , ['--global', '--replace-all', 'user.email', gitEmail]
  1020. // , ['--list']
  1021. // , ['credential', 'fill']
  1022. ]
  1023. console.log(tasklist)
  1024. var onEachError = function(e) { console.error( e.messages.join('\n') + e.result + '\n' + util.inspect(e) + '\n') }
  1025. var shellT = function(args) {
  1026. return getgitshelltask(args, onEachError)
  1027. // .catch(e => console.error( e.messages.join('\n') + e.result + '\n' + util.inspect(e) + '\n' + tasq.toString()) )
  1028. }
  1029. return execserial(tasklist, task, shellT, onEachError ).then(function(){
  1030. // git credential-store --file ./.elxrcredentials store
  1031. console.log('gathering git credentials')
  1032. var userhome = '~'
  1033. if(isWin()) userhome = '%userprofile%'
  1034. var host = reposerver.replace('https://','').replace('http://','')
  1035. var protocol = reposerver.replace('https://','') === host ? 'https' : 'http'
  1036. fs.writeFileSync('ic.txt', 'host='+host+'\r\nprotocol='+protocol+'\r\nusername='+gitUser+'\r\npassword='+gitpassword)
  1037. return nodeShellExec('git', ['credential-store', '--file', userhome + '/.elxrcredentials', 'store', '<', 'ic.txt'], options)
  1038. })
  1039. }
  1040. var gitpostinstallsteps = function(){
  1041. // Load just in case someone was smart enough to fill in before install.
  1042. var icf = fs.readFileSync( 'installchoices.js')
  1043. icf = icf.replace('module.exports = ', 'icf = ')
  1044. console.log(icf)
  1045. try {
  1046. icf = eval(icf)
  1047. }
  1048. catch(e) {
  1049. console.error(e)
  1050. }
  1051. // console.log(icf.reposerver)
  1052. instanceName = icf.instanceName
  1053. reposerver = icf.reposerver;
  1054. gitUser = icf.gitUser;
  1055. gitEmail = icf.gitEmail
  1056. // gitpassword = icf.??? ; we do not store password it should already be cached in the credential store.
  1057. // PB : TODO -- Detect failure or cancellation before attenpting postinstall steps...
  1058. var steps = [];
  1059. steps.push(
  1060. function(){
  1061. var choices = { 0 : 'elixir' }
  1062. return cli.prompt(choices, 'instanceName', instanceName).then(function(choice){ instanceName = choice } )
  1063. }
  1064. )
  1065. steps.push(
  1066. function(){
  1067. var choices = { 0 : 'https://git.bbh.org.in' }
  1068. return cli.prompt(choices, 'reposerver', reposerver).then(function(choice){ reposerver = choice } )
  1069. }
  1070. )
  1071. steps.push(
  1072. function(){
  1073. var choices = { 0 : 'guest', 1 : 'chessdemo' }
  1074. return cli.prompt(choices, 'git user name', gitUser).then(function(choice){ gitUser = choice } )
  1075. }
  1076. )
  1077. steps.push(
  1078. function(){
  1079. var choices = { }
  1080. return cli.prompt(choices, 'git password', gitpassword).then(function(choice){ gitpassword = choice } )
  1081. }
  1082. )
  1083. steps.push(
  1084. function(){
  1085. var choices = { 0 : 'guest@bbh.org.in', 1 : 'chessdemo@bbh.org.in' }
  1086. return cli.prompt(choices, 'git user email', gitEmail).then(function(choice){ gitEmail = choice })
  1087. }
  1088. )
  1089. return any(steps).then(function(){
  1090. // Save values to add credentials later in index.js...
  1091. // console.log('module.exports = { instanceName : "'+ instanceName +'", reposerver: "'+reposerver+'", gitUser: "'+gitUser+'", gitEmail:"'+gitEmail+'" }')
  1092. fs.writeFileSync( 'installchoices.js', 'module.exports = { instanceName : "'+ instanceName +'", reposerver: "'+reposerver+'", gitUser: "'+gitUser+'", gitEmail:"'+gitEmail+'" }' )
  1093. var steps = [
  1094. // ['git', ['config', '--global', '--add', 'user.name', gitUser]]
  1095. // , ['git', ['config', '--global', '--add', 'user.email', gitEmail]]
  1096. ]
  1097. if(!steps.map) steps.map = map;
  1098. return any(steps.map(callsheltask)).then(function(){
  1099. })
  1100. });
  1101. }
  1102. var prerequisites = [
  1103. {
  1104. shellcmd: 'git',
  1105. url: 'https://github.com/git-for-windows/git/releases/download/v2.33.0.windows.2/Git-2.33.0.2-64-bit.exe'
  1106. , installer: 'Git-2.33.0.2-64-bit.exe'
  1107. , installcmd: ['cmd', ['/c', 'start',
  1108. '/WAIT', downloadsdir + '/' + 'Git-2.33.0.2-64-bit.exe'
  1109. , '/VERYSILENT'
  1110. // , '/MERGETASKS=!runcode' // This is required only for vscode...
  1111. ]]
  1112. , preinstallsteps: function() {
  1113. var self = this;
  1114. console.log('Git preinstall steps')
  1115. var steps = [];
  1116. // steps.push(
  1117. // function(){
  1118. // // console.log('cli prompt steps')
  1119. // var choices = { 0 : 'guest', 1 : 'chessdemo' }
  1120. // return cli.prompt(choices, 'git user name', gitUser).then(function(choice){ gitUser = choice } )
  1121. // }
  1122. // )
  1123. // steps.push(
  1124. // function(){
  1125. // var choices = { 0 : 'guest@bbh.org.in', 1 : 'chessdemo@bbh.org.in' }
  1126. // return cli.prompt(choices, 'git user email', gitEmail).then(function(choice){ gitEmail = choice })
  1127. // }
  1128. // )
  1129. steps.push(
  1130. function(){
  1131. if (!existsSync(downloadsdir + '/' + self.installer)) {
  1132. return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', [self.url, downloadsdir + '/' + self.installer])
  1133. }
  1134. else {
  1135. console.log(self.installer + ' Already exits Download skipped.')
  1136. return Promise.resolve(true)
  1137. }
  1138. }
  1139. )
  1140. return any(steps)
  1141. // return any([any(steps), any(prompts)])
  1142. }
  1143. , installsteps: function () {
  1144. var self = this;
  1145. console.log('Git Installsteps called')
  1146. var ifns = [self.installcmd]
  1147. if(!ifns.map) ifns.map = map;
  1148. return any(ifns.map(callsheltask))['catch'](function(e){
  1149. if(e.code === 1602) {
  1150. console.warn("Installation was probably cancelled.")
  1151. }
  1152. else throw e
  1153. })
  1154. }
  1155. , postinstallsteps: gitpostinstallsteps
  1156. , install: function () {
  1157. gitPreinstalled = false;
  1158. var self = this;
  1159. console.log('Git Install called')
  1160. return any([ /*self.preinstallsteps,*/
  1161. function(){ return self.installsteps() }
  1162. , function() { return resetgitconfig() }
  1163. , function(){ return self.postinstallsteps() }
  1164. ])
  1165. }
  1166. // , verifyAndInstall : function(){
  1167. // var self = this;
  1168. // return self.exists().then( function(exits) {
  1169. // if(exists) return self.getUser(null, function(){ return self.postinstallsteps() } )
  1170. // else return self.install();
  1171. // })
  1172. // }
  1173. , exists : exists
  1174. , getUser : function(repo, onNoResult){
  1175. onNoResult = onNoResult || function(){return false}
  1176. var globalOrLocal = '--global';
  1177. if(!repo) globalOrLocal = '--global';
  1178. else globalOrLocal = '--local'
  1179. var fns = [['git', ['config', globalOrLocal, '--get-all', 'user.name']]]
  1180. if(!ifns.map) ifns.map = map;
  1181. return any(fns.map(callsheltask)).then(function(result){
  1182. // not yet configured.
  1183. if(!result.success) return onNoResult()
  1184. else {
  1185. var users = result.messages[0].trim().split('\n');
  1186. if(users.length === 0 ||
  1187. users.length === 1 && users[0] === 'guest') {
  1188. return onNoResult()
  1189. }
  1190. else return users[0]; // PB : TODO == We should probably prompt with all the users available for selection !
  1191. }
  1192. })
  1193. ['catch'](function(e){
  1194. console.log(e)
  1195. return onNoResult()
  1196. })
  1197. }
  1198. }
  1199. ,
  1200. {
  1201. shellcmd: 'node',
  1202. url: 'https://nodejs.org/dist/v14.17.6/node-v14.17.6-x64.msi'
  1203. , installer: 'node-v14.17.3-x64.msi'
  1204. , installcmd: ['MSIEXEC.exe', ['/i'
  1205. , path.normalize(downloadsdir + '/' + 'node-v14.17.3-x64.msi')
  1206. , 'ACCEPT=YES', '/passive']]
  1207. , install : install
  1208. , exists : exists
  1209. , preinstallsteps: function() {
  1210. var self = this;
  1211. console.log('Node preinstall steps')
  1212. var steps = [];
  1213. steps.push(
  1214. function(){
  1215. if (!existsSync(downloadsdir + '/' + self.installer)) {
  1216. return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', ['"' + self.url + '"', downloadsdir + '/' + self.installer]
  1217. , { waitmsg : 'downloading '+ self.shellcmd +' please wait' })
  1218. }
  1219. else {
  1220. console.log(self.installer + ' Already exits Download skipped.')
  1221. return Promise.resolve(true)
  1222. }
  1223. }
  1224. )
  1225. return any(steps)
  1226. // return any([any(steps), any(prompts)])
  1227. }
  1228. }
  1229. , {
  1230. shellcmd: 'python'
  1231. , optional : true
  1232. , url: 'https://www.python.org/ftp/python/2.7.18/python-2.7.18.amd64.msi'
  1233. , installer: 'python-2.7.18.amd64.msi'
  1234. , installcmd: ['MSIEXEC.exe', ['/i'
  1235. , path.normalize(downloadsdir + '/' + 'python-2.7.18.amd64.msi')
  1236. , 'ACCEPT=YES', '/passive']]
  1237. , preinstallsteps: function() {
  1238. var self = this;
  1239. console.log(self.shellcmd + ' preinstall steps')
  1240. var steps = [];
  1241. steps.push(
  1242. function(){
  1243. if (!existsSync(downloadsdir + '/' + self.installer)) {
  1244. return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', [self.url, downloadsdir + '/' + self.installer]
  1245. , { waitmsg : 'downloading '+ self.shellcmd +' please wait' })
  1246. }
  1247. else {
  1248. console.log(self.installer + ' Already exits Download skipped.')
  1249. return Promise.resolve(true)
  1250. }
  1251. }
  1252. )
  1253. return any(steps)
  1254. // return any([any(steps), any(prompts)])
  1255. }
  1256. , install : install
  1257. , postinstallsteps : function() { return sysAddPathVar('%USERPROFILE%\\AppData/Local\\Microsoft\\WindowsApps') }
  1258. , exists : exists
  1259. }
  1260. , {
  1261. shellcmd: 'code'
  1262. , optional : true
  1263. , url: 'https://code.visualstudio.com/sha/download?build=stable&os=win32-x64-user'
  1264. , installer: 'VSCodeUserSetup-x64-1.65.2.exe'
  1265. , installcmd: ['cmd /c', ['start /WAIT ' + downloadsdir + '/' + 'VSCodeUserSetup-x64-1.65.2.exe /VERYSILENT'
  1266. // , '/MERGETASKS=!runcode' // This is required only for vscode...
  1267. ]]
  1268. , preinstallsteps: function() {
  1269. var self = this;
  1270. console.log(self.shellcmd + ' preinstall steps')
  1271. var steps = [];
  1272. steps.push(
  1273. function(){
  1274. if (!existsSync(downloadsdir + '/' + self.installer)) {
  1275. console.log(self.url)
  1276. return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', ['"' + self.url + '"', downloadsdir + '/' + self.installer]
  1277. , { waitmsg : 'downloading '+ self.shellcmd +' please wait' })
  1278. }
  1279. else {
  1280. console.log(self.installer + ' Already exits Download skipped.')
  1281. return Promise.resolve(true)
  1282. }
  1283. }
  1284. )
  1285. return any(steps)
  1286. // return any([any(steps), any(prompts)])
  1287. }
  1288. , install : install
  1289. , postinstallsteps : function() { return sysAddPathVar('%USERPROFILE%\\AppData/Local\\Microsoft\\WindowsApps') }
  1290. , exists : exists
  1291. }
  1292. , {
  1293. // C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\Ssms.exe
  1294. // SQL Management studio 2018
  1295. shellcmd: 'Ssms.exe',
  1296. url: 'https://aka.ms/ssmsfullsetup'
  1297. , installer: 'SSMS-Setup-ENU.exe'
  1298. , installcmd: ['cmd', ['/c', 'start',
  1299. '/WAIT', downloadsdir + '/' + 'SSMS-Setup-ENU.exe'
  1300. , '/IAcceptSQLServerLicenseTerms'
  1301. //, 'SSMSInstallRoot=%systemdrive%\\Program Files (x86)\\Microsoft SQL Server\\140\\Tools\\Binn\\ManagementStudio'
  1302. ]]
  1303. , install : install
  1304. , exists : function(){
  1305. var self = this;
  1306. var installedpath = 'C:\\Program Files (x86)\\Microsoft SQL Server Management Studio 18\\Common7\\IDE\\Ssms.exe'
  1307. console.log('checking existence of ' + installedpath)
  1308. return Promise.resolve(existsSync(installedpath))
  1309. }
  1310. , preinstallsteps: function() {
  1311. var self = this;
  1312. console.log('smss 2018 preinstall steps')
  1313. var steps = [];
  1314. steps.push(
  1315. function(){
  1316. if (!existsSync(downloadsdir + '/' + self.installer)) {
  1317. console.log(self.url)
  1318. return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', ['"' + self.url + '"', downloadsdir + '/' + self.installer]
  1319. , { waitmsg : 'downloading '+ self.shellcmd +' please wait' })
  1320. }
  1321. else {
  1322. console.log(self.installer + ' Already exits Download skipped.')
  1323. return Promise.resolve(true)
  1324. }
  1325. }
  1326. )
  1327. return any(steps)
  1328. // return any([any(steps), any(prompts)])
  1329. }
  1330. }
  1331. , {
  1332. // C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\Ssms.exe
  1333. shellcmd: 'Ssms.exe', // SQL Mgmt Studo 2017
  1334. url: 'https://go.microsoft.com/fwlink/?linkid=2043154&clcid=0x409'
  1335. , installer: 'SSMS-Setup-ENU-2017.exe'
  1336. , installcmd: ['cmd', ['/c', 'start',
  1337. '/WAIT', downloadsdir + '/' + 'SSMS-Setup-ENU-2017.exe'
  1338. , '/IAcceptSQLServerLicenseTerms'
  1339. //, 'SSMSInstallRoot=%systemdrive%\\Program Files (x86)\\Microsoft SQL Server\\140\\Tools\\Binn\\ManagementStudio'
  1340. ]]
  1341. , install : install
  1342. , exists : function(){
  1343. return Promise.resolve(false)
  1344. var self = this;
  1345. // var installedpath = 'C:\\Program Files (x86)\\Microsoft SQL Server Management Studio 18\\Common7\\IDE\\Ssms.exe'
  1346. var installedpath = 'C:\\Program Files (x86)\\Microsoft SQL Server\\140\\Tools\\Binn\\ManagementStudio\\Ssms.exe'
  1347. console.log('checking existence of ' + installedpath)
  1348. return Promise.resolve(existsSync(installedpath))
  1349. }
  1350. , preinstallsteps: function() {
  1351. var self = this;
  1352. console.log('smss 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. var icf = fs.readFileSync( 'installchoices.js')
  1470. icf = icf.replace('module.exports = ', 'icf = ')
  1471. console.log(icf)
  1472. try {
  1473. icf = eval(icf)
  1474. }
  1475. catch(e) {
  1476. console.error(e)
  1477. }
  1478. // console.log(icf.reposerver)
  1479. instanceName = icf.instanceName
  1480. reposerver = icf.reposerver;
  1481. gitUser = icf.gitUser;
  1482. gitEmail = icf.gitEmail
  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. return resetgitconfig().then(function(){
  1508. var ifns = [
  1509. ['git', ['clone', reposerver + '/chess/elxr'] ]
  1510. ]
  1511. if(existsSyncFolder( selectedinstance.root + '\\elxr')) {
  1512. if(existsSyncFolder( selectedinstance.root + '\\elxr\\.git')) {
  1513. // PB : TODO -- use a elxr guid signature to detect more reliably folders named the same that is not us.
  1514. ifns = [ ['git', ['pull'], { cwd : selectedinstance.root + '\\elxr' } ] ]
  1515. }
  1516. else {
  1517. throw 'elxr subfolder not recognized as a git repository. Please cleanup and continue.'
  1518. }
  1519. }
  1520. else console.log(selectedinstance.root + '\\elxr' + ' NOT FOUND ')
  1521. var pkgjson = selectedinstance.root + '\\elxr\\package.json'
  1522. var pkgcontents = fs.readFileSync(pkgjson)
  1523. // PB : TODO -- Remove hardcode use proper replacement url..
  1524. fs.writeFileSync( pkgjson, pkgcontents.replace(/http\:\/\/git\.bbh/g, reposerver));
  1525. ifns.push(['npm', ['i'], { cwd : '.\\elxr' } ])
  1526. if(!ifns.map) ifns.map = map;
  1527. return any(ifns.map(callsheltask))['catch'](function(e){
  1528. if(e.code === 1602) {
  1529. console.warn("Installation was probably cancelled.")
  1530. }
  1531. else throw e
  1532. })
  1533. })
  1534. } )
  1535. }
  1536. var ifns = [ self.installcmd ]
  1537. if(!ifns.map) ifns.map = map;
  1538. return installIfNotExists().then(function(){
  1539. return any(ifns.map(callsheltask))['catch'](function(e){
  1540. if(e.code === 1602) {
  1541. console.warn("Installation was probably cancelled.")
  1542. }
  1543. else throw e
  1544. })
  1545. })
  1546. }
  1547. , install: function () {
  1548. var self = this;
  1549. console.log('Elxr Install called')
  1550. // PB : TODO -- detect external or internal and change elxr package.json dependencies to point to proper location.
  1551. fs.writeFileSync(selectedinstance.root + '\\ei.bat', 'cmd /c node ' + selectedinstance.root + '\\elxr\\index.js i ' + instanceName)
  1552. return any([ self.preinstallsteps, function(){ return self.installsteps() }
  1553. , nodeShellExec('start', ['/WAIT', '""', '"' + selectedinstance.root + '\\ei.bat' + '"'])
  1554. // , nodeShellExec('start', ['/WAIT', '""', '"C:\\Program Files\\Git\\bin\\sh.exe"', '-c', '"node ' + (selectedinstance.root + '\\elxr\\index.js').replace(/\\/g, '/') + ' i elixir"'])
  1555. // , nodeShellExec('node', [selectedinstance.root + 'elxr\\index.js'])
  1556. ])
  1557. // return any([ /*self.preinstallsteps,*/ function(){ return self.installsteps() }
  1558. // , nodeShellExec('node', [selectedinstance.root + '\\elxr\\index.js', 'init'])
  1559. // // , nodeShellExec('node', [selectedinstance.root + 'elxr\\index.js'])
  1560. // ])
  1561. }
  1562. // , exists : function(){
  1563. // console.log('Elxr PreInstallsteps called')
  1564. // var ifns = [ ['git', ['clone', 'http://git.bbh/chess\\elxr'] ] ]
  1565. // if(existsSyncFolder( selectedinstance.root + '\\elxr')) {
  1566. // if(existsSyncFolder( selectedinstance.root + '\\elxr\\.git')) {
  1567. // // PB : TODO -- use a elxr guid signature to detect more reliably folders named the same that is not us.
  1568. // ifns = [ ['git', ['pull'], { cwd : selectedinstance.root + '\\elxr' } ] ]
  1569. // }
  1570. // else {
  1571. // throw 'elxr subfolder not recognized as a git repository. Please cleanup and continue.'
  1572. // }
  1573. // }
  1574. // else console.log(selectedinstance.root + '\\elxr' + ' NOT FOUND ')
  1575. // if(!ifns.map) ifns.map = map;
  1576. // return any(ifns.map(callsheltask))['catch'](function(e){
  1577. // if(e.code === 1602) {
  1578. // console.warn("Installation was probably cancelled.")
  1579. // }
  1580. // else throw e
  1581. // })
  1582. // }
  1583. , exists : exists
  1584. }
  1585. ]
  1586. if(!prerequisites.forEach) prerequisites.forEach = forEach;
  1587. // nodeShellExec(selectedinstance.root + '/.elxr/run-' + '1629889572461' + '/download.bat'
  1588. // , ['https://github.com/git-for-windows/git/releases/download/v2.31.0.windows.1/Git-2.32.0.2-64-bit.exe'
  1589. // , downloadsdir + '/' + 'Git-2.32.0.2-64-bit.exe']).start()
  1590. promises.push(verifyAndInstallPrerequisites())
  1591. startPromises();
  1592. }