Skip to content

Generate templates' typed APIs with a shared template generator - #318

Merged
tnkuehne merged 2 commits into
mainfrom
feat/template-generator
Nov 23, 2026
Merged

tnkuehne merged 2 commits into
mainfrom
feat/template-generator

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Why

The Linear template has its own generator in scripts/generate.ts. It turns Linear's GraphQL schema into typed methods, field selections and approvals. Templates for other providers need the same pieces: selection types, change categories, approval questions and the approval level. Copying the generator into every template would mean copying fixes too.

What changes

  • packages/template-generator: the generator moves here and runs from the repository:
    pnpm --filter @platform/template-generator generate linear.
    Without a source file, it downloads the provider's current API description. With one, it reads that file instead.
  • Apps copied from a template: the generator also takes an app's directory (generate /path/to/your/app). It reads that app's rules and rewrites its generated and shared files, so copies can pick up provider changes too.
  • Rules stay in the template: scripts/operations.ts names the source and the service, and decides how each operation is offered.
  • Templates stay standalone copies: the generator writes src/api.ts and src/schema.ts. It also copies the shared runtime files (selection.ts, approval.ts) into the template's src, then formats them. A template has no dependency on the package.
  • Linear: scripts/generate.ts, its generate script and the graphql dev dependency are removed. The generated output only changes in its header, which now names the command.

Testing

  • pnpm check
  • Generator unit tests: offered methods, changes, hidden operations, stale and missing rules, name collisions.
  • Linear template tests.
  • Regenerating Linear from the saved schema reproduces the committed files.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable new issues were found.

Summary

Moves Linear's generator into packages/template-generator and keeps templates standalone.

  • One repository command regenerates templates and copied apps from provider rules.
  • Linear's approval question now names the service making the change.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Target["Template name or app directory"] --> Rules["Read scripts/operations.ts"]
  Rules --> Source["Read saved schema or download it"]
  Source --> Generate["Generate typed API and schema"]
  Generate --> Write["Write files into target app"]
  Runtime["Shared selection.ts and approval.ts"] --> Write
  Write --> Format["Format generated files"]
Loading

Reviews (3) · Last reviewed commit: "Regenerate apps copied from a template" · Reviewed by Greptile

@tnkuehne
tnkuehne added this pull request to stack #320 November 22, 2026 23:38
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs 6027592 Nov 23 2026, 10:06 AM

Comment thread templates/linear/template.md Resolved
The Linear template carried its own GraphQL generator. Templates for other
providers need the same rules, selection types and approvals, so the
generator moves to packages/template-generator and runs from the
repository: pnpm --filter @platform/template-generator generate linear.
Templates stay standalone copies: the generator writes their generated files
and copies the runtime files they share, the selection types and approvals,
into each template's src. The Linear template's output is unchanged apart
from the header.
The generator also takes an app's directory, so an app copied from a
template picks up its provider's API changes without copying files from the
repository. template.md describes it.
@tnkuehne
tnkuehne force-pushed the feat/template-generator branch from a6cf96f to 6027592 Compare November 23, 2026 10:05
@tnkuehne
tnkuehne merged commit 7c93765 into main Nov 23, 2026
17 checks passed
@tnkuehne
tnkuehne deleted the feat/template-generator branch November 23, 2026 10:49
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