|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------- |
|
|
// -------------------------------------------- |
|
|
|
|
|
|
|
|
var selectedinstance = { root : path.resolve(".") } |
|
|
|
|
|
|
|
|
// PB : TODO -- This should be parent dir if elxr is already installed. |
|
|
|
|
|
var selectedinstance = { root : path.resolve(".") } |
|
|
__main(selectedinstance) |
|
|
__main(selectedinstance) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function __main( selectedinstance ){ |
|
|
function __main( selectedinstance ){ |
|
|
var downloadsdir = selectedinstance.root + '/Downloads'; |
|
|
var downloadsdir = selectedinstance.root + '/Downloads'; |
|
|
|
|
|
|
|
|
var callsheltask = function(args) { return function() { return nodeShellExec.apply(null, args) } } |
|
|
|
|
|
|
|
|
var callsheltask = function(args) { |
|
|
|
|
|
// console.log('callsheltask : ' + args) |
|
|
|
|
|
return function() { |
|
|
|
|
|
return nodeShellExec.apply(null, args) } } |
|
|
var gitUser = 'guest'; |
|
|
var gitUser = 'guest'; |
|
|
var gitEmail = 'guest@bbh.org.in'; |
|
|
var gitEmail = 'guest@bbh.org.in'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// , nodeShellExec('set', [/*'/m',*/ 'PATH', '"%PATH%;' + newpath + '"' ]) |
|
|
// , nodeShellExec('set', [/*'/m',*/ 'PATH', '"%PATH%;' + newpath + '"' ]) |
|
|
] ); |
|
|
] ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var getCmdString = function(args){ return args[0] + ' ' + args[1].join(' ') } |
|
|
|
|
|
|
|
|
|
|
|
var getgitshelltask = function(args, onEachError) { return function(){ |
|
|
|
|
|
console.log('----------getgitshelltask--------------called') |
|
|
|
|
|
return nodeShellExec( "cmd", ['/c', getCmdString(args)], args[2]) |
|
|
|
|
|
// .catch( onEachError || function(e){ console.error(e) }) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
var prerequisites = [ |
|
|
var prerequisites = [ |
|
|
{ |
|
|
{ |
|
|
shellcmd: 'git', |
|
|
shellcmd: 'git', |
|
|
|
|
|
|
|
|
console.log('Git preinstall steps') |
|
|
console.log('Git preinstall steps') |
|
|
|
|
|
|
|
|
var 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(){ |
|
|
|
|
|
// // 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(){ |
|
|
|
|
|
// 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( |
|
|
steps.push( |
|
|
function(){ |
|
|
function(){ |
|
|
if (!existsSync(downloadsdir + '/' + self.installer)) { |
|
|
if (!existsSync(downloadsdir + '/' + self.installer)) { |
|
|
|
|
|
|
|
|
, install: function () { |
|
|
, install: function () { |
|
|
var self = this; |
|
|
var self = this; |
|
|
console.log('Git Install called') |
|
|
console.log('Git Install called') |
|
|
return any([ /*self.preinstallsteps,*/ function(){ return self.installsteps() }, function(){ return self.postinstallsteps() } ]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var createTasq = function(args, shellT, onEachError) { |
|
|
|
|
|
var tasq = shellT ? shellT(args) : ( function(){ |
|
|
|
|
|
console.log('sdsfdsdf ' + args) |
|
|
|
|
|
return any([nodeShellExec.apply(null, args)]) |
|
|
|
|
|
// .catch( onEachError || function(e){ console.error(e) } ) |
|
|
|
|
|
}) |
|
|
|
|
|
tasq.toString = function(){ return JSON.stringify(args)} |
|
|
|
|
|
return tasq; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var execserial = function(tasklist, task, shellT, onEachError){ |
|
|
|
|
|
var exec = function(taskArgs){ |
|
|
|
|
|
console.log('execcing ' + task) |
|
|
|
|
|
var thistask = task.concat(); |
|
|
|
|
|
thistask[1] = thistask[1].concat() |
|
|
|
|
|
thistask[1].push.apply(thistask[1], taskArgs) |
|
|
|
|
|
return createTasq(thistask, shellT) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
tasklist.map = map |
|
|
|
|
|
console.log('execlist ' + tasklist.map(exec)) |
|
|
|
|
|
return any(tasklist.map(exec)) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function resetgitconfig(){ |
|
|
|
|
|
|
|
|
|
|
|
// https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage |
|
|
|
|
|
// Git Credential storage... |
|
|
|
|
|
// git config --global credential.helper 'store --file ~/.gitcredentials' |
|
|
|
|
|
// git credential-store --file ~/.gitcredentials store |
|
|
|
|
|
// // notepad C:/Program Files/Git/etc/gitconfig |
|
|
|
|
|
// git config --global --unset credential |
|
|
|
|
|
// git config --edit --system |
|
|
|
|
|
// git config --global credential.helper "store --file ~/gitcredentials" |
|
|
|
|
|
// git credential fill |
|
|
|
|
|
// git credential-store --file ~/git.store store |
|
|
|
|
|
|
|
|
|
|
|
// Find system git config |
|
|
|
|
|
// git config --global --edit |
|
|
|
|
|
// git config --list --show-origin |
|
|
|
|
|
// git config --list --show-origin --show-scope |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// https://stackoverflow.com/questions/35942754/how-can-i-save-username-and-password-in-git |
|
|
|
|
|
// Recipie |
|
|
|
|
|
// git config --global --unset credentials.helper |
|
|
|
|
|
// cd /path/to/my/repo |
|
|
|
|
|
// git config --unset credential.helper |
|
|
|
|
|
// git config credential.helper 'store --file ~/.git_repo_credentials' |
|
|
|
|
|
// git config credential.*.username my_user_name |
|
|
|
|
|
// git config credential.https://gitlab.com.username my_user_name |
|
|
|
|
|
|
|
|
|
|
|
// git credential fill |
|
|
|
|
|
// git config --global credential.modalprompt false // doesnst work. |
|
|
|
|
|
// core askpass = ;;; https://stackoverflow.com/questions/37182847/how-do-i-disable-git-credential-manager-for-windows |
|
|
|
|
|
var options = { |
|
|
|
|
|
inherit: true, shell: true //, env: process.env |
|
|
|
|
|
, cwd: selectedinstance.root |
|
|
|
|
|
// , runas: processedArgs.runas |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var task = ['git', ['config'], options] |
|
|
|
|
|
|
|
|
|
|
|
var tasklist = [ |
|
|
|
|
|
// ['--global', '--unset credentials.helper'] |
|
|
|
|
|
// ['--unset', 'credentials.helper'] |
|
|
|
|
|
// , |
|
|
|
|
|
// ['credential.helper', `'store --file git_repo_credentials'`] |
|
|
|
|
|
['--global', 'credential.helper', "'store --file ~/.git_repo_credentials'"] |
|
|
|
|
|
, ['--global', '--replace-all', 'user.name', 'pb'] |
|
|
|
|
|
, ['--global', '--replace-all', 'user.email', 'pradeep@bbh.org.in'] |
|
|
|
|
|
|
|
|
|
|
|
// , ['--list'] |
|
|
|
|
|
// , ['credential', 'fill'] |
|
|
|
|
|
] |
|
|
|
|
|
var onEachError = function(e) { console.error( e.messages.join('\n') + e.result + '\n' + util.inspect(e) + '\n') } |
|
|
|
|
|
var shellT = function(args) { |
|
|
|
|
|
return getgitshelltask(args, onEachError) |
|
|
|
|
|
// .catch(e => console.error( e.messages.join('\n') + e.result + '\n' + util.inspect(e) + '\n' + tasq.toString()) ) |
|
|
|
|
|
} |
|
|
|
|
|
execserial(tasklist, task, shellT, onEachError ) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return any([ /*self.preinstallsteps,*/ |
|
|
|
|
|
function(){ return self.installsteps() } |
|
|
|
|
|
, function() { resetgitconfig() } |
|
|
|
|
|
, function(){ return self.postinstallsteps() } |
|
|
|
|
|
]) |
|
|
} |
|
|
} |
|
|
, verifyAndInstall : function(){ |
|
|
, verifyAndInstall : function(){ |
|
|
var self = this; |
|
|
var self = this; |
|
|
|
|
|
|
|
|
, installcmd: ['MSIEXEC.exe', ['/i' |
|
|
, installcmd: ['MSIEXEC.exe', ['/i' |
|
|
, path.normalize(downloadsdir + '/' + 'python-2.7.18.amd64.msi') |
|
|
, path.normalize(downloadsdir + '/' + 'python-2.7.18.amd64.msi') |
|
|
, 'ACCEPT=YES', '/passive']] |
|
|
, 'ACCEPT=YES', '/passive']] |
|
|
|
|
|
// , preinstallsteps : function() { return Promise.resolve(true) } |
|
|
, preinstallsteps: function() { |
|
|
, preinstallsteps: function() { |
|
|
var self = this; |
|
|
var self = this; |
|
|
console.log(self.shellcmd + ' preinstall steps') |
|
|
console.log(self.shellcmd + ' preinstall steps') |
|
|
|
|
|
|
|
|
, { |
|
|
, { |
|
|
shellcmd: 'code' |
|
|
shellcmd: 'code' |
|
|
, optional : true |
|
|
, optional : true |
|
|
, url: 'https://az764295.vo.msecnd.net/stable/c722ca6c7eed3d7987c0d5c3df5c45f6b15e77d1/VSCodeUserSetup-x64-1.65.2.exe' |
|
|
|
|
|
|
|
|
, url: 'https://code.visualstudio.com/sha/download?build=stable&os=win32-x64-user' |
|
|
, installer: 'VSCodeUserSetup-x64-1.65.2.exe' |
|
|
, installer: 'VSCodeUserSetup-x64-1.65.2.exe' |
|
|
, installcmd: ['cmd', ['/c', 'start', |
|
|
, installcmd: ['cmd', ['/c', 'start', |
|
|
'/WAIT', downloadsdir + '/' + 'VSCodeUserSetup-x64-1.65.2.exe' |
|
|
'/WAIT', downloadsdir + '/' + 'VSCodeUserSetup-x64-1.65.2.exe' |
|
|
, '/VERYSILENT' |
|
|
, '/VERYSILENT' |
|
|
// , '/MERGETASKS=!runcode' // This is required only for vscode... |
|
|
// , '/MERGETASKS=!runcode' // This is required only for vscode... |
|
|
]] |
|
|
]] |
|
|
|
|
|
// , preinstallsteps : function() { return Promise.resolve(true) } |
|
|
, preinstallsteps: function() { |
|
|
, preinstallsteps: function() { |
|
|
var self = this; |
|
|
var self = this; |
|
|
console.log(self.shellcmd + ' preinstall steps') |
|
|
console.log(self.shellcmd + ' preinstall steps') |
|
|
|
|
|
|
|
|
, exists : exists |
|
|
, exists : exists |
|
|
} |
|
|
} |
|
|
, { |
|
|
, { |
|
|
shellcmd: 'elxr' |
|
|
|
|
|
|
|
|
shellcmd: 'elxr' |
|
|
, installcmd: [ isWin() ? 'npm.cmd' : 'npm' , ['link'], { cwd : selectedinstance.root + '\\elxr' /* cwd should be the cloned dir*/}] |
|
|
, installcmd: [ isWin() ? 'npm.cmd' : 'npm' , ['link'], { cwd : selectedinstance.root + '\\elxr' /* cwd should be the cloned dir*/}] |
|
|
, preinstallsteps: function() { |
|
|
, preinstallsteps: function() { |
|
|
var self = this; |
|
|
var self = this; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var steps = []; |
|
|
var steps = []; |
|
|
steps.push( |
|
|
steps.push( |
|
|
function(){ |
|
|
|
|
|
console.log('Elxr PreInstallsteps called') |
|
|
|
|
|
var ifns = [ ['git', ['clone', 'http://git.bbh/chess\\elxr'] ] ] |
|
|
|
|
|
if(existsSyncFolder( selectedinstance.root + '\\elxr')) { |
|
|
|
|
|
if(existsSyncFolder( selectedinstance.root + '\\elxr\\.git')) { |
|
|
|
|
|
// PB : TODO -- use a elxr guid signature to detect more reliably folders named the same that is not us. |
|
|
|
|
|
ifns = [ ['git', ['pull'], { cwd : selectedinstance.root + '\\elxr' } ] ] |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
throw 'elxr subfolder not recognized as a git repository. Please cleanup and continue.' |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else console.log(selectedinstance.root + '\\elxr' + ' NOT FOUND ') |
|
|
|
|
|
if(!ifns.map) ifns.map = map; |
|
|
|
|
|
return any(ifns.map(callsheltask))['catch'](function(e){ |
|
|
|
|
|
if(e.code === 1602) { |
|
|
|
|
|
console.warn("Installation was probably cancelled.") |
|
|
|
|
|
} |
|
|
|
|
|
else throw e |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
) |
|
|
) |
|
|
return any([any(steps)]) |
|
|
return any([any(steps)]) |
|
|
} |
|
|
} |
|
|
, installsteps: function () { |
|
|
, installsteps: function () { |
|
|
var self = this; |
|
|
var self = this; |
|
|
console.log('Elxr Installsteps called') |
|
|
console.log('Elxr Installsteps called') |
|
|
var ifns = [self.installcmd] |
|
|
|
|
|
if(!ifns.map) ifns.map = map; |
|
|
|
|
|
return any(ifns.map(callsheltask))['catch'](function(e){ |
|
|
|
|
|
if(e.code === 1602) { |
|
|
|
|
|
console.warn("Installation was probably cancelled.") |
|
|
|
|
|
|
|
|
var installIfNotExists = function(){ |
|
|
|
|
|
console.log('Elxr PreInstallsteps called') |
|
|
|
|
|
var ifns = [ ['git', ['clone', 'http://git.bbh/chess/elxr'] ] ] |
|
|
|
|
|
if(existsSyncFolder( selectedinstance.root + '\\elxr')) { |
|
|
|
|
|
if(existsSyncFolder( selectedinstance.root + '\\elxr\\.git')) { |
|
|
|
|
|
// PB : TODO -- use a elxr guid signature to detect more reliably folders named the same that is not us. |
|
|
|
|
|
ifns = [ ['git', ['pull'], { cwd : selectedinstance.root + '\\elxr' } ] ] |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
throw 'elxr subfolder not recognized as a git repository. Please cleanup and continue.' |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
else throw e |
|
|
|
|
|
|
|
|
else console.log(selectedinstance.root + '\\elxr' + ' NOT FOUND ') |
|
|
|
|
|
if(!ifns.map) ifns.map = map; |
|
|
|
|
|
return any(ifns.map(callsheltask))['catch'](function(e){ |
|
|
|
|
|
if(e.code === 1602) { |
|
|
|
|
|
console.warn("Installation was probably cancelled.") |
|
|
|
|
|
} |
|
|
|
|
|
else throw e |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
var ifns = [ self.installcmd ] |
|
|
|
|
|
if(!ifns.map) ifns.map = map; |
|
|
|
|
|
return installIfNotExists().then(function(){ |
|
|
|
|
|
return any(ifns.map(callsheltask))['catch'](function(e){ |
|
|
|
|
|
if(e.code === 1602) { |
|
|
|
|
|
console.warn("Installation was probably cancelled.") |
|
|
|
|
|
} |
|
|
|
|
|
else throw e |
|
|
|
|
|
}) |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
, install: function () { |
|
|
, install: function () { |
|
|
var self = this; |
|
|
var self = this; |
|
|
console.log('Elxr Install called') |
|
|
console.log('Elxr Install called') |
|
|
return any([ /*self.preinstallsteps,*/ function(){ return self.installsteps() } ]) |
|
|
|
|
|
|
|
|
return any([ /*self.preinstallsteps,*/ function(){ return self.installsteps() } |
|
|
|
|
|
, nodeShellExec('node', [selectedinstance.root + '\\elxr\\index.js', 'init']) |
|
|
|
|
|
// , nodeShellExec('node', [selectedinstance.root + 'elxr\\index.js']) |
|
|
|
|
|
]) |
|
|
} |
|
|
} |
|
|
// , exists : function(){ |
|
|
// , exists : function(){ |
|
|
// console.log('Elxr PreInstallsteps called') |
|
|
// console.log('Elxr PreInstallsteps called') |