Lab 15: Capstone CLI Tool

Objective

Build a complete, production-quality TypeScript CLI tool: argument parsing, file processing, HTTP API client, typed configuration, error handling, and a test suite — tying together all concepts from Labs 01–14.

Background

This capstone builds a prodctl CLI tool — a product catalog manager that reads/writes JSON files and calls a REST API. You'll apply: interfaces (Lab 3), classes (Lab 4), generics (Lab 6), modules (Lab 7), error handling (Lab 8), async patterns (Lab 9), type manipulation (Lab 10), Node.js (Lab 12), and testing (Lab 13).

Time

60 minutes

Prerequisites

  • Labs 01–14

Tools

  • Docker image: zchencow/innozverse-ts:latest


Lab Instructions

Step 1: Project Types & Interfaces

💡 Omit<Product, 'id' | 'createdAt' | 'updatedAt'> creates the create/update DTOs automatically from the main interface. When you add a field to Product, you don't need to update the DTO types manually — they stay in sync. This is the DRY principle applied at the type level.

📸 Verified Output:


Step 2: Data Store

📸 Verified Output:


Step 3: CLI Parser

📸 Verified Output:


Step 4: Output Formatters

📸 Verified Output:


Step 5: Command Implementations

📸 Verified Output:


Step 6: Error Handling & Validation

📸 Verified Output:


Step 7: Test Suite

📸 Verified Output:


Step 8: Complete CLI — Main Entry Point

💡 Record<string, (args: ParsedArgs, store: Store) => Promise<void>> is the command registry type — a dictionary of async command handlers. Looking up a command with COMMANDS[parsed.command] is O(1) and type-safe. Adding a new command requires only one entry — no if/switch statements.

📸 Verified Output:


Verification

Summary

You've built a complete, production-quality TypeScript CLI tool using every concept from Labs 01–14:

Lab
Applied

01–02

Types, functions, type inference

03–04

Interfaces, classes, generics

05–06

Literal unions, generic Store

07–08

Module patterns, Result type

09–10

Async commands, type utilities

11–12

File I/O, process/path types

13–14

Test suite, Builder/Command patterns

Architecture: CLI Parser → Command Registry → Validation → JsonStore → Output Formatter

This mirrors real TypeScript CLIs like ts-node, prisma, nx, and angular-cli.

Further Reading

Last updated