| @@ -2496,7 +2496,7 @@ var shouldPrompt = function(k, mustPrompt, target){ | |||
| || reconfirm[k]) | |||
| } | |||
| var getBoundEachPrompt = function(target, mustPrompt, promptables, choices) { | |||
| var getBoundEachPrompt = function(target, mustPrompt, promptables, choices, promptsfilter) { | |||
| return function(prompts, k, i, a){ | |||
| @@ -2504,6 +2504,7 @@ var getBoundEachPrompt = function(target, mustPrompt, promptables, choices) { | |||
| // Confirm those that were not supplied as user choices in runtime args and proceed to reattempt. | |||
| // PB : TODO -- selectedinstance === __default check to prompt everything... | |||
| if( shouldPrompt(k, mustPrompt, target) ) { | |||
| delete reconfirm[k]; | |||
| // console.log(k) | |||
| // console.dir(mustPrompt); //console.dir(target) | |||
| prompts.push(async ()=>{ | |||
| @@ -2521,7 +2522,7 @@ var getBoundEachPrompt = function(target, mustPrompt, promptables, choices) { | |||
| } | |||
| } | |||
| var __interactive_prompts = function( target, choices ){ | |||
| var __interactive_prompts = function( target, choices, promptsfilter ){ | |||
| Object.defineProperty(target, 'node_env', { get : function(){ return this.instanceType } }); | |||
| @@ -2577,11 +2578,18 @@ var __interactive_prompts = function( target, choices ){ | |||
| return __interpreter.call(target) | |||
| } | |||
| } | |||
| , instanceName : { label : `Enter Instance Name ( <= ${target.instanceName || 'chess'} ) : `, choices : [], defaultchoice : 'chess'} | |||
| , instanceType : { label : `Enter Instance Type ( <= ${target.instanceType || 'development'} ) : `, choices : [], defaultchoice : 'development'} | |||
| , reposerver : { label : `Enter Instance Name ( <= ${target.reposerver || 'https://git.bbh.org.in'} ) : `, choices : [], defaultchoice : 'https://git.bbh.org.in'} | |||
| , username : { label : `Enter User Id for ${target.reposerver} ( <= ${target.username || 'chess'} ) : `, choices : [], defaultchoice : 'chess'} | |||
| , password : { label : `Enter Password for ${target.username} @ ${target.reposerver} ( <= ${target.password || ''} ) : `, choices : [], defaultchoice : ''} | |||
| , instanceName : { label : `Enter Instance Name ( <= ${target.instanceName || 'chess'} ) : ` | |||
| , choices : choices['instanceName'], defaultchoice : 'chess'} | |||
| , instanceType : { label : `Enter Instance Type ( <= ${target.instanceType || 'development'} ) : ` | |||
| , choices : choices['instanceType'], defaultchoice : 'development'} | |||
| , reposerver : { label : `Enter Instance Name ( <= ${target.reposerver || 'https://git.bbh.org.in'} ) : ` | |||
| , choices : choices['reposerver'], defaultchoice : 'https://git.bbh.org.in'} | |||
| , username : { label : `Enter User Id for ${target.reposerver} ( <= ${target.username || 'chess'} ) : ` | |||
| , choices : choices['username'], defaultchoice : 'chess'} | |||
| , password : { label : `Enter Password for ${target.username} @ ${target.reposerver} ( <= ${target.password || ''} ) : ` | |||
| , choices : choices['password'], defaultchoice : '***'} | |||
| , email : { label : `Enter Email for ${target.username} @ ${target.reposerver} ( <= ${target.email || ''} ) : ` | |||
| , choices : choices['email'], defaultchoice : 'guest@bbh.org.in'} | |||
| } | |||
| @@ -2590,8 +2598,8 @@ var __interactive_prompts = function( target, choices ){ | |||
| return promptkeys | |||
| } | |||
| var eachPrompt = getBoundEachPrompt( target, getPromptKeys() , interactionpoints, choices) | |||
| return Object.keys(interactionpoints).reduce(eachPrompt, []) | |||
| var eachPrompt = getBoundEachPrompt( target, getPromptKeys() , interactionpoints, choices, promptsfilter) | |||
| return Object.keys(promptsfilter || interactionpoints).reduce(eachPrompt, []) | |||
| } | |||
| @@ -2617,23 +2625,25 @@ var prerequisites = [ | |||
| } | |||
| ] | |||
| var prompts = this.getuser(null, ()=>{ | |||
| console.log('preinstallsteps') | |||
| var gitUser = 'guest'; | |||
| var gitEmail = 'guest@bbh.org.in'; | |||
| var prompts = []; | |||
| prompts.push( ()=>{ return cli.prompt(choices['username'], 'git user name').then(gituser => gitUser = gituser) } ) | |||
| prompts.push( ()=>{ return cli.prompt(choices['useremail'], 'git user email').then(gitemail => gitEmail = gitemail) } ) | |||
| // console.log('preinstallsteps') | |||
| // var gitUser = 'guest'; | |||
| // var gitEmail = 'guest@bbh.org.in'; | |||
| // var prompts = []; | |||
| // prompts.push( ()=>{ return cli.prompt(choices['username'], 'git user name').then(gituser => gitUser = gituser) } ) | |||
| // prompts.push( ()=>{ return cli.prompt(choices['useremail'], 'git user email').then(gitemail => gitEmail = gitemail) } ) | |||
| console.log('prompting in preinstallsteps') | |||
| return any(prompts).then(()=>{ | |||
| var steps = [ | |||
| ['git', ['config', '--global', '--add', 'user.name', `${gitUser}`]] | |||
| , ['git', ['config', '--global', '--add', 'user.email', `${gitEmail}`]] | |||
| ] | |||
| return any(steps.map(getshelltask)).then(() => { | |||
| // console.log('prompting in preinstallsteps') | |||
| // return any(prompts).then(()=>{ | |||
| // var steps = [ | |||
| // ['git', ['config', '--global', '--add', 'user.name', `${gitUser}`]] | |||
| // , ['git', ['config', '--global', '--add', 'user.email', `${gitEmail}`]] | |||
| // ] | |||
| // return any(steps.map(getshelltask)).then(() => { | |||
| }) | |||
| }); | |||
| // }) | |||
| // }); | |||
| return Promise.resolve(true) | |||
| }) | |||
| return any([any(steps), prompts]) | |||
| @@ -2646,7 +2656,7 @@ var prerequisites = [ | |||
| // ignore err and proceed with data as guest. | |||
| console.dir(data) | |||
| if(data && data.length === 1 && !shouldPrompt('username', promptkeys, selectedinstance) ) { | |||
| return gitUser = data[0]; | |||
| return username = data[0]; | |||
| } | |||
| data = data || ['guest'] | |||
| @@ -2654,20 +2664,23 @@ var prerequisites = [ | |||
| console.log('prompting in postinstallsteps') | |||
| var gitUser = 'guest'; | |||
| var gitEmail = 'guest@bbh.org.in'; | |||
| var prompts = []; | |||
| prompts.push( ()=>{ return cli.prompt(choices['username'], 'git user name').then(gituser => gitUser = gituser) } ) | |||
| prompts.push( ()=>{ return cli.prompt(choices['useremail'], 'git user email').then(gitemail => gitEmail = gitemail) } ) | |||
| return any(prompts).then(()=>{ | |||
| var steps = [ | |||
| ['git', ['config', '--global', '--add', 'user.name', `${gitUser}`]] | |||
| , ['git', ['config', '--global', '--add', 'user.email', `${gitEmail}`]] | |||
| ] | |||
| return any(steps.map(getshelltask)).then(() => { | |||
| var username = 'guest'; | |||
| var email = 'guest@bbh.org.in'; | |||
| var password = '***'; | |||
| return any( getInteractionPoints(selectedinstance, promptkeys, { username, password, email}) ).then(()=>{ | |||
| if(!data.find(e => e === selectedinstance.username)) { | |||
| var steps = [ | |||
| ['git', ['config', '--global', '--add', 'user.name', `${username}`]] | |||
| , ['git', ['config', '--global', '--add', 'user.email', `${email}`]] | |||
| ] | |||
| return any(steps.map(getshelltask)).then(() => { | |||
| }) | |||
| }) | |||
| } | |||
| else { | |||
| return Promise.resolve(true) | |||
| } | |||
| }); | |||
| }) | |||
| } | |||
| @@ -2701,7 +2714,7 @@ var prerequisites = [ | |||
| else { | |||
| var users = result.messages[0].trim().split('\n'); | |||
| if(users.length === 0 || | |||
| users.length === 1 && users[0] === defaults) { | |||
| users.length === 1 && users[0] === 'guest') { | |||
| return __onResult(result) | |||
| } | |||
| @@ -2955,7 +2968,7 @@ var choices = { | |||
| , username : ['guest', 'chessdemo', 'demo'] | |||
| } | |||
| var getInteractionPoints = function(detectedinstanceoptions, promptkeys){ | |||
| var getInteractionPoints = function(detectedinstanceoptions, promptkeys, promptsfilter){ | |||
| var instances = [] | |||
| var reposervers = []; | |||
| @@ -2982,7 +2995,7 @@ var getInteractionPoints = function(detectedinstanceoptions, promptkeys){ | |||
| choices['reposerver'] = Array.from( new Set(reposervers.concat(choices['reposerver'])) ) | |||
| choices['instanceType'] = Array.from( new Set(instanceTypes.concat(choices['instanceType'])) ) | |||
| return __interactive_prompts(selectedinstance, choices) | |||
| return __interactive_prompts(selectedinstance, choices, promptsfilter) | |||
| } | |||
| var detection_state = { | |||
| @@ -3025,17 +3038,22 @@ const HTTPAPI = (function(){ | |||
| var acquirer = getHTTP_S(options) | |||
| const req = acquirer.request(options, res => { | |||
| // console.dir(res) | |||
| console.log(`statusCode: ${res.statusCode}`) | |||
| res.setEncoding('utf8'); | |||
| res.on('data', d => { | |||
| // var jsonObject = JSON.parse(d); | |||
| process.stdout.write(d) | |||
| resolve(d) | |||
| }) | |||
| }) | |||
| if (res.statusCode < 200 || res.statusCode >= 300) { | |||
| return reject(new Error('statusCode=' + res.statusCode)); | |||
| } | |||
| var body = []; | |||
| res.on('data', function(chunk) { | |||
| body.push(chunk); | |||
| }); | |||
| res.on('end', function() { | |||
| try { | |||
| body = JSON.parse(Buffer.concat(body).toString()); | |||
| } catch(e) { | |||
| reject(e); | |||
| } | |||
| resolve(body); | |||
| }); | |||
| }); | |||
| req.on('error', error => { | |||
| console.error(error) | |||
| @@ -3081,7 +3099,7 @@ const HTTPAPI = (function(){ | |||
| delete _options.username | |||
| delete _options.password | |||
| HTTPAPI.post( _options, postoptions, function(tokenresp){ | |||
| tokenresp = JSON.parse(tokenresp) | |||
| // tokenresp = JSON.parse(tokenresp) | |||
| usertokens[options.username] = tokenresp.sha1 | |||
| resolve(tokenresp) | |||
| }, | |||
| @@ -3118,18 +3136,25 @@ const HTTPAPI = (function(){ | |||
| // } | |||
| // } | |||
| var acquirer = getHTTP_S(options) | |||
| var acquirer = getHTTP_S(options) | |||
| const req = acquirer.request(options, res => { | |||
| console.log(`statusCode: ${res.statusCode}`) | |||
| if (res.statusCode < 200 || res.statusCode >= 300) { | |||
| return reject(new Error('statusCode=' + res.statusCode)); | |||
| } | |||
| var body = []; | |||
| res.setEncoding('utf8'); | |||
| res.on('data', d => { | |||
| // var jsonObject = JSON.parse(d); | |||
| process.stdout.write(d) | |||
| resolve(d) | |||
| }) | |||
| }) | |||
| res.on('data', function(chunk) { | |||
| body.push(chunk); | |||
| }); | |||
| res.on('end', function() { | |||
| try { | |||
| body = JSON.parse(Buffer.concat(body).toString()); | |||
| } catch(e) { | |||
| reject(e); | |||
| } | |||
| resolve(body); | |||
| }); | |||
| }); | |||
| req.on('error', error => { | |||
| console.error(error) | |||
| @@ -3158,12 +3183,12 @@ const GITEA = (function(){ | |||
| // http://try.gitea.io/api/v1/repos/{owner}/{repo}/forks | |||
| httpoptions.path = `/api/v1/repos/${cmdoptions.owner}/${cmdoptions.repo}/forks` | |||
| httpoptions.method = 'POST' | |||
| HTTPAPI.post(httpoptions, giteaoptions, resolve || function(){}, reject || function(){} ) | |||
| return HTTPAPI.post(httpoptions, giteaoptions, resolve || function(){}, reject || function(){} ) | |||
| } | |||
| , updateattributes( httpoptions, cmdoptions, giteaoptions, resolve, reject ){ | |||
| httpoptions.path = `/api/v1/repos/${cmdoptions.owner}/${cmdoptions.repo}` | |||
| httpoptions.method = 'PATCH' | |||
| HTTPAPI.post(httpoptions, giteaoptions, resolve || function(){}, reject || function(){} ) | |||
| return HTTPAPI.post(httpoptions, giteaoptions, resolve || function(){}, reject || function(){} ) | |||
| } | |||
| } | |||
| @@ -3176,30 +3201,30 @@ function createInstance(selectedinstance) { | |||
| // http://try.gitea.io/api/v1/org/{org}/repos | |||
| console.dir(selectedinstance) | |||
| var server = new URL(selectedinstance.reposerver); | |||
| // GITEA.repository.fork( { hostname : server.host, protocol : server.protocol | |||
| // , username : selectedinstance.username, password : selectedinstance.password | |||
| // } | |||
| // // , { repo : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}`} | |||
| // , { repo : `chess-config`, owner : 'chess' }, function( repository ){ | |||
| // GITEA.repository.updateattributes( { | |||
| // hostname : server.host, protocol : server.protocol | |||
| // , username : selectedinstance.username, password : selectedinstance.password | |||
| // } | |||
| // , { repo : `chess-config`, owner : 'selectedinstance.username' } | |||
| // , { name : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}${selectedinstance.nodeName ? '-' + selectedinstance.nodeName : ''}`} | |||
| // ) | |||
| // } | |||
| // ) | |||
| return GITEA.repository.fork( { hostname : server.host, protocol : server.protocol | |||
| , username : selectedinstance.username, password : selectedinstance.password | |||
| } | |||
| // , { repo : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}`} | |||
| , { repo : `chess-config`, owner : 'chess' }, {}, function( repository ){ | |||
| return GITEA.repository.updateattributes( { | |||
| hostname : server.host, protocol : server.protocol | |||
| , username : selectedinstance.username, password : selectedinstance.password | |||
| } | |||
| , { repo : `chess-config`, owner : selectedinstance.username } | |||
| , { name : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}${selectedinstance.nodeName ? '-' + selectedinstance.nodeName : ''}`} | |||
| ) | |||
| } | |||
| ) | |||
| GITEA.repository.updateattributes( { | |||
| hostname : server.host, protocol : server.protocol | |||
| , username : selectedinstance.username, password : selectedinstance.password | |||
| } | |||
| , { repo : `chess-config`, owner : selectedinstance.username } | |||
| , { name : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}${selectedinstance.nodeName ? '-' + selectedinstance.nodeName : ''}`} | |||
| ) | |||
| return selectedinstance | |||
| // GITEA.repository.updateattributes( { | |||
| // hostname : server.host, protocol : server.protocol | |||
| // , username : selectedinstance.username, password : selectedinstance.password | |||
| // } | |||
| // , { repo : `chess-config`, owner : selectedinstance.username } | |||
| // , { name : `${selectedinstance.instanceName}-config-${selectedinstance.instanceType}${selectedinstance.nodeName ? '-' + selectedinstance.nodeName : ''}`} | |||
| // ) | |||
| // return selectedinstance | |||
| } | |||
| acquireElevationState().then(() => { | |||