@umarfarooq57/tasky 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -0
- package/bin/index.js +37 -0
- package/package.json +20 -0
- package/src/commands.js +33 -0
- package/src/storage.js +20 -0
- package/testing/tasks.json +12 -0
package/README.md
ADDED
|
File without changes
|
package/bin/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { program } from "commander";
|
|
4
|
+
import { addTask, editTask, listTasks } from "../src/commands.js";
|
|
5
|
+
|
|
6
|
+
program
|
|
7
|
+
.name("tasky")
|
|
8
|
+
.description("A simple CLI tool to manage your daily tasks")
|
|
9
|
+
.version("1.0.0");
|
|
10
|
+
|
|
11
|
+
// command to add a task
|
|
12
|
+
program
|
|
13
|
+
.command("add")
|
|
14
|
+
.description("Add a new task")
|
|
15
|
+
.argument("<task>", "The task description")
|
|
16
|
+
.action((task) => {
|
|
17
|
+
addTask(task);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// command to list all tasks
|
|
21
|
+
program
|
|
22
|
+
.command("list")
|
|
23
|
+
.description("List all saved tasks")
|
|
24
|
+
.action(() => listTasks());
|
|
25
|
+
|
|
26
|
+
// command to edit a task
|
|
27
|
+
program
|
|
28
|
+
.command("edit")
|
|
29
|
+
.description("Edit a task")
|
|
30
|
+
.argument("<id>", "The task id")
|
|
31
|
+
.argument("<newDesc>", "Modified task description")
|
|
32
|
+
.action((id, newDesc) => {
|
|
33
|
+
editTask(id, newDesc);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// parse the arguments passed by user
|
|
37
|
+
program.parse();
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@umarfarooq57/tasky",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A simple CLI tool to manage tasks",
|
|
5
|
+
"main": "bin/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"tasky": "./bin/index.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"chalk": "^5.6.2",
|
|
18
|
+
"commander": "^15.0.0"
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/commands.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { readTasks, saveTasks } from "./storage.js";
|
|
2
|
+
|
|
3
|
+
export const addTask = (taskDescription) => {
|
|
4
|
+
const tasks = readTasks();
|
|
5
|
+
tasks.push({ id: tasks.length + 1, task: taskDescription, done: false });
|
|
6
|
+
saveTasks(tasks);
|
|
7
|
+
console.log(`Task added successfully: "${taskDescription}"`);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const listTasks = () => {
|
|
11
|
+
const tasks = readTasks();
|
|
12
|
+
if (tasks.length === 0) {
|
|
13
|
+
console.log('No tasks found. Type `tasky add "your task"` to create one!');
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
console.log("\nYour Task List:");
|
|
17
|
+
tasks.forEach((t) => {
|
|
18
|
+
console.log(`${t.id}. [${t.done ? "X" : " "}] ${t.task}`);
|
|
19
|
+
console.log(""); // Extra line for spacing
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const editTask = (id, newDesc) => {
|
|
24
|
+
let tasks = readTasks();
|
|
25
|
+
const taskToEdit = tasks.find((t) => t.id == id);
|
|
26
|
+
if (!taskToEdit) {
|
|
27
|
+
console.log(`Task with id:${id} does not exist`);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
taskToEdit.task = newDesc;
|
|
31
|
+
saveTasks(tasks)
|
|
32
|
+
console.log(`Task with id:${id} is edited.`)
|
|
33
|
+
};
|
package/src/storage.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// This file handles reading and writing your tasks to a local tasks.json file so your data persists.
|
|
2
|
+
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
|
|
6
|
+
const FILE_PATH = path.join(process.cwd(), "tasks.json");
|
|
7
|
+
|
|
8
|
+
// helper to read tasks
|
|
9
|
+
export const readTasks = () => {
|
|
10
|
+
if (!fs.existsSync(FILE_PATH)) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
const data = fs.readFileSync(FILE_PATH, "utf-8");
|
|
14
|
+
return JSON.parse(data || "[]");
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// Helper to save tasks
|
|
18
|
+
export const saveTasks = (tasks) => {
|
|
19
|
+
fs.writeFileSync(FILE_PATH, JSON.stringify(tasks, null, 2));
|
|
20
|
+
};
|