P
IntermediateAll AIs

Build a complete Node.js CLI tool

Generate 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.

Why this prompt works

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

Use Cases

Create an internal tool to automate the team's workflowPublish an open-source npm CLI packageReplace 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.

Learn more

Check the full skill on Prompt Guide to master this technique from A to Z.

View on Prompt Guide