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