summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/hero.mjs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/hero.mjs b/src/hero.mjs
index 6b6fa77..8cbbe36 100644
--- a/src/hero.mjs
+++ b/src/hero.mjs
@@ -338,6 +338,25 @@ export const rmIf = path => {
export const mkfifo = path =>
child_process.execFileSync("mkfifo", [path]);
+export const makeLineEmitter = fn => {
+ let data = "";
+ return chunk => {
+ const segments = chunk.split("\n");
+ assert.ok(segments.length > 0);
+
+ if (segments.length === 1) {
+ data += segments[0];
+ return;
+ }
+
+ [
+ data + u.first(segments),
+ ...u.butlast(u.rest(segments)),
+ ].forEach(fn);
+ data = u.last(segments);
+ };
+};
+
export const buildRoutes = (routes, globalInterceptors = []) =>
routes.reduce(
(acc, [methods, path, handlerFn, interceptors = []]) =>