make stdout etc available via api

This commit is contained in:
Rich Harris
2018-05-23 21:56:35 -04:00
parent 046db325f1
commit 6aa3ce4f05
3 changed files with 15 additions and 13 deletions

View File

@@ -10,7 +10,7 @@ import prettyMs from 'pretty-ms';
import { locations } from '../config';
import { EventEmitter } from 'events';
import { create_routes, create_main_manifests, create_compilers, create_serviceworker_manifest } from '../core';
import * as events from '../interfaces';
import * as events from './interfaces';
export function dev(opts) {
return new Watcher(opts);
@@ -143,6 +143,10 @@ class Watcher extends EventEmitter {
fs.writeFileSync(path.join(dest, 'server_info.json'), JSON.stringify(info, null, ' '));
this.deferreds.client.promise.then(() => {
this.dev_server.send({
status: 'completed'
});
const restart = () => {
ports.wait(this.port).then(this.deferreds.server.fulfil);
};
@@ -158,7 +162,13 @@ class Watcher extends EventEmitter {
cwd: process.cwd(),
env: Object.assign({
PORT: this.port
}, process.env)
}, process.env),
stdio: ['ipc']
});
this.emit('ready', <events.ReadyEvent>{
port: this.port,
process: this.proc
});
});
}
@@ -186,16 +196,6 @@ class Watcher extends EventEmitter {
const client_files = info.assets.map((chunk: { name: string }) => `client/${chunk.name}`);
this.deferreds.server.promise.then(() => {
this.dev_server.send({
status: 'completed'
});
this.emit('ready', <events.ReadyEvent>{
port: this.port
});
});
create_serviceworker_manifest({
routes: create_routes(),
client_files

View File

@@ -1,5 +1,8 @@
import * as child_process from 'child_process';
export type ReadyEvent = {
port: number;
process: child_process.ChildProcess;
};
export type ErrorEvent = {