| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import readline from "readline";
- import fs from "fs";
- import yargs from "yargs";
- import packageJson from "./package.json";
- import * as Rx from "rxjs";
- import { hideBin } from "yargs/helpers";
- import { map, pluck, takeUntil } from "rxjs/operators";
- const args = yargs(hideBin(process.argv))
- .scriptName(Object.keys(packageJson.bin)[0])
- .usage("Usage: $0 logfile")
- .option("files", {
- boolean: true,
- describe: "Strip out and save the embedded files from the log file"
- })
- .argv;
- type LogLine = {
- log: string;
- stream: string;
- time: string;
- };
- const rl = readline.createInterface({
- input: fs.createReadStream(args._[0]?.toString())
- });
- Rx.fromEvent<string>(rl, "line")
- .pipe(
- takeUntil(Rx.fromEvent(rl, "close")),
- map<string, LogLine>(line => JSON.parse(line)),
- pluck("log"),
- map(log => log.replace(/\n$/, ""))
- )
- .subscribe({
- next: console.log,
- error: console.error,
- complete: () => rl.close()
- });
|