#!/usr/bin/env bun // Import the required modules import { readFile, writeFile } from 'fs/promises'; import { argv } from 'process'; // Function to generate HTML from the input text async function generateHTML(inputFile) { try { // Read the input file const data = await readFile(inputFile, 'utf-8'); // Split the data into lines const lines = data.split('\n').filter(line => line.trim() !== ''); // Start building the HTML content let htmlContent = ` ${inputFile} `; // Process each line and add it to the HTML content lines.forEach(line => { // Split the line at the first closing bracket const parts = line.split(']'); if (parts.length >= 2) { const timestamp = parts[0].replace('[', '').trim(); // Clean the timestamp const text = parts[1].trim(); // Clean the text htmlContent += ` `; } }); // Close the HTML tags htmlContent += `
${timestamp} ${text}
`; // Write the HTML content to a file const outputFile = inputFile.replace('.txt', '.html'); await writeFile(outputFile, htmlContent); console.log(`HTML file created: ${outputFile}`); } catch (error) { console.error('Error:', error); } } // Get the input file from command line arguments const inputFile = argv[2]; if (!inputFile) { console.error('Please provide a text file as an argument.'); } else { generateHTML(inputFile); }