555
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. // --------------
  2. // elxr
  3. // A cli tool for elixr.
  4. const { existsSync } = require('fs');
  5. const fs = require('fs')
  6. const { spawn, spawnSync } = require('child_process');
  7. const cliargs = require('../elxr/cliargs'); // Use minimist...
  8. const processedArgs = cliargs(process.argv.slice(2));
  9. console.dir(processedArgs)
  10. var path = require('path')
  11. // Serialize a set of functions that will execute to return a promises one after the other.
  12. // Will stop when any one fails.
  13. function any(iterable, continueOnFailure) {
  14. return iterable.reduce(
  15. (p, fn, i ,a) => {
  16. // console.log('accumulator :');
  17. // console.log(p);
  18. if(Promise.resolve(p) === p ) {
  19. return p.then((pVal) => {
  20. if(Promise.resolve(pVal) === pVal) {
  21. // Passed in function retured a promise. We still need to wait for it.
  22. pVal.then((pVal)=>{
  23. // console.log('Then --pVal = ' + pVal + ' bContinue = ' + continueOnFailure ); console.log(p);
  24. if(!pVal && !continueOnFailure) {
  25. console.error("E : pVal :" + pVal);
  26. // i==0 ? null : console.error("E :1 a[i-1] " + a[i-1]);
  27. // a.map((i)=>console.error(i.toString()));
  28. console.error('debugData 3 -------------------');
  29. // console.error(debugData);
  30. console.error('debugData 3 -------------------');
  31. console.log("Cancelling remaining...");
  32. throw 'Failed in reduce 1 '
  33. return false;
  34. }
  35. // console.log('calling fn : '+ fn);
  36. return (Promise.resolve(fn) === fn ) ? fn : fn() ;
  37. })
  38. }
  39. else {
  40. // console.log('Then --pVal = ' + pVal + ' bContinue = ' + continueOnFailure ); console.log(p);
  41. if(!pVal && !continueOnFailure) {
  42. console.error("E : pVal :" + pVal);
  43. // i==0 ? null : console.error("E :1 a[i-1] " + a[i-1]);
  44. // a.map((i)=>console.error(i.toString()));
  45. console.error('debugData 3 -------------------');
  46. // console.error(debugData);
  47. console.error('debugData 3 -------------------');
  48. console.log("Cancelling remaining...");
  49. throw 'Failed in reduce 1 '
  50. return false;
  51. }
  52. // console.log('calling fn : '+ fn);
  53. return (Promise.resolve(fn) === fn ) ? fn : fn() ;
  54. }
  55. }).catch((error) => {
  56. console.error("E : " + error);
  57. fn ? console.error("Fn : " + fn.toString()) : null;
  58. // i==0 ? null : console.error("E :2 a[i-1] " + a[i-1]);
  59. // a.map((i)=>console.error(i.toString()));
  60. console.error('debugData 4-------------------------');
  61. // console.error(debugData);
  62. console.error('debugData 4-------------------------');
  63. throw 'Failed in reduce 2 '
  64. return false;
  65. })
  66. }
  67. else if(!p) {
  68. console.log("Bypass on failure");
  69. return false;
  70. }
  71. }
  72. , Promise.resolve(true)
  73. );
  74. }
  75. var isRunningElevated = ()=>{
  76. return nodeShellExec( "fsutil", ["dirty", "query", "C:"], {
  77. inherit : true, shell: true
  78. , env: process.env
  79. , title : `check privileged execution mode using fsutil dirty query C:`
  80. }).then((exitcode)=>{
  81. console.log('Elevated')
  82. return true;
  83. }).catch(()=>{
  84. console.log('Not Elevated');
  85. throw false;
  86. });
  87. }
  88. var cli = 'elxr';
  89. var ver = '#unversioned';
  90. var help = '#unkown list of commands... please refer dveloper documentation for ' + cli;
  91. // grep -qxF 'alias elxr="node elxr/index.js"' ~/.bash_profile || echo 'alias elxr="node elxr/index.js"' >> ~/.bash_profile
  92. // nodeShellExec('echo', ['elxr'], { inherit : true}) //, {stdio: "inherit"}
  93. var dbForLabel = function(label){
  94. var dbsForLabel = {
  95. devmysql : 'mysql'
  96. , development : 'mssql'
  97. , production : 'mssql'
  98. }
  99. return dbsForLabel[label] || 'mysql'
  100. }
  101. // Relevant git repos
  102. var gitRepos = [
  103. 'ember-masonry-grid'
  104. , 'bbhverse'
  105. , 'clientverse'
  106. , 'serververse'
  107. , 'client'
  108. // , 'client/server'
  109. , 'elxr'
  110. , 'ember-searchable-select'
  111. , 'loopback-component-jsonapi'
  112. , 'elixir-config'
  113. , 'cihsr-config'
  114. , 'cihsr-data'
  115. , 'elixir-data'
  116. , 'loopback-connector-ds'
  117. , 'chess-server-lib'
  118. , 'setup'
  119. , 'elixir-client-todos'
  120. , 'elixir-client-unlinked'
  121. , 'elixir-client'
  122. , 'ember-service-worker'
  123. , 'ember-service-worker-asset-cache'
  124. , 'ember-service-worker-cache-fallback'
  125. , 'ember-service-worker-index'
  126. , 'ember-sw-client-route'
  127. , 'global-this'
  128. ]
  129. // Repositiories that have symlinks that required elevated priviletes in windows to create symlinks
  130. //
  131. var elevatedRunasRepos = [
  132. 'elixir-server'
  133. , 'cihsr-server'
  134. , 'chess-server'
  135. ]
  136. var env = Object.assign({}, process.env); // Shallow clone it.
  137. var __runcmd = function(label){
  138. var op = {
  139. 'h' : ()=>{ console.log(cli + ' ' + ver + ' ' + help); return '-h' }
  140. , 'upgrade' : ()=>{
  141. console.log('upgrade.......')
  142. var tasks = [
  143. ()=>{
  144. var p = nodeShellExec('npm', ['i', '-g', 'npm-upgrade'], {
  145. inherit : true, shell: true
  146. , env: process.env
  147. }).catch((e)=>{ console.error(e) })
  148. p.position = 1;
  149. console.log('One')
  150. return p;
  151. }
  152. , ()=>{
  153. var p = nodeShellExec('npm', ['cache', 'clean', '-f'], {
  154. inherit : true, shell: true
  155. , env: process.env
  156. }).catch((e)=>{ console.error(e) })
  157. p.position = 2;
  158. console.log('Two')
  159. return p;
  160. }
  161. , ()=>{
  162. var p = nodeShellExec('npm', ['install', '-g', 'n'], {
  163. inherit : true, shell: true
  164. , env: process.env
  165. }).catch((e)=>{ console.error(e) })
  166. p.position = 3;
  167. console.log('Three')
  168. return p;
  169. }
  170. , ()=>{
  171. var p = nodeShellExec('n', ['latest'], {
  172. inherit : true, shell: true
  173. , env: process.env
  174. }).catch((e)=>{ console.error(e) })
  175. p.position = 4;
  176. console.log('Four')
  177. return p;
  178. }
  179. ]
  180. any(tasks)
  181. console.log('.......done')
  182. console.log('Running exlr upgrade in : ' + path.dirname(__dirname))
  183. console.log('Currently only upgrades ember : ' + path.dirname(__dirname));
  184. console.info('Uninstalling existing ember globally') ;
  185. var step1 = nodeShellExec('cmd', ['/c', 'npm', 'uninstall', '-g', 'ember-cli'], {
  186. stdio: ['pipe', process.stdout, process.stderr],
  187. inherit : true,
  188. shell: true,
  189. cwd : path.dirname(__dirname),
  190. env: env
  191. })
  192. step1.on('close', ()=>{
  193. console.info('Installing ember globally') ;
  194. var step2 = nodeShellExec('cmd', ['/c', 'npm', 'install', '-g', 'ember-cli'], {
  195. stdio: ['pipe', process.stdout, process.stderr],
  196. inherit : true,
  197. shell: true,
  198. cwd : path.dirname(__dirname),
  199. env: env
  200. })
  201. step2.on('close', ()=>{
  202. nodeShellExec('cmd', ['/c', 'ember', '--version'], {
  203. stdio: ['pipe', process.stdout, process.stderr],
  204. inherit : true,
  205. shell: true,
  206. cwd : path.dirname(__dirname),
  207. env: env
  208. })
  209. })
  210. })
  211. }
  212. , 'runas' : ()=>{
  213. return isRunningElevated().then(
  214. () => op[ processedArgs.label || processedArgs._[0] || 'h']()
  215. )
  216. .catch(()=>{
  217. console.log('Not Elevated');
  218. console.dir(processedArgs)
  219. console.log('Requesting Elevated Privileges for : ' + `--insptec-brk elxr ${processedArgs._[0]} ${processedArgs._[1]} --runas=true`)
  220. nodeShellExec('MSHTA', [`javascript: var shell = new ActiveXObject('shell.application'); shell.ShellExecute('node', 'elxr ${processedArgs._[0]} ${processedArgs._[1]} --runas=true', '', 'runas', 1);close();`]
  221. , {
  222. // inherit : true
  223. // , shell: true
  224. env: process.env
  225. , title : `runas`
  226. }
  227. );
  228. })
  229. }
  230. , 'push' : ()=>{
  231. if(!processedArgs._[1]) { console.error('push all not supported. Specify repo name'); return }
  232. // init remote bare from local
  233. // pushandinitremotebare
  234. // https://www.jeffgeerling.com/blogs/jeff-geerling/push-your-git-repositories
  235. // connect to repo server -- net use 172.16.0.27
  236. // cd 172.16.0.27/repos/
  237. // mkdir repo.git
  238. // cd repo.git
  239. // git init --bare
  240. // cd localrepo
  241. // git remote rename origin githubclone
  242. // git remote add origin //172.16.0.27/repos/repo.git
  243. // git push origin master
  244. var repo = processedArgs._[1];
  245. var defaultRepoServer = '//172.16.0.27/repos'
  246. var sequentialTaskShellCommands = [];
  247. if(!existsSync(`Z:/${repo}.git`)){
  248. sequentialTaskShellCommands = [
  249. // ['net', ['use', 'Z:', defaultRepoServer.replace('/','\\')], {
  250. // inherit : true, shell: true
  251. // , env: process.env
  252. // }]
  253. ['pwd', { cwd : 'Z:', inherit : true}]
  254. , ['mkdir', [`${repo}.git`], {
  255. cwd : `Z:`
  256. , inherit : true, shell: true
  257. , env: process.env
  258. }]
  259. , ['pwd', { cwd : `Z:/${repo}.git`, inherit : true}]
  260. , ['git', ['init', '--bare'], { cwd : `Z:/${repo}.git`
  261. , inherit : true, shell: true
  262. , env: process.env
  263. }]
  264. , ['git', ['remote', 'rename', 'origin', 'githubclone'], { cwd : `${repo}`}, (err)=>{
  265. console.log('Ignoring origin rename error : ' + err); return true; //return true to continue.
  266. } ] // PB ; Todo -- new repositories created locally will not have origin. Handle this failure.
  267. , ['git', ['remote', 'add', 'origin', `${defaultRepoServer}/${repo}.git`], { cwd : `${repo}`}]
  268. ]
  269. if(!existsSync(`Z:`)){
  270. sequentialTaskShellCommands.splice(0,0, ['net', ['use', 'Z:', defaultRepoServer.replace(/\//gm,'\\')], {
  271. inherit : true, shell: true
  272. , env: process.env
  273. }])
  274. console.warn('Adding network drive z: for repo server. ' + sequentialTaskShellCommands[0])
  275. // throw 'done'
  276. }
  277. }
  278. sequentialTaskShellCommands.push(['git', ['push', 'origin', 'master'], { cwd : `${repo}`}])
  279. // console.dir(sequentialTaskShellCommands);
  280. var tasks = [];
  281. sequentialTaskShellCommands.forEach(shellcmd => {
  282. // console.log(shellcmd)
  283. tasks.push(()=>{
  284. var p = nodeShellExec.apply(null, shellcmd.slice(0,3)).catch((e)=>{ if(shellcmd[3]) { return shellcmd[3]() } else { console.error(e);} })
  285. return p;
  286. })
  287. })
  288. any(tasks);
  289. }
  290. , 'pull' : (label) => {
  291. var env = Object.assign({}, process.env); // Shallow clone it.
  292. // console.dir(env)
  293. console.log('Running exlr pull : ' + path.dirname(__dirname))
  294. // nodeShellExec('cmd', ['/c', 'setup\\utility\\chess.bat', 'pull'], {
  295. // // nodeShellExec('cmd', ['/c', '..\\setup\\utility\\chess.bat', 'pull'], {
  296. // stdio: ['pipe', process.stdout, process.stderr],
  297. // inherit : true,
  298. // shell: true,
  299. // cwd : path.dirname(__dirname),
  300. // env: env
  301. // })
  302. var performPull = repo => {
  303. if(existsSync(repo)) {
  304. console.log('pulling ' + repo)
  305. nodeShellExec('git', ['pull'], {
  306. inherit : true, shell: true,
  307. cwd : repo
  308. // , env: process.env
  309. , title : `git pull ${repo}`
  310. }).catch((e)=>{ console.error(e) })
  311. }
  312. else {
  313. console.log('cloning ' + repo)
  314. nodeShellExec('git', ['clone', '//172.16.0.27/repos/' + repo + '.git'],
  315. {
  316. inherit : true, shell: true,
  317. env: process.env
  318. , title : `git clone ${'//172.16.0.27/repos/' + repo + '.git'}`
  319. }).catch((e)=>{ console.error(e) })
  320. }
  321. }
  322. if(!processedArgs.runas) gitRepos.forEach(performPull)
  323. return isRunningElevated().then(
  324. ()=> elevatedRunasRepos.forEach(performPull))
  325. .catch(
  326. () => op['runas']()
  327. )
  328. }
  329. , 'npmi' : ()=>{
  330. var tasks = [];
  331. gitRepos.forEach(repo => {
  332. console.log('npm i for ' + repo)
  333. // nodeShellExec('pwd', [], {
  334. // // inherit : true, shell: true
  335. // cwd : repo
  336. // // , env: process.env
  337. // , title : `pwd for ${repo}`
  338. // }).catch((e)=>{ console.error(e) })
  339. nodeShellExec('rm', ['package-lock.json'], {
  340. inherit : true, shell: true
  341. , cwd : repo
  342. , env: process.env
  343. , title : `rm 'package-lock.json' for ${repo}`
  344. }).catch((e)=>{ console.error(e) })
  345. tasks.push(()=>{
  346. var p = nodeShellExec('npm', ['i'], {
  347. inherit : true, shell: true
  348. , cwd : repo
  349. , env: process.env
  350. , title : `npm i for ${repo}`
  351. }).catch((e)=>{ console.error(e) })
  352. return p;
  353. })
  354. })
  355. any(tasks);
  356. }
  357. , 'start' : (label)=>{
  358. console.log('Starting Elixir Server.');
  359. var env = Object.assign({}, process.env); // Shallow clone it.
  360. // console.dir(env)
  361. env.NODE_ENV = label || 'development';
  362. env.DEBUG = 'loopback:connector:' + dbForLabel(label)
  363. var cmd = env.NODE_ENV === 'development' ? 'nodemon' : 'node';
  364. // cmd = 'node'
  365. var childPromise = nodeShellExec(cmd, ['--inspect=9228', 'elixir/server.js'], {
  366. // inherit : true,
  367. shell: true,
  368. detached: true,
  369. stdio: 'ignore',
  370. cwd : 'elixir-server'
  371. , env: env
  372. })
  373. var child = childPromise.process;
  374. if (typeof child.pid !== 'undefined') {
  375. fs.writeFileSync('.elixir-server.elixir.server.pid', child.pid, {
  376. encoding: 'utf8'
  377. })
  378. }
  379. // nodeShellExec('node', ['--inspect=9226', ' bin/www'], {
  380. // inherit : true,
  381. // shell: true, detached: true,
  382. // cwd : 'qms/server',
  383. // env: env,
  384. // shell : true
  385. // })
  386. // nodeShellExec('ember', ['s'], {
  387. // // inherit : true,
  388. // shell: true, detached: true,
  389. // cwd : 'client/',
  390. // env: env
  391. // })
  392. var childPromise = nodeShellExec('ember', ['s'], {
  393. // var childPromise = nodeShellExec('node', ['--inspect=9227', './node_modules/.bin/ember', 's'], {
  394. // PB : TODO -- ember debugging.
  395. // inherit : true,
  396. shell: true,
  397. detached: true,
  398. stdio: 'ignore',
  399. cwd : 'client'
  400. , env: env
  401. })
  402. // .catch(e=>console.error(e))
  403. child = childPromise.process;
  404. if (typeof child.pid !== 'undefined') {
  405. fs.writeFileSync('.client.server.pid', child.pid, {
  406. encoding: 'utf8'
  407. })
  408. }
  409. }
  410. , 'stop' : (label)=>{
  411. const kill = require('tree-kill');
  412. var serverPid = fs.readFileSync('.elixir-server.elixir.server.pid', {
  413. encoding: 'utf8'
  414. })
  415. fs.unlinkSync('.elixir-server.elixir.server.pid')
  416. console.log(serverPid)
  417. kill(serverPid)
  418. serverPid = fs.readFileSync('.client.server.pid', {
  419. encoding: 'utf8'
  420. })
  421. fs.unlinkSync('.client.server.pid')
  422. console.log(serverPid)
  423. kill(serverPid)
  424. }
  425. , 'use' : ()=>{
  426. var runconfig = { NODE_ENV : process.env.NODE_ENV }
  427. try {
  428. runconfig = Object.assign(runconfig, require('../run.js'))
  429. } catch(e) { }
  430. if(runconfig.NODE_ENV === process.env.NODE_ENV && processedArgs._[1] && runconfig.use === processedArgs._[1]) return;
  431. var tasks = [
  432. ()=>{
  433. if(existsSync('config')) {
  434. var p = nodeShellExec('rmdir', ['config'], {inherit : true, shell: true, env: process.env }
  435. ).catch((err)=>{ console.log('Ignoring benign error : ' + err); return true; })
  436. return p;
  437. }
  438. else return Promise.resolve(true);
  439. },
  440. ()=>{
  441. if(existsSync('data')) {
  442. var p = nodeShellExec('rmdir', ['data'], { inherit : true, shell: true, env: process.env }
  443. ).catch((err)=>{ console.log('Ignoring benign error : ' + err); return true; })
  444. return p;
  445. }
  446. else return Promise.resolve(true);
  447. }
  448. ];
  449. any(tasks)
  450. if(!processedArgs.runas) return op['runas']()
  451. process.env.NODE_ENV = process.env.NODE_ENV || 'development';
  452. if(processedArgs._[1] && runconfig.use !== processedArgs._[1]) runconfig.use = processedArgs._[1];
  453. if(!runconfig.use) { throw 'unspecifed use not allowed. Please specify chess instance name.' }
  454. fs.writeFileSync('../run.js', 'module.exports = ' + JSON.stringify(runconfig))
  455. tasks = [
  456. ()=>{
  457. // Use junctions to avoid npm package issues
  458. var p = nodeShellExec('mklink', ['/J', 'config', runconfig.use + '-' + process.env.NODE_ENV + '-config'], {
  459. inherit : true, shell: true
  460. , env: process.env
  461. }).catch((e)=>{ console.error(e) })
  462. return p;
  463. }
  464. ];
  465. if(processedArgs._[1]) {
  466. tasks.concat(
  467. [
  468. ()=>{
  469. var p = nodeShellExec('mklink', ['/D', 'data', runconfig.use + '-data'], {
  470. inherit : true, shell: true
  471. , env: process.env
  472. }).catch((e)=>{ console.error(e) })
  473. return p;
  474. }
  475. ]
  476. )
  477. }
  478. any(tasks)
  479. // Antibiotic stewardship program.
  480. // 1st use is fine.
  481. // Max vials dispense
  482. // 2nd use Pharmacy needs justification Form.
  483. // Approval after a certain period of time.
  484. }
  485. , 'g' : ()=>{
  486. if(processedArgs.h) {
  487. console.log('elxr g [modelname] => generate a model named [modelname]');
  488. console.log('elxr g => regenerate all known models');
  489. return
  490. }
  491. // var child = nodeShellExec('mkdir', ['-p', label], { inherit : true} );
  492. // console.log('Starting directory: ' + process.cwd());
  493. // try {
  494. // child = child.on('close', () => { process.chdir(label) } );
  495. // console.log('New directory: ' + process.cwd());
  496. // }
  497. // catch (err) {
  498. // console.log('chdir: ' + err);
  499. // }
  500. // child.on('close', function(){
  501. // var options = {
  502. // shell : true
  503. // , inherit : true
  504. // // , cwd : '' + process.cwd
  505. // // , env : process.env
  506. // };
  507. // nodeShellExec('git', ['init'], { inherit : true});
  508. if(0){
  509. // PB : TODO -- Special google chrome profile for tests etc.
  510. nodeShellExec('pwd', { inherit : true});
  511. //$ "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --profile-directory="Profile 1" http://localhost:4200/tests/index.html?grep=loopback
  512. nodeShellExec("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe", [
  513. "--profile-directory=Profile 1"
  514. , 'http://localhost:4200/tests/index.html?grep=model convert ember to loopback' + '&filter=none' /*+ '&filter=model convert ember to loopback'*/]);
  515. }
  516. // nodeShellExec('npm', ['init', '-y'], options);
  517. // nodeShellExec('npm', ['init', '-y'], options);
  518. // })
  519. var g = {
  520. 'client' : ()=>{
  521. console.info('Creating new ember client named : ' + processedArgs._[2] ) ;
  522. var step1 = nodeShellExec('cmd', ['/c', 'ember', 'new', processedArgs._[2]], {
  523. stdio: ['pipe', process.stdout, process.stderr],
  524. inherit : true,
  525. shell: true,
  526. cwd : path.dirname(__dirname),
  527. env: env
  528. })
  529. }
  530. }
  531. g[processedArgs._[1]]();
  532. }
  533. }
  534. return op[label] ? op[label]() : op['start'](label);
  535. }
  536. // mysqldump --add-drop-table --no-data -u root -p db_name | grep 'DROP TABLE' ) > drop_all_tables.sql
  537. // mysql -u root -p db_name < drop_all_tables.sql
  538. var mysql = '../xampp/mysql/bin/mysql'
  539. var mysqldump = '../xampp/mysql/bin/mysqldump'
  540. __runcmd(processedArgs.label || processedArgs._[0] || 'h');
  541. // nodeShellExec('git', ['status']);
  542. function nodeShellExec() {
  543. var args = Array.from(arguments);
  544. args[2] ? null : args[2] = {}
  545. args[2].title ? null : args[2].title = `${args[0]} ${args[1]}`
  546. const child = spawn(...arguments);
  547. var p = new Promise(function(resolve, reject){
  548. if(!args[2].detached) {
  549. var messages = []; // PB : TODO -- Explore stream for Task level aggregation to prevent interleaved messages from multiple tasks...
  550. // use child.stdout.setEncoding('utf8'); if you want text chunks
  551. child.stdout.setEncoding('utf8');
  552. child.stderr.setEncoding('utf8');
  553. child.stdout.on('data', (chunk) => { messages.push(chunk); /*console.log(chunk)*/});
  554. child.on('error', (chunk) => { messages.push(chunk); /*console.error(chunk)*/ });
  555. child.stderr.on('data', (chunk) => { messages.push(chunk); /*console.log(chunk)*/});
  556. // child.stderr.pipe(process.stderr);
  557. child.on('close', (code) => {
  558. console.log([` ${args[2].title} exited with code ${code}`])
  559. // console.log([ messages.join('') ])
  560. process.stdout.write( messages.join('') )
  561. if(code !== 0 ) return reject(code)
  562. resolve(true)
  563. });
  564. }
  565. else {
  566. child.unref()
  567. resolve(true);
  568. }
  569. });
  570. p.process = child;
  571. return p;
  572. }