Ver código fonte

Merge branch 'master' of http://git.bbh/chess/elxr

pull/9/head
pb 2 anos atrás
pai
commit
1ca13b7610
2 arquivos alterados com 172 adições e 47 exclusões
  1. 155
    46
      i.win.js
  2. 17
    1
      index.js

+ 155
- 46
i.win.js Ver arquivo

@@ -59,7 +59,8 @@ try {

// --------------------------------------------

var selectedinstance = { root : path.resolve(".") }
// PB : TODO -- This should be parent dir if elxr is already installed.
var selectedinstance = { root : path.resolve(".") }
__main(selectedinstance)


@@ -789,7 +790,10 @@ catch(e) {
function __main( selectedinstance ){
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 gitEmail = 'guest@bbh.org.in';

@@ -936,6 +940,15 @@ function __main( selectedinstance ){
// , 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 = [
{
shellcmd: 'git',
@@ -951,20 +964,20 @@ function __main( selectedinstance ){
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(){
// // 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(
function(){
if (!existsSync(downloadsdir + '/' + self.installer)) {
@@ -1024,7 +1037,95 @@ function __main( selectedinstance ){
, install: function () {
var self = this;
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(){
var self = this;
@@ -1113,6 +1214,7 @@ function __main( selectedinstance ){
, installcmd: ['MSIEXEC.exe', ['/i'
, path.normalize(downloadsdir + '/' + 'python-2.7.18.amd64.msi')
, 'ACCEPT=YES', '/passive']]
// , preinstallsteps : function() { return Promise.resolve(true) }
, preinstallsteps: function() {
var self = this;
console.log(self.shellcmd + ' preinstall steps')
@@ -1155,13 +1257,14 @@ function __main( selectedinstance ){
, {
shellcmd: 'code'
, 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'
, installcmd: ['cmd', ['/c', 'start',
'/WAIT', downloadsdir + '/' + 'VSCodeUserSetup-x64-1.65.2.exe'
, '/VERYSILENT'
// , '/MERGETASKS=!runcode' // This is required only for vscode...
]]
// , preinstallsteps : function() { return Promise.resolve(true) }
, preinstallsteps: function() {
var self = this;
console.log(self.shellcmd + ' preinstall steps')
@@ -1202,7 +1305,7 @@ function __main( selectedinstance ){
, exists : exists
}
, {
shellcmd: 'elxr'
shellcmd: 'elxr'
, installcmd: [ isWin() ? 'npm.cmd' : 'npm' , ['link'], { cwd : selectedinstance.root + '\\elxr' /* cwd should be the cloned dir*/}]
, preinstallsteps: function() {
var self = this;
@@ -1210,46 +1313,52 @@ function __main( selectedinstance ){

var steps = [];
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)])
}
, installsteps: function () {
var self = this;
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 () {
var self = this;
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(){
// console.log('Elxr PreInstallsteps called')

+ 17
- 1
index.js Ver arquivo

@@ -2114,6 +2114,16 @@ var cmds = {
, requiresElevation : true
, requires : [ generateDependencies ]
}
, init : {
// return a interpreted set of arguments for this comd run context.
cmdFn : init
, interpret() { return { cmd : 'init' } }
, getPossiblePrompts(){ return {} }
, noprerequisites : true
, independentcmd : true
, requiresElevation : true
, requires : [ generateDependencies ]
}
, switch : {
interpret() {
return { cmd : subcommandlabels['switch'], runchoice : 'c', username : processedArgs._[2]
@@ -2646,6 +2656,7 @@ var instanceData = (function(){
, commonInstance(selected) { return __acquireData(selected, defaultRepoOwner
// , function(e){ console.info('This is probably an error unless the user is asking to create a new instance with this name.') }
) }
, genericChessInstance(selected) { return __acquireData(selected) }
}
})()

@@ -2660,6 +2671,11 @@ function reinit(){
resetgitconfig()
}

function init(){
sysAddPathVar('%AppData%\\npm')
resetgitconfig()
}


function resetgitconfig(){
@@ -2736,7 +2752,7 @@ var execserial = function(tasklist, task, shellT){
return any(tasklist.map(exec))
}

var execone = function(taskArgs, task){ return any([task[1].push.apply(task[1], taskArgs)].map(createTasq)) }
var execonce = function(taskArgs, task){ return any([task[1].push.apply(task[1], taskArgs)].map(createTasq)) }


var __acquireConfig = function (selected, owner, clusternodename, configrepo, errHandler) {

Carregando…
Cancelar
Salvar