@sanity/cli 3.50.0 → 3.50.1-detect-context-errors.9

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.
@@ -43624,19 +43624,17 @@ The default dataset configuration has a public dataset named "production".`;
43624
43624
  }
43625
43625
  const authorTS = `import {defineField, defineType} from 'sanity'
43626
43626
 
43627
- export default defineType({
43627
+ export const authorType = defineType({
43628
43628
  name: 'author',
43629
43629
  title: 'Author',
43630
43630
  type: 'document',
43631
43631
  fields: [
43632
43632
  defineField({
43633
43633
  name: 'name',
43634
- title: 'Name',
43635
43634
  type: 'string',
43636
43635
  }),
43637
43636
  defineField({
43638
43637
  name: 'slug',
43639
- title: 'Slug',
43640
43638
  type: 'slug',
43641
43639
  options: {
43642
43640
  source: 'name',
@@ -43645,7 +43643,6 @@ export default defineType({
43645
43643
  }),
43646
43644
  defineField({
43647
43645
  name: 'image',
43648
- title: 'Image',
43649
43646
  type: 'image',
43650
43647
  options: {
43651
43648
  hotspot: true,
@@ -43660,11 +43657,9 @@ export default defineType({
43660
43657
  }),
43661
43658
  defineField({
43662
43659
  name: 'bio',
43663
- title: 'Bio',
43664
43660
  type: 'array',
43665
43661
  of: [
43666
43662
  {
43667
- title: 'Block',
43668
43663
  type: 'block',
43669
43664
  styles: [{title: 'Normal', value: 'normal'}],
43670
43665
  lists: [],
@@ -43679,19 +43674,17 @@ export default defineType({
43679
43674
  },
43680
43675
  },
43681
43676
  })
43682
- `, authorJS = `export const author = {
43677
+ `, authorJS = `export const authorType = {
43683
43678
  name: 'author',
43684
43679
  title: 'Author',
43685
43680
  type: 'document',
43686
43681
  fields: [
43687
43682
  {
43688
43683
  name: 'name',
43689
- title: 'Name',
43690
43684
  type: 'string',
43691
43685
  },
43692
43686
  {
43693
43687
  name: 'slug',
43694
- title: 'Slug',
43695
43688
  type: 'slug',
43696
43689
  options: {
43697
43690
  source: 'name',
@@ -43700,7 +43693,6 @@ export default defineType({
43700
43693
  },
43701
43694
  {
43702
43695
  name: 'image',
43703
- title: 'Image',
43704
43696
  type: 'image',
43705
43697
  options: {
43706
43698
  hotspot: true,
@@ -43715,11 +43707,9 @@ export default defineType({
43715
43707
  },
43716
43708
  {
43717
43709
  name: 'bio',
43718
- title: 'Bio',
43719
43710
  type: 'array',
43720
43711
  of: [
43721
43712
  {
43722
- title: 'Block',
43723
43713
  type: 'block',
43724
43714
  styles: [{title: 'Normal', value: 'normal'}],
43725
43715
  lists: [],
@@ -43735,6 +43725,7 @@ export default defineType({
43735
43725
  },
43736
43726
  }
43737
43727
  `, blockContentTS = `import {defineType, defineArrayMember} from 'sanity'
43728
+ import {ImageIcon} from '@sanity/icons'
43738
43729
 
43739
43730
  /**
43740
43731
  * This is the schema type for block content used in the post document type
@@ -43747,13 +43738,12 @@ export default defineType({
43747
43738
  * }
43748
43739
  */
43749
43740
 
43750
- export default defineType({
43741
+ export const blockContentType = defineType({
43751
43742
  title: 'Block Content',
43752
43743
  name: 'blockContent',
43753
43744
  type: 'array',
43754
43745
  of: [
43755
43746
  defineArrayMember({
43756
- title: 'Block',
43757
43747
  type: 'block',
43758
43748
  // Styles let you define what blocks can be marked up as. The default
43759
43749
  // set corresponds with HTML tags, but you can set any title or value
@@ -43798,6 +43788,7 @@ export default defineType({
43798
43788
  // as a block type.
43799
43789
  defineArrayMember({
43800
43790
  type: 'image',
43791
+ icon: ImageIcon,
43801
43792
  options: {hotspot: true},
43802
43793
  fields: [
43803
43794
  {
@@ -43809,7 +43800,9 @@ export default defineType({
43809
43800
  }),
43810
43801
  ],
43811
43802
  })
43812
- `, blockContentJS = `/**
43803
+ `, blockContentJS = `import {ImageIcon} from '@sanity/icons'
43804
+
43805
+ /**
43813
43806
  * This is the schema type for block content used in the post document type
43814
43807
  * Importing this type into the studio configuration's \`schema\` property
43815
43808
  * lets you reuse it in other document types with:
@@ -43820,7 +43813,7 @@ export default defineType({
43820
43813
  * }
43821
43814
  */
43822
43815
 
43823
- export const blockContent = {
43816
+ export const blockContentType = {
43824
43817
  title: 'Block Content',
43825
43818
  name: 'blockContent',
43826
43819
  type: 'array',
@@ -43871,6 +43864,7 @@ export const blockContent = {
43871
43864
  // as a block type.
43872
43865
  {
43873
43866
  type: 'image',
43867
+ icon: ImageIcon,
43874
43868
  options: {hotspot: true},
43875
43869
  fields: [
43876
43870
  {
@@ -43884,55 +43878,48 @@ export const blockContent = {
43884
43878
  }
43885
43879
  `, categoryTS = `import {defineField, defineType} from 'sanity'
43886
43880
 
43887
- export default defineType({
43881
+ export const categoryType = defineType({
43888
43882
  name: 'category',
43889
- title: 'Category',
43890
43883
  type: 'document',
43891
43884
  fields: [
43892
43885
  defineField({
43893
43886
  name: 'title',
43894
- title: 'Title',
43895
43887
  type: 'string',
43896
43888
  }),
43897
43889
  defineField({
43898
43890
  name: 'description',
43899
- title: 'Description',
43900
43891
  type: 'text',
43901
43892
  }),
43902
43893
  ],
43903
43894
  })
43904
- `, categoryJS = `export const category = {
43895
+ `, categoryJS = `export const categoryType = {
43905
43896
  name: 'category',
43906
43897
  title: 'Category',
43907
43898
  type: 'document',
43908
43899
  fields: [
43909
43900
  {
43910
43901
  name: 'title',
43911
- title: 'Title',
43912
43902
  type: 'string',
43913
43903
  },
43914
43904
  {
43915
43905
  name: 'description',
43916
- title: 'Description',
43917
43906
  type: 'text',
43918
43907
  },
43919
43908
  ],
43920
43909
  }
43921
43910
  `, postTS = `import {defineField, defineType} from 'sanity'
43922
43911
 
43923
- export default defineType({
43912
+ export const postType = defineType({
43924
43913
  name: 'post',
43925
43914
  title: 'Post',
43926
43915
  type: 'document',
43927
43916
  fields: [
43928
43917
  defineField({
43929
43918
  name: 'title',
43930
- title: 'Title',
43931
43919
  type: 'string',
43932
43920
  }),
43933
43921
  defineField({
43934
43922
  name: 'slug',
43935
- title: 'Slug',
43936
43923
  type: 'slug',
43937
43924
  options: {
43938
43925
  source: 'title',
@@ -43941,13 +43928,11 @@ export default defineType({
43941
43928
  }),
43942
43929
  defineField({
43943
43930
  name: 'author',
43944
- title: 'Author',
43945
43931
  type: 'reference',
43946
43932
  to: {type: 'author'},
43947
43933
  }),
43948
43934
  defineField({
43949
43935
  name: 'mainImage',
43950
- title: 'Main image',
43951
43936
  type: 'image',
43952
43937
  options: {
43953
43938
  hotspot: true,
@@ -43956,28 +43941,24 @@ export default defineType({
43956
43941
  {
43957
43942
  name: 'alt',
43958
43943
  type: 'string',
43959
- title: 'Alternative Text',
43944
+ title: 'Alternative text',
43960
43945
  }
43961
43946
  ]
43962
43947
  }),
43963
43948
  defineField({
43964
43949
  name: 'categories',
43965
- title: 'Categories',
43966
43950
  type: 'array',
43967
43951
  of: [{type: 'reference', to: {type: 'category'}}],
43968
43952
  }),
43969
43953
  defineField({
43970
43954
  name: 'publishedAt',
43971
- title: 'Published at',
43972
43955
  type: 'datetime',
43973
43956
  }),
43974
43957
  defineField({
43975
43958
  name: 'body',
43976
- title: 'Body',
43977
43959
  type: 'blockContent',
43978
43960
  }),
43979
43961
  ],
43980
-
43981
43962
  preview: {
43982
43963
  select: {
43983
43964
  title: 'title',
@@ -43990,19 +43971,17 @@ export default defineType({
43990
43971
  },
43991
43972
  },
43992
43973
  })
43993
- `, postJS = `export const post = {
43974
+ `, postJS = `export const postType = {
43994
43975
  name: 'post',
43995
43976
  title: 'Post',
43996
43977
  type: 'document',
43997
43978
  fields: [
43998
43979
  {
43999
43980
  name: 'title',
44000
- title: 'Title',
44001
43981
  type: 'string',
44002
43982
  },
44003
43983
  {
44004
43984
  name: 'slug',
44005
- title: 'Slug',
44006
43985
  type: 'slug',
44007
43986
  options: {
44008
43987
  source: 'title',
@@ -44011,13 +43990,11 @@ export default defineType({
44011
43990
  },
44012
43991
  {
44013
43992
  name: 'author',
44014
- title: 'Author',
44015
43993
  type: 'reference',
44016
43994
  to: {type: 'author'},
44017
43995
  },
44018
43996
  {
44019
43997
  name: 'mainImage',
44020
- title: 'Main image',
44021
43998
  type: 'image',
44022
43999
  options: {
44023
44000
  hotspot: true,
@@ -44026,28 +44003,24 @@ export default defineType({
44026
44003
  {
44027
44004
  name: 'alt',
44028
44005
  type: 'string',
44029
- title: 'Alternative Text',
44006
+ title: 'Alternative text',
44030
44007
  }
44031
44008
  ]
44032
44009
  },
44033
44010
  {
44034
44011
  name: 'categories',
44035
- title: 'Categories',
44036
44012
  type: 'array',
44037
44013
  of: [{type: 'reference', to: {type: 'category'}}],
44038
44014
  },
44039
44015
  {
44040
44016
  name: 'publishedAt',
44041
- title: 'Published at',
44042
44017
  type: 'datetime',
44043
44018
  },
44044
44019
  {
44045
44020
  name: 'body',
44046
- title: 'Body',
44047
44021
  type: 'blockContent',
44048
44022
  },
44049
44023
  ],
44050
-
44051
44024
  preview: {
44052
44025
  select: {
44053
44026
  title: 'title',
@@ -44062,28 +44035,28 @@ export default defineType({
44062
44035
  }
44063
44036
  `, blogSchemaTS = `import { type SchemaTypeDefinition } from 'sanity'
44064
44037
 
44065
- import blockContent from './schemaTypes/blockContent'
44066
- import category from './schemaTypes/category'
44067
- import post from './schemaTypes/post'
44068
- import author from './schemaTypes/author'
44038
+ import {blockContentType} from './schemaTypes/blockContentType'
44039
+ import {categoryType} from './schemaTypes/categoryType'
44040
+ import {postType} from './schemaTypes/postType'
44041
+ import {authorType} from './schemaTypes/authorType'
44069
44042
 
44070
44043
  export const schema: { types: SchemaTypeDefinition[] } = {
44071
- types: [post, author, category, blockContent],
44044
+ types: [blockContentType, categoryType, postType, authorType],
44072
44045
  }
44073
- `, blogSchemaJS = `import {blockContent} from './schemaTypes/blockContent'
44074
- import {category} from './schemaTypes/category'
44075
- import {post} from './schemaTypes/post'
44076
- import {author} from './schemaTypes/author'
44046
+ `, blogSchemaJS = `import {blockContentType} from './schemaTypes/blockContentType'
44047
+ import {categoryType} from './schemaTypes/categoryType'
44048
+ import {postType} from './schemaTypes/postType'
44049
+ import {authorType} from './schemaTypes/authorType'
44077
44050
 
44078
44051
  export const schema = {
44079
- types: [post, author, category, blockContent],
44052
+ types: [blockContentType, categoryType, postType, authorType],
44080
44053
  }
44081
44054
  `, blogSchemaFolder = (useTypeScript) => ({
44082
- "author.": useTypeScript ? authorTS : authorJS,
44083
- "blockContent.": useTypeScript ? blockContentTS : blockContentJS,
44084
- "category.": useTypeScript ? categoryTS : categoryJS,
44085
- "post.": useTypeScript ? postTS : postJS
44086
- }), sanityConfigTemplate = `'use client'
44055
+ "authorType.": useTypeScript ? authorTS : authorJS,
44056
+ "blockContentType.": useTypeScript ? blockContentTS : blockContentJS,
44057
+ "categoryType.": useTypeScript ? categoryTS : categoryJS,
44058
+ "postType.": useTypeScript ? postTS : postJS
44059
+ }), sanityConfigTemplate = (hasSrcFolder = !1) => `'use client'
44087
44060
 
44088
44061
  /**
44089
44062
  * This configuration is used to for the Sanity Studio that\u2019s mounted on the \`:route:\` route
@@ -44094,8 +44067,8 @@ import {defineConfig} from 'sanity'
44094
44067
  import {structureTool} from 'sanity/structure'
44095
44068
 
44096
44069
  // Go to https://www.sanity.io/docs/api-versioning to learn how API versioning works
44097
- import {apiVersion, dataset, projectId} from './sanity/env'
44098
- import {schema} from './sanity/schema'
44070
+ import {apiVersion, dataset, projectId} from ${hasSrcFolder ? "'./src/sanity/env'" : "'./sanity/env'"}
44071
+ import {schema} from ${hasSrcFolder ? "'./src/sanity/schema'" : "'./sanity/schema'"}
44099
44072
 
44100
44073
  export default defineConfig({
44101
44074
  basePath: ':basePath:',
@@ -44151,8 +44124,6 @@ export const projectId = assertValue(
44151
44124
  'Missing environment variable: NEXT_PUBLIC_SANITY_PROJECT_ID'
44152
44125
  )
44153
44126
 
44154
- export const useCdn = false
44155
-
44156
44127
  function assertValue<T>(v: T | undefined, errorMessage: string): T {
44157
44128
  if (v === undefined) {
44158
44129
  throw new Error(errorMessage)
@@ -44165,7 +44136,6 @@ function assertValue<T>(v: T | undefined, errorMessage: string): T {
44165
44136
 
44166
44137
  export const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET;
44167
44138
  export const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID;
44168
- export const useCdn = false
44169
44139
  `, schemaTS = `import { type SchemaTypeDefinition } from 'sanity'
44170
44140
 
44171
44141
  export const schema: { types: SchemaTypeDefinition[] } = {
@@ -44176,39 +44146,34 @@ export const schema: { types: SchemaTypeDefinition[] } = {
44176
44146
  }
44177
44147
  `, client = `import { createClient } from 'next-sanity'
44178
44148
 
44179
- import { apiVersion, dataset, projectId, useCdn } from '../env'
44149
+ import { apiVersion, dataset, projectId } from '../env'
44180
44150
 
44181
44151
  export const client = createClient({
44182
44152
  projectId,
44183
44153
  dataset,
44184
44154
  apiVersion,
44185
- useCdn,
44186
- perspective: 'published',
44155
+ useCdn: true, // Set to false if statically generating pages, using ISR or tag-based revalidation
44187
44156
  })
44188
44157
  `, imageTS = `import createImageUrlBuilder from '@sanity/image-url'
44189
- import type { Image } from 'sanity'
44158
+ import { SanityImageSource } from "@sanity/image-url/lib/types/types";
44190
44159
 
44191
44160
  import { dataset, projectId } from '../env'
44192
44161
 
44193
- const imageBuilder = createImageUrlBuilder({
44194
- projectId: projectId || '',
44195
- dataset: dataset || '',
44196
- })
44162
+ // https://www.sanity.io/docs/image-url
44163
+ const builder = createImageUrlBuilder({ projectId, dataset })
44197
44164
 
44198
- export const urlForImage = (source: Image) => {
44199
- return imageBuilder?.image(source).auto('format').fit('max').url()
44165
+ export const urlFor = (source: SanityImageSource) => {
44166
+ return builder.image(source)
44200
44167
  }
44201
44168
  `, imageJS = `import createImageUrlBuilder from '@sanity/image-url'
44202
44169
 
44203
44170
  import { dataset, projectId } from '../env'
44204
44171
 
44205
- const imageBuilder = createImageUrlBuilder({
44206
- projectId: projectId || '',
44207
- dataset: dataset || '',
44208
- })
44172
+ // https://www.sanity.io/docs/image-url
44173
+ const builder = createImageUrlBuilder({ projectId, dataset })
44209
44174
 
44210
- export const urlForImage = (source) => {
44211
- return imageBuilder?.image(source).auto('format').fit('max').url()
44175
+ export const urlFor = (source) => {
44176
+ return builder.image(source)
44212
44177
  }
44213
44178
  `, sanityFolder = (useTypeScript, template) => {
44214
44179
  const isBlogTemplate = template === "blog", structure = {
@@ -44348,11 +44313,12 @@ You can find your project on Sanity Manage \u2014 https://www.sanity.io/manage/p
44348
44313
  if (outputPath = answers.outputPath, initNext) {
44349
44314
  const useTypeScript2 = unattended ? !0 : await promptForTypeScript(prompt2);
44350
44315
  trace.log({ step: "useTypeScript", selectedOption: useTypeScript2 ? "yes" : "no" });
44351
- const fileExtension = useTypeScript2 ? "ts" : "js";
44352
- if (unattended || await promptForEmbeddedStudio(prompt2)) {
44353
- const srcDir = "app";
44354
- let srcPath = path__default.default.join(workDir, srcDir);
44355
- fs$r.existsSync(srcPath) || (srcPath = path__default.default.join(workDir, "src", srcDir), fs$r.existsSync(srcPath) || await fs__default$1.default.mkdir(srcPath, { recursive: !0 }).catch(() => loadEnv.debug("Error creating folder %s", srcPath)));
44316
+ const fileExtension = useTypeScript2 ? "ts" : "js", embeddedStudio = unattended ? !0 : await promptForEmbeddedStudio(prompt2);
44317
+ let hasSrcFolder = !1;
44318
+ if (embeddedStudio) {
44319
+ const appDir = "app";
44320
+ let srcPath = path__default.default.join(workDir, appDir);
44321
+ fs$r.existsSync(srcPath) || (srcPath = path__default.default.join(workDir, "src", appDir), hasSrcFolder = !0, fs$r.existsSync(srcPath) || await fs__default$1.default.mkdir(srcPath, { recursive: !0 }).catch(() => loadEnv.debug("Error creating folder %s", srcPath)));
44356
44322
  const studioPath = unattended ? "/studio" : await promptForStudioPath(prompt2), embeddedStudioRouteFilePath = path__default.default.join(
44357
44323
  srcPath,
44358
44324
  `${studioPath}/`,
@@ -44368,19 +44334,27 @@ You can find your project on Sanity Manage \u2014 https://www.sanity.io/manage/p
44368
44334
  const sanityConfigPath = path__default.default.join(workDir, `sanity.config.${fileExtension}`);
44369
44335
  await writeOrOverwrite(
44370
44336
  sanityConfigPath,
44371
- sanityConfigTemplate.replace(":route:", embeddedStudioRouteFilePath.slice(workDir.length).replace("src/", "")).replace(":basePath:", studioPath)
44337
+ sanityConfigTemplate(hasSrcFolder).replace(":route:", embeddedStudioRouteFilePath.slice(workDir.length).replace("src/", "")).replace(":basePath:", studioPath)
44372
44338
  );
44373
44339
  }
44374
44340
  const sanityCliPath = path__default.default.join(workDir, `sanity.cli.${fileExtension}`);
44375
44341
  await writeOrOverwrite(sanityCliPath, sanityCliTemplate);
44376
- const writeSourceFiles = async (files, folderPath) => {
44342
+ const writeSourceFiles = async (files, folderPath, srcFolderPrefix) => {
44377
44343
  for (const [filePath, content] of Object.entries(files))
44378
44344
  filePath.includes(".") && typeof content == "string" ? await writeOrOverwrite(
44379
- path__default.default.join(workDir, "sanity", folderPath || "", `${filePath}${fileExtension}`),
44345
+ path__default.default.join(
44346
+ workDir,
44347
+ srcFolderPrefix ? "src" : "",
44348
+ "sanity",
44349
+ folderPath || "",
44350
+ `${filePath}${fileExtension}`
44351
+ ),
44380
44352
  content
44381
- ) : (await fs__default$1.default.mkdir(path__default.default.join(workDir, "sanity", filePath), { recursive: !0 }), typeof content == "object" && await writeSourceFiles(content, filePath));
44353
+ ) : (await fs__default$1.default.mkdir(path__default.default.join(workDir, srcFolderPrefix ? "src" : "", "sanity", filePath), {
44354
+ recursive: !0
44355
+ }), typeof content == "object" && await writeSourceFiles(content, filePath, srcFolderPrefix));
44382
44356
  }, templateToUse = unattended ? "clean" : await promptForNextTemplate(prompt2);
44383
- await writeSourceFiles(sanityFolder(useTypeScript2, templateToUse));
44357
+ await writeSourceFiles(sanityFolder(useTypeScript2, templateToUse), void 0, hasSrcFolder);
44384
44358
  const tsConfigPath = path__default.default.join(workDir, "tsconfig.json");
44385
44359
  if (useTypeScript2 && fs$r.existsSync(tsConfigPath)) {
44386
44360
  const tsConfigFile = fs$r.readFileSync(tsConfigPath, "utf8"), config2 = silverFleece.evaluate(tsConfigFile);
@@ -44413,7 +44387,8 @@ You can find your project on Sanity Manage \u2014 https://www.sanity.io/manage/p
44413
44387
  chosen === "npm" ? await execa$1("npm", ["install", "next-sanity@9"], execOptions) : chosen === "yarn" ? await execa$1("npx", ["install-peerdeps", "--yarn", "next-sanity@9"], execOptions) : chosen === "pnpm" && await execa$1("pnpm", ["install", "next-sanity@9"], execOptions), print(
44414
44388
  `
44415
44389
  ${chalk2.green("Success!")} Your Sanity configuration files has been added to this project`
44416
- ), process.exit(0);
44390
+ );
44391
+ return;
44417
44392
  }
44418
44393
  function countNestedFolders(path2) {
44419
44394
  const separator2 = path2.includes("\\") ? "\\" : "/";