Skip to content

Conversation

@boazpoolman
Copy link
Collaborator

@boazpoolman boazpoolman commented Oct 10, 2025

Warning

This PR is still in draft. Changes to the @strapi/generators package are needed for this to work correctly. This PR on the strapi/strapi repo addresses these changes

What does it do?

It adds a new command to the CLI to generate boilerplate code for your plugin.

npx @strapi/sdk-plugin generate

This command will start an interactive CLI where the user can give some input that is used to generate the code. The DX is almost exactly the same as the native strapi generate CLI. The only thing different is the fact that you don't have to select the destination.

Scherm­afbeelding 2025-10-10 om 13 16 10

This PR basically implements an extension of the @strapi/generators package. Both the file generation and most of the prompts are import from that package and re-used by calling the generate API.

Why is it needed?

The native strapi generate CLI allows for generating boilerplate code for plugins, but that only works for local plugins in the src/plugins directory. For standalone plugins there is no way to generate boilerplate code.

How to test it?

  1. Pull this branch
  2. Install dependencies: pnpm install
  3. Build and push the package: pnpm run build && npx yalc push --publish
  4. Navigate to a standalone plugin, or generate a new one with npx @strapi/sdk-plugin init
  5. Install the new package in your plugin npx yalc add @strapi/sdk-plugin
  6. Run the following command node_modules/.bin/strapi-plugin generate
  7. You can now use the interactive CLI and test the different options.

@changeset-bot
Copy link

changeset-bot bot commented Oct 10, 2025

🦋 Changeset detected

Latest commit: 608d305

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@strapi/sdk-plugin Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@maccomaccomaccomacco
Copy link

Looks all good to me, @boazpoolman :)
Thank you

{
kind: nameInfo.kind,
singularName: nameInfo.singularName,
id: nameInfo.displayName,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
id: nameInfo.displayName,
id: nameInfo.singularName,

const attributes = await getAttributesPrompts(inquirer);
const bootstrapInfo = await inquirer.prompt([...bootstrapApiPrompts] as any);

generate(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to await these

.description('Generate some boilerplate code for a Strapi plugin')
.option('-d, --debug', 'Enable debugging mode with verbose logs', false)
.option('--silent', "Don't log anything", false)
.action(async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily required, but could you make use of runAction here like the other commands, to help follow the error handling and awaiting that other commands use?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants