@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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/cli",
3
- "version": "3.50.0",
3
+ "version": "3.50.1-detect-context-errors.9+f64d68cae7",
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.21.0",
61
- "@sanity/codegen": "3.50.0",
61
+ "@sanity/codegen": "3.50.1-detect-context-errors.9+f64d68cae7",
62
62
  "@sanity/telemetry": "^0.7.7",
63
- "@sanity/util": "3.50.0",
63
+ "@sanity/util": "3.50.1-detect-context-errors.9+f64d68cae7",
64
64
  "chalk": "^4.1.2",
65
65
  "debug": "^4.3.4",
66
66
  "decompress": "^4.2.0",
@@ -82,7 +82,7 @@
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.50.0",
85
+ "@sanity/types": "3.50.1-detect-context-errors.9+f64d68cae7",
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": "49f278adb11869e91b7582e80cba0c548444d7be"
138
+ "gitHead": "f64d68cae702cf3269a370e1537c9da87a92df92"
139
139
  }
@@ -329,14 +329,16 @@ export default async function initSanity(
329
329
  const fileExtension = useTypeScript ? 'ts' : 'js'
330
330
 
331
331
  const embeddedStudio = unattended ? true : await promptForEmbeddedStudio(prompt)
332
+ let hasSrcFolder = false
332
333
 
333
334
  if (embeddedStudio) {
334
335
  // find source path (app or src/app)
335
- const srcDir = 'app'
336
- let srcPath = path.join(workDir, srcDir)
336
+ const appDir = 'app'
337
+ let srcPath = path.join(workDir, appDir)
337
338
 
338
339
  if (!existsSync(srcPath)) {
339
- srcPath = path.join(workDir, 'src', srcDir)
340
+ srcPath = path.join(workDir, 'src', appDir)
341
+ hasSrcFolder = true
340
342
  if (!existsSync(srcPath)) {
341
343
  await fs
342
344
  .mkdir(srcPath, {recursive: true})
@@ -369,7 +371,7 @@ export default async function initSanity(
369
371
  const sanityConfigPath = path.join(workDir, `sanity.config.${fileExtension}`)
370
372
  await writeOrOverwrite(
371
373
  sanityConfigPath,
372
- sanityConfigTemplate
374
+ sanityConfigTemplate(hasSrcFolder)
373
375
  .replace(':route:', embeddedStudioRouteFilePath.slice(workDir.length).replace('src/', ''))
374
376
  .replace(':basePath:', studioPath),
375
377
  )
@@ -382,18 +384,27 @@ export default async function initSanity(
382
384
  const writeSourceFiles = async (
383
385
  files: Record<string, string | Record<string, string>>,
384
386
  folderPath?: string,
387
+ srcFolderPrefix?: boolean,
385
388
  ) => {
386
389
  for (const [filePath, content] of Object.entries(files)) {
387
390
  // check if file ends with full stop to indicate it's file and not directory (this only works with our template tree structure)
388
391
  if (filePath.includes('.') && typeof content === 'string') {
389
392
  await writeOrOverwrite(
390
- path.join(workDir, 'sanity', folderPath || '', `${filePath}${fileExtension}`),
393
+ path.join(
394
+ workDir,
395
+ srcFolderPrefix ? 'src' : '',
396
+ 'sanity',
397
+ folderPath || '',
398
+ `${filePath}${fileExtension}`,
399
+ ),
391
400
  content,
392
401
  )
393
402
  } else {
394
- await fs.mkdir(path.join(workDir, 'sanity', filePath), {recursive: true})
403
+ await fs.mkdir(path.join(workDir, srcFolderPrefix ? 'src' : '', 'sanity', filePath), {
404
+ recursive: true,
405
+ })
395
406
  if (typeof content === 'object') {
396
- await writeSourceFiles(content, filePath)
407
+ await writeSourceFiles(content, filePath, srcFolderPrefix)
397
408
  }
398
409
  }
399
410
  }
@@ -402,7 +413,7 @@ export default async function initSanity(
402
413
  // ask what kind of schema setup the user wants
403
414
  const templateToUse = unattended ? 'clean' : await promptForNextTemplate(prompt)
404
415
 
405
- await writeSourceFiles(sanityFolder(useTypeScript, templateToUse))
416
+ await writeSourceFiles(sanityFolder(useTypeScript, templateToUse), undefined, hasSrcFolder)
406
417
 
407
418
  // set tsconfig.json target to ES2017
408
419
  const tsConfigPath = path.join(workDir, 'tsconfig.json')
@@ -459,8 +470,7 @@ export default async function initSanity(
459
470
  `\n${chalk.green('Success!')} Your Sanity configuration files has been added to this project`,
460
471
  )
461
472
 
462
- // eslint-disable-next-line no-process-exit
463
- process.exit(0)
473
+ return
464
474
  }
465
475
 
466
476
  // eslint-disable-next-line @typescript-eslint/no-shadow
@@ -1,6 +1,6 @@
1
1
  import {blogSchemaFolder, blogSchemaJS, blogSchemaTS} from './schemaTypes/blog'
2
2
 
3
- export const sanityConfigTemplate = `'use client'
3
+ export const sanityConfigTemplate = (hasSrcFolder = false): string => `'use client'
4
4
 
5
5
  /**
6
6
  * This configuration is used to for the Sanity Studio that’s mounted on the \`:route:\` route
@@ -11,8 +11,8 @@ import {defineConfig} from 'sanity'
11
11
  import {structureTool} from 'sanity/structure'
12
12
 
13
13
  // Go to https://www.sanity.io/docs/api-versioning to learn how API versioning works
14
- import {apiVersion, dataset, projectId} from './sanity/env'
15
- import {schema} from './sanity/schema'
14
+ import {apiVersion, dataset, projectId} from ${hasSrcFolder ? "'./src/sanity/env'" : "'./sanity/env'"}
15
+ import {schema} from ${hasSrcFolder ? "'./src/sanity/schema'" : "'./sanity/schema'"}
16
16
 
17
17
  export default defineConfig({
18
18
  basePath: ':basePath:',
@@ -75,8 +75,6 @@ export const projectId = assertValue(
75
75
  'Missing environment variable: NEXT_PUBLIC_SANITY_PROJECT_ID'
76
76
  )
77
77
 
78
- export const useCdn = false
79
-
80
78
  function assertValue<T>(v: T | undefined, errorMessage: string): T {
81
79
  if (v === undefined) {
82
80
  throw new Error(errorMessage)
@@ -91,7 +89,6 @@ const envJS = `export const apiVersion =
91
89
 
92
90
  export const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET;
93
91
  export const projectId = process.env.NEXT_PUBLIC_SANITY_PROJECT_ID;
94
- export const useCdn = false
95
92
  `
96
93
 
97
94
  const schemaTS = `import { type SchemaTypeDefinition } from 'sanity'
@@ -108,29 +105,26 @@ const schemaJS = `export const schema = {
108
105
 
109
106
  const client = `import { createClient } from 'next-sanity'
110
107
 
111
- import { apiVersion, dataset, projectId, useCdn } from '../env'
108
+ import { apiVersion, dataset, projectId } from '../env'
112
109
 
113
110
  export const client = createClient({
114
111
  projectId,
115
112
  dataset,
116
113
  apiVersion,
117
- useCdn,
118
- perspective: 'published',
114
+ useCdn: true, // Set to false if statically generating pages, using ISR or tag-based revalidation
119
115
  })
120
116
  `
121
117
 
122
118
  const imageTS = `import createImageUrlBuilder from '@sanity/image-url'
123
- import type { Image } from 'sanity'
119
+ import { SanityImageSource } from "@sanity/image-url/lib/types/types";
124
120
 
125
121
  import { dataset, projectId } from '../env'
126
122
 
127
- const imageBuilder = createImageUrlBuilder({
128
- projectId: projectId || '',
129
- dataset: dataset || '',
130
- })
123
+ // https://www.sanity.io/docs/image-url
124
+ const builder = createImageUrlBuilder({ projectId, dataset })
131
125
 
132
- export const urlForImage = (source: Image) => {
133
- return imageBuilder?.image(source).auto('format').fit('max').url()
126
+ export const urlFor = (source: SanityImageSource) => {
127
+ return builder.image(source)
134
128
  }
135
129
  `
136
130
 
@@ -138,13 +132,11 @@ const imageJS = `import createImageUrlBuilder from '@sanity/image-url'
138
132
 
139
133
  import { dataset, projectId } from '../env'
140
134
 
141
- const imageBuilder = createImageUrlBuilder({
142
- projectId: projectId || '',
143
- dataset: dataset || '',
144
- })
135
+ // https://www.sanity.io/docs/image-url
136
+ const builder = createImageUrlBuilder({ projectId, dataset })
145
137
 
146
- export const urlForImage = (source) => {
147
- return imageBuilder?.image(source).auto('format').fit('max').url()
138
+ export const urlFor = (source) => {
139
+ return builder.image(source)
148
140
  }
149
141
  `
150
142
 
@@ -2,19 +2,17 @@
2
2
 
3
3
  const authorTS = `import {defineField, defineType} from 'sanity'
4
4
 
5
- export default defineType({
5
+ export const authorType = defineType({
6
6
  name: 'author',
7
7
  title: 'Author',
8
8
  type: 'document',
9
9
  fields: [
10
10
  defineField({
11
11
  name: 'name',
12
- title: 'Name',
13
12
  type: 'string',
14
13
  }),
15
14
  defineField({
16
15
  name: 'slug',
17
- title: 'Slug',
18
16
  type: 'slug',
19
17
  options: {
20
18
  source: 'name',
@@ -23,7 +21,6 @@ export default defineType({
23
21
  }),
24
22
  defineField({
25
23
  name: 'image',
26
- title: 'Image',
27
24
  type: 'image',
28
25
  options: {
29
26
  hotspot: true,
@@ -38,11 +35,9 @@ export default defineType({
38
35
  }),
39
36
  defineField({
40
37
  name: 'bio',
41
- title: 'Bio',
42
38
  type: 'array',
43
39
  of: [
44
40
  {
45
- title: 'Block',
46
41
  type: 'block',
47
42
  styles: [{title: 'Normal', value: 'normal'}],
48
43
  lists: [],
@@ -59,19 +54,17 @@ export default defineType({
59
54
  })
60
55
  `
61
56
 
62
- const authorJS = `export const author = {
57
+ const authorJS = `export const authorType = {
63
58
  name: 'author',
64
59
  title: 'Author',
65
60
  type: 'document',
66
61
  fields: [
67
62
  {
68
63
  name: 'name',
69
- title: 'Name',
70
64
  type: 'string',
71
65
  },
72
66
  {
73
67
  name: 'slug',
74
- title: 'Slug',
75
68
  type: 'slug',
76
69
  options: {
77
70
  source: 'name',
@@ -80,7 +73,6 @@ const authorJS = `export const author = {
80
73
  },
81
74
  {
82
75
  name: 'image',
83
- title: 'Image',
84
76
  type: 'image',
85
77
  options: {
86
78
  hotspot: true,
@@ -95,11 +87,9 @@ const authorJS = `export const author = {
95
87
  },
96
88
  {
97
89
  name: 'bio',
98
- title: 'Bio',
99
90
  type: 'array',
100
91
  of: [
101
92
  {
102
- title: 'Block',
103
93
  type: 'block',
104
94
  styles: [{title: 'Normal', value: 'normal'}],
105
95
  lists: [],
@@ -117,6 +107,7 @@ const authorJS = `export const author = {
117
107
  `
118
108
 
119
109
  const blockContentTS = `import {defineType, defineArrayMember} from 'sanity'
110
+ import {ImageIcon} from '@sanity/icons'
120
111
 
121
112
  /**
122
113
  * This is the schema type for block content used in the post document type
@@ -129,13 +120,12 @@ const blockContentTS = `import {defineType, defineArrayMember} from 'sanity'
129
120
  * }
130
121
  */
131
122
 
132
- export default defineType({
123
+ export const blockContentType = defineType({
133
124
  title: 'Block Content',
134
125
  name: 'blockContent',
135
126
  type: 'array',
136
127
  of: [
137
128
  defineArrayMember({
138
- title: 'Block',
139
129
  type: 'block',
140
130
  // Styles let you define what blocks can be marked up as. The default
141
131
  // set corresponds with HTML tags, but you can set any title or value
@@ -180,6 +170,7 @@ export default defineType({
180
170
  // as a block type.
181
171
  defineArrayMember({
182
172
  type: 'image',
173
+ icon: ImageIcon,
183
174
  options: {hotspot: true},
184
175
  fields: [
185
176
  {
@@ -193,7 +184,9 @@ export default defineType({
193
184
  })
194
185
  `
195
186
 
196
- const blockContentJS = `/**
187
+ const blockContentJS = `import {ImageIcon} from '@sanity/icons'
188
+
189
+ /**
197
190
  * This is the schema type for block content used in the post document type
198
191
  * Importing this type into the studio configuration's \`schema\` property
199
192
  * lets you reuse it in other document types with:
@@ -204,7 +197,7 @@ const blockContentJS = `/**
204
197
  * }
205
198
  */
206
199
 
207
- export const blockContent = {
200
+ export const blockContentType = {
208
201
  title: 'Block Content',
209
202
  name: 'blockContent',
210
203
  type: 'array',
@@ -255,6 +248,7 @@ export const blockContent = {
255
248
  // as a block type.
256
249
  {
257
250
  type: 'image',
251
+ icon: ImageIcon,
258
252
  options: {hotspot: true},
259
253
  fields: [
260
254
  {
@@ -270,38 +264,33 @@ export const blockContent = {
270
264
 
271
265
  const categoryTS = `import {defineField, defineType} from 'sanity'
272
266
 
273
- export default defineType({
267
+ export const categoryType = defineType({
274
268
  name: 'category',
275
- title: 'Category',
276
269
  type: 'document',
277
270
  fields: [
278
271
  defineField({
279
272
  name: 'title',
280
- title: 'Title',
281
273
  type: 'string',
282
274
  }),
283
275
  defineField({
284
276
  name: 'description',
285
- title: 'Description',
286
277
  type: 'text',
287
278
  }),
288
279
  ],
289
280
  })
290
281
  `
291
282
 
292
- const categoryJS = `export const category = {
283
+ const categoryJS = `export const categoryType = {
293
284
  name: 'category',
294
285
  title: 'Category',
295
286
  type: 'document',
296
287
  fields: [
297
288
  {
298
289
  name: 'title',
299
- title: 'Title',
300
290
  type: 'string',
301
291
  },
302
292
  {
303
293
  name: 'description',
304
- title: 'Description',
305
294
  type: 'text',
306
295
  },
307
296
  ],
@@ -310,19 +299,17 @@ const categoryJS = `export const category = {
310
299
 
311
300
  const postTS = `import {defineField, defineType} from 'sanity'
312
301
 
313
- export default defineType({
302
+ export const postType = defineType({
314
303
  name: 'post',
315
304
  title: 'Post',
316
305
  type: 'document',
317
306
  fields: [
318
307
  defineField({
319
308
  name: 'title',
320
- title: 'Title',
321
309
  type: 'string',
322
310
  }),
323
311
  defineField({
324
312
  name: 'slug',
325
- title: 'Slug',
326
313
  type: 'slug',
327
314
  options: {
328
315
  source: 'title',
@@ -331,13 +318,11 @@ export default defineType({
331
318
  }),
332
319
  defineField({
333
320
  name: 'author',
334
- title: 'Author',
335
321
  type: 'reference',
336
322
  to: {type: 'author'},
337
323
  }),
338
324
  defineField({
339
325
  name: 'mainImage',
340
- title: 'Main image',
341
326
  type: 'image',
342
327
  options: {
343
328
  hotspot: true,
@@ -346,28 +331,24 @@ export default defineType({
346
331
  {
347
332
  name: 'alt',
348
333
  type: 'string',
349
- title: 'Alternative Text',
334
+ title: 'Alternative text',
350
335
  }
351
336
  ]
352
337
  }),
353
338
  defineField({
354
339
  name: 'categories',
355
- title: 'Categories',
356
340
  type: 'array',
357
341
  of: [{type: 'reference', to: {type: 'category'}}],
358
342
  }),
359
343
  defineField({
360
344
  name: 'publishedAt',
361
- title: 'Published at',
362
345
  type: 'datetime',
363
346
  }),
364
347
  defineField({
365
348
  name: 'body',
366
- title: 'Body',
367
349
  type: 'blockContent',
368
350
  }),
369
351
  ],
370
-
371
352
  preview: {
372
353
  select: {
373
354
  title: 'title',
@@ -382,19 +363,17 @@ export default defineType({
382
363
  })
383
364
  `
384
365
 
385
- const postJS = `export const post = {
366
+ const postJS = `export const postType = {
386
367
  name: 'post',
387
368
  title: 'Post',
388
369
  type: 'document',
389
370
  fields: [
390
371
  {
391
372
  name: 'title',
392
- title: 'Title',
393
373
  type: 'string',
394
374
  },
395
375
  {
396
376
  name: 'slug',
397
- title: 'Slug',
398
377
  type: 'slug',
399
378
  options: {
400
379
  source: 'title',
@@ -403,13 +382,11 @@ const postJS = `export const post = {
403
382
  },
404
383
  {
405
384
  name: 'author',
406
- title: 'Author',
407
385
  type: 'reference',
408
386
  to: {type: 'author'},
409
387
  },
410
388
  {
411
389
  name: 'mainImage',
412
- title: 'Main image',
413
390
  type: 'image',
414
391
  options: {
415
392
  hotspot: true,
@@ -418,28 +395,24 @@ const postJS = `export const post = {
418
395
  {
419
396
  name: 'alt',
420
397
  type: 'string',
421
- title: 'Alternative Text',
398
+ title: 'Alternative text',
422
399
  }
423
400
  ]
424
401
  },
425
402
  {
426
403
  name: 'categories',
427
- title: 'Categories',
428
404
  type: 'array',
429
405
  of: [{type: 'reference', to: {type: 'category'}}],
430
406
  },
431
407
  {
432
408
  name: 'publishedAt',
433
- title: 'Published at',
434
409
  type: 'datetime',
435
410
  },
436
411
  {
437
412
  name: 'body',
438
- title: 'Body',
439
413
  type: 'blockContent',
440
414
  },
441
415
  ],
442
-
443
416
  preview: {
444
417
  select: {
445
418
  title: 'title',
@@ -458,31 +431,31 @@ const postJS = `export const post = {
458
431
 
459
432
  export const blogSchemaTS = `import { type SchemaTypeDefinition } from 'sanity'
460
433
 
461
- import blockContent from './schemaTypes/blockContent'
462
- import category from './schemaTypes/category'
463
- import post from './schemaTypes/post'
464
- import author from './schemaTypes/author'
434
+ import {blockContentType} from './schemaTypes/blockContentType'
435
+ import {categoryType} from './schemaTypes/categoryType'
436
+ import {postType} from './schemaTypes/postType'
437
+ import {authorType} from './schemaTypes/authorType'
465
438
 
466
439
  export const schema: { types: SchemaTypeDefinition[] } = {
467
- types: [post, author, category, blockContent],
440
+ types: [blockContentType, categoryType, postType, authorType],
468
441
  }
469
442
  `
470
443
 
471
- export const blogSchemaJS = `import {blockContent} from './schemaTypes/blockContent'
472
- import {category} from './schemaTypes/category'
473
- import {post} from './schemaTypes/post'
474
- import {author} from './schemaTypes/author'
444
+ export const blogSchemaJS = `import {blockContentType} from './schemaTypes/blockContentType'
445
+ import {categoryType} from './schemaTypes/categoryType'
446
+ import {postType} from './schemaTypes/postType'
447
+ import {authorType} from './schemaTypes/authorType'
475
448
 
476
449
  export const schema = {
477
- types: [post, author, category, blockContent],
450
+ types: [blockContentType, categoryType, postType, authorType],
478
451
  }
479
452
  `
480
453
 
481
454
  export const blogSchemaFolder = (useTypeScript: boolean): Record<string, string> => {
482
455
  return {
483
- 'author.': useTypeScript ? authorTS : authorJS,
484
- 'blockContent.': useTypeScript ? blockContentTS : blockContentJS,
485
- 'category.': useTypeScript ? categoryTS : categoryJS,
486
- 'post.': useTypeScript ? postTS : postJS,
456
+ 'authorType.': useTypeScript ? authorTS : authorJS,
457
+ 'blockContentType.': useTypeScript ? blockContentTS : blockContentJS,
458
+ 'categoryType.': useTypeScript ? categoryTS : categoryJS,
459
+ 'postType.': useTypeScript ? postTS : postJS,
487
460
  }
488
461
  }