fastify / fastify-cli

Run a Fastify application with one command!
MIT License
640 stars 159 forks source link

Make the tool more interactive #740

Open jean-michelet opened 4 days ago

jean-michelet commented 4 days ago

Prerequisites

🚀 Feature Proposal

After #737, I think we should make fastify-cli more interactive.

1) When running generate, we should perhaps ask users a few questions in a relevant order.

2. We could also create a command to create plugins for an existing project.

If the plugin is customized :

3. We could also enable core and community plugins to be installed with fastify-cli.

After installation, we could check whether a plugin has a specific configuration file following the convention of our choice, and use it to automatically generate the plugin file with some default configuration and comments in the project.

Motivation

The idea here is to make a more relevant and educative tool. I realize it would be a lot of work, but it could also improve the developer experience, I think, and that's something I'd love to do.

Example

1. generate command

When a user runs fastify generate, the CLI might interact with them to configure the project specifics:

$ fastify generate
Welcome to Fastify project generator!

? Use TypeScript? (Y/n) Y
? Module system (Use arrow keys)
> ESM
  CJS
? Set up an environment configuration? (Y/n) Y
? Set up a database with migration system? (Y/n) n
? Include Swagger for API documentation? (Y/n) Y
? Include authentication? (Y/n) Y
? What kind of authentication:
  > OAuth
    JWT
    Basic

Generating project with TypeScript, ESM, Swagger, and OAuth authentication...
Project generated successfully!

2. New command to add plugins to a project

When creating a new plugin within an existing project, the CLI can guide through setting it up:

$ fastify add-plugin
? Name of the plugin: awesome-logger
? Does this plugin have any dependencies? (Y/n) Y
? List dependencies (comma separated): pino

Creating plugin 'awesome-logger' with dependencies: pino
Plugin created successfully!

3. Installation of core and community plugins

The process to install plugins can also be streamlined with smart configuration:

$ fastify @fastify/cors
? Search and install plugin: '@fastify/cors'
Searching '@fastify/cors'...
? '@fastify/cors' requires specific configuration. Generate default config? (Y/n) Y
Installing '@fastify/cors'...

Plugin installed and configured successfully!
climba03003 commented 3 days ago

which is #491 and I give up.