You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 3.9KB

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