todo-manager-cli-node-js 0.1.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/index.js +142 -0
- package/package.json +31 -0
- package/readme.md +59 -0
- package/todo.json +1 -0
package/index.js
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
const fs = require('fs');
|
2
|
+
const chalk = require('chalk').default;
|
3
|
+
const inquirer = require('inquirer').default;
|
4
|
+
const ora = require('ora').default;
|
5
|
+
const figlet = require('figlet');
|
6
|
+
|
7
|
+
const FILE = 'todo.json';
|
8
|
+
|
9
|
+
console.log(
|
10
|
+
chalk.yellow(figlet.textSync("TODO CLI", { horizontalLayout: "full" }))
|
11
|
+
);
|
12
|
+
|
13
|
+
function loadTasks() {
|
14
|
+
if (!fs.existsSync(FILE)) return [];
|
15
|
+
const data = fs.readFileSync(FILE);
|
16
|
+
return JSON.parse(data);
|
17
|
+
}
|
18
|
+
|
19
|
+
function saveTasks(tasks) {
|
20
|
+
fs.writeFileSync(FILE, JSON.stringify(tasks, null, 2));
|
21
|
+
}
|
22
|
+
|
23
|
+
async function addTask() {
|
24
|
+
const { task } = await inquirer.prompt([
|
25
|
+
{
|
26
|
+
type: 'input',
|
27
|
+
name: 'task',
|
28
|
+
message: 'Enter your task:',
|
29
|
+
validate: input => input ? true : 'Task cannot be empty!'
|
30
|
+
}
|
31
|
+
]);
|
32
|
+
|
33
|
+
const tasks = loadTasks();
|
34
|
+
const spinner = ora(`Saving your task...`).start();
|
35
|
+
tasks.push({ id: Date.now(), task, completed: false });
|
36
|
+
saveTasks(tasks);
|
37
|
+
await new Promise(resolve => setTimeout(resolve, 3000)); // wait here properly
|
38
|
+
spinner.succeed(chalk.green("Your task has been added successfully!"));
|
39
|
+
}
|
40
|
+
|
41
|
+
async function listTasks() {
|
42
|
+
const spinner = ora('Fetching your tasks...').start();
|
43
|
+
await new Promise(resolve => setTimeout(resolve, 3000)); // Simulate delay
|
44
|
+
spinner.stop();
|
45
|
+
|
46
|
+
const tasks = loadTasks();
|
47
|
+
if (tasks.length === 0) {
|
48
|
+
console.log(chalk.red('No tasks found!'));
|
49
|
+
} else {
|
50
|
+
console.log(chalk.blue.bold('\nYour Tasks:\n'));
|
51
|
+
tasks.forEach((t, index) => {
|
52
|
+
const status = t.completed ? chalk.green('✓ Completed') : chalk.red('✗ Incomplete');
|
53
|
+
console.log(`${index + 1}. ${t.task} - ${status}`);
|
54
|
+
});
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
async function deleteTask() {
|
59
|
+
const tasks = loadTasks();
|
60
|
+
if (tasks.length === 0) {
|
61
|
+
return console.log(chalk.red('No tasks to delete.'));
|
62
|
+
}
|
63
|
+
|
64
|
+
const { index } = await inquirer.prompt([
|
65
|
+
{
|
66
|
+
type: 'list',
|
67
|
+
name: 'index',
|
68
|
+
message: 'Select a task to delete:',
|
69
|
+
choices: tasks.map((t, i) => ({
|
70
|
+
name: `${t.task} (${t.completed ? '✓' : '✗'})`,
|
71
|
+
value: i
|
72
|
+
}))
|
73
|
+
}
|
74
|
+
]);
|
75
|
+
|
76
|
+
const spinner = ora('Deleting your task...').start();
|
77
|
+
await new Promise(resolve => setTimeout(resolve, 3000));
|
78
|
+
tasks.splice(index, 1);
|
79
|
+
saveTasks(tasks);
|
80
|
+
spinner.succeed(chalk.green('Task deleted successfully!'));
|
81
|
+
}
|
82
|
+
|
83
|
+
async function main() {
|
84
|
+
try {
|
85
|
+
const { name } = await inquirer.prompt([
|
86
|
+
{
|
87
|
+
type: 'input',
|
88
|
+
name: 'name',
|
89
|
+
message: 'What is your name?',
|
90
|
+
validate: input => input ? true : "Please provide name."
|
91
|
+
}
|
92
|
+
]);
|
93
|
+
|
94
|
+
console.log(chalk.cyan(`\nWelcome, ${name}\n! Have a nice day.`));
|
95
|
+
|
96
|
+
let exit = false;
|
97
|
+
while (!exit) {
|
98
|
+
const { choice } = await inquirer.prompt([
|
99
|
+
{
|
100
|
+
type: 'list',
|
101
|
+
name: 'choice',
|
102
|
+
message: 'What would you like to do?',
|
103
|
+
choices: [
|
104
|
+
{ name: '1. Add a Task', value: 'add' },
|
105
|
+
{ name: '2. View Tasks', value: 'list' },
|
106
|
+
{ name: '3. Delete a Task', value: 'delete' },
|
107
|
+
{ name: '4. Exit', value: 'exit' }
|
108
|
+
]
|
109
|
+
}
|
110
|
+
]);
|
111
|
+
|
112
|
+
switch (choice) {
|
113
|
+
case 'add':
|
114
|
+
await addTask();
|
115
|
+
break;
|
116
|
+
case 'list':
|
117
|
+
await listTasks();
|
118
|
+
break;
|
119
|
+
case 'delete':
|
120
|
+
await deleteTask();
|
121
|
+
break;
|
122
|
+
case 'exit':
|
123
|
+
console.log(
|
124
|
+
chalk.yellow(figlet.textSync("GOODBYE!", { horizontalLayout: "full" }))
|
125
|
+
);
|
126
|
+
exit = true;
|
127
|
+
break;
|
128
|
+
}
|
129
|
+
}
|
130
|
+
} catch (err) {
|
131
|
+
if (err.name === 'ExitPromptError') {
|
132
|
+
console.log(chalk.red('\nPrompt closed by user. Exiting gracefully...'));
|
133
|
+
// Do NOT call process.exit(1) here!
|
134
|
+
return;
|
135
|
+
} else {
|
136
|
+
console.error(chalk.red('An unexpected error occurred:\n'), err);
|
137
|
+
process.exit(1);
|
138
|
+
}
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
main();
|
package/package.json
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
{
|
2
|
+
"name": "todo-manager-cli-node-js",
|
3
|
+
"version": "0.1.0",
|
4
|
+
"description": "Todo-manager-with-cli",
|
5
|
+
"main": "index.js",
|
6
|
+
"bin": {
|
7
|
+
"todo": "./index.js"
|
8
|
+
},
|
9
|
+
"repository": {
|
10
|
+
"type": "git",
|
11
|
+
"url": "git+https://github.com/muhammadfarooq85/Todo-Manager-CLI-Node-Js.git"
|
12
|
+
},
|
13
|
+
"keywords": [
|
14
|
+
"node-js",
|
15
|
+
"javascript"
|
16
|
+
],
|
17
|
+
"author": "M. Farooq",
|
18
|
+
"license": "ISC",
|
19
|
+
"bugs": {
|
20
|
+
"url": "https://github.com/muhammadfarooq85/Todo-Manager-CLI-Node-Js/issues"
|
21
|
+
},
|
22
|
+
"homepage": "https://github.com/muhammadfarooq85/Todo-Manager-CLI-Node-Js#readme",
|
23
|
+
"dependencies": {
|
24
|
+
"chalk": "^5.4.1",
|
25
|
+
"cli-spinners": "^3.2.0",
|
26
|
+
"commander": "^14.0.0",
|
27
|
+
"figlet": "^1.8.1",
|
28
|
+
"inquirer": "^12.6.3",
|
29
|
+
"ora": "^8.2.0"
|
30
|
+
}
|
31
|
+
}
|
package/readme.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Todo Manager CLI
|
2
|
+
|
3
|
+
## A simple and interactive command-line Todo Manager built with Node.js. Manage your tasks easily with options to add, view, and delete tasks—all from your terminal!
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- Add new tasks
|
8
|
+
- List all tasks
|
9
|
+
- Delete tasks interactively
|
10
|
+
- Friendly command-line interface with spinner animations
|
11
|
+
- Data persistence using a local JSON file (todo.json)
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
1. Clone the repository or download the source code:
|
16
|
+
|
17
|
+
```
|
18
|
+
git clone https://github.com/muhammadfarooq85/Todo-Manager-CLI-Node-Js
|
19
|
+
cd Todo-Manager-CLI-Node
|
20
|
+
```
|
21
|
+
|
22
|
+
2. Install dependencies:
|
23
|
+
|
24
|
+
```
|
25
|
+
npm install
|
26
|
+
```
|
27
|
+
|
28
|
+
3. Usage
|
29
|
+
|
30
|
+
```
|
31
|
+
node index.js todo
|
32
|
+
```
|
33
|
+
|
34
|
+
## How it works
|
35
|
+
|
36
|
+
1. Enter your name.
|
37
|
+
|
38
|
+
2. Choose an action from the menu:
|
39
|
+
|
40
|
+
- Add a Task
|
41
|
+
|
42
|
+
- View Tasks
|
43
|
+
|
44
|
+
- Delete a Task
|
45
|
+
|
46
|
+
- Exit
|
47
|
+
|
48
|
+
3. Follow on-screen prompts to manage your todo list.
|
49
|
+
|
50
|
+
## File Storage
|
51
|
+
|
52
|
+
- Tasks are stored locally in todo.json in the project directory.
|
53
|
+
- Make sure to keep this file safe if you want to retain your task list.
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
Feel free to submit issues or pull requests for improvements or bug fixes!
|
58
|
+
|
59
|
+
## Made With 💖 by Muhammad Farooq!
|
package/todo.json
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
[]
|