mirror of
https://github.com/LukeHagar/VA-Log-Parser.git
synced 2025-12-06 04:21:55 +00:00
Adjusted functionality to account for significantly larger files Better organizational Structure Added Progress Bars, added support for multiple concurrent files at once Adjusted flow so logs are parsed and sorted as lines are read and identified, this should improve performance, reliability, and error reporting.
56 lines
1.4 KiB
JavaScript
56 lines
1.4 KiB
JavaScript
import inquirer from "inquirer";
|
|
import boxen from "boxen";
|
|
import ora from "ora";
|
|
import fs from "fs";
|
|
import parseLogFile from "./parseLogFile.js";
|
|
import chalk from "chalk";
|
|
import parseMultipleLogFiles from "./parseMultipleLogFiles.js";
|
|
|
|
function checkDirectory(path) {
|
|
const stats = fs.statSync(path);
|
|
return stats.isDirectory();
|
|
}
|
|
|
|
export default function startCLI() {
|
|
const spinner = ora();
|
|
console.log(
|
|
boxen(`VA-Log-Parser`, {
|
|
title: `Written by: Luke Hagar`,
|
|
titleAlignment: "center",
|
|
padding: 5,
|
|
})
|
|
);
|
|
spinner.start(`Getting Current Directory`);
|
|
const currentDirectory = process.cwd();
|
|
spinner.succeed();
|
|
spinner.start(`Reading Directory: ${currentDirectory}`);
|
|
let directoryContents = fs.readdirSync(currentDirectory);
|
|
spinner.succeed();
|
|
inquirer
|
|
.prompt([
|
|
{
|
|
type: "checkbox",
|
|
message: "Select Log Files to Parse",
|
|
name: "Files",
|
|
choices: [
|
|
new inquirer.Separator(chalk.green("------Files------")),
|
|
...directoryContents.filter((Obj) => checkDirectory(Obj) === false),
|
|
],
|
|
validate(answer) {
|
|
if (answer.length < 1) {
|
|
return "You must choose at least one File.";
|
|
}
|
|
|
|
return true;
|
|
},
|
|
},
|
|
])
|
|
.then((answers) => {
|
|
if (answers.Files.length > 1) {
|
|
parseMultipleLogFiles(answers.Files);
|
|
} else {
|
|
parseLogFile(answers.Files[0]);
|
|
}
|
|
});
|
|
}
|