Task Tracker CLI

Overview

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

Installation

# Install dependencies
pnpm install

# Build
pnpm run build

# Run
cd ./bin
task-cli add "task 1"
task-cli list

Command examples

# 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

TODO (along with TDD)

Testability is high, importance is high

  • 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
  • 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 [] if list is empty
    • should return [] if list 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
  • 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
  • updateStatus() updates the status of a task

    • refactor markInPprogress() and markDone() to use updateStatus()
    • should update status to "in-progress"
    • should update updatedAt to the current time
    • should not update other tasks
  • markInPprogress() marks a task as in progress

    • should update status to "in-progress"
  • markDone() marks a task as done

    • should update status to "done"
  • 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]
  • 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() invokes run() with arguments

    • should throw error if subcommand is not passed
    • should throw error if a wrong subcommand is passed

Testability is low, importance is low

  • create ./bin/task-cli to run the command
  • list() filters tasks with the given status, then pass it to display()
    • 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