| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 | 
// --------------
// elxr 
//   A cli tool for elixr.
const { spawn } = require('child_process');
const cliargs = require('../elxr/cliargs'); // Use minimist...
const processedArgs = cliargs(process.argv.slice(2));
console.dir(processedArgs)
var cli = 'elxr';
var ver = '#unversioned'; 
var help = '#unkown list of commands... please refer dveloper documentation for ' + cli;
// grep -qxF 'alias elxr="node elxr/index.js"'  ~/.bash_profile || echo 'alias elxr="node elxr/index.js"' >> ~/.bash_profile
// nodeShellExec('echo', ['elxr'], { inherit : true}) //, {stdio: "inherit"}
var __runcmd = function(label){
  var op = {
      'h' : ()=>{ console.log(cli + ' ' + ver + ' ' + help); return '-h' }
    , 'devmysql' : ()=>{ 
      console.log('Starting Elixir Server.');
      var env = Object.assign({}, process.env); // Shallow clone it.
      // console.dir(env)
      env.NODE_ENV = 'devmysql';
      env.DEBUG = 'loopback:connector:mysql'
     
      nodeShellExec('node', ['sage-rw/server.js'], {
        shell: true, detached: true,
        cwd : 'loopback',
        env: env,
        shell : true
      })
      
      // nodeShellExec('c:/Program Files/nodejs/node.exe', { inherit : true, cwd : '../loopback'});
      // nodeShellExec('pwd', { 
      //     inherit : true
      //   , cwd : '../loopback'
      //   , env : env
      // })
      // nodeShellExec('node', ['sage-rw/server.js'], { 
      //     inherit : true
      //   , cwd : '../loopback'
      //   , env : env
      // }) //, {stdio: "inherit"}
    }
    , 'g' : ()=>{
      if(processedArgs.h) { 
        console.log('elxr g [modelname] => generate a model named [modelname]'); 
        console.log('elxr g => regenerate all known models'); 
        return 
      }
      // var child = nodeShellExec('mkdir', ['-p', label], { inherit : true} );
      // console.log('Starting directory: ' + process.cwd());
      // try {
      //     child = child.on('close', () => { process.chdir(label) } );
      //     console.log('New directory: ' + process.cwd()); 
      // }
      // catch (err) {
      //     console.log('chdir: ' + err);
      // }
      // child.on('close', function(){
          // var options = {
          //       shell : true 
          //     , inherit : true
          //     // , cwd : '' + process.cwd
          //     // , env : process.env
          // };
          // nodeShellExec('git', ['init'], { inherit : true});
          nodeShellExec('pwd', { inherit : true});
          //$ "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --profile-directory="Profile 1" http://localhost:4200/tests/index.html?grep=loopback
          nodeShellExec("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe", [
              "--profile-directory=Profile 1"
            , 'http://localhost:4200/tests/index.html?grep=model convert ember to loopback' + '&filter=none' /*+ '&filter=model convert ember to loopback'*/]);
          
          // nodeShellExec('npm', ['init', '-y'], options);
          // nodeShellExec('npm', ['init', '-y'], options);
      // })
    }
  }
  return op[label]();
} 
// mysqldump --add-drop-table --no-data -u root -p db_name | grep 'DROP TABLE' ) > drop_all_tables.sql
// mysql -u root -p db_name < drop_all_tables.sql
var mysql = '../xampp/mysql/bin/mysql'
var mysqldump = '../xampp/mysql/bin/mysqldump'
__runcmd(processedArgs.label || processedArgs._[0] || '-h');
// nodeShellExec('git', ['status']);
function nodeShellExec() {
    const child = spawn(...arguments);
    // use child.stdout.setEncoding('utf8'); if you want text chunks
    child.stdout.setEncoding('utf8');
    // console.log('here')
    child.stdout.on('data', (chunk) => console.log(chunk));
    child.on('error', (chunk) => console.error(chunk));
    child.stderr.pipe(process.stderr);
    child.on('close', (code) => console.log(`child process ${Array.from(arguments)[0]} exited with code ${code}`));
    return child;
}
 |