Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC(typegen): Add ability to format schematype names #6559

Closed
wants to merge 3 commits into from

Conversation

largis21
Copy link
Contributor

@largis21 largis21 commented May 3, 2024

Description

Extra config property for customizing type names on schema types.

Feedback on this feature would be appriciated

Example:

//sanity-typegen.json

{
  "path": "'./**/*.{ts,tsx,js,jsx}'",
  "schema": "schema.json",
  "generates": "sanity.types.ts",
  "format": {
    "schemaTypes": {
      "literal": "i{name}Schema",
      "nameCase": "pascal"
    },
    "queries": {
      "literal": "i{name}query",
      "nameCase": "pascal"
    }
  }
}
// schema.ts

defineType({
  name: "documentName",
  type: "document"
})
// Old result

export type DocumentName = {...}
// New result

export type iDocumentNameSchema = {...}

What to review

The way the formatting is done, I don't know if it is the best way to do it.
@sanity/cli @sanity/codegen is affected

Testing

No, this is only a proof of concept

Notes for release

@largis21 largis21 requested a review from a team as a code owner May 3, 2024 09:42
Copy link

vercel bot commented May 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
performance-studio ✅ Ready (Inspect) Visit Preview May 3, 2024 1:52pm
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 3, 2024 1:52pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview May 3, 2024 1:52pm

Copy link

vercel bot commented May 3, 2024

@largis21 is attempting to deploy a commit to the Sanity Team on Vercel.

A member of the Team first needs to authorize it.

@largis21
Copy link
Contributor Author

largis21 commented May 3, 2024

Planning on adding support for queries as well, havent gotten that far yet. There is also a bug where the capitalization is wrong because of the order of the format functions.

@sgulseth
Copy link
Member

sgulseth commented May 7, 2024

Hi! Thanks for the PR, we've been going a bit back and forth with the naming, and our long/short term plan is to move the configuration into sanity.cli.ts to reduce configuration fatigue.
This would allow us to add additional overrides methods for generating the type name in {java,type}script.
To reduce the overhead needed to then migrate we're gonna wait with this change.

@sgulseth sgulseth closed this May 7, 2024
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.

None yet

2 participants