@umarfarooq57/tasky 1.2.0 → 1.3.1
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 +19 -1
- package/package.json +1 -1
- package/src/commands.js +17 -1
- package/testing/tasks.json +8 -3
- package/umarfarooq57-tasky-1.0.1.tgz +0 -0
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, deleteTask, editTask, listTasks } from "../src/commands.js";
|
|
4
|
+
import { addTask, deleteTask, editTask, listTasks, toggleTaskStatus } from "../src/commands.js";
|
|
5
5
|
|
|
6
6
|
program
|
|
7
7
|
.name("tasky")
|
|
@@ -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
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.
|
|
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
|
+
};
|
package/testing/tasks.json
CHANGED
|
Binary file
|