@sanity/cli 3.42.2-sdx-1339.35 → 3.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,7 +39,7 @@ async function typegenGenerateAction(args, context) {
39
39
  }
40
40
  const outputPath = path.join(process.cwd(), codegenConfig.generates), outputDir = path.dirname(outputPath);
41
41
  await fs.mkdir(outputDir, { recursive: !0 });
42
- const prettierConfig = await prettier__default.default.resolveConfig(outputPath).catch((err) => (output.warn(`Failed to load prettier config: ${err.message}`), null)), workerPath = await cliWorker.getCliWorkerPath("typegenGenerate"), spinner = output.spinner({}).start("Generating types"), worker = new node_worker_threads.Worker(workerPath, {
42
+ const prettierConfig = codegenConfig.formatGeneratedCode ? await prettier__default.default.resolveConfig(outputPath).catch((err) => (output.warn(`Failed to load prettier config: ${err.message}`), null)) : null, workerPath = await cliWorker.getCliWorkerPath("typegenGenerate"), spinner = output.spinner({}).start("Generating types"), worker = new node_worker_threads.Worker(workerPath, {
43
43
  workerData: {
44
44
  workDir,
45
45
  schemaPath: codegenConfig.schema,
@@ -1 +1 @@
1
- {"version":3,"file":"generateAction.js","sources":["../../src/actions/typegen/generate.telemetry.ts","../../src/actions/typegen/generateAction.ts"],"sourcesContent":["import {defineTrace} from '@sanity/telemetry'\n\ninterface TypesGeneratedTraceAttrubutes {\n outputSize: number\n queriesCount: number\n schemaTypesCount: number\n queryFilesCount: number\n filesWithErrors: number\n typeNodesGenerated: number\n unknownTypeNodesGenerated: number\n unknownTypeNodesRatio: number\n emptyUnionTypeNodesGenerated: number\n}\n\nexport const TypesGeneratedTrace = defineTrace<TypesGeneratedTraceAttrubutes>({\n name: 'Types Generated',\n version: 0,\n description: 'Trace emitted when generating TypeScript types for queries',\n})\n","import {constants, mkdir, open, stat} from 'node:fs/promises'\nimport {dirname, join} from 'node:path'\nimport {Worker} from 'node:worker_threads'\n\nimport {readConfig} from '@sanity/codegen'\nimport prettier from 'prettier'\n\nimport {type CliCommandArguments, type CliCommandContext} from '../../types'\nimport {getCliWorkerPath} from '../../util/cliWorker'\nimport {\n type TypegenGenerateTypesWorkerData,\n type TypegenGenerateTypesWorkerMessage,\n} from '../../workers/typegenGenerate'\nimport {TypesGeneratedTrace} from './generate.telemetry'\n\nexport interface TypegenGenerateTypesCommandFlags {\n 'config-path'?: string\n}\n\nconst generatedFileWarning = `/**\n * ---------------------------------------------------------------------------------\n * This file has been generated by Sanity TypeGen.\n * Command: \\`sanity typegen generate\\`\n *\n * Any modifications made directly to this file will be overwritten the next time\n * the TypeScript definitions are generated. Please make changes to the Sanity\n * schema definitions and/or GROQ queries if you need to update these types.\n *\n * For more information on how to use Sanity TypeGen, visit the official documentation:\n * https://www.sanity.io/docs/sanity-typegen\n * ---------------------------------------------------------------------------------\n */\\n\\n`\n\nexport default async function typegenGenerateAction(\n args: CliCommandArguments<TypegenGenerateTypesCommandFlags>,\n context: CliCommandContext,\n): Promise<void> {\n const flags = args.extOptions\n const {output, workDir, telemetry} = context\n\n const trace = telemetry.trace(TypesGeneratedTrace)\n trace.start()\n\n const codegenConfig = await readConfig(flags['config-path'] || 'sanity-typegen.json')\n\n try {\n const schemaStats = await stat(codegenConfig.schema)\n if (!schemaStats.isFile()) {\n throw new Error(`Schema path is not a file: ${codegenConfig.schema}`)\n }\n } catch (err) {\n if (err.code === 'ENOENT') {\n // If the user has not provided a specific schema path (eg we're using the default), give some help\n const hint =\n codegenConfig.schema === './schema.json' ? ` - did you run \"sanity schema extract\"?` : ''\n throw new Error(`Schema file not found: ${codegenConfig.schema}${hint}`)\n }\n throw err\n }\n\n const outputPath = join(process.cwd(), codegenConfig.generates)\n const outputDir = dirname(outputPath)\n await mkdir(outputDir, {recursive: true})\n\n const prettierConfig = await prettier.resolveConfig(outputPath).catch((err) => {\n output.warn(`Failed to load prettier config: ${err.message}`)\n return null\n })\n const workerPath = await getCliWorkerPath('typegenGenerate')\n\n const spinner = output.spinner({}).start('Generating types')\n\n const worker = new Worker(workerPath, {\n workerData: {\n workDir,\n schemaPath: codegenConfig.schema,\n searchPath: codegenConfig.path,\n prettierConfig,\n } satisfies TypegenGenerateTypesWorkerData,\n // eslint-disable-next-line no-process-env\n env: process.env,\n })\n\n const typeFile = await open(\n outputPath,\n // eslint-disable-next-line no-bitwise\n constants.O_TRUNC | constants.O_CREAT | constants.O_WRONLY,\n )\n\n typeFile.write(generatedFileWarning)\n\n const stats = {\n queryFilesCount: 0,\n errors: 0,\n queriesCount: 0,\n schemaTypesCount: 0,\n unknownTypeNodesGenerated: 0,\n typeNodesGenerated: 0,\n emptyUnionTypeNodesGenerated: 0,\n size: 0,\n }\n\n await new Promise<void>((resolve, reject) => {\n worker.addListener('message', (msg: TypegenGenerateTypesWorkerMessage) => {\n if (msg.type === 'error') {\n if (msg.fatal) {\n trace.error(msg.error)\n reject(msg.error)\n return\n }\n const errorMessage = msg.filename\n ? `${msg.error.message} in \"${msg.filename}\"`\n : msg.error.message\n spinner.fail(errorMessage)\n stats.errors++\n return\n }\n if (msg.type === 'complete') {\n resolve()\n return\n }\n\n let fileTypeString = `// Source: ${msg.filename}\\n`\n\n if (msg.type === 'schema') {\n stats.schemaTypesCount += msg.length\n fileTypeString += msg.schema\n typeFile.write(fileTypeString)\n return\n }\n\n stats.queryFilesCount++\n for (const {\n queryName,\n query,\n type,\n typeNodesGenerated,\n unknownTypeNodesGenerated,\n emptyUnionTypeNodesGenerated,\n } of msg.types) {\n fileTypeString += `// Variable: ${queryName}\\n`\n fileTypeString += `// Query: ${query.replace(/(\\r\\n|\\n|\\r)/gm, '')}\\n`\n fileTypeString += type\n stats.queriesCount++\n stats.typeNodesGenerated += typeNodesGenerated\n stats.unknownTypeNodesGenerated += unknownTypeNodesGenerated\n stats.emptyUnionTypeNodesGenerated += emptyUnionTypeNodesGenerated\n }\n typeFile.write(fileTypeString)\n stats.size += Buffer.byteLength(fileTypeString)\n })\n worker.addListener('error', reject)\n })\n\n typeFile.close()\n\n trace.log({\n outputSize: stats.size,\n queriesCount: stats.queriesCount,\n schemaTypesCount: stats.schemaTypesCount,\n queryFilesCount: stats.queryFilesCount,\n filesWithErrors: stats.errors,\n typeNodesGenerated: stats.typeNodesGenerated,\n unknownTypeNodesGenerated: stats.unknownTypeNodesGenerated,\n unknownTypeNodesRatio:\n stats.typeNodesGenerated > 0 ? stats.unknownTypeNodesGenerated / stats.typeNodesGenerated : 0,\n emptyUnionTypeNodesGenerated: stats.emptyUnionTypeNodesGenerated,\n })\n\n trace.complete()\n if (stats.errors > 0) {\n spinner.warn(`Encountered errors in ${stats.errors} files while generating types`)\n }\n\n spinner.succeed(\n `Generated TypeScript types for ${stats.schemaTypesCount} schema types and ${stats.queriesCount} GROQ queries in ${stats.queryFilesCount} files into: ${codegenConfig.generates}`,\n )\n}\n"],"names":["defineTrace","telemetry","readConfig","stat","join","dirname","mkdir","prettier","getCliWorkerPath","Worker","open","constants"],"mappings":";;;;;;AAcO,MAAM,sBAAsBA,UAAAA,YAA2C;AAAA,EAC5E,MAAM;AAAA,EACN,SAAS;AAAA,EACT,aAAa;AACf,CAAC,GCCK,uBAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAcC,eAAA,sBAC5B,MACA,SACe;AACf,QAAM,QAAQ,KAAK,YACb,EAAC,QAAQ,SAAS,WAAAC,WAAS,IAAI,SAE/B,QAAQA,WAAU,MAAM,mBAAmB;AACjD,QAAM,MAAM;AAEZ,QAAM,gBAAgB,MAAMC,QAAA,WAAW,MAAM,aAAa,KAAK,qBAAqB;AAEhF,MAAA;AAEF,QAAI,EADgB,MAAMC,GAAA,KAAK,cAAc,MAAM,GAClC,OAAO;AACtB,YAAM,IAAI,MAAM,8BAA8B,cAAc,MAAM,EAAE;AAAA,WAE/D,KAAK;AACR,QAAA,IAAI,SAAS,UAAU;AAEzB,YAAM,OACJ,cAAc,WAAW,kBAAkB,4CAA4C;AACzF,YAAM,IAAI,MAAM,0BAA0B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AAA,EAAA;AAEnL;;"}
1
+ {"version":3,"file":"generateAction.js","sources":["../../src/actions/typegen/generate.telemetry.ts","../../src/actions/typegen/generateAction.ts"],"sourcesContent":["import {defineTrace} from '@sanity/telemetry'\n\ninterface TypesGeneratedTraceAttrubutes {\n outputSize: number\n queriesCount: number\n schemaTypesCount: number\n queryFilesCount: number\n filesWithErrors: number\n typeNodesGenerated: number\n unknownTypeNodesGenerated: number\n unknownTypeNodesRatio: number\n emptyUnionTypeNodesGenerated: number\n}\n\nexport const TypesGeneratedTrace = defineTrace<TypesGeneratedTraceAttrubutes>({\n name: 'Types Generated',\n version: 0,\n description: 'Trace emitted when generating TypeScript types for queries',\n})\n","import {constants, mkdir, open, stat} from 'node:fs/promises'\nimport {dirname, join} from 'node:path'\nimport {Worker} from 'node:worker_threads'\n\nimport {readConfig} from '@sanity/codegen'\nimport prettier from 'prettier'\n\nimport {type CliCommandArguments, type CliCommandContext} from '../../types'\nimport {getCliWorkerPath} from '../../util/cliWorker'\nimport {\n type TypegenGenerateTypesWorkerData,\n type TypegenGenerateTypesWorkerMessage,\n} from '../../workers/typegenGenerate'\nimport {TypesGeneratedTrace} from './generate.telemetry'\n\nexport interface TypegenGenerateTypesCommandFlags {\n 'config-path'?: string\n}\n\nconst generatedFileWarning = `/**\n * ---------------------------------------------------------------------------------\n * This file has been generated by Sanity TypeGen.\n * Command: \\`sanity typegen generate\\`\n *\n * Any modifications made directly to this file will be overwritten the next time\n * the TypeScript definitions are generated. Please make changes to the Sanity\n * schema definitions and/or GROQ queries if you need to update these types.\n *\n * For more information on how to use Sanity TypeGen, visit the official documentation:\n * https://www.sanity.io/docs/sanity-typegen\n * ---------------------------------------------------------------------------------\n */\\n\\n`\n\nexport default async function typegenGenerateAction(\n args: CliCommandArguments<TypegenGenerateTypesCommandFlags>,\n context: CliCommandContext,\n): Promise<void> {\n const flags = args.extOptions\n const {output, workDir, telemetry} = context\n\n const trace = telemetry.trace(TypesGeneratedTrace)\n trace.start()\n\n const codegenConfig = await readConfig(flags['config-path'] || 'sanity-typegen.json')\n\n try {\n const schemaStats = await stat(codegenConfig.schema)\n if (!schemaStats.isFile()) {\n throw new Error(`Schema path is not a file: ${codegenConfig.schema}`)\n }\n } catch (err) {\n if (err.code === 'ENOENT') {\n // If the user has not provided a specific schema path (eg we're using the default), give some help\n const hint =\n codegenConfig.schema === './schema.json' ? ` - did you run \"sanity schema extract\"?` : ''\n throw new Error(`Schema file not found: ${codegenConfig.schema}${hint}`)\n }\n throw err\n }\n\n const outputPath = join(process.cwd(), codegenConfig.generates)\n const outputDir = dirname(outputPath)\n await mkdir(outputDir, {recursive: true})\n\n const prettierConfig = codegenConfig.formatGeneratedCode\n ? await prettier.resolveConfig(outputPath).catch((err) => {\n output.warn(`Failed to load prettier config: ${err.message}`)\n return null\n })\n : null\n const workerPath = await getCliWorkerPath('typegenGenerate')\n\n const spinner = output.spinner({}).start('Generating types')\n\n const worker = new Worker(workerPath, {\n workerData: {\n workDir,\n schemaPath: codegenConfig.schema,\n searchPath: codegenConfig.path,\n prettierConfig,\n } satisfies TypegenGenerateTypesWorkerData,\n // eslint-disable-next-line no-process-env\n env: process.env,\n })\n\n const typeFile = await open(\n outputPath,\n // eslint-disable-next-line no-bitwise\n constants.O_TRUNC | constants.O_CREAT | constants.O_WRONLY,\n )\n\n typeFile.write(generatedFileWarning)\n\n const stats = {\n queryFilesCount: 0,\n errors: 0,\n queriesCount: 0,\n schemaTypesCount: 0,\n unknownTypeNodesGenerated: 0,\n typeNodesGenerated: 0,\n emptyUnionTypeNodesGenerated: 0,\n size: 0,\n }\n\n await new Promise<void>((resolve, reject) => {\n worker.addListener('message', (msg: TypegenGenerateTypesWorkerMessage) => {\n if (msg.type === 'error') {\n if (msg.fatal) {\n trace.error(msg.error)\n reject(msg.error)\n return\n }\n const errorMessage = msg.filename\n ? `${msg.error.message} in \"${msg.filename}\"`\n : msg.error.message\n spinner.fail(errorMessage)\n stats.errors++\n return\n }\n if (msg.type === 'complete') {\n resolve()\n return\n }\n\n let fileTypeString = `// Source: ${msg.filename}\\n`\n\n if (msg.type === 'schema') {\n stats.schemaTypesCount += msg.length\n fileTypeString += msg.schema\n typeFile.write(fileTypeString)\n return\n }\n\n stats.queryFilesCount++\n for (const {\n queryName,\n query,\n type,\n typeNodesGenerated,\n unknownTypeNodesGenerated,\n emptyUnionTypeNodesGenerated,\n } of msg.types) {\n fileTypeString += `// Variable: ${queryName}\\n`\n fileTypeString += `// Query: ${query.replace(/(\\r\\n|\\n|\\r)/gm, '')}\\n`\n fileTypeString += type\n stats.queriesCount++\n stats.typeNodesGenerated += typeNodesGenerated\n stats.unknownTypeNodesGenerated += unknownTypeNodesGenerated\n stats.emptyUnionTypeNodesGenerated += emptyUnionTypeNodesGenerated\n }\n typeFile.write(fileTypeString)\n stats.size += Buffer.byteLength(fileTypeString)\n })\n worker.addListener('error', reject)\n })\n\n typeFile.close()\n\n trace.log({\n outputSize: stats.size,\n queriesCount: stats.queriesCount,\n schemaTypesCount: stats.schemaTypesCount,\n queryFilesCount: stats.queryFilesCount,\n filesWithErrors: stats.errors,\n typeNodesGenerated: stats.typeNodesGenerated,\n unknownTypeNodesGenerated: stats.unknownTypeNodesGenerated,\n unknownTypeNodesRatio:\n stats.typeNodesGenerated > 0 ? stats.unknownTypeNodesGenerated / stats.typeNodesGenerated : 0,\n emptyUnionTypeNodesGenerated: stats.emptyUnionTypeNodesGenerated,\n })\n\n trace.complete()\n if (stats.errors > 0) {\n spinner.warn(`Encountered errors in ${stats.errors} files while generating types`)\n }\n\n spinner.succeed(\n `Generated TypeScript types for ${stats.schemaTypesCount} schema types and ${stats.queriesCount} GROQ queries in ${stats.queryFilesCount} files into: ${codegenConfig.generates}`,\n )\n}\n"],"names":["defineTrace","telemetry","readConfig","stat","join","dirname","mkdir","prettier","getCliWorkerPath","Worker","open","constants"],"mappings":";;;;;;AAcO,MAAM,sBAAsBA,UAAAA,YAA2C;AAAA,EAC5E,MAAM;AAAA,EACN,SAAS;AAAA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,MAAM,QAAQ,OAAO,WAAW,cAAc;AAAA,IAC/C,CAAA,GACD,OAAO,YAAY,SAAS,MAAM;AAAA,EACnC,CAAA,GAED,SAAS,SAET,MAAM,IAAI;AAAA,IACR,YAAY,MAAM;AAAA,IAClB,cAAc,MAAM;AAAA,IACpB,kBAAkB,MAAM;AAAA,IACxB,iBAAiB,MAAM;AAAA,IACvB,iBAAiB,MAAM;AAAA,IACvB,oBAAoB,MAAM;AAAA,IAC1B,2BAA2B,MAAM;AAAA,IACjC,uBACE,MAAM,qBAAqB,IAAI,MAAM,4BAA4B,MAAM,qBAAqB;AAAA,IAC9F,8BAA8B,MAAM;AAAA,EAAA,CACrC,GAED,MAAM,SAAA,GACF,MAAM,SAAS,KACjB,QAAQ,KAAK,yBAAyB,MAAM,MAAM,+BAA+B,GAGnF,QAAQ;AAAA,IACN,kCAAkC,MAAM,gBAAgB,qBAAqB,MAAM,YAAY,oBAAoB,MAAM,eAAe,gBAAgB,cAAc,SAAS;AAAA,EAAA;AAEnL;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/cli",
3
- "version": "3.42.2-sdx-1339.35+b5d66f5409",
3
+ "version": "3.43.0",
4
4
  "description": "Sanity CLI tool for managing Sanity installations, managing plugins, schemas and datasets",
5
5
  "keywords": [
6
6
  "sanity",
@@ -58,9 +58,9 @@
58
58
  "dependencies": {
59
59
  "@babel/traverse": "^7.23.5",
60
60
  "@sanity/client": "^6.18.2",
61
- "@sanity/codegen": "3.42.2-sdx-1339.35+b5d66f5409",
61
+ "@sanity/codegen": "3.43.0",
62
62
  "@sanity/telemetry": "^0.7.6",
63
- "@sanity/util": "3.42.2-sdx-1339.35+b5d66f5409",
63
+ "@sanity/util": "3.43.0",
64
64
  "chalk": "^4.1.2",
65
65
  "debug": "^4.3.4",
66
66
  "decompress": "^4.2.0",
@@ -77,12 +77,12 @@
77
77
  },
78
78
  "devDependencies": {
79
79
  "@jest/globals": "^29.7.0",
80
- "@repo/package.config": "3.42.1",
80
+ "@repo/package.config": "3.43.0",
81
81
  "@rexxars/gitconfiglocal": "^3.0.1",
82
82
  "@rollup/plugin-node-resolve": "^15.2.3",
83
83
  "@sanity/eslint-config-studio": "^4.0.0",
84
84
  "@sanity/generate-help-url": "^3.0.0",
85
- "@sanity/types": "3.42.2-sdx-1339.35+b5d66f5409",
85
+ "@sanity/types": "3.43.0",
86
86
  "@types/babel__traverse": "^7.20.5",
87
87
  "@types/configstore": "^5.0.1",
88
88
  "@types/cpx": "^1.5.2",
@@ -135,5 +135,5 @@
135
135
  "engines": {
136
136
  "node": ">=18"
137
137
  },
138
- "gitHead": "b5d66f54090988707b1bc08be39fb13b0d094168"
138
+ "gitHead": "2b66ff20c9c529b58f6bed31813ae5752f325ed9"
139
139
  }
@@ -48,7 +48,6 @@ import {tryGitInit} from './git'
48
48
  import {promptForDatasetName} from './promptForDatasetName'
49
49
  import {promptForAclMode, promptForDefaultConfig, promptForTypeScript} from './prompts'
50
50
  import {
51
- promptForAppDir,
52
51
  promptForAppendEnv,
53
52
  promptForEmbeddedStudio,
54
53
  promptForNextTemplate,
@@ -60,8 +59,7 @@ import {
60
59
  sanityCliTemplate,
61
60
  sanityConfigTemplate,
62
61
  sanityFolder,
63
- sanityStudioAppTemplate,
64
- sanityStudioPagesTemplate,
62
+ sanityStudioTemplate,
65
63
  } from './templates/nextjs'
66
64
 
67
65
  // eslint-disable-next-line no-process-env
@@ -330,12 +328,8 @@ export default async function initSanity(
330
328
  const embeddedStudio = unattended ? true : await promptForEmbeddedStudio(prompt)
331
329
 
332
330
  if (embeddedStudio) {
333
- // this one is trickier on unattended, as we should probably scan for which one
334
- // they're using, but they can also use both
335
- const useAppDir = unattended ? false : await promptForAppDir(prompt)
336
-
337
- // find source path (app or pages dir)
338
- const srcDir = useAppDir ? 'app' : 'pages'
331
+ // find source path (app or src/app)
332
+ const srcDir = 'app'
339
333
  let srcPath = path.join(workDir, srcDir)
340
334
 
341
335
  if (!existsSync(srcPath)) {
@@ -352,7 +346,7 @@ export default async function initSanity(
352
346
  const embeddedStudioRouteFilePath = path.join(
353
347
  srcPath,
354
348
  `${studioPath}/`,
355
- useAppDir ? `[[...index]]/page.${fileExtension}x` : `[[...index]].${fileExtension}x`,
349
+ `[[...tool]]/page.${fileExtension}x`,
356
350
  )
357
351
 
358
352
  // this selects the correct template string based on whether the user is using the app or pages directory and
@@ -361,7 +355,7 @@ export default async function initSanity(
361
355
  // relative paths to reach the root level of the project
362
356
  await writeOrOverwrite(
363
357
  embeddedStudioRouteFilePath,
364
- (useAppDir ? sanityStudioAppTemplate : sanityStudioPagesTemplate).replace(
358
+ sanityStudioTemplate.replace(
365
359
  ':configPath:',
366
360
  new Array(countNestedFolders(embeddedStudioRouteFilePath.slice(workDir.length)))
367
361
  .join('../')
@@ -451,11 +445,11 @@ export default async function initSanity(
451
445
  }
452
446
 
453
447
  if (chosen === 'npm') {
454
- await execa('npm', ['install', 'next-sanity@7'], execOptions)
448
+ await execa('npm', ['install', 'next-sanity@9'], execOptions)
455
449
  } else if (chosen === 'yarn') {
456
- await execa('npx', ['install-peerdeps', '--yarn', 'next-sanity@7'], execOptions)
450
+ await execa('npx', ['install-peerdeps', '--yarn', 'next-sanity@9'], execOptions)
457
451
  } else if (chosen === 'pnpm') {
458
- await execa('pnpm', ['install', 'next-sanity@7'], execOptions)
452
+ await execa('pnpm', ['install', 'next-sanity@9'], execOptions)
459
453
  }
460
454
 
461
455
  print(
@@ -8,14 +8,6 @@ export function promptForEmbeddedStudio(prompt: CliPrompter): Promise<string> {
8
8
  })
9
9
  }
10
10
 
11
- export function promptForAppDir(prompt: CliPrompter): Promise<string> {
12
- return prompt.single({
13
- type: 'confirm',
14
- message: `Would you like to use the Next.js app directory for routes?`,
15
- default: false,
16
- })
17
- }
18
-
19
11
  export function promptForStudioPath(prompt: CliPrompter): Promise<string> {
20
12
  return prompt.single({
21
13
  type: 'input',
@@ -1,6 +1,8 @@
1
1
  import {blogSchemaFolder, blogSchemaJS, blogSchemaTS} from './schemaTypes/blog'
2
2
 
3
- export const sanityConfigTemplate = `/**
3
+ export const sanityConfigTemplate = `'use client'
4
+
5
+ /**
4
6
  * This configuration is used to for the Sanity Studio that’s mounted on the \`:route:\` route
5
7
  */
6
8
 
@@ -39,27 +41,7 @@ const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET
39
41
  export default defineCliConfig({ api: { projectId, dataset } })
40
42
  `
41
43
 
42
- export const sanityStudioPagesTemplate = `import Head from 'next/head'
43
- import { NextStudio } from 'next-sanity/studio'
44
- import { metadata } from 'next-sanity/studio/metadata'
45
- import config from ':configPath:'
46
-
47
- export default function StudioPage() {
48
- return (
49
- <>
50
- <Head>
51
- {Object.entries(metadata).map(([key, value]) => (
52
- <meta key={key} name={key} content={value} />
53
- ))}
54
- </Head>
55
- <NextStudio config={config} />
56
- </>
57
- )
58
- }`
59
-
60
- export const sanityStudioAppTemplate = `'use client'
61
-
62
- /**
44
+ export const sanityStudioTemplate = `/**
63
45
  * This route is responsible for the built-in authoring environment using Sanity Studio.
64
46
  * All routes under your studio path is handled by this file using Next.js' catch-all routes:
65
47
  * https://nextjs.org/docs/routing/dynamic-routes#catch-all-routes
@@ -71,12 +53,14 @@ export const sanityStudioAppTemplate = `'use client'
71
53
  import { NextStudio } from 'next-sanity/studio'
72
54
  import config from ':configPath:'
73
55
 
56
+ export const dynamic = 'force-static'
57
+
58
+ export { metadata, viewport } from 'next-sanity/studio'
59
+
74
60
  export default function StudioPage() {
75
61
  return <NextStudio config={config} />
76
62
  }`
77
63
 
78
- export const sanityStudioAppLayoutTemplate = `export {metadata} from 'next-sanity/studio'`
79
-
80
64
  // Format today's date like YYYY-MM-DD
81
65
  const envTS = `export const apiVersion =
82
66
  process.env.NEXT_PUBLIC_SANITY_API_VERSION || '${new Date().toISOString().split('T')[0]}'
@@ -127,10 +111,11 @@ const client = `import { createClient } from 'next-sanity'
127
111
  import { apiVersion, dataset, projectId, useCdn } from '../env'
128
112
 
129
113
  export const client = createClient({
130
- apiVersion,
131
- dataset,
132
114
  projectId,
115
+ dataset,
116
+ apiVersion,
133
117
  useCdn,
118
+ perspective: 'published',
134
119
  })
135
120
  `
136
121
 
@@ -62,10 +62,12 @@ export default async function typegenGenerateAction(
62
62
  const outputDir = dirname(outputPath)
63
63
  await mkdir(outputDir, {recursive: true})
64
64
 
65
- const prettierConfig = await prettier.resolveConfig(outputPath).catch((err) => {
66
- output.warn(`Failed to load prettier config: ${err.message}`)
67
- return null
68
- })
65
+ const prettierConfig = codegenConfig.formatGeneratedCode
66
+ ? await prettier.resolveConfig(outputPath).catch((err) => {
67
+ output.warn(`Failed to load prettier config: ${err.message}`)
68
+ return null
69
+ })
70
+ : null
69
71
  const workerPath = await getCliWorkerPath('typegenGenerate')
70
72
 
71
73
  const spinner = output.spinner({}).start('Generating types')