您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 dbForLabel = function(label){
  14. var dbsForLabel = {
  15. devmysql : 'mysql'
  16. , development : 'mssql'
  17. , production : 'mssql'
  18. }
  19. return dbsForLabel[label] || 'mysql'
  20. }
  21. var __runcmd = function(label){
  22. var op = {
  23. 'h' : ()=>{ console.log(cli + ' ' + ver + ' ' + help); return '-h' }
  24. , 'start' : (label)=>{
  25. console.log('Starting Elixir Server.');
  26. var env = Object.assign({}, process.env); // Shallow clone it.
  27. // console.dir(env)
  28. env.NODE_ENV = label;
  29. env.DEBUG = 'loopback:connector:' + dbForLabel(label)
  30. nodeShellExec('node', ['--inspect=9228', 'sage-rw/server.js'], {
  31. inherit : true,
  32. shell: true, detached: true,
  33. cwd : 'loopback',
  34. env: env,
  35. shell : true
  36. })
  37. nodeShellExec('node', ['--inspect=9227', 'sage-r/server.js'], {
  38. inherit : true,
  39. shell: true, detached: true,
  40. cwd : 'loopback',
  41. env: env,
  42. shell : true
  43. })
  44. // nodeShellExec('node', ['--inspect=9226', ' bin/www'], {
  45. // inherit : true,
  46. // shell: true, detached: true,
  47. // cwd : 'qms/server',
  48. // env: env,
  49. // shell : true
  50. // })
  51. nodeShellExec('ember', ['s'], {
  52. inherit : true,
  53. shell: true, detached: true,
  54. cwd : 'qms/',
  55. env: env,
  56. shell : true
  57. })
  58. }
  59. , 'g' : ()=>{
  60. if(processedArgs.h) {
  61. console.log('elxr g [modelname] => generate a model named [modelname]');
  62. console.log('elxr g => regenerate all known models');
  63. return
  64. }
  65. // var child = nodeShellExec('mkdir', ['-p', label], { inherit : true} );
  66. // console.log('Starting directory: ' + process.cwd());
  67. // try {
  68. // child = child.on('close', () => { process.chdir(label) } );
  69. // console.log('New directory: ' + process.cwd());
  70. // }
  71. // catch (err) {
  72. // console.log('chdir: ' + err);
  73. // }
  74. // child.on('close', function(){
  75. // var options = {
  76. // shell : true
  77. // , inherit : true
  78. // // , cwd : '' + process.cwd
  79. // // , env : process.env
  80. // };
  81. // nodeShellExec('git', ['init'], { inherit : true});
  82. nodeShellExec('pwd', { inherit : true});
  83. //$ "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --profile-directory="Profile 1" http://localhost:4200/tests/index.html?grep=loopback
  84. nodeShellExec("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe", [
  85. "--profile-directory=Profile 1"
  86. , 'http://localhost:4200/tests/index.html?grep=model convert ember to loopback' + '&filter=none' /*+ '&filter=model convert ember to loopback'*/]);
  87. // nodeShellExec('npm', ['init', '-y'], options);
  88. // nodeShellExec('npm', ['init', '-y'], options);
  89. // })
  90. }
  91. }
  92. return op[label] ? op[label]() : op['start'](label);
  93. }
  94. // mysqldump --add-drop-table --no-data -u root -p db_name | grep 'DROP TABLE' ) > drop_all_tables.sql
  95. // mysql -u root -p db_name < drop_all_tables.sql
  96. var mysql = '../xampp/mysql/bin/mysql'
  97. var mysqldump = '../xampp/mysql/bin/mysqldump'
  98. __runcmd(processedArgs.label || processedArgs._[0] || 'h');
  99. // nodeShellExec('git', ['status']);
  100. function nodeShellExec() {
  101. const child = spawn(...arguments);
  102. // use child.stdout.setEncoding('utf8'); if you want text chunks
  103. child.stdout.setEncoding('utf8');
  104. // console.log('here')
  105. child.stdout.on('data', (chunk) => console.log(chunk));
  106. child.on('error', (chunk) => console.error(chunk));
  107. child.stderr.pipe(process.stderr);
  108. child.on('close', (code) => console.log(`child process ${Array.from(arguments)[0]} exited with code ${code}`));
  109. return child;
  110. }