Преглед изворни кода

environment switching support

production
Pradeep Bhaskaran пре 4 година
родитељ
комит
20111ba7f0
1 измењених фајлова са 130 додато и 80 уклоњено
  1. 130
    80
      index.js

+ 130
- 80
index.js Прегледај датотеку

@@ -388,14 +388,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,
@@ -404,70 +414,102 @@ 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;
}
else runconfig.use = processedArgs._[1];
fs.writeFileSync('./run.js', 'module.exports = ' + JSON.stringify(runconfig))
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 = [
()=>{
var p = nodeShellExec('rm', ['config']
, { inherit : true, shell: true, env: process.env }
).catch((err)=>{ console.log('Ignoring benign error : ' + err); return true; })
return p;
},
()=>{
var p = nodeShellExec('rm', ['data'], { inherit : true, shell: true, env: process.env }
).catch((err)=>{ console.log('Ignoring benign error : ' + err); return true; })
return p;
}
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 = [
()=>{
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 = [
()=>{
var p = nodeShellExec('rm', ['config'], {
inherit : true, shell: true
, cwd : repo
, env: process.env
, title : `rm 'package-lock.json' for ${repo}`
}).catch((e)=>{ console.error(e) })
return p;
},
()=>{
var p = nodeShellExec('rm', ['data'], {
inherit : true, shell: true
, cwd : repo
, env: process.env
, title : `rm 'package-lock.json' for ${repo}`
}).catch((e)=>{ console.error(e) })
return p;
},
()=>{
var p = nodeShellExec('mklink', ['/D', 'data', runconfig.use + '-data'], {
inherit : true, shell: true
, env: process.env
}).catch((e)=>{ console.error(e) })
return p;
},
()=>{
var p = nodeShellExec('mklink', ['/D', 'config', runconfig.use + '-config'], {
inherit : true, shell: true
, env: process.env
}).catch((e)=>{ console.error(e) })
return p;
}
]
any(tasks)
];
if(processedArgs._[1]) {
tasks.concat(
[
()=>{
var p = nodeShellExec('mklink', ['/D', 'data', runconfig.use + '-data'], {
inherit : true, shell: true
, env: process.env
}).catch((e)=>{ console.error(e) })
return p;
}
]
)
}
any(tasks)

// Antibiotic stewardship program.
// 1st use is fine.
@@ -546,25 +588,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;
}


Loading…
Откажи
Сачувај