This project is an implementation of a learning project featured on roadmap.sh.
- ✅ Developed through TDD
- 📝 Tested with Node.js native test suite
- 🧑🎓 Good example for learners
# Install dependencies
pnpm install
# Build
pnpm run build
# Run
cd ./bin
task-cli add "task 1"
task-cli list
# Adding a new task
task-cli add "Buy groceries"
# Output: Task added successfully (ID: 1)
# Updating and deleting tasks
task-cli update 1 "Buy groceries and cook dinner"
task-cli delete 1
# Marking a task as in progress or done
task-cli mark-in-progress 1
task-cli mark-done 1
# Listing all tasks
task-cli list
# Listing tasks by status
task-cli list done
task-cli list todo
task-cli list in-progress
-
run()
accept subcommands as a second argument- should throw error if subcommand is not passed
- should throw error if specified subcommand does not exist
- should run a command if specified subcommand exists
-
getNextId()
returns an incremented next id- should return 1 if
list
is empty - should return 2 if
list
has one task with id 1
- should return 1 if
-
add()
adds a new task to the list- should create a task and add it to the list
- should increment the id to 2 for the secondaly added task
-
remove()
removes a task with the given id from the list- should return
[]
iflist
is empty - should return
[]
iflist
contains just one task with id 1 and the given id is also 1 - should return the same list if the task with the given id is not found
- should return the same list if no task is found with the given id
- should return
-
update()
updates a task with the given id in the list- should update
description
- should update
updatedAt
to the current time - should not update other tasks
- should update
-
updateStatus()
updates the status of a task- refactor
markInPprogress()
andmarkDone()
to useupdateStatus()
- should update
status
to "in-progress" - should update
updatedAt
to the current time - should not update other tasks
- refactor
-
markInPprogress()
marks a task as in progress- should update
status
to "in-progress"
- should update
-
markDone()
marks a task as done- should update
status
to "done"
- should update
-
define zod shemas for subcommand arguments
- zod schema for the arguments of
add()
- should parse [string]
- should fail when parsing an empty args
- zod schema for the arguments of
remove()
- should parse [string]
- should fail when parsing an empty args
- zod schema for the arguments of
update()
- should parse [string, string]
- should fail when parsing an empty args
- zod schema for the arguments of
updateStatus()
- should parse [string]
- should fail when parsing an empty args
- zod schema for the arguments of
list()
- should parse []
- should parse [string]
- should fail when parsing a non-status [string]
- zod schema for the arguments of
-
readTasks()
reads the JSON data file- should write an empty data to the data file if the data file does not exist
- should read a task list from the data file
-
writeTasks()
writes a data to the JSON data file- should create a data file if the data file does not exist
- should write a task list to the data file
- should write an empty task list to the data file
-
emptyData()
empties the data file- should create the data file it if not exists
- should empty the data file
-
run()
runs related subcommand function- should run 'list' command
-
index()
invokesrun()
with arguments- should throw error if subcommand is not passed
- should throw error if a wrong subcommand is passed
- create ./bin/task-cli to run the command
-
list()
filters tasks with the given status, then pass it todisplay()
- should call console.log 2 times with 2 length task list when status is not specified
- should call console.log 1 time with filtered tasks
-
display()
displays a given task- should console.log a task