555
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

index.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // --------------
  2. // elxr
  3. // A cli tool for elixr.
  4. const { spawn } = require('child_process');
  5. const cliargs = require('../elxr/cliargs'); // Use minimist...
  6. const processedArgs = cliargs(process.argv.slice(2));
  7. console.dir(processedArgs)
  8. var cli = 'elxr';
  9. var ver = '#unversioned';
  10. var help = '#unkown list of commands... please refer dveloper documentation for ' + cli;
  11. // grep -qxF 'alias elxr="node elxr/index.js"' ~/.bash_profile || echo 'alias elxr="node elxr/index.js"' >> ~/.bash_profile
  12. // nodeShellExec('echo', ['elxr'], { inherit : true}) //, {stdio: "inherit"}
  13. var __runcmd = function(label){
  14. var op = {
  15. 'h' : ()=>{ console.log(cli + ' ' + ver + ' ' + help); return '-h' }
  16. , 'devmysql' : ()=>{
  17. console.log('Starting Elixir Server.');
  18. var env = Object.assign({}, process.env); // Shallow clone it.
  19. // console.dir(env)
  20. env.NODE_ENV = 'devmysql';
  21. env.DEBUG = 'loopback:connector:mysql'
  22. nodeShellExec('node', ['sage-rw/server.js'], {
  23. shell: true, detached: true,
  24. cwd : 'loopback',
  25. env: env,
  26. shell : true
  27. })
  28. // nodeShellExec('c:/Program Files/nodejs/node.exe', { inherit : true, cwd : '../loopback'});
  29. // nodeShellExec('pwd', {
  30. // inherit : true
  31. // , cwd : '../loopback'
  32. // , env : env
  33. // })
  34. // nodeShellExec('node', ['sage-rw/server.js'], {
  35. // inherit : true
  36. // , cwd : '../loopback'
  37. // , env : env
  38. // }) //, {stdio: "inherit"}
  39. }
  40. , 'g' : ()=>{
  41. if(processedArgs.h) {
  42. console.log('elxr g [modelname] => generate a model named [modelname]');
  43. console.log('elxr g => regenerate all known models');
  44. return
  45. }
  46. // var child = nodeShellExec('mkdir', ['-p', label], { inherit : true} );
  47. // console.log('Starting directory: ' + process.cwd());
  48. // try {
  49. // child = child.on('close', () => { process.chdir(label) } );
  50. // console.log('New directory: ' + process.cwd());
  51. // }
  52. // catch (err) {
  53. // console.log('chdir: ' + err);
  54. // }
  55. // child.on('close', function(){
  56. // var options = {
  57. // shell : true
  58. // , inherit : true
  59. // // , cwd : '' + process.cwd
  60. // // , env : process.env
  61. // };
  62. // nodeShellExec('git', ['init'], { inherit : true});
  63. nodeShellExec('pwd', { inherit : true});
  64. //$ "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --profile-directory="Profile 1" http://localhost:4200/tests/index.html?grep=loopback
  65. nodeShellExec("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe", [
  66. "--profile-directory=Profile 1"
  67. , 'http://localhost:4200/tests/index.html?grep=model convert ember to loopback' + '&filter=none' /*+ '&filter=model convert ember to loopback'*/]);
  68. // nodeShellExec('npm', ['init', '-y'], options);
  69. // nodeShellExec('npm', ['init', '-y'], options);
  70. // })
  71. }
  72. }
  73. return op[label]();
  74. }
  75. // mysqldump --add-drop-table --no-data -u root -p db_name | grep 'DROP TABLE' ) > drop_all_tables.sql
  76. // mysql -u root -p db_name < drop_all_tables.sql
  77. var mysql = '../xampp/mysql/bin/mysql'
  78. var mysqldump = '../xampp/mysql/bin/mysqldump'
  79. __runcmd(processedArgs.label || processedArgs._[0] || '-h');
  80. // nodeShellExec('git', ['status']);
  81. function nodeShellExec() {
  82. const child = spawn(...arguments);
  83. // use child.stdout.setEncoding('utf8'); if you want text chunks
  84. child.stdout.setEncoding('utf8');
  85. // console.log('here')
  86. child.stdout.on('data', (chunk) => console.log(chunk));
  87. child.on('error', (chunk) => console.error(chunk));
  88. child.stderr.pipe(process.stderr);
  89. child.on('close', (code) => console.log(`child process ${Array.from(arguments)[0]} exited with code ${code}`));
  90. return child;
  91. }