Skip to content

Commit

Permalink
feat(typegen): add optout for prettier formatting (#6702)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgulseth committed May 21, 2024
1 parent 74f2fd5 commit ac5103a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/@sanity/cli/src/actions/typegen/generateAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ export default async function typegenGenerateAction(
const outputDir = dirname(outputPath)
await mkdir(outputDir, {recursive: true})

const prettierConfig = await prettier.resolveConfig(outputPath).catch((err) => {
output.warn(`Failed to load prettier config: ${err.message}`)
return null
})
const prettierConfig = codegenConfig.formatGeneratedCode
? await prettier.resolveConfig(outputPath).catch((err) => {
output.warn(`Failed to load prettier config: ${err.message}`)
return null
})
: null
const workerPath = await getCliWorkerPath('typegenGenerate')

const spinner = output.spinner({}).start('Generating types')
Expand Down
1 change: 1 addition & 0 deletions packages/@sanity/codegen/src/readConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const configDefintion = z.object({
]),
schema: z.string().default('./schema.json'),
generates: z.string().default('./sanity.types.ts'),
formatGeneratedCode: z.boolean().default(true),
})

export type CodegenConfig = z.infer<typeof configDefintion>
Expand Down

0 comments on commit ac5103a

Please sign in to comment.