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.

i.win.js 65KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768
  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. try {
  1042. // Load just in case someone was smart enough to fill in before install.
  1043. var icf = fs.readFileSync( 'installchoices.js')
  1044. icf = icf.replace('module.exports = ', 'icf = ')
  1045. console.log(icf)
  1046. icf = eval(icf)
  1047. // console.log(icf.reposerver)
  1048. instanceName = icf.instanceName
  1049. reposerver = icf.reposerver;
  1050. gitUser = icf.gitUser;
  1051. gitEmail = icf.gitEmail
  1052. }
  1053. catch(e) {
  1054. console.error(e)
  1055. }
  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. 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. }