555
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.

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