mirror of
https://github.com/nuintun/command-manager.git
synced 2025-06-06 10:54:07 +08:00
update files
This commit is contained in:
parent
1b8e084879
commit
12e9d713c5
@ -9,43 +9,56 @@ var Emulator = require('./emulator');
|
|||||||
var emulator;
|
var emulator;
|
||||||
|
|
||||||
// thread
|
// thread
|
||||||
process.on('message', function (project){
|
process.on('message', function (message){
|
||||||
var stream;
|
if (message.action === 'stop') {
|
||||||
|
if (emulator) {
|
||||||
|
emulator.stop();
|
||||||
|
}
|
||||||
|
|
||||||
if (emulator) {
|
process.exit();
|
||||||
emulator.stop();
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
emulator = new Emulator({
|
if (message.action === 'start') {
|
||||||
cwd: project.path,
|
var stream;
|
||||||
command: project.command.value
|
var project = message.project;
|
||||||
});
|
|
||||||
|
|
||||||
stream = emulator.start();
|
if (emulator) {
|
||||||
|
emulator.stop();
|
||||||
|
}
|
||||||
|
|
||||||
stream.stdout.on('data', function (data){
|
emulator = new Emulator({
|
||||||
process.send({
|
cwd: project.path,
|
||||||
event: 'data',
|
command: project.command.value
|
||||||
project: project,
|
|
||||||
data: data.toString()
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
stream.stderr.on('data', function (error){
|
stream = emulator.start();
|
||||||
emulator.stop();
|
|
||||||
process.send({
|
|
||||||
event: 'error',
|
|
||||||
project: project,
|
|
||||||
data: error.toString()
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
stream.on('close', function (signal){
|
stream.stdout.on('data', function (data){
|
||||||
emulator.stop();
|
process.send({
|
||||||
process.send({
|
event: 'data',
|
||||||
event: 'close',
|
project: project,
|
||||||
project: project,
|
data: data.toString()
|
||||||
data: signal.toString()
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
stream.stderr.on('data', function (error){
|
||||||
|
emulator.stop();
|
||||||
|
process.send({
|
||||||
|
event: 'error',
|
||||||
|
project: project,
|
||||||
|
data: error.toString()
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
stream.on('close', function (signal){
|
||||||
|
emulator.stop();
|
||||||
|
process.send({
|
||||||
|
event: 'close',
|
||||||
|
project: project,
|
||||||
|
data: signal.toString()
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
@ -26,7 +26,13 @@ Emulator.prototype = {
|
|||||||
},
|
},
|
||||||
stop: function (){
|
stop: function (){
|
||||||
if (this.thread) {
|
if (this.thread) {
|
||||||
this.thread.kill('SIGTERM');
|
this.thread.kill('SIGKILL');
|
||||||
|
|
||||||
|
['stdin', 'stdout', 'stderr'].forEach(function (stream){
|
||||||
|
this.thread[stream].removeAllListeners();
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
this.thread = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
exec: function (){
|
exec: function (){
|
||||||
|
@ -19,7 +19,9 @@ function killThread(name){
|
|||||||
var thread = threads[name];
|
var thread = threads[name];
|
||||||
|
|
||||||
if (thread && thread.connected) {
|
if (thread && thread.connected) {
|
||||||
thread.kill('SIGTERM');
|
thread.send({
|
||||||
|
action: 'stop'
|
||||||
|
});
|
||||||
|
|
||||||
delete threads[name];
|
delete threads[name];
|
||||||
}
|
}
|
||||||
@ -28,8 +30,7 @@ function killThread(name){
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
start: function (){
|
start: function (){
|
||||||
ipc.on('emulator', function (event, project, action){
|
ipc.on('emulator', function (event, project, action){
|
||||||
var key = project.name + '-' + project.command.name;
|
var thread = threads[project.name];
|
||||||
var thread = threads[key];
|
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'start':
|
case 'start':
|
||||||
@ -58,13 +59,19 @@ module.exports = {
|
|||||||
|
|
||||||
delete project.env;
|
delete project.env;
|
||||||
|
|
||||||
thread.send(project);
|
thread.send({
|
||||||
|
action: 'start',
|
||||||
|
project: project
|
||||||
|
});
|
||||||
|
|
||||||
threads[project.name] = thread;
|
threads[project.name] = thread;
|
||||||
} else {
|
} else {
|
||||||
delete project.env;
|
delete project.env;
|
||||||
|
|
||||||
thread.send(project);
|
thread.send({
|
||||||
|
action: 'start',
|
||||||
|
project: project
|
||||||
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'stop':
|
case 'stop':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user