Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 path = require('path')
  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 dbForLabel = function(label){
  15. var dbsForLabel = {
  16. devmysql : 'mysql'
  17. , development : 'mssql'
  18. , production : 'mssql'
  19. }
  20. return dbsForLabel[label] || 'mysql'
  21. }
  22. var env = Object.assign({}, process.env); // Shallow clone it.
  23. var __runcmd = function(label){
  24. var op = {
  25. 'h' : ()=>{ console.log(cli + ' ' + ver + ' ' + help); return '-h' }
  26. , 'upgrade' : ()=>{
  27. console.log('Running exlr upgrade in : ' + path.dirname(__dirname))
  28. console.log('Currently only upgrades ember : ' + path.dirname(__dirname));
  29. console.info('Uninstalling existing ember globally') ;
  30. var step1 = nodeShellExec('cmd', ['/c', 'npm', 'uninstall', '-g', 'ember-cli'], {
  31. stdio: ['pipe', process.stdout, process.stderr],
  32. inherit : true,
  33. shell: true,
  34. cwd : path.dirname(__dirname),
  35. env: env
  36. })
  37. step1.on('close', ()=>{
  38. console.info('Installing ember globally') ;
  39. var step2 = nodeShellExec('cmd', ['/c', 'npm', 'install', '-g', 'ember-cli'], {
  40. stdio: ['pipe', process.stdout, process.stderr],
  41. inherit : true,
  42. shell: true,
  43. cwd : path.dirname(__dirname),
  44. env: env
  45. })
  46. step2.on('close', ()=>{
  47. nodeShellExec('cmd', ['/c', 'ember', '--version'], {
  48. stdio: ['pipe', process.stdout, process.stderr],
  49. inherit : true,
  50. shell: true,
  51. cwd : path.dirname(__dirname),
  52. env: env
  53. })
  54. })
  55. })
  56. }
  57. , 'pull' : (label) => {
  58. var env = Object.assign({}, process.env); // Shallow clone it.
  59. // console.dir(env)
  60. console.log('Running exlr pull : ' + path.dirname(__dirname))
  61. nodeShellExec('cmd', ['/c', 'setup\\utility\\chess.bat', 'pull'], {
  62. // nodeShellExec('cmd', ['/c', '..\\setup\\utility\\chess.bat', 'pull'], {
  63. stdio: ['pipe', process.stdout, process.stderr],
  64. inherit : true,
  65. shell: true,
  66. cwd : path.dirname(__dirname),
  67. env: env
  68. })
  69. }
  70. , 'start' : (label)=>{
  71. console.log('Starting Elixir Server.');
  72. var env = Object.assign({}, process.env); // Shallow clone it.
  73. // console.dir(env)
  74. env.NODE_ENV = label || 'development';
  75. env.DEBUG = 'loopback:connector:' + dbForLabel(label)
  76. nodeShellExec('node', ['--inspect=9228', 'elixir/server.js'], {
  77. inherit : true,
  78. shell: true, detached: true,
  79. cwd : 'elixir-server',
  80. env: env
  81. })
  82. nodeShellExec('node', ['--inspect=9227', 'elixr/server.js'], {
  83. inherit : true,
  84. shell: true, detached: true,
  85. cwd : 'elixir-server',
  86. env: env
  87. })
  88. // nodeShellExec('node', ['--inspect=9226', ' bin/www'], {
  89. // inherit : true,
  90. // shell: true, detached: true,
  91. // cwd : 'qms/server',
  92. // env: env,
  93. // shell : true
  94. // })
  95. nodeShellExec('ember', ['s'], {
  96. inherit : true,
  97. shell: true, detached: true,
  98. cwd : 'client/',
  99. env: env
  100. })
  101. }
  102. , 'g' : ()=>{
  103. if(processedArgs.h) {
  104. console.log('elxr g [modelname] => generate a model named [modelname]');
  105. console.log('elxr g => regenerate all known models');
  106. return
  107. }
  108. // var child = nodeShellExec('mkdir', ['-p', label], { inherit : true} );
  109. // console.log('Starting directory: ' + process.cwd());
  110. // try {
  111. // child = child.on('close', () => { process.chdir(label) } );
  112. // console.log('New directory: ' + process.cwd());
  113. // }
  114. // catch (err) {
  115. // console.log('chdir: ' + err);
  116. // }
  117. // child.on('close', function(){
  118. // var options = {
  119. // shell : true
  120. // , inherit : true
  121. // // , cwd : '' + process.cwd
  122. // // , env : process.env
  123. // };
  124. // nodeShellExec('git', ['init'], { inherit : true});
  125. if(0){
  126. nodeShellExec('pwd', { inherit : true});
  127. //$ "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --profile-directory="Profile 1" http://localhost:4200/tests/index.html?grep=loopback
  128. nodeShellExec("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe", [
  129. "--profile-directory=Profile 1"
  130. , 'http://localhost:4200/tests/index.html?grep=model convert ember to loopback' + '&filter=none' /*+ '&filter=model convert ember to loopback'*/]);
  131. }
  132. // nodeShellExec('npm', ['init', '-y'], options);
  133. // nodeShellExec('npm', ['init', '-y'], options);
  134. // })
  135. var g = {
  136. 'client' : ()=>{
  137. console.info('Creating new ember client named : ' + processedArgs._[2] ) ;
  138. var step1 = nodeShellExec('cmd', ['/c', 'ember', 'new', processedArgs._[2]], {
  139. stdio: ['pipe', process.stdout, process.stderr],
  140. inherit : true,
  141. shell: true,
  142. cwd : path.dirname(__dirname),
  143. env: env
  144. })
  145. }
  146. }
  147. g[processedArgs._[1]]();
  148. }
  149. }
  150. return op[label] ? op[label]() : op['start'](label);
  151. }
  152. // mysqldump --add-drop-table --no-data -u root -p db_name | grep 'DROP TABLE' ) > drop_all_tables.sql
  153. // mysql -u root -p db_name < drop_all_tables.sql
  154. var mysql = '../xampp/mysql/bin/mysql'
  155. var mysqldump = '../xampp/mysql/bin/mysqldump'
  156. __runcmd(processedArgs.label || processedArgs._[0] || 'h');
  157. // nodeShellExec('git', ['status']);
  158. function nodeShellExec() {
  159. const child = spawn(...arguments);
  160. // use child.stdout.setEncoding('utf8'); if you want text chunks
  161. // child.stdout.setEncoding('utf8');
  162. // console.log('here')
  163. // child.stdout.on('data', (chunk) => console.log(chunk));
  164. child.on('error', (chunk) => console.error(chunk));
  165. // child.stderr.pipe(process.stderr);
  166. child.on('close', (code) => console.log(`child process ${Array.from(arguments)[0]} exited with code ${code}`));
  167. return child;
  168. }