todo-list-cli-aui 0.0.0-stage → 2.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Afaq Ul Islam
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,124 @@
1
- # Temporary Holding Version
1
+ # ToDo List
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm version](https://img.shields.io/npm/v/todo-list-cli-aui?style=flat-square&logo=npm&label=npm)](https://www.npmjs.com/package/todo-list-cli-aui)
4
+ [![npm downloads](https://img.shields.io/npm/dm/todo-list-cli-aui?style=flat-square&logo=npm)](https://www.npmjs.com/package/todo-list-cli-aui)
5
+ [![Node.js](https://img.shields.io/node/v/todo-list-cli-aui?style=flat-square&logo=node.js&logoColor=white)](https://nodejs.org)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-3178C6?style=flat-square&logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow?style=flat-square)](./LICENSE)
8
+
9
+ > A persistent terminal to-do list with add, update, delete, complete and clear operations stored in a local JSON file.
10
+
11
+ Part of the [**12 CLI Based Projects**](https://github.com/afaqulislam/12-CLI-Based-Projects) collection — a set of production-grade
12
+ TypeScript command-line applications by [Afaq Ul Islam](https://github.com/afaqulislam).
13
+
14
+ ## Features
15
+
16
+ - Add, update, delete and complete tasks
17
+ - Persistent JSON storage between runs
18
+ - Input validation and clear error messages
19
+ - Bulk view and clear operations
20
+
21
+ ## Quick start
22
+
23
+ Run instantly with `npx`:
24
+
25
+ ```bash
26
+ npx todo-list-cli-aui
27
+ ```
28
+
29
+ ```text
30
+ $ npx todo-list-cli-aui
31
+ ? Select an operation: Add
32
+ ? Add an item to the list: Ship the production rewrite
33
+ Added: Ship the production rewrite
34
+ 1. [ ] Ship the production rewrite
35
+ ```
36
+
37
+ ### Install globally
38
+
39
+ ```bash
40
+ npm install -g todo-list-cli-aui
41
+ todo-list-cli-aui
42
+ ```
43
+
44
+ ### Install locally
45
+
46
+ ```bash
47
+ npm install todo-list-cli-aui
48
+ npx todo-list-cli-aui
49
+ ```
50
+
51
+ ## Usage
52
+
53
+ The app is fully interactive. Launch it and follow the prompts. Every screen
54
+ validates its input and shows a helpful message instead of crashing on bad data.
55
+ Use `Ctrl+C` at any time to quit.
56
+
57
+ ## How it works
58
+
59
+ The project separates the **pure domain logic** (`src/todo.ts`) from the
60
+ **CLI layer** (`src/index.ts`). The domain module contains no I/O, which makes it
61
+ easy to test and reuse; the CLI layer is only responsible for prompting the user
62
+ and rendering results.
63
+
64
+ ```text
65
+ CLI ToDo List/
66
+ ├── src/
67
+ │ ├── index.ts # Interactive CLI entry point
68
+ │ └── todo.ts # Pure, testable domain logic
69
+ ├── test/
70
+ │ └── todo.test.ts
71
+ ├── package.json
72
+ ├── tsconfig.json # Build config (NodeNext, strict)
73
+ └── tsconfig.test.json # Type-check config for tests
74
+ ```
75
+
76
+ ## Scripts
77
+
78
+ | Command | Description |
79
+ | --- | --- |
80
+ | `npm run build` | Compile TypeScript to `dist/` |
81
+ | `npm start` | Run the compiled CLI |
82
+ | `npm run dev` | Run the CLI from source with `tsx` |
83
+ | `npm test` | Run the unit tests with Vitest |
84
+ | `npm run typecheck` | Type-check source and tests |
85
+ | `npm run clean` | Remove the build output |
86
+
87
+ ## Tech stack
88
+
89
+ - **TypeScript** (strict mode, `NodeNext` modules)
90
+ - **Node.js** 20+
91
+ - **[Inquirer](https://github.com/SBoudrias/Inquirer.js)** for interactive prompts
92
+ - **Vitest** for unit testing
93
+
94
+ ## Testing
95
+
96
+ ```bash
97
+ npm install
98
+ npm test
99
+ ```
100
+
101
+ The test suite covers the domain logic, including edge cases and validation
102
+ errors, without touching the interactive prompt layer.
103
+
104
+ ## Publishing
105
+
106
+ This package is part of a monorepo but is published independently:
107
+
108
+ ```bash
109
+ npm login
110
+ npm publish
111
+ ```
112
+
113
+ `prepublishOnly` automatically cleans, builds and tests before every publish.
114
+
115
+ ## Contributing
116
+
117
+ Contributions are welcome. Please read the
118
+ [contributing guide](../CONTRIBUTING.md) and open an issue or pull request.
119
+
120
+ For security issues, follow the [security policy](../SECURITY.md).
121
+
122
+ ## License
123
+
124
+ MIT © [Afaq Ul Islam](https://github.com/afaqulislam). See [LICENSE](./LICENSE).
package/dist/index.js ADDED
@@ -0,0 +1,194 @@
1
+ #!/usr/bin/env node
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import inquirer from "inquirer";
5
+ import { TodoError, TodoStore } from "./todo.js";
6
+ function defaultStoragePath() {
7
+ const override = process.env["TODO_LIST_CLI_AUI_FILE"];
8
+ if (override !== undefined && override.trim() !== "") {
9
+ return override;
10
+ }
11
+ return path.join(os.homedir(), ".todo-list-cli-aui", "todos.json");
12
+ }
13
+ function printTasks(todos) {
14
+ if (todos.length === 0) {
15
+ console.log("\nNo tasks yet. Add one to get started.\n");
16
+ return;
17
+ }
18
+ console.log(`\n--- Tasks (${todos.length}) ---`);
19
+ todos.forEach((todo, index) => {
20
+ console.log(`${index + 1}. ${todo.completed ? "[x]" : "[ ]"} ${todo.title}`);
21
+ });
22
+ console.log("--------------------\n");
23
+ }
24
+ async function selectTask(message, todos) {
25
+ if (todos.length === 0) {
26
+ console.log("\nNo tasks available for that operation.\n");
27
+ return undefined;
28
+ }
29
+ const { id } = await inquirer.prompt([
30
+ {
31
+ name: "id",
32
+ type: "list",
33
+ message,
34
+ loop: false,
35
+ choices: todos.map((todo) => ({
36
+ name: `${todo.completed ? "[x]" : "[ ]"} ${todo.title}`,
37
+ value: todo.id,
38
+ })),
39
+ },
40
+ ]);
41
+ return id;
42
+ }
43
+ async function main() {
44
+ const store = new TodoStore({ filePath: defaultStoragePath() });
45
+ console.log("\n=== ToDo List ===");
46
+ console.log(`Storage: ${store.storagePath ?? "in memory"}\n`);
47
+ try {
48
+ await store.load();
49
+ }
50
+ catch (error) {
51
+ console.error(error instanceof Error ? error.message : String(error));
52
+ process.exit(1);
53
+ }
54
+ const persist = async () => {
55
+ try {
56
+ await store.save();
57
+ }
58
+ catch (error) {
59
+ console.error(`Could not save tasks: ${error instanceof Error ? error.message : String(error)}`);
60
+ }
61
+ };
62
+ let running = true;
63
+ while (running) {
64
+ const { action } = await inquirer.prompt([
65
+ {
66
+ name: "action",
67
+ type: "list",
68
+ message: "Select an operation:",
69
+ loop: false,
70
+ choices: [
71
+ "Add",
72
+ "Update",
73
+ "Delete",
74
+ "Toggle Complete",
75
+ "View",
76
+ "Clear Completed",
77
+ "Clear All",
78
+ "Exit",
79
+ ],
80
+ },
81
+ ]);
82
+ try {
83
+ switch (action) {
84
+ case "Add": {
85
+ const { title } = await inquirer.prompt([
86
+ {
87
+ name: "title",
88
+ type: "input",
89
+ message: "Add an item to the list:",
90
+ validate: (input) => typeof input === "string" && input.trim() !== ""
91
+ ? true
92
+ : "Please enter a non-empty item.",
93
+ },
94
+ ]);
95
+ const todo = store.add(title);
96
+ console.log(`\nAdded: ${todo.title}`);
97
+ await persist();
98
+ printTasks(store.list());
99
+ break;
100
+ }
101
+ case "Update": {
102
+ const id = await selectTask("Select the task to update:", store.list());
103
+ if (id === undefined)
104
+ break;
105
+ const { title } = await inquirer.prompt([
106
+ {
107
+ name: "title",
108
+ type: "input",
109
+ message: "Enter the new title:",
110
+ validate: (input) => typeof input === "string" && input.trim() !== ""
111
+ ? true
112
+ : "Please enter a non-empty item.",
113
+ },
114
+ ]);
115
+ const todo = store.update(id, title);
116
+ console.log(`\nUpdated: ${todo.title}`);
117
+ await persist();
118
+ printTasks(store.list());
119
+ break;
120
+ }
121
+ case "Delete": {
122
+ const id = await selectTask("Select the task to delete:", store.list());
123
+ if (id === undefined)
124
+ break;
125
+ store.remove(id);
126
+ console.log("\nTask deleted.");
127
+ await persist();
128
+ printTasks(store.list());
129
+ break;
130
+ }
131
+ case "Toggle Complete": {
132
+ const id = await selectTask("Select the task to toggle:", store.list());
133
+ if (id === undefined)
134
+ break;
135
+ const todo = store.toggle(id);
136
+ console.log(`\n${todo.completed ? "Completed" : "Reopened"}: ${todo.title}`);
137
+ await persist();
138
+ printTasks(store.list());
139
+ break;
140
+ }
141
+ case "View":
142
+ printTasks(store.list());
143
+ break;
144
+ case "Clear Completed": {
145
+ const removed = store.clearCompleted();
146
+ console.log(`\nRemoved ${removed} completed task(s).`);
147
+ await persist();
148
+ printTasks(store.list());
149
+ break;
150
+ }
151
+ case "Clear All": {
152
+ const { confirm } = await inquirer.prompt([
153
+ {
154
+ name: "confirm",
155
+ type: "confirm",
156
+ message: "Delete all tasks? This cannot be undone.",
157
+ default: false,
158
+ },
159
+ ]);
160
+ if (confirm) {
161
+ const removed = store.clear();
162
+ console.log(`\nRemoved ${removed} task(s).`);
163
+ await persist();
164
+ }
165
+ printTasks(store.list());
166
+ break;
167
+ }
168
+ case "Exit":
169
+ console.log("\nYour tasks are saved. Goodbye!\n");
170
+ running = false;
171
+ break;
172
+ default:
173
+ console.log("\nUnknown option.\n");
174
+ }
175
+ }
176
+ catch (error) {
177
+ if (error instanceof TodoError) {
178
+ console.error(`\n${error.message}\n`);
179
+ }
180
+ else {
181
+ throw error;
182
+ }
183
+ }
184
+ }
185
+ }
186
+ main().catch((error) => {
187
+ if (error instanceof Error && error.name === "ExitPromptError") {
188
+ console.log("\nGoodbye!\n");
189
+ process.exit(0);
190
+ }
191
+ console.error("Unexpected error:", error);
192
+ process.exit(1);
193
+ });
194
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAa,MAAM,WAAW,CAAC;AAE5D,SAAS,kBAAkB;IACzB,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IAEvD,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACrD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,oBAAoB,EAAE,YAAY,CAAC,CAAC;AACrE,CAAC;AAED,SAAS,UAAU,CAAC,KAAsB;IACxC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;QACzD,OAAO;IACT,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,gBAAgB,KAAK,CAAC,MAAM,OAAO,CAAC,CAAC;IACjD,KAAK,CAA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,OAAO,CAAC,KAAK,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;IAC1C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
package/dist/todo.js ADDED
@@ -0,0 +1,142 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
3
+ import path from "node:path";
4
+ export class TodoError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = "TodoError";
8
+ }
9
+ }
10
+ export const MAX_TITLE_LENGTH = 200;
11
+ function isTodo(value) {
12
+ if (typeof value !== "object" || value === null) {
13
+ return false;
14
+ }
15
+ const candidate = value;
16
+ return (typeof candidate.id === "string" &&
17
+ typeof candidate.title === "string" &&
18
+ typeof candidate.completed === "boolean" &&
19
+ typeof candidate.createdAt === "string" &&
20
+ typeof candidate.updatedAt === "string");
21
+ }
22
+ export function normalizeTitle(title) {
23
+ if (typeof title !== "string") {
24
+ throw new TodoError("Task title must be text.");
25
+ }
26
+ const trimmed = title.trim();
27
+ if (trimmed === "") {
28
+ throw new TodoError("Task title cannot be empty.");
29
+ }
30
+ if (trimmed.length > MAX_TITLE_LENGTH) {
31
+ throw new TodoError(`Task title cannot exceed ${MAX_TITLE_LENGTH} characters.`);
32
+ }
33
+ return trimmed;
34
+ }
35
+ export class TodoStore {
36
+ todos = [];
37
+ filePath;
38
+ now;
39
+ idFactory;
40
+ constructor(options = {}) {
41
+ this.filePath = options.filePath;
42
+ this.now = options.now ?? (() => new Date());
43
+ this.idFactory = options.idFactory ?? randomUUID;
44
+ }
45
+ get storagePath() {
46
+ return this.filePath;
47
+ }
48
+ async load() {
49
+ if (this.filePath === undefined) {
50
+ this.todos = [];
51
+ return;
52
+ }
53
+ let raw;
54
+ try {
55
+ raw = await readFile(this.filePath, "utf8");
56
+ }
57
+ catch (error) {
58
+ if (error.code === "ENOENT") {
59
+ this.todos = [];
60
+ return;
61
+ }
62
+ throw error;
63
+ }
64
+ let parsed;
65
+ try {
66
+ parsed = JSON.parse(raw);
67
+ }
68
+ catch {
69
+ throw new TodoError(`The task file at ${this.filePath} is not valid JSON.`);
70
+ }
71
+ const data = parsed;
72
+ if (typeof parsed !== "object" || parsed === null || !Array.isArray(data.todos)) {
73
+ throw new TodoError(`The task file at ${this.filePath} has an unexpected format.`);
74
+ }
75
+ this.todos = data.todos.filter(isTodo);
76
+ }
77
+ async save() {
78
+ if (this.filePath === undefined) {
79
+ return;
80
+ }
81
+ const directory = path.dirname(this.filePath);
82
+ await mkdir(directory, { recursive: true });
83
+ const payload = { version: 1, todos: this.todos };
84
+ const temporaryPath = `${this.filePath}.${process.pid}.tmp`;
85
+ await writeFile(temporaryPath, `${JSON.stringify(payload, null, 2)}\n`, "utf8");
86
+ await rename(temporaryPath, this.filePath);
87
+ }
88
+ add(title) {
89
+ const normalized = normalizeTitle(title);
90
+ const timestamp = this.now().toISOString();
91
+ const todo = {
92
+ id: this.idFactory(),
93
+ title: normalized,
94
+ completed: false,
95
+ createdAt: timestamp,
96
+ updatedAt: timestamp,
97
+ };
98
+ this.todos.push(todo);
99
+ return todo;
100
+ }
101
+ get(id) {
102
+ const todo = this.todos.find((item) => item.id === id);
103
+ if (todo === undefined) {
104
+ throw new TodoError("Task not found.");
105
+ }
106
+ return todo;
107
+ }
108
+ update(id, title) {
109
+ const todo = this.get(id);
110
+ todo.title = normalizeTitle(title);
111
+ todo.updatedAt = this.now().toISOString();
112
+ return todo;
113
+ }
114
+ toggle(id) {
115
+ const todo = this.get(id);
116
+ todo.completed = !todo.completed;
117
+ todo.updatedAt = this.now().toISOString();
118
+ return todo;
119
+ }
120
+ remove(id) {
121
+ const index = this.todos.findIndex((item) => item.id === id);
122
+ if (index === -1) {
123
+ return false;
124
+ }
125
+ this.todos.splice(index, 1);
126
+ return true;
127
+ }
128
+ clearCompleted() {
129
+ const before = this.todos.length;
130
+ this.todos = this.todos.filter((todo) => !todo.completed);
131
+ return before - this.todos.length;
132
+ }
133
+ clear() {
134
+ const removed = this.todos.length;
135
+ this.todos = [];
136
+ return removed;
137
+ }
138
+ list() {
139
+ return [...this.todos];
140
+ }
141
+ }
142
+ //# sourceMappingURL=todo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"todo.js","sourceRoot":"","sources":["../src/todo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,IAAI,MAAM,WAAW,CAAC;AAgB7B,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;IAC1B,CAAC;CACF;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAOpC,SAAS,MAAM,CAAC,KAAc;IAC5B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,SAAS,GAAG,KAAgC,CAAC;IAEnD,OAAO,CACL,OAAO,SAAS,CAAC,EAAE,KAAK,QAAQ;QAChC,OAAO,SAAS,CAAC,KAAK,KAAK,QAAQ;QACnC,OAAO,SAAS,CAAC,SAAS,KAAK,SAAS;QACxC,OAAO,SAAS,CAAC,SAAS,KAAK,QAAQ;QACvC,OAAO,SAAS,CAAC,SAAS,KAAK,QAAQ,CACxC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,SAAS,CAAC,0BAA0B,CAAC,CAAC;IAClD,CAAC;IAED,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAE7B,IAAI,OA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AG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAE7D,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;YACjB,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,cAAc;QACZ,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC1D,OAAO,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IACpC,CAAC;IAED,KAAK;QACH,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;QAClC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,IAAI;QACF,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,67 @@
1
1
  {
2
2
  "name": "todo-list-cli-aui",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.0.0",
4
+ "description": "A persistent terminal to-do list with add, update, delete, complete and clear operations stored in a local JSON file. Run it with: npx todo-list-cli-aui",
5
+ "keywords": [
6
+ "cli",
7
+ "command-line",
8
+ "typescript",
9
+ "nodejs",
10
+ "inquirer",
11
+ "portfolio",
12
+ "afaq-ul-islam",
13
+ "todo",
14
+ "tasks",
15
+ "productivity",
16
+ "notes"
17
+ ],
18
+ "homepage": "https://github.com/afaqulislam/12-CLI-Based-Projects/tree/main/CLI%20ToDo%20List",
19
+ "bugs": {
20
+ "url": "https://github.com/afaqulislam/12-CLI-Based-Projects/issues"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/afaqulislam/12-CLI-Based-Projects.git",
25
+ "directory": "CLI ToDo List"
26
+ },
27
+ "license": "MIT",
28
+ "author": {
29
+ "name": "Afaq Ul Islam",
30
+ "url": "https://github.com/afaqulislam"
31
+ },
32
+ "type": "module",
33
+ "bin": {
34
+ "todo-list-cli-aui": "dist/index.js"
35
+ },
36
+ "files": [
37
+ "dist",
38
+ "README.md",
39
+ "LICENSE"
40
+ ],
41
+ "engines": {
42
+ "node": ">=20"
43
+ },
44
+ "scripts": {
45
+ "build": "tsc -p tsconfig.json",
46
+ "start": "node dist/index.js",
47
+ "dev": "tsx src/index.ts",
48
+ "test": "vitest run",
49
+ "test:watch": "vitest",
50
+ "typecheck": "tsc -p tsconfig.test.json",
51
+ "clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
52
+ "prepublishOnly": "npm run clean && npm run build && npm test"
53
+ },
54
+ "dependencies": {
55
+ "inquirer": "^9.2.16"
56
+ },
57
+ "devDependencies": {
58
+ "@types/inquirer": "^9.0.7",
59
+ "@types/node": "^22.10.0",
60
+ "tsx": "^4.19.0",
61
+ "typescript": "^5.7.0",
62
+ "vitest": "^2.1.0"
63
+ },
64
+ "publishConfig": {
65
+ "access": "public"
66
+ }
67
+ }