tfd-test
Version:
Developer task manager. No more TODO or FIXME comments. A simple wrapper function to create tasks.
98 lines (96 loc) • 2.88 kB
JavaScript
// src/functions.ts
import { promises as fs } from "fs";
import path from "path";
var filePath = path.join(process.cwd(), "tasks.json");
async function readTasksFromFile(filePath2) {
try {
const data = await fs.readFile(filePath2, "utf8");
return JSON.parse(data);
} catch (error) {
if (error.code === "ENOENT") {
await fs.writeFile(filePath2, JSON.stringify([]), "utf8");
return [];
} else {
console.error("Error reading tasks file:", error);
throw error;
}
}
}
async function writeTasksToFile(filePath2, tasks) {
try {
const data = JSON.stringify(tasks, null, 2);
await fs.writeFile(filePath2, data, "utf8");
} catch (error) {
console.error("Error writing tasks file:", error);
}
}
function parseStackTrace(stackLine) {
const match = /at (.+):(\d+):(\d+)/.exec(stackLine || "");
return {
file: match ? match[1] : "unknown",
line: match ? parseInt(match[2], 10) : -1
};
}
async function logTask(details) {
const error = new Error();
const stackLine = error.stack?.split("\n")[2];
const { file, line } = parseStackTrace(stackLine);
const extendedDetails = { ...details, file, line };
const tasks = await readTasksFromFile(filePath);
tasks.push(extendedDetails);
await writeTasksToFile(filePath, tasks);
}
// src/components/TaskDisplay.tsx
import React from "react";
var TaskListDisplay = ({ tasks }) => {
return /* @__PURE__ */ React.createElement("aside", { style: asideStyle }, /* @__PURE__ */ React.createElement("h2", { style: headingStyle }, "Tasks"), /* @__PURE__ */ React.createElement("hr", { style: separatorStyle }), /* @__PURE__ */ React.createElement("ul", { style: listStyle }, tasks.map((task, index) => /* @__PURE__ */ React.createElement("li", { key: index }, task.description))));
};
var asideStyle = {
backgroundColor: "white",
// White background
borderRadius: "8px",
// Medium-rounded corners
border: "1px solid #ddd",
// Greyish border
boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
// Slight shadow
position: "fixed",
// Fixed positioning
bottom: "20px",
// Positioned 20px from the bottom
right: "20px",
// Positioned 20px from the right
width: "250px",
// Width of the component
height: "400px",
// Height based on content
padding: "10px",
// Padding inside the component
overflowY: "hidden"
// Scrollable if content is too long
};
var headingStyle = {
textAlign: "center",
// Center align text
fontWeight: "bold",
// Bold text
fontSize: "16px"
// Larger font size
};
var separatorStyle = {
border: "0",
borderTop: "1px solid #ccc",
margin: "10px 0",
width: "100%"
};
var listStyle = {
maxHeight: "100%",
// Max height to fit the container
overflowY: "auto"
// Scrollable list
};
var TaskDisplay_default = TaskListDisplay;
export {
TaskDisplay_default as TaskListDisplay,
logTask
};