Pārlūkot izejas kodu

Merge branch 'master' elxr

pull/1/head
Pradeep Bhaskaran pirms 4 gadiem
vecāks
revīzija
641dc82772
1 mainītis faili ar 131 papildinājumiem un 80 dzēšanām
  1. 131
    80
      index.js

+ 131
- 80
index.js Parādīt failu

@@ -396,14 +396,24 @@ var __runcmd = function(label){
// console.dir(env)
env.NODE_ENV = label || 'development';
env.DEBUG = 'loopback:connector:' + dbForLabel(label)
nodeShellExec('node', ['--inspect=9228', 'elixir/server.js'], {
var cmd = env.NODE_ENV === 'development' ? 'nodemon' : 'node';
// cmd = 'node'
var childPromise = nodeShellExec(cmd, ['--inspect=9228', 'elixir/server.js'], {
// inherit : true,
shell: true, detached: true,
cwd : 'elixir-server',
env: env
shell: true,
detached: true,
stdio: 'ignore',
cwd : 'elixir-server'
, env: env
})

var child = childPromise.process;
if (typeof child.pid !== 'undefined') {
fs.writeFileSync('.elixir-server.elixir.server.pid', child.pid, {
encoding: 'utf8'
})
}

// nodeShellExec('node', ['--inspect=9226', ' bin/www'], {
// inherit : true,
// shell: true, detached: true,
@@ -412,75 +422,108 @@ var __runcmd = function(label){
// shell : true
// })

nodeShellExec('ember', ['s'], {
// inherit : true,
shell: true, detached: true,
cwd : 'client/',
env: env
// nodeShellExec('ember', ['s'], {
// // inherit : true,
// shell: true, detached: true,
// cwd : 'client/',
// env: env
// })
var childPromise = nodeShellExec('ember', ['s'], {
// var childPromise = nodeShellExec('node', ['--inspect=9227', './node_modules/.bin/ember', 's'], {
// PB : TODO -- ember debugging.
// inherit : true,
shell: true,
detached: true,
stdio: 'ignore',
cwd : 'client'
, env: env
})
// .catch(e=>console.error(e))

child = childPromise.process;
if (typeof child.pid !== 'undefined') {
fs.writeFileSync('.client.server.pid', child.pid, {
encoding: 'utf8'
})
}

}
, 'stop' : (label)=>{
const kill = require('tree-kill');

var serverPid = fs.readFileSync('.elixir-server.elixir.server.pid', {
encoding: 'utf8'
})
fs.unlinkSync('.elixir-server.elixir.server.pid')
console.log(serverPid)
kill(serverPid)

serverPid = fs.readFileSync('.client.server.pid', {
encoding: 'utf8'
})
fs.unlinkSync('.client.server.pid')
console.log(serverPid)
kill(serverPid)
}
, 'use' : ()=>{

if(!processedArgs.runas){
try {
var runconfig = require('./run.js')
if(processedArgs._[1] && runconfig.use === processedArgs._[1]) {
return;
var runconfig = { NODE_ENV : process.env.NODE_ENV }
try {
runconfig = Object.assign(runconfig, require('../run.js'))
} catch(e) { }
if(runconfig.NODE_ENV === process.env.NODE_ENV && processedArgs._[1] && runconfig.use === processedArgs._[1]) return;

var tasks = [
()=>{
if(existsSync('config')) {
var p = nodeShellExec('rmdir', ['config'], {inherit : true, shell: true, env: process.env }
).catch((err)=>{ console.log('Ignoring benign error : ' + err); return true; })
return p;
}
else return Promise.resolve(true);
},
()=>{
if(existsSync('data')) {
var p = nodeShellExec('rmdir', ['data'], { inherit : true, shell: true, env: process.env }
).catch((err)=>{ console.log('Ignoring benign error : ' + err); return true; })
return p;
}
else runconfig.use = processedArgs._[1];
fs.writeFileSync('./run.js', 'module.exports = ' + JSON.stringify(runconfig))
else return Promise.resolve(true);
}
catch(e) {
runconfig = { use : processedArgs._[1] };
fs.writeFileSync('./run.js', 'module.exports = ' + JSON.stringify(runconfig))
];
any(tasks)
if(!processedArgs.runas) return op['runas']()

process.env.NODE_ENV = process.env.NODE_ENV || 'development';
if(processedArgs._[1] && runconfig.use !== processedArgs._[1]) runconfig.use = processedArgs._[1];
if(!runconfig.use) { throw 'unspecifed use not allowed. Please specify chess instance name.' }

fs.writeFileSync('../run.js', 'module.exports = ' + JSON.stringify(runconfig))
tasks = [
()=>{
// Use junctions to avoid npm package issues
var p = nodeShellExec('mklink', ['/J', 'config', runconfig.use + '-' + process.env.NODE_ENV + '-config'], {
inherit : true, shell: true
, env: process.env
}).catch((e)=>{ console.error(e) })
return p;
}
op['runas']()
}
else {
var runconfig = require('../run.js')
console.log('runconfig.use : ' + runconfig.use)
var tasks = [
()=>{
if(existsSync('config')) {
var p = nodeShellExec('rmdir', ['config'], {
inherit : true, shell: true
, env: process.env
, title : `rmdir config`
}).catch((e)=>{ console.error(e) })
return p;
}
else return Promise.resolve(true);
},
()=>{
if(existsSync('data')) {
var p = nodeShellExec('rmdir', ['data'], {
];
if(processedArgs._[1]) {
tasks.concat(
[
()=>{
var p = nodeShellExec('mklink', ['/D', 'data', runconfig.use + '-data'], {
inherit : true, shell: true
, env: process.env
, title : `rm data`
}).catch((e)=>{ console.error(e) })
}).catch((e)=>{ console.error(e) })
return p;
}
else return Promise.resolve(true);
},
()=>{
var p = nodeShellExec('mklink', ['/D', 'data', runconfig.use + '-data'], {
inherit : true, shell: true
, env: process.env
}).catch((e)=>{ console.error(e) })
return p;
},
()=>{
// Use junctions to avoid npm package issues
var p = nodeShellExec('mklink', ['/J', 'config', runconfig.use + '-config'], {
inherit : true, shell: true
, env: process.env
}).catch((e)=>{ console.error(e) })
return p;
}
]
any(tasks)
]
)
}
any(tasks)

// Antibiotic stewardship program.
// 1st use is fine.
@@ -559,25 +602,33 @@ function nodeShellExec() {
args[2].title ? null : args[2].title = `${args[0]} ${args[1]}`
const child = spawn(...arguments);

return new Promise(function(resolve, reject){
var messages = []; // PB : TODO -- Explore stream for Task level aggregation to prevent interleaved messages from multiple tasks...
// use child.stdout.setEncoding('utf8'); if you want text chunks
child.stdout.setEncoding('utf8');
child.stderr.setEncoding('utf8');
child.stdout.on('data', (chunk) => { messages.push(chunk); /*console.log(chunk)*/});
child.on('error', (chunk) => { messages.push(chunk); /*console.error(chunk)*/ });
child.stderr.on('data', (chunk) => { messages.push(chunk); /*console.log(chunk)*/});
// child.stderr.pipe(process.stderr);

child.on('close', (code) => {
var p = new Promise(function(resolve, reject){
if(!args[2].detached) {
var messages = []; // PB : TODO -- Explore stream for Task level aggregation to prevent interleaved messages from multiple tasks...
console.log([` ${args[2].title} exited with code ${code}`])
// console.log([ messages.join('') ])
process.stdout.write( messages.join('') )
if(code !== 0 ) return reject(code)
resolve(true)
});
// use child.stdout.setEncoding('utf8'); if you want text chunks
child.stdout.setEncoding('utf8');
child.stderr.setEncoding('utf8');
child.stdout.on('data', (chunk) => { messages.push(chunk); /*console.log(chunk)*/});
child.on('error', (chunk) => { messages.push(chunk); /*console.error(chunk)*/ });
child.stderr.on('data', (chunk) => { messages.push(chunk); /*console.log(chunk)*/});
// child.stderr.pipe(process.stderr);
child.on('close', (code) => {
console.log([` ${args[2].title} exited with code ${code}`])
// console.log([ messages.join('') ])
process.stdout.write( messages.join('') )
if(code !== 0 ) return reject(code)
resolve(true)
});
}
else {
child.unref()
resolve(true);
}
});
p.process = child;
return p;
}


Notiek ielāde…
Atcelt
Saglabāt