|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
-
-
-
-
- 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)
-
- var path = require('path')
-
-
- 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 env = Object.assign({}, process.env);
- 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
- }).catch((e)=>{ console.error(e) })
- p.position = 1;
- console.log('One')
- return p;
- }
- , ()=>{
- var p = nodeShellExec('npm', ['cache', 'clean', '-f'], {
- inherit : true, shell: true
- , env: process.env
- }).catch((e)=>{ console.error(e) })
-
- p.position = 2;
- console.log('Two')
- return p;
- }
- , ()=>{
- var p = nodeShellExec('npm', ['install', '-g', 'n'], {
- inherit : true, shell: true
- , env: process.env
- }).catch((e)=>{ console.error(e) })
- p.position = 3;
- console.log('Three')
- return p;
- }
- , ()=>{
- var p = nodeShellExec('n', ['latest'], {
- inherit : true, shell: true
- , env: process.env
- }).catch((e)=>{ console.error(e) })
- p.position = 4;
- console.log('Four')
- return p;
- }
- ]
- any(tasks)
- console.log('.......done')
- console.log('Running exlr upgrade in : ' + path.dirname(__dirname))
- console.log('Currently only upgrades ember : ' + path.dirname(__dirname));
- console.info('Uninstalling existing ember globally') ;
- var step1 = nodeShellExec('cmd', ['/c', 'npm', 'uninstall', '-g', 'ember-cli'], {
- stdio: ['pipe', process.stdout, process.stderr],
- inherit : true,
- shell: true,
- cwd : path.dirname(__dirname),
- env: env
- })
- step1.on('close', ()=>{
- console.info('Installing ember globally') ;
- var step2 = nodeShellExec('cmd', ['/c', 'npm', 'install', '-g', 'ember-cli'], {
- stdio: ['pipe', process.stdout, process.stderr],
- inherit : true,
- shell: true,
- cwd : path.dirname(__dirname),
- env: env
- })
-
- step2.on('close', ()=>{
- nodeShellExec('cmd', ['/c', 'ember', '--version'], {
- stdio: ['pipe', process.stdout, process.stderr],
- inherit : true,
- shell: true,
- cwd : path.dirname(__dirname),
- env: env
- })
- })
- })
- }
- , 'pull' : (label) => {
- var env = Object.assign({}, process.env);
-
- console.log('Running exlr pull : ' + path.dirname(__dirname))
-
-
-
-
-
-
-
-
-
- var isElevated;
- try {
- nodeShellExec( "fsutil", ["dirty", "query", "C:"], {
- inherit : true, shell: true
- , env: process.env
- }).then((exitcode)=>{
- console.log('Elevated')
- }).catch(()=>{
- console.log('Not Elevated')
- console.log('Requesting Elevated Privileges')
- nodeShellExec('MSHTA', ["javascript: var shell = new ActiveXObject('shell.application'); shell.ShellExecute('node', 'elxr pull', '', 'runas', 1);close();"]
- , {
- inherit : true
-
-
- ,
- title : `runsAs`
- }
- );
- });
-
- }
- catch ( e ) {
-
- }
-
-
-
-
- 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 => {
- if(existsSync(clonable)) {
- console.log('pulling ' + clonable)
- nodeShellExec('git', ['pull'], {
- inherit : true, shell: true
- , cwd : clonable
- , env: process.env
- , title : `git pull ${clonable}`
- }).catch((e)=>{ console.error(e) })
- }
- else {
- console.log('cloning ' + clonable)
- nodeShellExec('git', ['clone', '//172.16.0.27/repos/' + clonable + '.git'],
- {
- inherit : true, shell: true
- , cwd : clonable
- , env: process.env
- , title : `git pull ${clonable}`
- }).catch((e)=>{ console.error(e) })
- }
- })
- }
- , 'start' : (label)=>{
- console.log('Starting Elixir Server.');
- var env = Object.assign({}, process.env);
-
- env.NODE_ENV = label || 'development';
- env.DEBUG = 'loopback:connector:' + dbForLabel(label)
-
- nodeShellExec('node', ['--inspect=9228', 'elixir/server.js'], {
- inherit : true,
- shell: true, detached: true,
- cwd : 'elixir-server',
- env: env
- })
-
- nodeShellExec('node', ['--inspect=9227', 'elixr/server.js'], {
- inherit : true,
- shell: true, detached: true,
- cwd : 'elixir-server',
- env: env
- })
-
-
-
-
-
-
-
-
-
- nodeShellExec('ember', ['s'], {
- inherit : true,
- shell: true, detached: true,
- cwd : 'client/',
- env: env
- })
- }
- , 'g' : ()=>{
- if(processedArgs.h) {
-
- console.log('elxr g [modelname] => generate a model named [modelname]');
- console.log('elxr g => regenerate all known models');
- return
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if(0){
- 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' ]);
-
- }
-
-
-
-
- var g = {
- 'client' : ()=>{
- console.info('Creating new ember client named : ' + processedArgs._[2] ) ;
- var step1 = nodeShellExec('cmd', ['/c', 'ember', 'new', processedArgs._[2]], {
- stdio: ['pipe', process.stdout, process.stderr],
- inherit : true,
- shell: true,
- cwd : path.dirname(__dirname),
- env: env
- })
- }
- }
- g[processedArgs._[1]]();
- }
- }
- 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() {
-
- var args = Array.from(arguments);
- 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(` ${args[2].title} exited with code ${code}`)
- if(code !== 0 ) return reject(code)
- resolve(true)
- });
- });
- }
-
|