Skip to content

feat(create-app): add plugin template for Capture and Dashboard plugins - #644

Open
kabaros wants to merge 9 commits into
masterfrom
feat/create-app-plugin-template
Open

kabaros wants to merge 9 commits into
masterfrom
feat/create-app-plugin-template

Conversation

@kabaros

@kabaros kabaros commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Why

There's no starter for DHIS2 plugins. Developers copy a reference repo and wire up entryPoints.plugin and pluginType by hand, and the prop types they copy often don't match what Capture or the Dashboard actually passes.

Changes

New plugin template with --pluginType

pnpm create @dhis2/app my-plugin --template plugin --pluginType enrollment
--pluginType Host pluginType in d2.config
form-field Capture form field CAPTURE_FORM_FIELD
enrollment Capture enrollment dashboard widget CAPTURE_ENROLLMENT
bulk-data-entry Capture working-list bulk data entry TRACKER_BULK_DATA_ENTRY
dashboard Dashboard app item DASHBOARD
  • A shared TypeScript base (templates/template-ts-plugin), plus an overlay for each type (templates/plugin-types/<type>). Each overlay has:
    • d2.config.js with both app and plugin entry points.
    • A small starter Plugin.tsx built with @dhis2/ui.
    • src/types/plugin.ts, with the host props typed from the Capture and Dashboard app source (not from the docs, which are out of date in places).
    • An App.tsx harness that renders the plugin with mocked props and stateful callbacks, so you can develop it with pnpm start without a host.
  • --pluginType on its own implies --template plugin. Using it with another template is an error. Interactive mode asks "Which kind of plugin?", and --template plugin --yes without --pluginType exits with an error listing the valid types.
  • pluginType values follow a naming convention (table above). Capture doesn't read the value. The Dashboard only lists plugins whose type is DASHBOARD (or unset).
  • The JS conversion now deletes .ts files as well as .tsx.

All TypeScript templates now use "moduleResolution": "bundler". They're built with Vite, and node resolution ignores package exports. (dhis2/app-runtime#1448 also fixes this on the runtime side.)

Docs: docs/commands/create-app.md and the package README.

Testing

  • New tape tests in tests/plugin-templates.js cover option resolution and check that every overlay has its required files.
  • Scaffolded all four types: tsc --noEmit, lint, pnpm build and pnpm test pass, and the built manifest contains plugin_type.
  • A --js plugin scaffold builds.
  • The basic and react-router TS templates still type-check and lint with bundler.

Related PRs

Part of a set that makes DHIS2 plugins (Capture form field / enrollment / bulk data entry, Dashboard) easier to build, and brings the docs in line with what the host apps actually pass:

🤖 Generated with Claude Code

kabaros and others added 4 commits December 1, 2026 09:52
Add `--template plugin` with a `--pluginType` option (form-field,
enrollment, bulk-data-entry, dashboard). The plugin template is a shared
TypeScript base plus a per-type overlay containing d2.config.js,
Plugin.tsx, typed host props (taken from the Capture and Dashboard app
source) and an App.tsx harness that renders the plugin with mocked props.

pluginType values follow a CAPTURE_<KIND> convention for Capture plugins
and DASHBOARD for dashboard plugins. Passing --pluginType alone implies
--template plugin; an interactive prompt asks for the type otherwise.

Also delete .ts files (not only .tsx) when converting a template to JS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… prettier check

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The templates are built with Vite, and "moduleResolution": "node"
ignores package "exports", so subpath entry points such as
@dhis2/app-runtime/experimental could not be resolved by tsc.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kabaros and others added 2 commits December 2, 2026 09:31
…ATA_ENTRY

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kabaros
kabaros marked this pull request as ready for review December 3, 2026 12:09
@kabaros
kabaros requested a review from KaiVandivier December 3, 2026 13:02
kabaros and others added 3 commits December 3, 2026 14:09
There is no default plugin type any more. Interactive runs prompt for it
(with nothing preselected), and --template plugin --yes without
--pluginType exits with an error listing the valid types.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Dec 3, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
7 New issues
7 New Code Smells (required ≤ 0)
1 New Blocker Issues (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

This branch has not been deployed

No deployments
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