P
IntermediateAll AIs

Build a Complete Node.js CLI Tool

Generates the complete structure of a professional Node.js CLI with Commander.js, polished UX (colors, spinners), configuration, error handling, tests and npm publishing.

Paste in your AI

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

Tu es un expert Node.js et développement d'outils CLI. Aide-moi à créer un outil en ligne de commande complet.

Objectif du CLI : [OBJECTIF_CLI]
Commandes souhaitées : [COMMANDES] (ex: init, build, deploy, status)
Runtime cible : [RUNTIME] (Node.js 20+, Bun)
Publication : [PUBLICATION] (npm public, usage interne)

Génère :

  1. Structure du projet : arborescence recommandée
  2. package.json : configuration bin, scripts, dépendances (Commander.js ou alternative)
  3. Implémentation des commandes : code pour chaque commande avec options et arguments
  4. UX du CLI :
    • Messages d'aide clairs
    • Couleurs avec chalk (succès/erreur/info)
    • Spinners pour les opérations longues
    • Mode verbose/quiet
  5. Configuration : fichier de config utilisateur (cosmiconfig pattern)
  6. Gestion des erreurs : codes de sortie, messages explicites
  7. Tests : stratégie de test pour CLI (vitest, child_process)
  8. Publication npm : .npmignore, README, workflow de release

Fournis le code complet pour au moins 2 commandes.

Personalize this prompt with Léa

Answer 3 questions and Léa tailors the prompt to your situation.

Why this prompt works

The cosmiconfig pattern for configuration is an npm ecosystem standard often ignored by less experienced developers. Requesting explicit UX (colors, spinners, verbose modes) produces usable CLIs, not just functional ones. Exit codes are critical for integration into scripts and pipelines.

Use Cases

Creating an internal tool to automate team workflowPublishing an open-source npm CLI packageReplacing shell scripts with a maintainable CLI

Expected Output

Project structure, configured package.json, command code with UX (colors/spinners), error handling, cosmiconfig configuration, tests and npm publishing guide.

Improve this prompt

Run this prompt through the Optimizer to strengthen its context, constraints and expected format.

Improve this prompt with the Optimizer

Comments

  • LéaAI

    **Astuce clé** : remplacez `process.exit(n)` par `process.exitCode = n` dans vos commandes. Associez à un wrapper async global qui capture les erreurs et définit `exitCode` avant de rejeter. Cela évite les sorties brutales, facilite les tests (pas de crash inattendu) et permet aux hooks (afterAll, etc.) de s'exécuter.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further