123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
-
-
-
-
- const { existsSync } = require('fs');
- const { spawn, spawnSync } = require('child_process');
- const cliargs = require('../elxr/cliargs');
- const processedArgs = cliargs(process.argv.slice(2));
- console.dir(processedArgs)
-
-
-
- function any(iterable) {
- return iterable.reduce(
- (p, fn, i ,a) => {
-
-
- if(Promise.resolve(p) === p ) {
- return p.then((pVal) => {
-
- if(Promise.resolve(pVal) === pVal) {
-
- pVal.then((pVal)=>{
-
-
- if(!pVal && !continueOnFailure) {
- console.error("E : pVal :" + pVal);
-
-
- console.error('debugData 3 -------------------');
-
- console.error('debugData 3 -------------------');
-
- console.log("Cancelling remaining...");
- throw 'Failed in reduce 1 '
- return false;
- }
-
- return (Promise.resolve(fn) === fn ) ? fn : fn() ;
- })
- }
- else {
-
-
- if(!pVal && !continueOnFailure) {
- console.error("E : pVal :" + pVal);
-
-
- console.error('debugData 3 -------------------');
-
- console.error('debugData 3 -------------------');
-
- console.log("Cancelling remaining...");
- throw 'Failed in reduce 1 '
- return false;
- }
-
- return (Promise.resolve(fn) === fn ) ? fn : fn() ;
- }
-
-
-
- }).catch((error) => {
- console.error("E : " + error);
- fn ? console.error("Fn : " + fn.toString()) : null;
-
-
- console.error('debugData 4-------------------------');
-
- console.error('debugData 4-------------------------');
-
- throw 'Failed in reduce 2 '
- return false;
- })
- }
- else if(!p) {
- console.log("Bypass on failure");
- return false;
- }
- }
- , Promise.resolve(true)
- );
- }
-
-
-
- var cli = 'elxr';
- var ver = '#unversioned';
- var help = '#unkown list of commands... please refer dveloper documentation for ' + cli;
-
-
-
-
-
-
- var dbForLabel = function(label){
- var dbsForLabel = {
- devmysql : 'mysql'
- , development : 'mssql'
- , production : 'mssql'
- }
- return dbsForLabel[label] || 'mysql'
- }
-
- var __runcmd = function(label){
-
- var op = {
- 'h' : ()=>{ console.log(cli + ' ' + ver + ' ' + help); return '-h' }
- , 'upgrade' : ()=>{
- console.log('upgrade.......')
- var tasks = [
- ()=>{
- var p = nodeShellExec('npm', ['i', '-g', 'npm-upgrade'], {
- inherit : true, shell: true
- , env: process.env
- })
- p.position = 1;
- console.log('One')
- return p;
- }
- , ()=>{
- var p = nodeShellExec('npm', ['cache', 'clean', '-f'], {
- inherit : true, shell: true
- , env: process.env
- })
-
- p.position = 2;
- console.log('Two')
- return p;
- }
- , ()=>{
- var p = nodeShellExec('npm', ['install', '-g', 'n'], {
- inherit : true, shell: true
- , env: process.env
- })
- p.position = 3;
- console.log('Three')
- return p;
- }
- , ()=>{
- var p = nodeShellExec('n', ['latest'], {
- inherit : true, shell: true
- , env: process.env
- })
- p.position = 4;
- console.log('Four')
- return p;
- }
- ]
- any(tasks)
- console.log('.......done')
- }
- , 'pull' : ()=>{
-
- var gitclonables = [
- 'ember-masonry-grid'
- , 'bbhverse'
- , 'clientverse'
- , 'serververse'
- , 'client'
- , 'elixir-client'
- , 'elixir-client-unlinked'
- , 'ember-searchable-select'
- , 'loopback-component-jsonapi'
- , 'config'
- , 'loopback-connector-ds'
- , 'chess-server-lib'
- , 'elixir-server'
- , 'chess-server'
- , 'setup'
- ]
-
- gitclonables.forEach(clonable => {
- console.log('' + process.cwd())
- if(existsSync(clonable)) {
- console.log('pulling ' + clonable)
- nodeShellExec('git', ['pull'], {
- inherit : true, shell: true
- , cwd : clonable
- , env: process.env
- })
- }
- else {
- console.log('cloning...')
- nodeShellExec('git', ['clone', '//172.16.0.27/repos/' + clonable + '.git'])
- }
- })
-
- console.log('pull')
- }
- , 'start' : (label)=>{
- console.log('Starting Elixir Server.');
- var env = Object.assign({}, process.env);
-
- env.NODE_ENV = label;
- env.DEBUG = 'loopback:connector:' + dbForLabel(label)
-
- nodeShellExec('node', ['--inspect=9228', 'sage-rw/server.js'], {
- inherit : true,
- shell: true, detached: true,
- cwd : 'loopback',
- env: env
- })
-
- nodeShellExec('node', ['--inspect=9227', 'sage-r/server.js'], {
- inherit : true,
- shell: true, detached: true,
- cwd : 'loopback',
- env: env
- })
-
-
-
-
-
-
-
-
-
- nodeShellExec('ember', ['s'], {
- inherit : true,
- shell: true, detached: true,
- cwd : 'qms/',
- env: env,
- shell : true
- })
- }
- , 'g' : ()=>{
- if(processedArgs.h) {
-
- console.log('elxr g [modelname] => generate a model named [modelname]');
- console.log('elxr g => regenerate all known models');
- return
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- nodeShellExec('pwd', { inherit : true});
-
- 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' ]);
-
-
-
-
- }
- }
- return op[label] ? op[label]() : op['start'](label);
- }
-
-
-
-
- var mysql = '../xampp/mysql/bin/mysql'
- var mysqldump = '../xampp/mysql/bin/mysqldump'
-
- __runcmd(processedArgs.label || processedArgs._[0] || 'h');
-
-
- function nodeShellExec() {
-
- const child = spawn(...arguments);
-
-
- return new Promise(function(resolve, reject){
-
-
- child.stdout.setEncoding('utf8');
-
-
- 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}`)
- if(code !== 0 ) return reject(code)
- resolve(true)
- });
- });
- }
|