2020-07-21 01:33:33 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const util = require('util');
|
|
|
|
const stream = require('stream');
|
|
|
|
const pipeline = util.promisify(stream.pipeline);
|
|
|
|
const split = require('split2');
|
|
|
|
const MetricsCollector = require('./metrics-collector');
|
|
|
|
|
|
|
|
module.exports = async function metro ({ input = process.stdin, output = process.stdout, metrics = {} } = {}) {
|
|
|
|
const metricsCollector = new MetricsCollector(metrics);
|
|
|
|
const { stream: metricsStream } = metricsCollector;
|
|
|
|
|
|
|
|
try {
|
|
|
|
await metricsCollector.start();
|
2020-07-21 22:36:23 +08:00
|
|
|
await pipeline(input, split(), metricsStream, output);
|
2020-07-21 01:33:33 +08:00
|
|
|
} finally {
|
|
|
|
await metricsCollector.stop();
|
|
|
|
}
|
|
|
|
};
|