@umarfarooq57/tasky 1.0.1 → 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
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { program } from "commander";
4
- import { addTask, editTask, listTasks } from "../src/commands.js";
4
+ import { addTask, deleteTask, editTask, listTasks } from "../src/commands.js";
5
5
 
6
6
  program
7
7
  .name("tasky")
@@ -33,5 +33,32 @@ program
33
33
  editTask(id, newDesc);
34
34
  });
35
35
 
36
+ // command to delete a task
37
+ program
38
+ .command("delete")
39
+ .description("Delete a task")
40
+ .argument("<id>", "The task id")
41
+ .action((id) => {
42
+ deleteTask(id);
43
+ });
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
+
36
63
  // parse the arguments passed by user
37
64
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umarfarooq57/tasky",
3
- "version": "1.0.1",
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
  };
@@ -11,7 +12,11 @@ export const addTask = (taskDescription) => {
11
12
  export const listTasks = () => {
12
13
  const tasks = readTasks();
13
14
  if (tasks.length === 0) {
14
- console.log(chalk.red.bold('No tasks found. Type `tasky add "your task"` to create one!'));
15
+ console.log(
16
+ chalk.red.bold(
17
+ 'No tasks found. Type `tasky add "your task"` to create one!',
18
+ ),
19
+ );
15
20
  return;
16
21
  }
17
22
  console.log("\nYour Task List:");
@@ -25,10 +30,41 @@ export const editTask = (id, newDesc) => {
25
30
  let tasks = readTasks();
26
31
  const taskToEdit = tasks.find((t) => t.id == id);
27
32
  if (!taskToEdit) {
28
- console.log(`Task with id:${id} does not exist`);
33
+ console.log(chalk.red(`Task with id:${id} does not exist`));
29
34
  return;
30
35
  }
31
36
  taskToEdit.task = newDesc;
32
- saveTasks(tasks)
33
- console.log(`Task with id:${chalk.blue.underline(id)} was successfully edited!`)
37
+ saveTasks(tasks);
38
+ console.log(
39
+ `Task with id:${chalk.blue.underline(id)} was successfully edited!`,
40
+ );
41
+ };
42
+
43
+ export const deleteTask = (id) => {
44
+ const tasks = readTasks();
45
+ const taskToDelete = tasks.find((t) => t.id == id);
46
+ if (!taskToDelete) {
47
+ console.log(`Task with id:${id} does not exist`);
48
+ return;
49
+ }
50
+ const updatedTasks = tasks.filter((t) => t.id != id);
51
+ saveTasks(updatedTasks);
52
+ console.log(
53
+ `Task with id:${chalk.blue.underline(id)} was successfully deleted!`,
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}!`);
34
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
  ]