@umarfarooq57/tasky 1.2.0 → 1.3.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/bin/index.js CHANGED
@@ -42,5 +42,23 @@ program
42
42
  deleteTask(id);
43
43
  });
44
44
 
45
+ // command to mark a task as done
46
+ program
47
+ .command("done")
48
+ .description("Mark a task as completed")
49
+ .argument("<id>", "The task id")
50
+ .action((id) => {
51
+ toggleTaskStatus(id, true);
52
+ });
53
+
54
+ // command to mark a task as incomplete
55
+ program
56
+ .command("undone")
57
+ .description("Mark a task as incomplete")
58
+ .argument("<id>", "The task id")
59
+ .action((id) => {
60
+ toggleTaskStatus(id, false);
61
+ });
62
+
45
63
  // parse the arguments passed by user
46
64
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umarfarooq57/tasky",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "A simple CLI tool to manage tasks",
5
5
  "main": "bin/index.js",
6
6
  "bin": {
package/src/commands.js CHANGED
@@ -3,7 +3,8 @@ import { readTasks, saveTasks } from "./storage.js";
3
3
 
4
4
  export const addTask = (taskDescription) => {
5
5
  const tasks = readTasks();
6
- tasks.push({ id: tasks.length + 1, task: taskDescription, done: false });
6
+ const nextId = tasks.length > 0 ? Math.max(...tasks.map(t => t.id)) + 1 : 1;
7
+ tasks.push({ id: nextId, task: taskDescription, done: false });
7
8
  saveTasks(tasks);
8
9
  console.log(chalk.green(`Task added successfully: "${taskDescription}"`));
9
10
  };
@@ -52,3 +53,18 @@ export const deleteTask = (id) => {
52
53
  `Task with id:${chalk.blue.underline(id)} was successfully deleted!`,
53
54
  );
54
55
  };
56
+
57
+ export const toggleTaskStatus = (id, isDone) => {
58
+ const tasks = readTasks();
59
+ const task = tasks.find((t) => t.id == id);
60
+ if (!task) {
61
+ console.log(chalk.red(`Task with id:${id} does not exist`));
62
+ return;
63
+ }
64
+ task.done = isDone;
65
+ saveTasks(tasks);
66
+ const statusMessage = isDone
67
+ ? chalk.green("completed [X]")
68
+ : chalk.yellow("incomplete [ ]");
69
+ console.log(`Task ${chalk.blue.underline(id)} marked as ${statusMessage}!`);
70
+ };
@@ -5,8 +5,13 @@
5
5
  "done": false
6
6
  },
7
7
  {
8
- "id": 2,
9
- "task": "Task 2",
10
- "done": true
8
+ "id": 3,
9
+ "task": "task 3",
10
+ "done": false
11
+ },
12
+ {
13
+ "id": 3,
14
+ "task": "task 4",
15
+ "done": false
11
16
  }
12
17
  ]
Binary file