Skip to content

Add strapi-plugin-factory CLI#8

Open
ayhid wants to merge 3 commits into
pluginpal:mainfrom
ayhid:feat/cli
Open

Add strapi-plugin-factory CLI#8
ayhid wants to merge 3 commits into
pluginpal:mainfrom
ayhid:feat/cli

Conversation

@ayhid
Copy link
Copy Markdown
Contributor

@ayhid ayhid commented May 19, 2026

Summary

Adds packages/cli/ — an interactive scaffolder published as strapi-plugin-factory so users can run npx strapi-plugin-factory my-plugin instead of git clone + manual rename. Uses @clack/prompts for the UX, giget to fetch the template at scaffold time (no embedded copy, no drift), and patches the fetched tree to the user's answers.

Changes

  • New packages/cli/ package with a tsup-bundled CJS entry at dist/index.cjs
  • Interactive prompt flow: plugin name, display name, description, npm scope, author (defaults from git config), GitHub org/repo, license, git init, pnpm install
  • Transform engine: JSON-aware package.json patching for the plugin, playground, root, and dev-utils; token replacement in known source files (pluginId.ts, controller.ts, tests, READMEs); plugin directory rename
  • Removes obsolete artifacts from scaffolded output: the CLI itself, the in-repo rename.ts + rename-plugin.sh bin, and the rename-plugin script entry
  • ASCII banner with Strapi-purple accent rendered at startup
  • Flags: --yes, --dry-run, --no-cache, --force, --ref <ref>, --help, --version

Test plan

  • pnpm --filter cli build produces a 24 KB CJS bundle
  • node dist/index.cjs --yes --no-cache /tmp/test/my-plugin end-to-end: fetch → transform → git init → pnpm install (~48s, clean)
  • Verified output: plugin dir renamed, package.json identity fields patched, pluginId.ts + controller.ts updated, packages/cli/ and rename artifacts removed
  • Vitest unit + integration tests (follow-up PR)
  • Root README rewrite to reflect the npx flow (follow-up PR)

Notes

  • Default --ref is main while unpublished. Before the first npm publish, this should be pinned to a stable tag so CLI versions map deterministically to template snapshots.
  • The CLI strips packages/cli/ from the fetched output so users never see the scaffolder inside their scaffolded project.

ayhid added 3 commits May 18, 2026 13:46
Add packages/cli/ with @clack/prompts UX and giget-based template fetch.
Phase 1+2 of the CLI: skeleton, flag parsing, and live fetch from the
boilerplate repo. Transform engine and prompt flow land in follow-ups.
Add the full scaffold pipeline: clack prompt flow with git defaults,
JSON-aware package.json patching for plugin/playground/root, token
replacement in known source files, removal of obsolete CLI + rename
artifacts, optional git init and pnpm install. --yes mode enables
non-interactive runs.
Render a two-column rectangle: SPF block art on the left, title + version
+ feature highlights on the right. Bordered with rounded corners in dim
magenta, art rendered in bold magenta. Skipped when --help or --version
short-circuit so scripted invocations stay quiet.
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 089cc5f8da

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

): void {
if (!existsSync(rootPkgPath)) return;
const pkg = readJson<PluginPkg>(rootPkgPath);
pkg.name = answers.pluginName;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid duplicating the plugin package name

With the default prompt path (npmScope is empty), patchPluginPackageJson names plugins/<name>/package.json as the same unscoped answers.pluginName; this line also renames the workspace root to that exact value. The generated repo then contains two workspace projects with the same package name, so the default post-scaffold pnpm install path can fail before the user can run the new project. Keep the root package name distinct from the plugin package name, or include the npm scope when deriving it.

Useful? React with 👍 / 👎.

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.

1 participant