|  |  | @@ -1,4 +1,7 @@ | 
		
	
		
			
			|  |  |  | var repolog = require('./repolog') | 
		
	
		
			
			|  |  |  | var path = require('path'); | 
		
	
		
			
			|  |  |  | var utils = require('bbhverse'); | 
		
	
		
			
			|  |  |  | var any = utils.any; | 
		
	
		
			
			|  |  |  | // 'use strict'; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | // PB : TODO -- make sure folder context is proper coz we can now run elxr from anywhere. | 
		
	
	
		
			
			|  |  | @@ -18,7 +21,7 @@ | 
		
	
		
			
			|  |  |  | const { existsSync } = require('fs'); | 
		
	
		
			
			|  |  |  | const fs = require('fs') | 
		
	
		
			
			|  |  |  | const { spawn, spawnSync } = require('child_process'); | 
		
	
		
			
			|  |  |  | const cliargs = require('../elxr/cliargs'); // Use minimist... | 
		
	
		
			
			|  |  |  | const cliargs = utils.cliargs; | 
		
	
		
			
			|  |  |  | const processedArgs = cliargs(process.argv.slice(2)); | 
		
	
		
			
			|  |  |  | console.dir(processedArgs) | 
		
	
		
			
			|  |  |  | var globSync = require('glob').sync; | 
		
	
	
		
			
			|  |  | @@ -32,88 +35,11 @@ var reposervers = [ | 
		
	
		
			
			|  |  |  | , 'https://git.bbh.org.in' | 
		
	
		
			
			|  |  |  | , '//172.16.0.27/repos' | 
		
	
		
			
			|  |  |  | ] | 
		
	
		
			
			|  |  |  | var defaultRepoServer = reposervers[1] | 
		
	
		
			
			|  |  |  | var defaultRepoServer = reposervers[0] | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | var currentGitAuthUser ; // nodeShellExec('git', ['config', 'user.email']) ... PB : TODO-- get the current gittea username | 
		
	
		
			
			|  |  |  | var defaultRepoOwner = 'chess'; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | // Serialize a set of functions that will execute to return a promises one after the other. | 
		
	
		
			
			|  |  |  | // Will stop when any one fails unless continueOnFailure is true. | 
		
	
		
			
			|  |  |  | // All tasks in iterables can be functions or promises. | 
		
	
		
			
			|  |  |  | // promises as usual can return other promises or resolve to either truthy or falsy values. | 
		
	
		
			
			|  |  |  | // functions must return a promise | 
		
	
		
			
			|  |  |  | function any(iterable, continueOnFailure) { | 
		
	
		
			
			|  |  |  | return iterable.reduce( | 
		
	
		
			
			|  |  |  | (p, fn, i ,a) => { | 
		
	
		
			
			|  |  |  | // console.log('accumulator :'); | 
		
	
		
			
			|  |  |  | // console.log(p); | 
		
	
		
			
			|  |  |  | if(Promise.resolve(p) === p ) { | 
		
	
		
			
			|  |  |  | return p.then((pVal) => { | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | // Falsy values are task failure. | 
		
	
		
			
			|  |  |  | if(!pVal) { | 
		
	
		
			
			|  |  |  | console.warn('Possible failure for result : ' + pVal) | 
		
	
		
			
			|  |  |  | console.warn(a[i-1]) | 
		
	
		
			
			|  |  |  | fn ? console.error("Fn : " + fn.toString()) : null; | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | // Truthy values are failures if obj has error=true. | 
		
	
		
			
			|  |  |  | if(pVal && pVal.error) { console.error('Failed : ' + pVal.message + ' ' + pVal) } | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | if(Promise.resolve(pVal) === pVal) { | 
		
	
		
			
			|  |  |  | // Passed in function retured a promise. We still need to wait for it. | 
		
	
		
			
			|  |  |  | pVal.then((pVal)=>{ | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | // console.log('Then --pVal = ' + pVal + ' bContinue = ' +  continueOnFailure ); console.log(p); | 
		
	
		
			
			|  |  |  | if(!pVal && !continueOnFailure) { | 
		
	
		
			
			|  |  |  | console.error(`E1 : i = ${i} : pVal :` + pVal); | 
		
	
		
			
			|  |  |  | console.error('debugData 2 -------------------'); | 
		
	
		
			
			|  |  |  |  | 
		
	
		
			
			|  |  |  | console.log("Cancelling remaining..."); | 
		
	
		
			
			|  |  |  | throw 'Failed in reduce 1 ' | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | if(!fn && !continueOnFailure) { console.error('Error : No task specified.'); throw false;} | 
		
	
		
			
			|  |  |  | else if(!fn) return false; | 
		
	
		
			
			|  |  |  | return (Promise.resolve(fn) === fn ) ? fn : fn() ; | 
		
	
		
			
			|  |  |  | }) | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | else { | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | // We will stop on null resolved values on any one task unless continueOnFailure is true. | 
		
	
		
			
			|  |  |  | // console.log('Then --pVal = ' + pVal + ' bContinue = ' +  continueOnFailure ); console.log(p); | 
		
	
		
			
			|  |  |  | if(!pVal && !continueOnFailure) { | 
		
	
		
			
			|  |  |  | console.error(`E2 : i = ${i} : pVal :` + pVal); | 
		
	
		
			
			|  |  |  | console.error('debugData 2 -------------------'); | 
		
	
		
			
			|  |  |  |  | 
		
	
		
			
			|  |  |  | console.log("Cancelling remaining..."); | 
		
	
		
			
			|  |  |  | throw 'Failed in reduce 2 ' | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | if(!fn && !continueOnFailure) { console.error('Error : No task specified.'); throw false;} | 
		
	
		
			
			|  |  |  | else if(!fn) return false; | 
		
	
		
			
			|  |  |  | return (Promise.resolve(fn) === fn ) ? fn : fn() ; | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  |  | 
		
	
		
			
			|  |  |  |  | 
		
	
		
			
			|  |  |  | }).catch((error) => { | 
		
	
		
			
			|  |  |  | console.error(`E3 : i = ${i} `); | 
		
	
		
			
			|  |  |  | fn ? console.error("Fn : " + fn.toString()) : null; | 
		
	
		
			
			|  |  |  | console.error('debugData 3-------------------------'); | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | throw 'Failed in reduce 3 ' | 
		
	
		
			
			|  |  |  | }) | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | else if(!p) { | 
		
	
		
			
			|  |  |  | console.log("Bypass on failure"); | 
		
	
		
			
			|  |  |  | return false; | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | , Promise.resolve(true) | 
		
	
		
			
			|  |  |  | ); | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | var __isElevated = null; | 
		
	
		
			
			|  |  |  | var isRunningElevated = ()=>{ | 
		
	
		
			
			|  |  |  | if(__isElevated === null) { | 
		
	
	
		
			
			|  |  | @@ -171,7 +97,7 @@ var gitRepos = [ | 
		
	
		
			
			|  |  |  | , 'loopback-jsonapi-model-serializer' | 
		
	
		
			
			|  |  |  | , 'elixir-config-development' | 
		
	
		
			
			|  |  |  | , 'elixir-config-test' | 
		
	
		
			
			|  |  |  | , 'cihsr-config' | 
		
	
		
			
			|  |  |  | , 'cihsr-config-development' | 
		
	
		
			
			|  |  |  | , 'cihsr-data' | 
		
	
		
			
			|  |  |  | , 'elixir-data' | 
		
	
		
			
			|  |  |  | , 'loopback-connector-ds' | 
		
	
	
		
			
			|  |  | @@ -606,9 +532,9 @@ var __runcmd = function(label){ | 
		
	
		
			
			|  |  |  | var options = {  cwd : repo } | 
		
	
		
			
			|  |  |  | // console.log(repo) | 
		
	
		
			
			|  |  |  | return [ | 
		
	
		
			
			|  |  |  | ['git', ['remote', 'add', 'chess', 'http://git.bbh/chess/elxr.git'], {  cwd : repo }] | 
		
	
		
			
			|  |  |  | ['git', ['remote', 'add', 'chess', `${defaultRepoServer}/${user}/${repo}.git`], {  cwd : repo }] | 
		
	
		
			
			|  |  |  | , ['git', ['remote', 'set-url', '--push', 'chess', 'no-pushing'], {  cwd : repo }] | 
		
	
		
			
			|  |  |  | , ['git', ['remote', 'set-url', 'origin', `http://git.bbh/${user}/${repo}.git`], {  cwd : repo }] | 
		
	
		
			
			|  |  |  | , ['git', ['remote', 'set-url', 'origin', `${defaultRepoServer}/${user}/${repo}.git`], {  cwd : repo }] | 
		
	
		
			
			|  |  |  | ]} | 
		
	
		
			
			|  |  |  | var x = (args)=>{ | 
		
	
		
			
			|  |  |  | return ()=>{ | 
		
	
	
		
			
			|  |  | @@ -1168,7 +1094,9 @@ var __runcmd = function(label){ | 
		
	
		
			
			|  |  |  | if(0){ | 
		
	
		
			
			|  |  |  | // PB : TODO -- Special google chrome profile for tests etc. | 
		
	
		
			
			|  |  |  | nodeShellExec('pwd', { inherit : true}); | 
		
	
		
			
			|  |  |  | //$ "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --profile-directory="Profile 1" http://localhost:4200/tests/index.html?grep=loopback | 
		
	
		
			
			|  |  |  | // /c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe --user-data-dir=/c/chess/instances/elixir_01/data/Google/Chrome/User\ Data --profile-directory="chess" | 
		
	
		
			
			|  |  |  | // "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --user-data-dir="C:\chess\instances\elixir_01\data\Google\Chrome\User Data" --profile-directory="chess" http://localhost:4200/admin/crud/create/item | 
		
	
		
			
			|  |  |  | // "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --user-data-dir="C:\chess\instances\elixir_01\data\Google\Chrome\User Data" --profile-directory="chess" http://localhost:4200/tests/index.html?grep=loopback | 
		
	
		
			
			|  |  |  | nodeShellExec("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe", [ | 
		
	
		
			
			|  |  |  | "--profile-directory=Profile 1" | 
		
	
		
			
			|  |  |  | , 'http://localhost:4200/tests/index.html?grep=model convert ember to loopback' + '&filter=none' /*+ '&filter=model convert ember to loopback'*/]); | 
		
	
	
		
			
			|  |  | @@ -1178,19 +1106,68 @@ var __runcmd = function(label){ | 
		
	
		
			
			|  |  |  | // nodeShellExec('npm', ['init', '-y'], options); | 
		
	
		
			
			|  |  |  | // }) | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | var g = { | 
		
	
		
			
			|  |  |  | 'client' : ()=>{ | 
		
	
		
			
			|  |  |  | console.info('Creating new ember client named : ' + processedArgs._[2] ) ; | 
		
	
		
			
			|  |  |  | var step1 = nodeShellExec('cmd', ['/c', 'ember', 'new', processedArgs._[2]], { | 
		
	
		
			
			|  |  |  | stdio: ['pipe', process.stdout, process.stderr], | 
		
	
		
			
			|  |  |  | inherit : true, | 
		
	
		
			
			|  |  |  | shell: true, | 
		
	
		
			
			|  |  |  | cwd : path.dirname(__dirname), | 
		
	
		
			
			|  |  |  | env: env | 
		
	
		
			
			|  |  |  | }) | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | var g = { | 
		
	
		
			
			|  |  |  | 'client' : ()=>{ | 
		
	
		
			
			|  |  |  | console.info('Creating new ember client named : ' + processedArgs._[2] ) ; | 
		
	
		
			
			|  |  |  | var step1 = nodeShellExec('cmd', ['/c', 'ember', 'new', processedArgs._[2]], { | 
		
	
		
			
			|  |  |  | stdio: ['pipe', process.stdout, process.stderr], | 
		
	
		
			
			|  |  |  | inherit : true, | 
		
	
		
			
			|  |  |  | shell: true, | 
		
	
		
			
			|  |  |  | cwd : path.dirname(__dirname), | 
		
	
		
			
			|  |  |  | env: env | 
		
	
		
			
			|  |  |  | }) | 
		
	
		
			
			|  |  |  | }, | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | 'modelr' : ()=>{ | 
		
	
		
			
			|  |  |  | var tasks = [ | 
		
	
		
			
			|  |  |  | ()=>{ | 
		
	
		
			
			|  |  |  | var p = nodeShellExec('"ember"', [ | 
		
	
		
			
			|  |  |  | 'g' | 
		
	
		
			
			|  |  |  | , 'modelr' | 
		
	
		
			
			|  |  |  | , processedArgs._[2]], { | 
		
	
		
			
			|  |  |  | inherit : true, shell: true, env: process.env | 
		
	
		
			
			|  |  |  | }).then(()=>{ | 
		
	
		
			
			|  |  |  | console.log('Blueprint generation complete for : ' + processedArgs._[2]) | 
		
	
		
			
			|  |  |  | return true; | 
		
	
		
			
			|  |  |  | }).catch((e)=>{ console.error(e) }) | 
		
	
		
			
			|  |  |  | return p; | 
		
	
		
			
			|  |  |  | }, | 
		
	
		
			
			|  |  |  | ()=>{ | 
		
	
		
			
			|  |  |  | var chromePrefsFile = "C:\\chess\\instances\\elixir_01\\data\\Google\\Chrome\\User Data\\chess\\Preferences"; | 
		
	
		
			
			|  |  |  | var chromeprefs = fs.readFileSync(chromePrefsFile, { encoding: 'utf8' }) | 
		
	
		
			
			|  |  |  | chromeprefs = JSON.parse(chromeprefs) | 
		
	
		
			
			|  |  |  | var previous = chromeprefs.download.default_directory; | 
		
	
		
			
			|  |  |  | var parentDir = path.dirname(__dirname); | 
		
	
		
			
			|  |  |  | chromeprefs.download.default_directory = parentDir + "\\client\\app\\templates\\components\\resource"; | 
		
	
		
			
			|  |  |  | fs.writeFileSync(chromePrefsFile, JSON.stringify(chromeprefs)) | 
		
	
		
			
			|  |  |  | // PB : TODO -- detect where chrome is installed. | 
		
	
		
			
			|  |  |  | // PB : TODO -- set the download dir to the place where files are needed. | 
		
	
		
			
			|  |  |  | var p = nodeShellExec('"C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"', [ | 
		
	
		
			
			|  |  |  | '--user-data-dir="C:\\chess\\instances\\elixir_01\\data\\Google\\Chrome\\User Data"' | 
		
	
		
			
			|  |  |  | , '--profile-directory="chess"' | 
		
	
		
			
			|  |  |  | , 'http://localhost:4200/admin/crud/create/' + processedArgs._[2]], { | 
		
	
		
			
			|  |  |  | inherit : true, shell: true | 
		
	
		
			
			|  |  |  | , env: process.env | 
		
	
		
			
			|  |  |  | }).then(()=>{ | 
		
	
		
			
			|  |  |  | chromeprefs.download.default_directory = previous; | 
		
	
		
			
			|  |  |  | fs.writeFileSync(chromePrefsFile, JSON.stringify(chromeprefs)) | 
		
	
		
			
			|  |  |  | return true; | 
		
	
		
			
			|  |  |  | }).catch((e)=>{ console.error(e) }) | 
		
	
		
			
			|  |  |  | return p; | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | , | 
		
	
		
			
			|  |  |  | ()=>{ | 
		
	
		
			
			|  |  |  | console.log('Browser process should have closed here....') | 
		
	
		
			
			|  |  |  | return true; | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | ] | 
		
	
		
			
			|  |  |  | any(tasks) | 
		
	
		
			
			|  |  |  |  | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | g[processedArgs._[1]](); | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | g[processedArgs._[1]](); | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | return op[label] ? op[label]() : null; |