選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

index.js 61KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654
  1. var path = require('path');
  2. var utils = require('bbhverse');
  3. var any = utils.any;
  4. var Tasq = utils.Tasq
  5. var statuslog = utils.Traq
  6. var Traq = utils.Traq
  7. Tasq.addlistener(statuslog.statuslog)
  8. var cli = require('./cliverse')
  9. var nodeShellExec = cli.nodeShellExec;
  10. var chalk = require('chalk')
  11. const BUILD_VERSION = '[VI]Version: {version} - built on {date}[/VI]';
  12. function getVersion() { return BUILD_VERSION; }
  13. console.log(getVersion())
  14. // 'use strict';
  15. // PB : TODO -- make sure folder context is proper coz we can now run elxr from anywhere.
  16. // PB : TODO --
  17. // runas bypass non elevated tasks when we request privelege
  18. // runas message is always error needs to be fixed.
  19. // runas wait needs to be parallelized.
  20. // suppress elevation check error messages
  21. // support runas lauched directly from shell.
  22. // pass in environment in hta to shellexecute.
  23. const { existsSync } = require('fs');
  24. const fs = require('fs')
  25. const cliargs = utils.cliargs;
  26. const processedArgs = cliargs(process.argv.slice(2));
  27. console.dir(processedArgs)
  28. var globSync = require('glob').sync;
  29. var ENV = Object.assign({}, process.env); // Shallow clone it.
  30. const { readdir } = require("fs").promises
  31. // Directory shallow walk and do perform on each dir.
  32. const dirs = async (perform, path) => {
  33. for (const dir of await readdir(path || process.cwd(), { withFileTypes: true })) {
  34. if (dir.isDirectory()) perform(dir)
  35. }
  36. }
  37. var getShellTask = (command, args, options) => {
  38. return () => {
  39. var p = nodeShellExec.apply(null, [command, args, Object.assign({
  40. inherit: true, shell: true, env: ENV, title: `${command} ${args}`
  41. }, options)
  42. ])
  43. if (options.ignorefailures) {
  44. return p.catch(e => {
  45. // Ignore. Not a major error.
  46. })
  47. }
  48. else return p;
  49. }
  50. }
  51. var callsheltask = (args) => { return () => { return nodeShellExec.apply(null, args) } }
  52. var getTaskCheckExists = (command, options) => {
  53. options = options || {}
  54. return () => {
  55. var p = nodeShellExec.apply(null, ['where', [command]])
  56. if (options.ignorefailures) {
  57. return p.then(() => { return true }).catch(e => { // Ignore. Not a major error.
  58. return false;
  59. })
  60. }
  61. else return p.then(() => { return true });
  62. }
  63. }
  64. var getPullCmd = (repo) => {
  65. // console.log(useGitPull)
  66. var pullCmd = [gitInstallDir
  67. , ['-c', 'branch=`git rev-parse --abbrev-ref HEAD`;for i in `git remote`; do git pull $i $branch; done;']
  68. , { cwd: instanceroot + '/' + repo, title: 'pull all origins for ' + repo }]
  69. // var pullCmd = ['pullall', [], { cwd : repo }]
  70. if (useGitPull) pullCmd = ['git', ['pull'], {
  71. inherit: true, shell: true,
  72. cwd: instanceroot + '/' + repo
  73. // , env: process.env
  74. , runas: processedArgs.runas
  75. , title: `git pull ${repo}`
  76. }]
  77. return pullCmd
  78. }
  79. var performPull = (repo) => {
  80. if (existsSync(instanceroot + '/' + repo)) {
  81. console.log('pulling ' + instanceroot + '/' + repo)
  82. return nodeShellExec.apply(null, getPullCmd(repo)).then(() => {
  83. if (__isElevated) {
  84. fs.writeFileSync('run.log', ', ' + JSON.stringify({ repo, success: true }), { 'flag': 'a+' })
  85. }
  86. else statuslog.statuslog(null, repo)
  87. return true;
  88. })
  89. .catch((e) => {
  90. e.repo = repo;
  91. if (__isElevated) {
  92. fs.writeFileSync('run.log', ', ' + JSON.stringify(e), { 'flag': 'a+' })
  93. }
  94. else statuslog.statuslog(e); console.error(e)
  95. })
  96. }
  97. else {
  98. console.log('cloning ' + repo)
  99. // PB : TODO -- detect if a clonable repo exists in currentGitAuthUser
  100. return nodeShellExec('git', ['clone', '-c', 'core.symlinks=true', defaultRepoServer + `/${defaultRepoOwner}/` + repo + '.git'],
  101. {
  102. inherit: true, shell: true,
  103. env: process.env
  104. , cwd : instanceroot
  105. , runas: processedArgs.runas
  106. }).catch((e) => {
  107. throw e;
  108. }).then(() => {
  109. return nodeShellExec('git', ['config', '--replace-all', 'core.symlinks', true],
  110. {
  111. inherit: true, shell: true,
  112. env: process.env
  113. , cwd: instanceroot + '/' + repo
  114. , runas: processedArgs.runas
  115. , title: `git core.symlinks --replace-all true for ${defaultRepoServer + `/${defaultRepoOwner}/` + repo + '.git'}`
  116. })
  117. .then(() => {
  118. if (__isElevated) {
  119. fs.writeFileSync('run.log', ', ' + JSON.stringify({ repo, success: true }), { 'flag': 'a+' })
  120. }
  121. else statuslog.statuslog(null, repo)
  122. })
  123. .catch((e) => {
  124. e.repo = repo;
  125. if (__isElevated) {
  126. fs.writeFileSync('run.log', ', ' + JSON.stringify(e), { 'flag': 'a+' })
  127. }
  128. else statuslog.statuslog(e);
  129. })
  130. })
  131. .catch(e => {
  132. e.repo = repo;
  133. if (__isElevated) {
  134. fs.writeFileSync('run.log', ', ' + JSON.stringify(e), { 'flag': 'a+' })
  135. }
  136. else statuslog.statuslog(e);
  137. })
  138. }
  139. }
  140. // PB : TODO -- If we are run from an elevated shell it never moves forward and simply exits.
  141. // -- Currently workaround is to always run from a non-elevated shell.
  142. var __isElevated = null; // We assume non-Elevated until someone evaluates and sets this variable.
  143. var acquireElevationState = () => {
  144. if (__isElevated === null) {
  145. return nodeShellExec("fsutil", ["dirty", "query", "C:"], {
  146. inherit: true
  147. // , shell: true
  148. , stdio: 'ignore'
  149. , env: process.env
  150. , title: `check privileged execution mode using "fsutil dirty query C:"`
  151. }).then((exitcode) => {
  152. console.log('Elevated')
  153. __isElevated = true;
  154. return true;
  155. }).catch(() => {
  156. __isElevated = false;
  157. console.log('Not Elevated');
  158. return false;
  159. });
  160. }
  161. else return Promise.resolve(__isElevated);
  162. }
  163. var repomanifest = null;
  164. var currentGitAuthUser; // nodeShellExec('git', ['config', 'user.email']) ... PB : TODO-- get the current gittea username
  165. var defaultRepoOwner = 'chess';
  166. var elevatedRunasRepos = null
  167. var gitRepos = null
  168. var defaultRepoServer = null
  169. // grep -qxF 'alias elxr="node elxr/index.js"' ~/.bash_profile || echo 'alias elxr="node elxr/index.js"' >> ~/.bash_profile
  170. // nodeShellExec('echo', ['elxr'], { inherit : true}) //, {stdio: "inherit"}
  171. var dbForLabel = function (label) {
  172. var dbsForLabel = {
  173. devmysql: 'mysql'
  174. , development: 'mssql'
  175. , production: 'mssql'
  176. }
  177. return dbsForLabel[label] || 'mysql'
  178. }
  179. // SAM : TODO Use nodeshellexec where to detect git installation dir
  180. var gitInstallDir = "C:\\Program Files\\Git\\bin\\sh.exe"
  181. // var gitInstallDir = "G:\\Installed\\Git\\bin\\sh.exe"
  182. // Relevant git repos
  183. // var repomanifest = require('../'+repomanifest.instanceName+'-config-'+ nodeenv +'/repo-manifest')()
  184. var exludeMergeRepos = [];
  185. var useGitPull = processedArgs.useGitPull || false;
  186. var configPromise = null
  187. // elxr cli operations
  188. var op = {
  189. 'h': () => { console.log(elxr.help()); return '-h' }
  190. , 'clean' : () => {
  191. // delete all node_module folders and links.
  192. var tasklist = [];
  193. dirs( (repodir)=> tasklist.push(getShellTask('rm',['-rf', 'node_modules'], { cwd : instanceroot + '/' + repodir.name })()), instanceroot )
  194. return Promise.all(tasklist)
  195. }
  196. , 'undefined': () => { return op.h(); }
  197. , 'reset': () => {
  198. // Reset NPM packages semver so major versions can be updated.
  199. const fs = require('fs')
  200. const wipeDependencies = (__package) => {
  201. const file = fs.readFileSync(__package + '/package.json')
  202. const content = JSON.parse(file)
  203. for (var devDep in content.devDependencies) {
  204. if (content.devDependencies[devDep].match(/\W+\d+.\d+.\d+-?((alpha|beta|rc)?.\d+)?/g)) {
  205. content.devDependencies[devDep] = '*';
  206. }
  207. }
  208. for (var dep in content.dependencies) {
  209. if (content.dependencies[dep].match(/\W+\d+.\d+.\d+-?((alpha|beta|rc)?.\d+)?/g)) {
  210. content.dependencies[dep] = '*';
  211. }
  212. }
  213. fs.writeFileSync(__package + '/package.json', JSON.stringify(content))
  214. }
  215. var repos = ['client'];
  216. // repos = gitRepos;
  217. repos.forEach(wipeDependencies)
  218. // if (require.main === module) {
  219. // } else {
  220. // module.exports = wipeDependencies
  221. // }
  222. }
  223. , 'upgrade': () => {
  224. console.log('upgrade.......')
  225. var tasks = [
  226. () => {
  227. var p = nodeShellExec('npm', ['i', '-g', 'npm-upgrade'], {
  228. inherit: true, shell: true
  229. , env: process.env
  230. }).catch((e) => { console.error(e) })
  231. p.position = 1;
  232. console.log('One')
  233. return p;
  234. }
  235. , () => {
  236. var p = nodeShellExec('npm', ['cache', 'clean', '-f'], {
  237. inherit: true, shell: true
  238. , env: process.env
  239. }).catch((e) => { console.error(e) })
  240. p.position = 2;
  241. console.log('Two')
  242. return p;
  243. }
  244. , () => {
  245. var p = nodeShellExec('npm', ['install', '-g', 'n'], {
  246. inherit: true, shell: true
  247. , env: process.env
  248. }).catch((e) => { console.error(e) })
  249. p.position = 3;
  250. console.log('Three')
  251. return p;
  252. }
  253. , () => {
  254. var p = nodeShellExec('n', ['latest'], {
  255. inherit: true, shell: true
  256. , env: process.env
  257. }).catch((e) => { console.error(e) })
  258. p.position = 4;
  259. console.log('Four')
  260. return p;
  261. }
  262. ]
  263. any(tasks)
  264. console.log('.......done')
  265. console.log('Running exlr upgrade in : ' + path.dirname(__dirname))
  266. console.log('Currently only upgrades ember : ' + path.dirname(__dirname));
  267. console.info('Uninstalling existing ember globally');
  268. var step1 = nodeShellExec('cmd', ['/c', 'npm', 'uninstall', '-g', 'ember-cli'], {
  269. stdio: ['pipe', process.stdout, process.stderr],
  270. inherit: true,
  271. shell: true,
  272. cwd: path.dirname(__dirname),
  273. env: env
  274. })
  275. step1.on('close', () => {
  276. console.info('Installing ember globally');
  277. var step2 = nodeShellExec('cmd', ['/c', 'npm', 'install', '-g', 'ember-cli'], {
  278. stdio: ['pipe', process.stdout, process.stderr],
  279. inherit: true,
  280. shell: true,
  281. cwd: path.dirname(__dirname),
  282. env: env
  283. })
  284. step2.on('close', () => {
  285. nodeShellExec('cmd', ['/c', 'ember', '--version'], {
  286. stdio: ['pipe', process.stdout, process.stderr],
  287. inherit: true,
  288. shell: true,
  289. cwd: path.dirname(__dirname),
  290. env: env
  291. })
  292. })
  293. })
  294. }
  295. , 'runas': () => {
  296. console.log('Testing Elevation')
  297. if (__isElevated) {
  298. try {
  299. op[processedArgs.label || processedArgs._[0] || 'h']()
  300. }
  301. catch (e) {
  302. console.error('Error Invalid command : ' + e)
  303. fs.writeFileSync('run.done', 'error')
  304. }
  305. finally {
  306. }
  307. }
  308. else {
  309. console.log('Requesting Elevated Privileges');
  310. // Wait for the runas to complete before we read it.
  311. try {
  312. fs.unlinkSync('run.done')
  313. fs.unlinkSync('run.log')
  314. }
  315. catch (e) { } //Ignore
  316. // Find node path to send to hta.
  317. return nodeShellExec('where', ['node']).then(r => {
  318. var namedArgs = [];
  319. console.log('result : ' + JSON.stringify(r))
  320. Object.keys(processedArgs).forEach((v) => { v != '_' ? namedArgs.push('--' + v + '=' + processedArgs[v]) : null; })
  321. // PB : TODO -- Convert all the cli args back to string.
  322. var args = [__dirname + '/windowselevate.hta'].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self');
  323. args.push('--nodepath=' + r[r.length - 1])
  324. if (!processedArgs.node_env) args.push('--node_env=' + ENV.NODE_ENV)
  325. if (processedArgs.debug) args.push('--debug=true') // Enable to debug elevated..
  326. return nodeShellExec('MSHTA', [`"${args.join('" "')}"`]
  327. , {
  328. inherit: true
  329. , shell: true
  330. , env: ENV
  331. , runas: 'self'
  332. , title: `runas`
  333. }
  334. ).then(() => {
  335. // runas returned.
  336. try {
  337. // PB : TODO -- Log is comma prefixed. Needs to be proper JSON.
  338. var runaslog = JSON.parse('[ { "success" : true, "result" : "started"}' + fs.readFileSync('run.log', { flags: 'a+' }) + ']');
  339. runaslog.forEach((logEntry) => {
  340. statuslog.statuslog(logEntry.success ? null : logEntry, logEntry)
  341. logEntry.success ? (console.log(['success :' + logEntry.result]), console.log((logEntry.messages || []).join(' '))) : (console.error(['error :' + logEntry.result]), console.error((logEntry.messages || []).join(' ')))
  342. })
  343. }
  344. catch (e) {
  345. // We must have a runas log
  346. statuslog.statuslog(e)
  347. console.error('Run log error probably was not created by runas : ' + e)
  348. }
  349. })
  350. .catch(err => console.error('Elevation failed : ' + err));
  351. })
  352. }
  353. }
  354. , 'push': () => {
  355. if (!processedArgs._[1]) { console.error('push all not supported. Specify repo name'); return }
  356. // init remote bare from local
  357. // pushandinitremotebare
  358. // https://www.jeffgeerling.com/blogs/jeff-geerling/push-your-git-repositories
  359. // connect to repo server -- net use 172.16.0.27
  360. // cd 172.16.0.27/repos/
  361. // mkdir repo.git
  362. // cd repo.git
  363. // git init --bare
  364. // cd localrepo
  365. // git remote rename origin githubclone
  366. // git remote add origin //172.16.0.27/repos/repo.git
  367. // git push origin master
  368. var repo = processedArgs._[1];
  369. var sequentialTaskShellCommands = [];
  370. if (!existsSync(`Z:/${repo}.git`)) {
  371. sequentialTaskShellCommands = [
  372. // ['net', ['use', 'Z:', defaultRepoServer.replace('/','\\')], {
  373. // inherit : true, shell: true
  374. // , env: process.env
  375. // }]
  376. ['pwd', { cwd: 'Z:', inherit: true }]
  377. , ['mkdir', [`${repo}.git`], {
  378. cwd: `Z:`
  379. , inherit: true, shell: true
  380. , env: process.env
  381. }]
  382. , ['pwd', { cwd: `Z:/${repo}.git`, inherit: true }]
  383. , ['git', ['init', '--bare'], {
  384. cwd: `Z:/${repo}.git`
  385. , inherit: true, shell: true
  386. , env: process.env
  387. }]
  388. // PB : TODO -- Do this conditionally only...
  389. , ['git', ['remote', 'rename', 'origin', 'githubclone'], { cwd: `${instanceroot + '/' + repo}` }, (err) => {
  390. console.log('Ignoring origin rename error : ' + err); return true; //return true to continue.
  391. }] // PB ; Todo -- new repositories created locally will not have origin. Handle this failure.
  392. , ['git', ['remote', 'add', 'origin', `${defaultRepoServer}/${repo}.git`], { cwd: `${instanceroot + '/' + repo}` }]
  393. // PB : TODO -- If threre is a gitbubclone origin
  394. // Set the master to pull from the local repo.
  395. ]
  396. if (!existsSync(`Z:`)) {
  397. sequentialTaskShellCommands.splice(0, 0, ['net', ['use', 'Z:', defaultRepoServer.replace(/\//gm, '\\')], {
  398. inherit: true, shell: true
  399. , env: process.env
  400. }])
  401. console.warn('Adding network drive z: for repo server. ' + sequentialTaskShellCommands[0])
  402. // throw 'done'
  403. }
  404. }
  405. sequentialTaskShellCommands.push(['git', ['push', 'origin', 'master'], { cwd: `${instanceroot + '/' + repo}` }])
  406. // console.dir(sequentialTaskShellCommands);
  407. var tasks = [];
  408. sequentialTaskShellCommands.forEach(shellcmd => {
  409. // console.log(shellcmd)
  410. tasks.push(() => {
  411. var p = nodeShellExec.apply(null, shellcmd.slice(0, 3)).catch((e) => { if (shellcmd[3]) { return shellcmd[3]() } else { console.error(e); } })
  412. return p;
  413. })
  414. })
  415. any(tasks);
  416. }
  417. , 'is-git-repo': (dir) => {
  418. return nodeShellExec('git', ['-C', dir.name, 'rev-parse'], { stdio: 'ignore' })
  419. }
  420. , 'set-url': (remotename, url) => {
  421. var pushable = processedArgs.pushable || false;
  422. remotename = remotename || processedArgs._[1]
  423. url = url || processedArgs._[2]
  424. var serial_perform_git_seturl = (repo) => {
  425. var options = { cwd: instanceroot + '/' + repo }
  426. // console.log(repo)
  427. if (pushable) {
  428. return [
  429. ['git', ['remote', 'set-url', remotename, url + '/' + repo], { cwd: instanceroot + '/' + repo }]
  430. ]
  431. }
  432. else {
  433. console.error('not supported for non-pushable')
  434. }
  435. }
  436. var perform_git_seturl = (dir) => {
  437. op['is-git-repo'](dir).then((code) => {
  438. any(serial_perform_git_seturl(dir.name).map(x))
  439. }).catch((e) => {
  440. // console.log('Failed : ' + dir.name)
  441. })
  442. }
  443. dirs(perform_git_seturl)
  444. }
  445. , 'add': (remotename, url, branch) => {
  446. var pushable = processedArgs.pushable || false;
  447. remotename = remotename || processedArgs._[1]
  448. url = url || processedArgs._[2]
  449. branch = branch || processedArgs._[3]
  450. var serial_perform_git_add = (repo) => {
  451. var options = { cwd: instanceroot + '/' + repo }
  452. // console.log(repo)
  453. if (pushable) {
  454. return [
  455. ['git', ['remote', 'add', remotename, url + '/' + repo], { cwd: instanceroot + '/' + repo }]
  456. , ['git', ['pull', remotename, branch], { cwd: instanceroot + '/' + repo }]
  457. , ['git', ['branch', `--set-upstream-to=${remotename}/${branch}`, branch], { cwd: instanceroot + '/' + repo }]
  458. ]
  459. }
  460. else {
  461. return [
  462. ['git', ['remote', 'add', remotename, url + '/' + repo], { cwd: instanceroot + '/' + repo }]
  463. , ['git', ['remote', `set-url`, '--push', remotename, 'no-pushing'], { cwd: instanceroot + '/' + repo }]
  464. , ['git', ['pull', remotename, branch], { cwd: instanceroot + '/' + repo }]
  465. , ['git', ['branch', `--set-upstream-to=${remotename}/${branch}`, branch], { cwd: instanceroot + '/' + repo }]
  466. ]
  467. }
  468. }
  469. var x = (args) => {
  470. return () => {
  471. // console.log(args)
  472. return nodeShellExec.apply(null, args)
  473. }
  474. // return Promise.resolve(true)
  475. }
  476. var perform_git_add = (dir) => {
  477. op['is-git-repo'](dir).then((code) => {
  478. // console.log(code)
  479. if (code) {
  480. nodeShellExec('git', ['remote', 'get-url', remotename], { cwd: dir.name, stdio: 'ignore' }).then(() => {
  481. console.log('skipped : ' + dir.name + ', reason : A remote with same name already exists.')
  482. })
  483. .catch((e) => {
  484. any(serial_perform_git_add(dir.name).map(x))
  485. })
  486. }
  487. // else console.log('Skipped : Not a Git Repo : ' + dir.name)
  488. }).catch((e) => {
  489. // console.log('Failed : ' + dir.name)
  490. })
  491. }
  492. const { readdir } = require("fs").promises
  493. const dirs = async (perform, path) => {
  494. for (const dir of await readdir(path || process.cwd(), { withFileTypes: true })) {
  495. if (dir.isDirectory()) perform(dir)
  496. }
  497. }
  498. dirs(perform_git_add)
  499. }
  500. , 'remove': (remotename) => {
  501. remotename = remotename || processedArgs._[1]
  502. var serial_perform_git_remove = (repo) => {
  503. var options = { cwd: instanceroot + '/' + repo }
  504. // console.log(repo)
  505. return [
  506. ['git', ['remote', 'remove', remotename], { cwd: instanceroot + '/' + repo }]
  507. ]
  508. }
  509. var x = (args) => {
  510. return () => {
  511. // console.log(args)
  512. return nodeShellExec.apply(null, args)
  513. }
  514. // return Promise.resolve(true)
  515. }
  516. var perform_git_remove = (dir) => {
  517. op['is-git-repo'](dir).then((code) => {
  518. // console.log(code)
  519. if (code) {
  520. nodeShellExec('git', ['remote', 'get-url', remotename], { cwd: dir.name, stdio: 'ignore' }).then(() => {
  521. any(serial_perform_git_remove(dir.name).map(x))
  522. })
  523. .catch((e) => {
  524. console.log('skipped : ' + dir.name + ', reason : No remote named origin')
  525. })
  526. }
  527. // else console.log('Skipped : Not a Git Repo : ' + dir.name)
  528. }).catch((e) => {
  529. // console.log('Failed : ' + dir.name)
  530. })
  531. }
  532. const { readdir } = require("fs").promises
  533. const dirs = async (perform, path) => {
  534. for (const dir of await readdir(path || process.cwd(), { withFileTypes: true })) {
  535. if (dir.isDirectory()) perform(dir)
  536. }
  537. }
  538. dirs(perform_git_remove)
  539. }
  540. , 'init-gitea': (user) => {
  541. user = user || processedArgs._[1]
  542. if (!user) throw 'User name required'
  543. var serial_perform_init_gitea = (repo) => {
  544. var options = { cwd: instanceroot + '/' + repo }
  545. // console.log(repo)
  546. return [
  547. ['git', ['remote', 'add', 'chess', `${defaultRepoServer}/${user}/${repo}.git`], { cwd: instanceroot + '/' + repo }]
  548. , ['git', ['remote', 'set-url', '--push', 'chess', 'no-pushing'], { cwd: instanceroot + '/' + repo }]
  549. , ['git', ['remote', 'set-url', 'origin', `${defaultRepoServer}/${user}/${repo}.git`], { cwd: instanceroot + '/' + repo }]
  550. ]
  551. }
  552. var x = (args) => {
  553. return () => {
  554. // console.log(args)
  555. return nodeShellExec.apply(null, args)
  556. }
  557. // return Promise.resolve(true)
  558. }
  559. var perform_init_gitea = (dir) => {
  560. op['is-git-repo'](dir).then((code) => {
  561. // console.log(code)
  562. if (code) {
  563. nodeShellExec('git', ['remote', 'get-url', 'chess'], { cwd: dir.name, stdio: 'ignore' }).then(() => {
  564. console.log('skipped : ' + dir.name + ', reason : Already has remote chess ')
  565. })
  566. .catch((e) => {
  567. any(serial_perform_init_gitea(dir.name).map(x))
  568. })
  569. }
  570. // else console.log('Skipped : Not a Git Repo : ' + dir.name)
  571. }).catch((e) => {
  572. // console.log('Failed : ' + dir.name)
  573. })
  574. }
  575. const { readdir } = require("fs").promises
  576. const dirs = async (perform, path) => {
  577. for (const dir of await readdir(path || process.cwd(), { withFileTypes: true })) {
  578. if (dir.isDirectory()) perform(dir)
  579. }
  580. }
  581. dirs(perform_init_gitea)
  582. }
  583. , 'syncmaster': (label) => {
  584. // Usage :
  585. // elxr pull -- Defaults to run config
  586. var env = Object.assign({}, process.env); // Shallow clone it.
  587. // console.dir(env)
  588. console.log('Running exlr pull : ' + path.dirname(__dirname))
  589. if (!processedArgs.runas) gitRepos.forEach(performPull)
  590. if (__isElevated) {
  591. return any(elevatedRunasRepos.map((repo) => performPull(repo))).then(() => {
  592. fs.writeFileSync('run.done', 'success')
  593. }).catch(() => {
  594. fs.writeFileSync('run.done', 'error')
  595. })
  596. }
  597. else return op['runas']()
  598. }
  599. , 'pull': (label) => {
  600. // Usage :
  601. // elxr pull -- Defaults to run config
  602. var env = Object.assign({}, process.env); // Shallow clone it.
  603. console.log('Running exlr pull : ' + path.dirname(__dirname))
  604. var useGitPull = processedArgs.useGitPull || false;
  605. if (__isElevated) {
  606. return any(elevatedRunasRepos.map((repo) => performPull(repo))).then(() => {
  607. fs.writeFileSync('run.done', 'success')
  608. return true;
  609. }).catch(() => {
  610. fs.writeFileSync('run.done', 'error')
  611. })
  612. }
  613. else {
  614. // PB : TODO -- Rename op['runas'] to 'elevate'
  615. return op['runas']().then(() => { return true; })
  616. .catch((e) => {
  617. console.error(e)
  618. })
  619. .finally(() => {
  620. if (!processedArgs.runas) {
  621. var pendingpulls = [];
  622. gitRepos.forEach((r) => { pendingpulls.push(performPull(r)) })
  623. return Promise.all(pendingpulls).then(results => {
  624. return true;
  625. }).finally(Traq.finally)
  626. }
  627. })
  628. }
  629. }
  630. , 'isInstalled': () => {
  631. return nodeShellExec('where', [processedArgs._[1]], { inherit: true }).then(() => {
  632. console.log(processedArgs._[1] + ' exists.')
  633. return true;
  634. });
  635. }
  636. , 'i': () => {
  637. var tasks = []
  638. tasks.push(op['pull']);
  639. tasks.push(getShellTask.apply(null, ['rm', [instanceroot + '/run.js'], { ignorefailures: true }]))
  640. tasks.push(op['use'])
  641. if (!__isElevated) {
  642. tasks.push(op['npmi'])
  643. }
  644. // var tasksdefs = [
  645. // ['elxr', ['pull']]
  646. // , ['elxr', ['use', 'elixir']]
  647. // , ['elxr', ['npmi']]
  648. // ]
  649. // tasksdefs.forEach(tasksdef=>{
  650. // tasks.push( ()=> nodeShellExec.apply(null, tasksdef) )
  651. // })
  652. return any(tasks);
  653. }
  654. , 'npmi': () => {
  655. var tasks = [];
  656. var npmbuildrepos = ['loopback-jsonapi-model-serializer']
  657. npmbuildrepos.forEach(repo => {
  658. tasks.push(() => {
  659. return nodeShellExec('npm', ['i --force'], {
  660. inherit: true, shell: true
  661. , cwd: instanceroot + '/' + repo
  662. , env: process.env
  663. , title: `npm i for ${repo}`
  664. }).catch((e) => {
  665. console.error('Ignoring Benign Error'); console.error(e);
  666. }).then(() => {
  667. console.log(`--------------------npm run build for ${repo}--------------------`)
  668. return nodeShellExec('npm', ['run build'], {
  669. inherit: true, shell: true
  670. , cwd: instanceroot + '/' + repo
  671. , env: process.env
  672. , title: `npm run build for ${repo}`
  673. }).then(Tasq.then).catch(Tasq.catch)
  674. })
  675. })
  676. })
  677. any(tasks).then(() => {
  678. gitRepos.push('client/server');
  679. gitRepos = gitRepos.concat(elevatedRunasRepos);
  680. var rmtasks = []
  681. var repotasks = []
  682. gitRepos.forEach(repo => {
  683. rmtasks.push(() => {
  684. console.log(`--------------------rm package-lock.json for ${repo}--------------------`)
  685. return nodeShellExec('rm', ['package-lock.json'], {
  686. inherit: true, shell: true
  687. , cwd: instanceroot + '/' + repo
  688. , env: process.env
  689. , title: `rm 'package-lock.json' for ${repo}`
  690. }).catch((e) => { console.error(e) })
  691. })
  692. if (npmbuildrepos.indexOf(repo) < 0) {
  693. repotasks.push(
  694. () => {
  695. console.log(`--------------------npm i for ${repo}--------------------`)
  696. var p = nodeShellExec('npm', ['i --force'], {
  697. inherit: true, shell: true
  698. , cwd: instanceroot + '/' + repo
  699. , env: process.env
  700. , title: `npm i for ${repo}`
  701. }).then(Tasq.then).catch(Tasq.catch)
  702. return p;
  703. })
  704. }
  705. })
  706. var bowerRepos = ['client']
  707. bowerRepos.forEach(repo => {
  708. repotasks.push(() => {
  709. var p = nodeShellExec('bower', ['install'], {
  710. inherit: true, shell: true
  711. , cwd: instanceroot + '/' + repo
  712. , env: process.env
  713. , title: `bower i for ${repo}`
  714. }).then(Tasq.then).catch(Tasq.catch)
  715. return p;
  716. })
  717. })
  718. return Promise.all(rmtasks).then(() => any(repotasks));
  719. }).catch(e => {
  720. }).finally(statuslog.finally)
  721. }
  722. , 'start': (label) => {
  723. console.log('Starting Elixir Server.');
  724. var env = Object.assign({}, process.env); // Shallow clone it.
  725. // console.dir(env)
  726. env.NODE_ENV = process.env.NODE_ENV || 'development';
  727. env.DEBUG = 'loopback:connector:' + dbForLabel(label)
  728. var cmd = env.NODE_ENV === 'development' ? 'nodemon' : 'node';
  729. // cmd = 'node'
  730. cmd = [cmd, ['--inspect=9228', 'elixir/server.js']]
  731. var childPromise = nodeShellExec(...cmd, {
  732. // inherit : true,
  733. shell: true,
  734. detached: true,
  735. stdio: 'ignore',
  736. cwd: instanceroot + '/' + 'elixir-server'
  737. , env: env
  738. })
  739. var child = childPromise.process;
  740. if (typeof child.pid !== 'undefined') {
  741. console.log(`started Elixir Server PID(${child.pid}) : NODE_ENV=${process.NODE_ENV} ${cmd}`);
  742. fs.writeFileSync('.elixir-server.elixir.server.pid', child.pid, {
  743. encoding: 'utf8'
  744. })
  745. }
  746. // nodeShellExec('node', ['--inspect=9226', ' bin/www'], {
  747. // inherit : true,
  748. // shell: true, detached: true,
  749. // cwd : 'qms/server',
  750. // env: env,
  751. // shell : true
  752. // })
  753. // nodeShellExec('ember', ['s'], {
  754. // // inherit : true,
  755. // shell: true, detached: true,
  756. // cwd : 'client/',
  757. // env: env
  758. // })
  759. console.log('Starting Elixir Client Host.');
  760. var cmd = ['ember', ['s']]
  761. var childPromise = nodeShellExec(...cmd, {
  762. // var childPromise = nodeShellExec('node', ['--inspect=9227', './node_modules/.bin/ember', 's'], {
  763. // PB : TODO -- ember debugging.
  764. // inherit : true,
  765. shell: true,
  766. detached: true,
  767. stdio: 'ignore',
  768. cwd: instanceroot + '/' + 'client'
  769. , env: env
  770. })
  771. // .catch(e=>console.error(e))
  772. child = childPromise.process;
  773. if (typeof child.pid !== 'undefined') {
  774. console.log(`started Elixir Client Host PID(${child.pid}) : NODE_ENV=${process.NODE_ENV} ${cmd}`);
  775. fs.writeFileSync('.client.server.pid', child.pid, {
  776. encoding: 'utf8'
  777. })
  778. }
  779. }
  780. , 'stop': (label) => {
  781. const kill = require('tree-kill');
  782. var serverPid = fs.readFileSync('.elixir-server.elixir.server.pid', {
  783. encoding: 'utf8'
  784. })
  785. fs.unlinkSync('.elixir-server.elixir.server.pid')
  786. console.log(serverPid)
  787. kill(serverPid)
  788. serverPid = fs.readFileSync('.client.server.pid', {
  789. encoding: 'utf8'
  790. })
  791. fs.unlinkSync('.client.server.pid')
  792. console.log(serverPid)
  793. kill(serverPid)
  794. }
  795. , 'use': () => {
  796. // use a certain named instance.
  797. // Eg :
  798. // 1) elxr use elixir
  799. // 2) elxr use cihsr
  800. // If environment is not specified defaults to development.
  801. // 1) NODE=test elxr use elixir
  802. /*// Steps
  803. 1) Delete Config and Data symlinks
  804. 2) Make Links for config ({{name}}-config-{{node_env}}) and data with the NODE_ENV specified or default to dev
  805. 3) Iterates all repos and pull all. 'git', ['pull', '--all'].
  806. 4) Iterates all repos and checkout to the ENV specified. 'git', ['checkout', checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV]
  807. 5) Iterates all repos and merge from source configured in mergeSource. 'git', ['merge', mergeSource],
  808. */
  809. var runconfig = { NODE_ENV: repomanifest.node_env }
  810. try { runconfig = Object.assign(runconfig, require(instanceroot + '/run.js')) } catch (e) { }
  811. if ((!processedArgs.runas || processedArgs.runas !== 'self') &&
  812. runconfig.NODE_ENV && runconfig.NODE_ENV === (repomanifest.node_env || runconfig.NODE_ENV) &&
  813. repomanifest.instanceName && runconfig.use === repomanifest.instanceName) {
  814. console.log(`No change detected. Already using requested specs : ${runconfig.NODE_ENV} ${runconfig.use}`)
  815. if (processedArgs.runas) { fs.writeFileSync('run.done', 'success') }
  816. return
  817. }
  818. var tasks = [
  819. () => {
  820. if (existsSync('config')) {
  821. var p = nodeShellExec('rmdir', ['config'], { inherit: true, shell: true, env: process.env }
  822. ).catch((err) => { console.log('Ignoring benign error : ' + err); return true; })
  823. return p;
  824. }
  825. else return Promise.resolve(true);
  826. },
  827. () => {
  828. if (existsSync('data')) {
  829. var p = nodeShellExec('rmdir', ['data'], { inherit: true, shell: true, env: process.env }
  830. ).catch((err) => { console.log('Ignoring benign error : ' + err); return true; })
  831. return p;
  832. }
  833. else return Promise.resolve(true);
  834. },
  835. ];
  836. runconfig.NODE_ENV = process.env.NODE_ENV = process.env.NODE_ENV || runconfig.NODE_ENV || 'development';
  837. if (processedArgs._[1] && runconfig.use !== processedArgs._[1]) runconfig.use = processedArgs._[1];
  838. if (!runconfig.use) { throw 'unspecifed use not allowed. Please specify chess instance name.' }
  839. // console.log(process.env.cwd)
  840. fs.writeFileSync(instanceroot + '/run.js', 'module.exports = ' + JSON.stringify(runconfig))
  841. // Maps an environment to a branch. Not required if the branch is appropriately named.
  842. var checkoutMap = { 'development': 'master' }
  843. // cant use git checkout -b it fails with branch already exists.
  844. var performCheckout = (repo, branch) => {
  845. if (!branch) return Promise.resolve({ 'skipped': true })
  846. if (excludeCheckouts[repo]) return Promise.resolve({ 'skipped': true })
  847. return nodeShellExec('git', ['checkout', branch || checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], {
  848. // return nodeShellExec('git', ['switch', '-m', '-C', checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV], {
  849. // inherit : true, shell: true,
  850. cwd: repoinstanceroot + '/' + repo
  851. // , stdio : ignore // Use when we want to silcence output completely.
  852. , runas: processedArgs.runas
  853. , title: `git checkout ${branch || checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV} for ${repo}`
  854. }).catch((e) => { console.error(e); return { error: true, message: repo } })
  855. }
  856. if (runconfig.NODE_ENV === 'development') performCheckout = () => { return Promise.resolve(true) }
  857. var performPullAll = (repo) => {
  858. if (excludeCheckouts[repo]) return Promise.resolve({ 'skipped': true })
  859. return nodeShellExec('git', ['pull', '--all'], {
  860. // inherit : true, shell: true,
  861. cwd: instanceroot + '/' + repo
  862. , runas: processedArgs.runas
  863. , title: `git pull -all for ${checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV} ${repo}`
  864. }).catch((e) => { console.error(e); return { error: true, message: repo } })
  865. }
  866. var mergeSources = {
  867. 'development': null,
  868. 'test': 'master',
  869. 'production': 'master'
  870. }
  871. var excludeCheckouts = Object.assign(exludeMergeRepos)
  872. delete excludeCheckouts[`elixir-config-${runconfig.NODE_ENV}`]
  873. delete excludeCheckouts[`cihsr-config-${runconfig.NODE_ENV}`]
  874. var mergeSource = mergeSources[checkoutMap[runconfig.NODE_ENV] || runconfig.NODE_ENV]
  875. var performMerge = (repo) => {
  876. if (exludeMergeRepos[repo]) return Promise.resolve({ 'skipped': true })
  877. return nodeShellExec('git', ['merge', mergeSource], {
  878. inherit: true, shell: true,
  879. cwd: instanceroot + '/' + repo
  880. , runas: processedArgs.runas
  881. }).catch((e) => { console.error(e) })
  882. }
  883. if (runconfig.NODE_ENV === 'development') performMerge = () => { return Promise.resolve(true) }
  884. any(tasks).then(() => {
  885. if (!processedArgs.runas) return op['runas']()
  886. tasks = [
  887. () => {
  888. // Use junctions to avoid npm package issues
  889. var p = nodeShellExec('mklink', ['/J', 'config', runconfig.use + '-config' + '-' + process.env.NODE_ENV], {
  890. inherit: true, shell: true
  891. , env: process.env
  892. }).catch((e) => { console.error(e) })
  893. return p;
  894. }
  895. ];
  896. if (processedArgs._[1]) {
  897. tasks = tasks.concat(
  898. [
  899. () => {
  900. var p = nodeShellExec('mklink', ['/J', 'data', runconfig.use + '-data'], {
  901. inherit: true, shell: true
  902. , env: process.env
  903. }).catch((e) => { console.error(e) })
  904. return p;
  905. }
  906. ]
  907. )
  908. }
  909. return any(tasks)
  910. //target is the env is we specify in elxr use command. Default is dev
  911. .then( //Switch to target branch
  912. () => any([any(gitRepos.map((repo) => performCheckout(repo, process.env.NODE_ENV || 'development')))
  913. , any(elevatedRunasRepos.map((repo) => performCheckout(repo, process.env.NODE_ENV || 'development')))]))
  914. .then( //PULL from target branch
  915. () => any([any(gitRepos.map((repo) => performPullAll(repo))), any(elevatedRunasRepos.map((repo) => performPullAll(repo)))]))
  916. .then( //Switch to merge source branch
  917. () => any([any(gitRepos.map((repo) => performCheckout(repo, mergeSources[process.env.NODE_ENV || 'development'])))
  918. , any(elevatedRunasRepos.map((repo) => performCheckout(repo, mergeSources[process.env.NODE_ENV || 'development'])))]))
  919. .then( //Pull on merge source branch
  920. () => any([any(gitRepos.map((repo) => performPullAll(repo))), any(elevatedRunasRepos.map((repo) => performPullAll(repo)))]))
  921. .then( //Switch to target branch
  922. () => any([any(gitRepos.map((repo) => performCheckout(repo, process.env.NODE_ENV || 'development')))
  923. , any(elevatedRunasRepos.map((repo) => performCheckout(repo, process.env.NODE_ENV || 'development')))]))
  924. .then( //Merge source branch to target branch
  925. () => any([any(gitRepos.map((repo) => performMerge(repo))).catch(err => { console.error('error in performMerge ' + err) }),
  926. any(elevatedRunasRepos.map((repo) => performMerge(repo))).catch(err => { console.error('error in performMerge ' + err) })]))
  927. .then(() => {
  928. // Move test config from dev.
  929. // if(process.env.NODE_ENV === 'test'){
  930. // var devcfgreponame = runconfig.use + '-config' + '-development';
  931. // var testcfgreponame = runconfig.use + '-config' + '-test';
  932. // var testcfgdir = path.dirname(__dirname) + '/' + testcfgreponame + '/'
  933. // var devcfgdir = path.dirname(__dirname) + '/' + devcfgreponame + '/' //eg (elxr/../elixir-config.development)
  934. // return any([
  935. // ()=>{
  936. // return nodeShellExec('git', ['checkout', 'test'], {
  937. // inherit : true, shell: true,
  938. // cwd : testcfgdir
  939. // // , env: process.env
  940. // , runas : processedArgs.runas
  941. // , title : `git checkout test for ${testcfgreponame}`
  942. // }).catch((e)=>{ console.error(e) })
  943. // }
  944. // , ()=> {
  945. // return nodeShellExec('git', ['checkout', 'master'], {
  946. // inherit : true, shell: true,
  947. // cwd : devcfgdir
  948. // // , env: process.env
  949. // , runas : processedArgs.runas
  950. // , title : `git checkout master for ${devcfgreponame}`
  951. // }).catch((e)=>{ console.error(e) })
  952. // }
  953. // , ()=> {
  954. // globSync( '**/*.test.js', {cwd : devcfgdir}).map((filename) => {
  955. // console.log('File found : ' + devcfgdir + filename)
  956. // fs.copyFileSync(devcfgdir + filename, testcfgdir+ filename);
  957. // })
  958. // return nodeShellExec('git', ['checkout', 'test'], {
  959. // inherit : true, shell: true,
  960. // cwd : devcfgdir
  961. // // , env: process.env
  962. // , runas : processedArgs.runas
  963. // , title : `git checkout test for ${devcfgreponame}`
  964. // }).catch((e)=>{ console.error(e) })
  965. // }
  966. // ])
  967. // }
  968. // else {
  969. return Promise.resolve(true)
  970. // }
  971. })
  972. .then(() => {
  973. fs.writeFileSync('run.done', 'success')
  974. }).catch(() => {
  975. fs.writeFileSync('run.done', 'error')
  976. })
  977. }).catch(() => {
  978. fs.writeFileSync('run.done', 'error')
  979. })
  980. // Antibiotic stewardship program.
  981. // 1st use is fine.
  982. // Max vials dispense
  983. // 2nd use Pharmacy needs justification Form.
  984. // Approval after a certain period of time.
  985. }
  986. , 'g': () => {
  987. if (processedArgs.h) {
  988. console.log('elxr g [modelname] => generate a model named [modelname]');
  989. console.log('elxr g => regenerate all known models');
  990. return
  991. }
  992. // var child = nodeShellExec('mkdir', ['-p', label], { inherit : true} );
  993. // console.log('Starting directory: ' + process.cwd());
  994. // try {
  995. // child = child.on('close', () => { process.chdir(label) } );
  996. // console.log('New directory: ' + process.cwd());
  997. // }
  998. // catch (err) {
  999. // console.log('chdir: ' + err);
  1000. // }
  1001. // child.on('close', function(){
  1002. // var options = {
  1003. // shell : true
  1004. // , inherit : true
  1005. // // , cwd : '' + process.cwd
  1006. // // , env : process.env
  1007. // };
  1008. // nodeShellExec('git', ['init'], { inherit : true});
  1009. if (0) {
  1010. // PB : TODO -- Special google chrome profile for tests etc.
  1011. nodeShellExec('pwd', { inherit: true });
  1012. // /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"
  1013. // "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
  1014. // "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
  1015. nodeShellExec("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe", [
  1016. "--profile-directory=Profile 1"
  1017. , 'http://localhost:4200/tests/index.html?grep=model convert ember to loopback' + '&filter=none' /*+ '&filter=model convert ember to loopback'*/]);
  1018. }
  1019. // nodeShellExec('npm', ['init', '-y'], options);
  1020. // nodeShellExec('npm', ['init', '-y'], options);
  1021. // })
  1022. var g = {
  1023. 'client': () => {
  1024. console.info('Creating new ember client named : ' + processedArgs._[2]);
  1025. var step1 = nodeShellExec('cmd', ['/c', 'ember', 'new', processedArgs._[2]], {
  1026. stdio: ['pipe', process.stdout, process.stderr],
  1027. inherit: true,
  1028. shell: true,
  1029. cwd: path.dirname(__dirname),
  1030. env: env
  1031. })
  1032. },
  1033. 'modelr': () => {
  1034. var tasks = [
  1035. () => {
  1036. var p = nodeShellExec('"ember"', [
  1037. 'g'
  1038. , 'modelr'
  1039. , processedArgs._[2]], {
  1040. inherit: true, shell: true, env: process.env
  1041. }).then(() => {
  1042. console.log('Blueprint generation complete for : ' + processedArgs._[2])
  1043. return true;
  1044. }).catch((e) => { console.error(e) })
  1045. return p;
  1046. },
  1047. () => {
  1048. var chromePrefsFile = "C:\\chess\\instances\\elixir_01\\data\\Google\\Chrome\\User Data\\chess\\Preferences";
  1049. var chromeprefs = fs.readFileSync(chromePrefsFile, { encoding: 'utf8' })
  1050. chromeprefs = JSON.parse(chromeprefs)
  1051. var previous = chromeprefs.download.default_directory;
  1052. var parentDir = path.dirname(__dirname);
  1053. chromeprefs.download.default_directory = parentDir + "\\client\\app\\templates\\components\\resource";
  1054. fs.writeFileSync(chromePrefsFile, JSON.stringify(chromeprefs))
  1055. // PB : TODO -- detect where chrome is installed.
  1056. // PB : TODO -- set the download dir to the place where files are needed.
  1057. var p = nodeShellExec('"C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"', [
  1058. '--user-data-dir="C:\\chess\\instances\\elixir_01\\data\\Google\\Chrome\\User Data"'
  1059. , '--profile-directory="chess"'
  1060. , 'http://localhost:4200/admin/crud/create/' + processedArgs._[2]], {
  1061. inherit: true, shell: true
  1062. , env: process.env
  1063. }).then(() => {
  1064. chromeprefs.download.default_directory = previous;
  1065. fs.writeFileSync(chromePrefsFile, JSON.stringify(chromeprefs))
  1066. return true;
  1067. }).catch((e) => { console.error(e) })
  1068. return p;
  1069. }
  1070. ,
  1071. () => {
  1072. console.log('Browser process should have closed here....')
  1073. return true;
  1074. }
  1075. ]
  1076. any(tasks)
  1077. }
  1078. }
  1079. g[processedArgs._[1]]();
  1080. }
  1081. }
  1082. var util = require('util')
  1083. var cliname = 'elxr';
  1084. var ver = '1.1';
  1085. var help = `# list of commands... please refer dveloper documentation for ${cliname}
  1086. ${
  1087. // util.inspect(
  1088. [Object.keys(op)]
  1089. // )
  1090. }
  1091. `;
  1092. var elxr = {
  1093. help() {
  1094. return chalk.cyanBright(`
  1095. -------------------------------------------------------------------------------
  1096. *** BBH Elixir ***
  1097. -------------------------------------------------------------------------------
  1098. elxr ${ver}
  1099. A cli tool for chess
  1100. ${help}
  1101. -------------------------------------------------------------------------------
  1102. `)
  1103. }
  1104. , info() {
  1105. return chalk.cyanBright(`
  1106. -------------------------------------------------------------------------------
  1107. *** BBH Elixir ***
  1108. -------------------------------------------------------------------------------
  1109. elxr ${ver}
  1110. A cli tool for chess
  1111. -------------------------------------------------------------------------------
  1112. `)
  1113. }
  1114. }
  1115. // The main elxr cli process
  1116. function elxrworker(hasconfig) {
  1117. // Everything runs after this check is completed. Elevation occurs out of process when needed.
  1118. gitRepos = repomanifest.repos
  1119. // Repositiories that have symlinks that require elevated priviletes in windows to create symlinks
  1120. elevatedRunasRepos = repomanifest.elevated
  1121. // Repos that should excluded from merge for releases...
  1122. exludeMergeRepos = repomanifest.exludeMergeRepos
  1123. var env = Object.assign({}, process.env); // Shallow clone it.
  1124. var __runcmd = function (label) {
  1125. return op[label] ? op[label]() : null;
  1126. }
  1127. // mysqldump --add-drop-table --no-data -u root -p db_name | grep 'DROP TABLE' ) > drop_all_tables.sql
  1128. // mysql -u root -p db_name < drop_all_tables.sql
  1129. var mysql = '../xampp/mysql/bin/mysql'
  1130. var mysqldump = '../xampp/mysql/bin/mysqldump'
  1131. // --runas
  1132. if (processedArgs.runas) {
  1133. // Weve been asked to run in priviledged mode. Check if we already are privileged.
  1134. return __runcmd('runas')
  1135. }
  1136. else return __runcmd(processedArgs.label || processedArgs._[0] || 'h');
  1137. }
  1138. var getManifest = function () {
  1139. // Once choices are made we need to load config according to those choices.
  1140. // No trace of a previous run...
  1141. // Default Config...
  1142. return repomanifest = selectedinstance;
  1143. }
  1144. function acquireChoices(selectedinstance) {
  1145. var hasconfig = false;
  1146. console.warn(chalk.yellow(`
  1147. -------------------------------------------------------------------------------
  1148. Warning : Cannot locate your preferred configuration since it was not specified
  1149. You should fork the default chess configuration to customize and make it
  1150. your own instance with a named config as
  1151. {{yourowninstancename}}-config-{{yourcurrentenvironment}}
  1152. And then run this tool as follows
  1153. NODE_ENV={{yourenvironment}} elxr i {{yourowninstancename}}
  1154. OR
  1155. Run this tool with the following command to use a quick start default.
  1156. node elxr --default
  1157. OR
  1158. Choose the the option to create a new instance for you interactively.
  1159. We will run your choice of default or create your own at the next prompt.
  1160. -------------------------------------------------------------------------------
  1161. `))
  1162. var prompt = cli.prompt;
  1163. return prompt.ask(`Choose an option :
  1164. d) Install the default chess instance.
  1165. => elxr i chess node_env=development --default
  1166. n) Create your custom new instance interactively
  1167. => elxr i {{instanceName}} node_env={{environment}}
  1168. i) Choose an instance and environment to install
  1169. => elxr i {{instanceName}} node_env={{environment}}
  1170. c) Choose a command to run ( pull, use, i, npmi ... ) <= pull
  1171. => elxr {{cmd}} {{instanceName}} node_env={{environment}}
  1172. h) Help
  1173. q) Quit
  1174. Default <= d
  1175. : `).then((choice) => {
  1176. prompt.close();
  1177. if (choice && choice === 'd' || !choice) {
  1178. processedArgs._[0] = 'i'
  1179. selectedinstance.instanceName = processedArgs._[1] = processedArgs._[1] || 'chess'
  1180. selectedinstance.node_env = processedArgs.node_env = (process.env.NODE_ENV && process.env.NODE_ENV.trim()) || processedArgs.node_env || 'development'
  1181. defaultRepoServer = 'https://git.bbh.org.in'
  1182. getManifest() // PB : TODO -- acquire the manifest directly from http url instead of clone before cloning the config. Since
  1183. // This is because the manifest at any server location can redirect to the preferred server..
  1184. }
  1185. else if (choice === 'h') {
  1186. processedArgs._[0] = 'h'
  1187. fs.writeFileSync('run.done', 'noop help');
  1188. console.log(elxr.help()); process.exit()
  1189. }
  1190. else if (choice === 'n' || choice === 'i') {
  1191. var p1 = cli.prompt;
  1192. return p1.ask(`Enter Instance Name ( <= ${selectedinstance.instanceName} ) : `).then(function (instanceName) {
  1193. processedArgs._[0] = 'i'
  1194. selectedinstance.instanceName = processedArgs._[1] = instanceName || selectedinstance.instanceName;
  1195. return p1.ask(`Enter Environment ( <= ${selectedinstance.node_env} ) : `).then(function (node_env) {
  1196. selectedinstance.node_env = processedArgs.node_env = node_env || selectedinstance.node_env
  1197. if (choice === 'n') {
  1198. defaultRepoServer = 'https://git.bbh.org.in'
  1199. console.warn(
  1200. chalk.magenta('No Option Available. Your account may not have privileges. You can request here http://git.bbh.org.in/chess'))
  1201. process.exit();
  1202. }
  1203. return p1.ask(`Enter preferred repo server ( <= ${selectedinstance.reposervers[0]} ) : `).then(function (reposerver) {
  1204. p1.close()
  1205. defaultRepoServer = reposerver || selectedinstance.reposervers[0] || 'https://git.bbh.org.in'
  1206. })
  1207. })
  1208. })
  1209. } else if (choice === 'c') {
  1210. var p1 = cli.prompt;
  1211. return p1.ask(`Enter Instance Name ( <= ${selectedinstance.instanceName} ) : `).then(function (instanceName) {
  1212. selectedinstance.instanceName = processedArgs._[1] = instanceName || selectedinstance.instanceName
  1213. return p1.ask(`Enter Environment ( <= ${selectedinstance.node_env} ) : `).then(function (node_env) {
  1214. selectedinstance.node_env = processedArgs.node_env = node_env || selectedinstance.node_env
  1215. return p1.ask(`Enter cmd :
  1216. p) pull
  1217. Default <= p
  1218. : `).then(function (cmd) {
  1219. if (!cmd || cmd === 'p') {
  1220. processedArgs._[0] = 'pull'
  1221. }
  1222. else processedArgs._[0] = cmd
  1223. return p1.ask(`Enter preferred repo server ( <= ${selectedinstance.reposervers[0]} ) : `).then(function (reposerver) {
  1224. defaultRepoServer = reposerver || selectedinstance.reposervers[0] || 'https://git.bbh.org.in'
  1225. p1.close()
  1226. })
  1227. })
  1228. })
  1229. })
  1230. } else {
  1231. console.log(chalk.gray(`Default option not exercised. Please follow manual instructions to customize your instance here http://git.bbh.org.in/chess and try again.`));
  1232. fs.writeFileSync('run.log', ', ' + JSON.stringify({ success: 'quit without execution' }), { 'flag': 'a+' })
  1233. fs.writeFileSync('run.done', 'noop quit');
  1234. process.exit()
  1235. }
  1236. })
  1237. }
  1238. var acquireConfig = function (selected, chessinstances) {
  1239. var configrepo = selected.instanceName + '-config-' + selected.node_env;
  1240. return performPull(configrepo).then(() => {
  1241. var manifestpath = path.normalize(selected.root + '/' + selected.instanceName + '-config-' + selected.node_env + '/repo-manifest');
  1242. repomanifest = require(manifestpath)()
  1243. chessinstances = chessinstances || {};
  1244. chessinstances[selected.instanceName] = chessinstances[selected.instanceName] || {}
  1245. chessinstances[selected.instanceName][selected.node_env] = chessinstances[selected.instanceName][selected.node_env] || {}
  1246. chessinstances['current_run'] = { instanceName: selected.instanceName, node_env: selected.node_env }
  1247. // Config from server always override merges into selection ecept for the current selection.
  1248. selectedinstance = utils.assign(chessinstances[selected.instanceName][selected.node_env], selected, repomanifest)
  1249. fs.writeFileSync(instanceroot + '/chessinstances.js', 'module.exports = ' + JSON.stringify(chessinstances) + '', { 'flag': 'w' })
  1250. // PB : TODO -- We should probably write the new server config also...
  1251. defaultRepoServer = selectedinstance.reposervers[0] // PB : TODO -- Attempt first one that is available and online...
  1252. ENV.NODE_ENV = selectedinstance.node_env;
  1253. })
  1254. .catch((e) => {
  1255. console.error(e)
  1256. console.error('Config acquisition failed.')
  1257. })
  1258. }
  1259. var launchpath = process.cwd()
  1260. var thisscriptdir = __dirname
  1261. var instanceroot = launchpath;
  1262. var detectInstance = function () {
  1263. console.log(`launchpath = ${launchpath}`)
  1264. console.log(`thisscriptdir = ${thisscriptdir}`)
  1265. var root = launchpath;
  1266. // We need a reference to the root director for elxr cli to be properly oriented.
  1267. if ((launchpath + path.normalize('/elxr')) === thisscriptdir) {
  1268. // We ran unbuilt from the proper root with elxr subfolder.
  1269. console.log(`Instance Path : ${root}`)
  1270. }
  1271. else {
  1272. if (launchpath === thisscriptdir) {
  1273. // Same directory doesn't mean we are being run from elxr directory or the root directory.
  1274. // It could be a standalone elxr build which may or maynot be in the proper location.
  1275. if (BUILD_VERSION.indexOf('Version: {version} - built on {date}') > -1) {
  1276. // Unbuilt therefore we are in the elxr directory.
  1277. root = path.normalize(launchpath + '/..');
  1278. }
  1279. else {
  1280. // Built version.
  1281. // check if we have a elxr subfolder.
  1282. if (fs.existsSync(launchpath + '/..' + path.normalize('/elxr'))) {
  1283. // Probably in the right place.
  1284. root = path.normalize(launchpath + '/..');
  1285. }
  1286. else {
  1287. // Assume launchpath is meaningless.
  1288. // Figure it out from the input instance name and environment parameters if we are in the right location.
  1289. root = path.normalize(launchpath + '/' + processedArgs._[1] + '/' + processedArgs.node_env)
  1290. }
  1291. }
  1292. }
  1293. }
  1294. instanceroot = root;
  1295. var __default = {
  1296. // Default is public server only.
  1297. reposervers: ['https://git.bbh.org.in']
  1298. // All public repos are by default available.
  1299. , repos: [
  1300. 'setup'
  1301. , 'elxr'
  1302. , 'loopback-connector-mysql'
  1303. , 'loopback-jsonapi-model-serializer'
  1304. , 'loopback-component-jsonapi'
  1305. , 'ember-service-worker'
  1306. , 'ember-service-worker-asset-cache'
  1307. , 'ember-service-worker-cache-fallback'
  1308. , 'ember-service-worker-index'
  1309. , 'ember-sw-client-route'
  1310. ]
  1311. , elevated: []
  1312. , exludeMergeRepos: {}
  1313. , instanceName: 'chess'
  1314. // Runas windowshta clobbers and removes the NODE_ENV !!! We therefore pass it in.
  1315. , node_env: 'development'
  1316. }
  1317. return Object.assign({ root }, __default);
  1318. }
  1319. var gitUser = 'chessdemo';
  1320. var gitEmail = 'chessdemo@bbh.org.in'
  1321. var downloadsdir = '../Downloads';
  1322. var prerequisites = [
  1323. {
  1324. shellcmd: 'git',
  1325. url: 'https://github.com/git-for-windows/git/releases/download/v2.31.0.windows.1/Git-2.31.0-64-bit.exe'
  1326. , installer: 'Git-2.31.0-64-bit.exe'
  1327. , installcmd: ['cmd', ['/c', 'start',
  1328. '/WAIT', path.resolve(downloadsdir + '/' + 'Git-2.31.0-64-bit.exe')
  1329. , '/VERYSILENT'
  1330. // , '/MERGETASKS=!runcode' // This is required only for vscode...
  1331. ]]
  1332. , preinstallsteps: () => {
  1333. var prompt = cli.prompt;
  1334. var steps = [
  1335. () => {
  1336. if (!existsSync(downloadsdir + '/' + preq.installer)) {
  1337. return nodeShellExec('download.bat', [preq.url, downloadsdir + '/' + preq.installer])
  1338. }
  1339. else return Promise.resolve(true)
  1340. }
  1341. ]
  1342. var prompts = [
  1343. () => prompt.ask(`git user name : ( <= ${gitUser} )`).then((user) => { gitUser = user; })
  1344. , () => prompt.ask(`git user name : ( <= ${gitEmail} )`).then((email) => { gitEmail = email; })
  1345. ]
  1346. return Promise.all([any(steps), any(prompts)]).finally(() => { prompt.close() })
  1347. }
  1348. , installsteps: function () {
  1349. return any([this.installcmd].map(callsheltask))
  1350. }
  1351. , postinstallsteps: () => {
  1352. var steps = [
  1353. ['git', ['config', '--global', '--add', 'user.name', `${gitUser}`]]
  1354. , ['git', ['config', '--global', '--add', 'user.email', `${gitEmail}`]]
  1355. ]
  1356. return any(steps.map(callsheltask)).then(() => { })
  1357. }
  1358. , install: function () {
  1359. return any([ /*this.preinstallsteps,*/ this.installsteps, this.postinstallsteps])
  1360. }
  1361. }
  1362. ,
  1363. {
  1364. shellcmd: 'node',
  1365. url: 'https://nodejs.org/dist/v14.16.0/node-v14.16.0-x64.msi'
  1366. , installer: 'node-v14.16.0-x64.msi'
  1367. , installcmd: ['MSIEXEC.exe', ['/i'
  1368. , path.resolve(downloadsdir + '/' + 'node-v14.16.0-x64.msi')
  1369. , 'ACCEPT=YES', '/passive']]
  1370. }
  1371. ]
  1372. function ensureDirectoryExistence(filePath) {
  1373. var dirname = path.dirname(filePath);
  1374. if (fs.existsSync(dirname)) {
  1375. return filePath;
  1376. }
  1377. ensureDirectoryExistence(dirname);
  1378. fs.mkdirSync(dirname);
  1379. return filePath;
  1380. }
  1381. var mainTasks = [];
  1382. function verifyAndInstallPrerequisites() {
  1383. fs.writeFileSync(ensureDirectoryExistence(path.normalize(downloadsdir + '/readme.txt')), `${getVersion()} Your local downloads for this instance`)
  1384. var downloadbatch =
  1385. `::**************************************************************************
  1386. :Download_ <url> <File>
  1387. Powershell.exe ^
  1388. $AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'; ^
  1389. [System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols; ^
  1390. (New-Object System.Net.WebClient).DownloadFile('%1','%2')
  1391. exit /b
  1392. ::**************************************************************************`
  1393. fs.writeFileSync('download.bat', downloadbatch)
  1394. var downloadtasks = [];
  1395. var installtasks = [];
  1396. prerequisites.forEach(preq => {
  1397. downloadtasks.push(getTaskCheckExists(preq.shellcmd, { ignorefailures: true })().then((exists) => {
  1398. if (exists) console.log(`${preq.shellcmd} exists`)
  1399. else {
  1400. console.log(`${preq.shellcmd} is not installed`)
  1401. return preq.preinstallsteps().then(() => {
  1402. installtasks.push(task.install)
  1403. })
  1404. }
  1405. }))
  1406. })
  1407. return Promise.all(downloadtasks).then(() => { return any(installtasks) })
  1408. }
  1409. function initinstances(chessinstances, selected) {
  1410. chessinstances.current_run.instanceName = processedArgs._[1] = processedArgs._[1] || chessinstances.current_run.instanceName || selected.instanceName;
  1411. chessinstances.current_run.node_env = processedArgs.node_env = processedArgs.node_env || chessinstances.current_run.node_env || selected.node_env;
  1412. chessinstances[chessinstances.current_run.instanceName] = chessinstances[chessinstances.current_run.instanceName] || {}
  1413. selectedinstance = Object.assign(selected, chessinstances[chessinstances.current_run.instanceName][chessinstances.current_run.node_env], clioverrides);
  1414. repomanifest = selectedinstance
  1415. return chessinstances
  1416. }
  1417. function acquirelocalinstances(selected){
  1418. var chessinstances = utils.assign(require(path.normalize(selected.root + '/chessinstances.js')));
  1419. return initinstances(chessinstances, selected)
  1420. }
  1421. function updateselection(selected) { selectedinstance = utils.assign(selectedinstance, selected) }
  1422. var detectedInstance = detectInstance(); // From launch location etc.
  1423. var selectedinstance = detectedInstance
  1424. var clioverrides = { }
  1425. processedArgs._[1] ? clioverrides.instanceName = processedArgs._[1]: null;
  1426. processedArgs.node_env ? clioverrides.node_env = (process.env.NODE_ENV && process.env.NODE_ENV.trim()) || processedArgs.node_env
  1427. : (process.env.NODE_ENV && process.env.NODE_ENV.trim()) ? clioverrides.node_env = (process.env.NODE_ENV && process.env.NODE_ENV.trim()): null;
  1428. var maintask = () => {
  1429. try {
  1430. // Default cmd to run !
  1431. var chessinstances = acquirelocalinstances(selectedinstance);
  1432. processedArgs._[0] === processedArgs._[0] || 'pull';
  1433. // defaultRepoServer = repomanifest.reposervers[0] // PB : TODO -- Attempt first one that is available and online from all that are available...
  1434. return acquireConfig(selectedinstance, chessinstances).catch((e) => {
  1435. console.error('Exisitng config Failed. Fix config and rerun or chose another.')
  1436. console.error(e);
  1437. }).then(() => { return elxrworker(true) })
  1438. }
  1439. catch (e) {
  1440. console.error(e)
  1441. // No local instances config found. We acquire user choices and proceed to reattempt.
  1442. chessinstances = {}
  1443. chessinstances.current_run = {}
  1444. initinstances(chessinstances, selectedinstance)
  1445. return acquireChoices(selectedinstance).then(() => {
  1446. try {
  1447. var chessinstances = acquirelocalinstances(selectedinstance)
  1448. }
  1449. catch (e) {
  1450. console.error(e)
  1451. console.error('No local instances config found in current root = ' + selectedinstance.root);
  1452. console.log('A config will be createed with the instance and environment chosen...')
  1453. }
  1454. finally {
  1455. return acquireConfig(selectedinstance, chessinstances).catch((e) => {
  1456. console.error('Chosen cofiguraton failed or not found')
  1457. console.error(e)
  1458. }).then(() => { return elxrworker(true) })
  1459. .finally(()=>{
  1460. fs.writeFileSync('run.log', ', ' + JSON.stringify({ error: e.message }), { 'flag': 'a+' })
  1461. fs.writeFileSync('run.done', 'error');
  1462. // return process.exit()
  1463. })
  1464. }
  1465. })
  1466. }
  1467. }
  1468. acquireElevationState().then(() => {
  1469. var skipprerequisites = false
  1470. if (!skipprerequisites && !__isElevated) mainTasks.push(verifyAndInstallPrerequisites);
  1471. mainTasks.push(maintask)
  1472. return any(mainTasks);
  1473. })
  1474. // detect if alread installed -> Take no action.
  1475. // download if no installer avalable -> next()
  1476. // install
  1477. function chackandinstall(items) {
  1478. var tasks = []
  1479. items.forEach(item => {
  1480. tasks.push(getTaskCheckExists(item.shellcommand || prerequisites[item]))
  1481. })
  1482. return Promise.all(tasks).then(existances => {
  1483. existances.forEach((exists, i) => {
  1484. if (!exists) {
  1485. return downloadandinstall([items[i]])
  1486. }
  1487. })
  1488. })
  1489. }
  1490. function downloadandinstall(items) {
  1491. var tasks = []
  1492. items.forEach(item => {
  1493. tasks.push(getTaskDownload(item))
  1494. })
  1495. return Promise.all(tasks)
  1496. }
  1497. // Sample instances config.
  1498. // var instances = {
  1499. // "elixir": {
  1500. // "production": {
  1501. // "reposervers": ["http://git.bbh", "https://git.bbh.org.in"]
  1502. // , "repos": ["ember-masonry-grid", "client", "elixir-client"]
  1503. // , "exludeMergeRepos": {
  1504. // "elixir-config-development": true, "elixir-config-test": true
  1505. // , "elixir-config-production": true, "elixir-data": true
  1506. // }
  1507. // , "instanceName": "elixir", "node_env": "production"
  1508. // }
  1509. // },
  1510. // "current_run": { "instanceName": "elixir", "node_env": "production" }
  1511. // }