Parcourir la source

Windwos installer

master
chess il y a 3 ans
Parent
révision
9d26691f1e
1 fichiers modifiés avec 205 ajouts et 169 suppressions
  1. 205
    169
      i.win.js

+ 205
- 169
i.win.js Voir le fichier

@@ -143,8 +143,8 @@ catch(e){
}
var handleNext = function(){
console.log('Task finished with result : ')
console.dir(pVal)
// console.log('Task finished with result : ')
// console.dir(pVal)
if(i>0 && a[i-1].info) console.dir(a[i-1].info)
if(!tasq && !continueOnFailure) { console.log('Error : No task specified.'); throw false;}
else if(!tasq) { console.log('Error : No task specified.'); return false;}
@@ -208,7 +208,7 @@ catch(e){
var existsSync = function(filepath){ return fso.FileExists(filepath) }
var fs = {
writeFileSync : function(filepath, text) {
console.log(filepath)
// console.log(filepath)
var fh = fso.CreateTextFile(filepath, true);
fh.WriteLine(text);
fh.Close();
@@ -268,6 +268,33 @@ catch(e){
var objShell = WScript.createobject("wscript.shell")
var oExec = objShell.Exec(cmd + ' ' + argstr.join(' '))
var result = {}
var shellresult = { shell : objShell, result : result }

var WshRunning = 0
var WshFinished = 1
var WshFailed = 2
while(oExec.Status === WshRunning){
WScript.StdOut.write('.')
WScript.Sleep(500)
}
var strOutput = ''
switch(oExec.Status) {
case WshFinished :
strOutput = oExec.StdOut.ReadAll()
result.success = true;
result.code = 0
break;
case WshFailed :
strOutput = oExec.StdErr.ReadAll()
result.success = false;
result.code = WshFailed
break;
default : strOutput = 'failed'
break;
}
result.result = command + ' ' + cargs + ' exited with code ' + result.code
result.messages = [strOutput]
// WScript.Echo(oExec.Status)
// WScript.Echo(oExec.ProcessID)
// WScript.Echo(oExec.ExitCode)
@@ -275,24 +302,25 @@ catch(e){
// console.log(objShell.StdOut.ReadAll)
// console.log(objShell.StdErr.ReadAll)

return objShell;
return shellresult;
}

var p = null;
var pworker = function(resolve, reject){
// console.dir(p)
var pfx = selectedinstance.root + '/.elxr/run-' + runtimestamp + '/' + stampedFilePfx(new Date())
console.log('p.chain.length ================ ' + p.chain.length)
// console.log('p.chain.length ================ ' + p.chain.length)
options = options || {
runFile : path.normalize( pfx + "out.txt")
// runFile : null
}
runFile = options.runFile
var runFile = null;
// var runFile = options.runFile
// var runFile = selectedinstance.root + '\\' + stampedFilePfx(new Date()) + command + cargs + "out.txt";
console.log(runFile)
// console.log(runFile)
var args = cargs.concat()
// runFile ? (args.push(">"), args.push(runFile)) : cargs
console.log(command + ' ' + args.join(' '))
// console.log(command + ' ' + args.join(' '))

// command = 'cmd'
// args = ['/c', 'start',
@@ -303,7 +331,7 @@ catch(e){


var runbat = path.normalize(pfx + "run.bat")
console.log('runbat : ' + runbat)
// console.log('runbat : ' + runbat)
fs.writeFileSync(runbat, command + ' ' + args.join(' ') + ' \r\n' + 'echo done > ' + runFile )
// fs.writeFileSync(runFile, 'started')
// WScript.Quit()
@@ -315,31 +343,25 @@ catch(e){
// shellExec( command, args)
// // cmd /b /c
// }, 500) }
shellExec( 'cmd', ['/c', runbat])
// shellExec( command, args)

console.log(options.waitmsg || ('awaiting ' + command + ' ' + args.join(' ')))
// var shellresult = shellExec( 'cmd', ['/c', runbat])
var shellresult = shellExec( command, args)
var wrapup = function() {
console.log('Wrapping up')
var wrapup = function(result) {
// console.log('Wrapping up')
try {
var strFileText = fs.readFileSync(runFile)
var messages = [];
messages.push(strFileText)
var result = { result : command + ' ' + cargs + ' exited with code ???', messages : messages, code : 0, success : true }
console.log('resolving'); console.dir(result)
resolve(result)
// fs.unlinkSync(runFile)
}
catch(e){
// console.dir(e)
if(e.message === 'Input past end of file') {
var result = { result : 'cmd /c ' + command + ' ' + cargs + " > " + runFile + ' exited with code ???', messages : [] , code : 0, success : false }
// console.log('resolving'); console.dir(result)
resolve(result)
// fs.unlinkSync(runFile)
}
else {
// fs.unlinkSync(runFile)
reject(e)
}
}
@@ -347,14 +369,25 @@ catch(e){

if(runFile){
var waitr = function(){
console.log('awiting output : ' + runFile)
if(existsSync(runFile)) return wrapup()
WScript.StdOut.write('.')
if(existsSync(runFile)) {
var strOutput = fs.readFileSync(runFile)
shellresult.result.messages = [strOutput]
wrapup(shellresult.result)
sfs.unlinkSync(runFile)
}
wait( waitr, 500)
}
console.log(wait)
// console.log(wait)
wait( waitr, 500)
}
else wrapup()
else {
// console.log('There is no runfile.')
// console.log(shellresult.strOutput)
wrapup(shellresult.result)
}
}
p = new Promise(pworker)
// promises.push(p)
@@ -416,7 +449,7 @@ function createPromiseClass(overrides) {
}
else {
// console.log( 'result is value waiting for promisechain' )
console.dir(result)
// console.dir(result)
return p.processchain(result)
}
};
@@ -427,7 +460,7 @@ function createPromiseClass(overrides) {
var i = __i;
var __e = null;
p = this;
console.log('processchain chain.length : ' + p.chain.length)
// console.log('processchain chain.length : ' + p.chain.length)

function __processchain(r){

@@ -445,7 +478,8 @@ function createPromiseClass(overrides) {
p.result.start()
// console.log(p.result.fn + ' ------------------ ')
waitForResult(p.result, function(r){
console.log('we waited')
// console.log('we waited')
// WScript.write('.')
p.result = r; i++; __i = i;
waitForThen(p)
})
@@ -509,7 +543,7 @@ function createPromiseClass(overrides) {
then : function(thenfn){
// console.log('Adding then')
thenfn.isThen = true
if(Object.prototype.toString.call(p.chain) !== '[object Array]') console.dir(p.chain)
// if(Object.prototype.toString.call(p.chain) !== '[object Array]') console.dir(p.chain)
p.chain.push(thenfn)
return p;
}
@@ -648,8 +682,8 @@ function createPromiseClass(overrides) {
}
}
if(allResolved) {
console.log('All Reseloved')
console.dir(results)
// console.log('All Reseloved')
// console.dir(results)
resolve(results)
}
else wait(allwaitr, 500)
@@ -729,11 +763,12 @@ function __main( selectedinstance ){
var installtasks = [];
prerequisites.forEach(function(preq) {
var p = preq.exists().then(function(exists) {
if (exists && false) console.log( preq.shellcmd + ' exists');
if (exists) console.log( preq.shellcmd + ' exists');
else {
console.log(exists)
console.log(preq.shellcmd + ' is not installed');
return preq.preinstallsteps().then(function(){
console.log(' task.install : ' + preq.install)
// console.log(' task.install : ' + preq.install)
installtasks.push( function(){ return preq.install() } );
})
}
@@ -744,7 +779,7 @@ function __main( selectedinstance ){
// console.log('downloadtasks')
// console.dir(downloadtasks[0])
var p = Promise.all(downloadtasks).then(function(){
console.log('calling install tasks : ' + installtasks.length)
// console.log('calling install tasks : ' + installtasks.length)
return any(installtasks) })

// console.log('Promise.all.chain : ' + p.chain)
@@ -766,142 +801,142 @@ function __main( selectedinstance ){
// }

var prerequisites = [
// {
// shellcmd: 'git',
// url: 'https://github.com/git-for-windows/git/releases/download/v2.33.0.windows.2/Git-2.33.0.2-64-bit.exe'
// , installer: 'Git-2.33.0.2-64-bit.exe'
// , installcmd: ['cmd', ['/c', 'start',
// '/WAIT', downloadsdir + '/' + 'Git-2.33.0.2-64-bit.exe'
// , '/VERYSILENT'
// // , '/MERGETASKS=!runcode' // This is required only for vscode...
// ]]
// , preinstallsteps: function() {
// var self = this;
// console.log('Git preinstall steps')
// var steps = [];
// steps.push(
// function(){
// // console.log('cli prompt steps')
// var choices = { 0 : 'guest', 1 : 'chessdemo' }
// return cli.prompt(choices, 'git user name', gitUser).then(function(choice){ gitUser = choice } )
// }
// )
// steps.push(
// function(){
// var choices = { 0 : 'guest@bbh.org.in', 1 : 'chessdemo@bbh.org.in' }
// return cli.prompt(choices, 'git user email', gitEmail).then(function(choice){ gitEmail = choice })
// }
// )
// steps.push(
// function(){
// if (!existsSync(downloadsdir + '/' + self.installer)) {
// return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', [self.url, downloadsdir + '/' + self.installer])
// }
// else {
// console.log(self.installer + ' Already exits Download skipped.')
// return Promise.resolve(true)
// }
// }
// )
// return any(steps)
// // return any([any(steps), any(prompts)])
// }
// , installsteps: function () {
// var self = this;
// console.log('Git Installsteps called')
// var ifns = [self.installcmd]
// ifns.map = map;
// return any(ifns.map(callsheltask))['catch'](function(e){
// if(e.code === 1602) {
// console.warn("Installation was probably cancelled.")
// }
// else throw e
// })
// }
// , postinstallsteps: function(){
// // PB : TODO -- Detect failure or cancellation before attenpting postinstall steps...
// var steps = [];
// steps.push(
// function(){
// var choices = { 0 : 'guest', 1 : 'chessdemo' }
// return cli.prompt(choices, 'git user name', gitUser).then(function(choice){ gitUser = choice } )
// }
// )
// steps.push(
// function(){
// var choices = { 0 : 'guest@bbh.org.in', 1 : 'chessdemo@bbh.org.in' }
// return cli.prompt(choices, 'git user email', gitEmail).then(function(choice){ gitEmail = choice })
// }
// )
// return any(steps).then(function(){
// var steps = [
// ['git', ['config', '--global', '--add', 'user.name', gitUser]]
// , ['git', ['config', '--global', '--add', 'user.email', gitEmail]]
// ]
{
shellcmd: 'git',
url: 'https://github.com/git-for-windows/git/releases/download/v2.33.0.windows.2/Git-2.33.0.2-64-bit.exe'
, installer: 'Git-2.33.0.2-64-bit.exe'
, installcmd: ['cmd', ['/c', 'start',
'/WAIT', downloadsdir + '/' + 'Git-2.33.0.2-64-bit.exe'
, '/VERYSILENT'
// , '/MERGETASKS=!runcode' // This is required only for vscode...
]]
, preinstallsteps: function() {
var self = this;
console.log('Git preinstall steps')
var steps = [];
steps.push(
function(){
// console.log('cli prompt steps')
var choices = { 0 : 'guest', 1 : 'chessdemo' }
return cli.prompt(choices, 'git user name', gitUser).then(function(choice){ gitUser = choice } )
}
)
steps.push(
function(){
var choices = { 0 : 'guest@bbh.org.in', 1 : 'chessdemo@bbh.org.in' }
return cli.prompt(choices, 'git user email', gitEmail).then(function(choice){ gitEmail = choice })
}
)
steps.push(
function(){
if (!existsSync(downloadsdir + '/' + self.installer)) {
return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', [self.url, downloadsdir + '/' + self.installer])
}
else {
console.log(self.installer + ' Already exits Download skipped.')
return Promise.resolve(true)
}
}
)
return any(steps)
// return any([any(steps), any(prompts)])
}
, installsteps: function () {
var self = this;
console.log('Git Installsteps called')
var ifns = [self.installcmd]
ifns.map = map;
return any(ifns.map(callsheltask))['catch'](function(e){
if(e.code === 1602) {
console.warn("Installation was probably cancelled.")
}
else throw e
})
}
, postinstallsteps: function(){
// PB : TODO -- Detect failure or cancellation before attenpting postinstall steps...
var steps = [];
steps.push(
function(){
var choices = { 0 : 'guest', 1 : 'chessdemo' }
return cli.prompt(choices, 'git user name', gitUser).then(function(choice){ gitUser = choice } )
}
)
steps.push(
function(){
var choices = { 0 : 'guest@bbh.org.in', 1 : 'chessdemo@bbh.org.in' }
return cli.prompt(choices, 'git user email', gitEmail).then(function(choice){ gitEmail = choice })
}
)
return any(steps).then(function(){
var steps = [
['git', ['config', '--global', '--add', 'user.name', gitUser]]
, ['git', ['config', '--global', '--add', 'user.email', gitEmail]]
]
// steps.map = map;
// return any(steps.map(callsheltask)).then(function(){
// })
// });
// }
// , install: function () {
// var self = this;
// console.log('Git Install called')
// return any([ /*self.preinstallsteps,*/ function(){ return self.installsteps() }, function(){ return self.postinstallsteps() } ])
// }
// , verifyAndInstall : function(){
// var self = this;
// return self.exists().then( function(exits) {
// if(exists) return self.getUser(null, function(){ return self.postinstallsteps() } )
// else return self.install();
// })
// }
// , exists : function(next){
// var self = this;
// return getTaskCheckExists(self.shellcmd, { ignorefailures: true })().then(function(exists) {
// console.dir(exists)
// console.log(exists + ' git exists')
// if(exists && exists.messages.join(' ').indexOf(self.shellcmd) > -1 ) {
// return true;
// }
// else return false
// })
// }
// , getUser : function(repo, onNoResult){
steps.map = map;
return any(steps.map(callsheltask)).then(function(){
})
});
}
, install: function () {
var self = this;
console.log('Git Install called')
return any([ /*self.preinstallsteps,*/ function(){ return self.installsteps() }, function(){ return self.postinstallsteps() } ])
}
, verifyAndInstall : function(){
var self = this;
return self.exists().then( function(exits) {
if(exists) return self.getUser(null, function(){ return self.postinstallsteps() } )
else return self.install();
})
}
, exists : function(next){
var self = this;
return getTaskCheckExists(self.shellcmd, { ignorefailures: true })().then(function(exists) {
// console.dir(exists)
// console.log(exists + ' git exists')
if(exists && exists.messages.join(' ').indexOf(self.shellcmd) > -1 ) {
return true;
}
else return false
})
}
, getUser : function(repo, onNoResult){
// onNoResult = onNoResult || function(){return false}
// var globalOrLocal = '--global';
// if(!repo) globalOrLocal = '--global';
// else globalOrLocal = '--local'
// var fns = [['git', ['config', globalOrLocal, '--get-all', 'user.name']]]
// fns.map = map;
// return any(fns.map(callsheltask)).then(function(result){
// // not yet configured.
// if(!result.success) return onNoResult()
// else {
// var users = result.messages[0].trim().split('\n');
// if(users.length === 0 ||
// users.length === 1 && users[0] === 'guest') {
onNoResult = onNoResult || function(){return false}
var globalOrLocal = '--global';
if(!repo) globalOrLocal = '--global';
else globalOrLocal = '--local'
var fns = [['git', ['config', globalOrLocal, '--get-all', 'user.name']]]
fns.map = map;
return any(fns.map(callsheltask)).then(function(result){
// not yet configured.
if(!result.success) return onNoResult()
else {
var users = result.messages[0].trim().split('\n');
if(users.length === 0 ||
users.length === 1 && users[0] === 'guest') {
// return onNoResult()
// }
// else return users[0]; // PB : TODO == We should probably prompt with all the users available for selection !
// }
// })
// .pcatch(function(e){
// console.log(e)
// return onNoResult()
// })
// }
// }
// ,
return onNoResult()
}
else return users[0]; // PB : TODO == We should probably prompt with all the users available for selection !
}
})
.pcatch(function(e){
console.log(e)
return onNoResult()
})
}
}
,
{
shellcmd: 'node',
url: 'https://nodejs.org/dist/v14.17.6/node-v14.17.6-x64.msi'
@@ -924,7 +959,7 @@ function __main( selectedinstance ){
, exists : function(next){
var self = this;
return getTaskCheckExists(self.shellcmd, { ignorefailures: true })().then(function(exists) {
console.log(self.shellcmd + ' ' + exists + ' node exists')
// console.log(self.shellcmd + ' ' + exists + ' node exists')
if(exists && exists.messages.join(' ').indexOf(self.shellcmd) > -1 ) {
return true
}
@@ -942,7 +977,8 @@ function __main( selectedinstance ){
steps.push(
function(){
if (!existsSync(downloadsdir + '/' + self.installer)) {
return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', [self.url, downloadsdir + '/' + self.installer])
return nodeShellExec(selectedinstance.root + '/.elxr/run-' + runtimestamp + '/download.bat', [self.url, downloadsdir + '/' + self.installer]
, { waitmsg : 'downloading node please wait' })
}
else {
console.log(self.installer + ' Already exits Download skipped.')

Chargement…
Annuler
Enregistrer