better CLI, more port control. fixes #169

This commit is contained in:
Rich Harris
2018-03-05 13:51:11 -05:00
parent dd6c51567a
commit 5289fc11d8
10 changed files with 178 additions and 120 deletions

View File

@@ -5,7 +5,7 @@ import express from 'express';
import cheerio from 'cheerio';
import URL from 'url-parse';
import fetch from 'node-fetch';
import { wait_for_port } from './utils';
import * as port_utils from './port-utils';
import { dest } from '../config';
const app = express();
@@ -27,7 +27,7 @@ export default async function exporter(export_dir: string) {
sander.copyFileSync(build_dir, 'service-worker.js').to(export_dir, 'service-worker.js');
}
const port = await require('get-port')(3000);
const port = await port_utils.find(3000);
const origin = `http://localhost:${port}`;
@@ -88,7 +88,7 @@ export default async function exporter(export_dir: string) {
});
}
wait_for_port(port)
return port_utils.wait(port)
.then(() => handle(new URL(origin))) // TODO all static routes
.then(() => proc.kill());
}