sanity-io / sanity

Sanity Studio – Rapidly configure content workspaces powered by structured content
https://www.sanity.io
MIT License
5.27k stars 426 forks source link

CLI Configuration for Typegen #7621

Open okj579 opened 3 weeks ago

okj579 commented 3 weeks ago

Is your feature request related to a problem? Please describe. Using Typegen across separate repositories (e.g. on for studio, one for the frontend) is difficult, as you can't mix local settings and those that are committed to the repository. The only configuration possibility at the moment is sanity-typegen.json.

Describe the solution you'd like Configuration via CLI options and/or environment variables

Describe alternatives you've considered I'm using an external script at the moment to gather the relevant options from constant, project and local settings, then resolve paths to be relative to the Sanity Studio root, write a temporary sanity-typegen.json, run typegen and clean up again afterwards. This is much more cumbersome than it has to be, though.

sgulseth commented 1 week ago

👋 We have had internal discussions around moving sanity-typegen.json config into the sanity.config.ts, as a separate object. The config would look something similar to:

import {defineConfig} from 'sanity'

export default defineConfig({
  ... // the rest of your config
  schemaExtract: {
     ...
  },
  typegen: {
    generates: 'sanity.types.ts` // or process.env.TYPEGEN_OUTPUT || 'sanity.types.ts`
  },
})

Since this all being executed then during runtime it should work by reading options from the environment.

Would this solve your use case?

okj579 commented 3 days ago

Yes, I think with that I could set all relevant settings on the command line without temporary files and the like.