@sanity/cli 3.42.2-canary.47 → 3.42.2-sdx-1339.35

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.42.2-canary.47+efe8bcae60",
3
+ "version": "3.42.2-sdx-1339.35+b5d66f5409",
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-canary.47+efe8bcae60",
61
+ "@sanity/codegen": "3.42.2-sdx-1339.35+b5d66f5409",
62
62
  "@sanity/telemetry": "^0.7.6",
63
- "@sanity/util": "3.42.2-canary.47+efe8bcae60",
63
+ "@sanity/util": "3.42.2-sdx-1339.35+b5d66f5409",
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.42.2-canary.47+efe8bcae60",
85
+ "@sanity/types": "3.42.2-sdx-1339.35+b5d66f5409",
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": "efe8bcae60fd92c1624252e05811dfd85f3474c1"
138
+ "gitHead": "b5d66f54090988707b1bc08be39fb13b0d094168"
139
139
  }
@@ -48,6 +48,7 @@ import {tryGitInit} from './git'
48
48
  import {promptForDatasetName} from './promptForDatasetName'
49
49
  import {promptForAclMode, promptForDefaultConfig, promptForTypeScript} from './prompts'
50
50
  import {
51
+ promptForAppDir,
51
52
  promptForAppendEnv,
52
53
  promptForEmbeddedStudio,
53
54
  promptForNextTemplate,
@@ -59,7 +60,8 @@ import {
59
60
  sanityCliTemplate,
60
61
  sanityConfigTemplate,
61
62
  sanityFolder,
62
- sanityStudioTemplate,
63
+ sanityStudioAppTemplate,
64
+ sanityStudioPagesTemplate,
63
65
  } from './templates/nextjs'
64
66
 
65
67
  // eslint-disable-next-line no-process-env
@@ -328,8 +330,12 @@ export default async function initSanity(
328
330
  const embeddedStudio = unattended ? true : await promptForEmbeddedStudio(prompt)
329
331
 
330
332
  if (embeddedStudio) {
331
- // find source path (app or src/app)
332
- const srcDir = 'app'
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'
333
339
  let srcPath = path.join(workDir, srcDir)
334
340
 
335
341
  if (!existsSync(srcPath)) {
@@ -346,7 +352,7 @@ export default async function initSanity(
346
352
  const embeddedStudioRouteFilePath = path.join(
347
353
  srcPath,
348
354
  `${studioPath}/`,
349
- `[[...tool]]/page.${fileExtension}x`,
355
+ useAppDir ? `[[...index]]/page.${fileExtension}x` : `[[...index]].${fileExtension}x`,
350
356
  )
351
357
 
352
358
  // this selects the correct template string based on whether the user is using the app or pages directory and
@@ -355,7 +361,7 @@ export default async function initSanity(
355
361
  // relative paths to reach the root level of the project
356
362
  await writeOrOverwrite(
357
363
  embeddedStudioRouteFilePath,
358
- sanityStudioTemplate.replace(
364
+ (useAppDir ? sanityStudioAppTemplate : sanityStudioPagesTemplate).replace(
359
365
  ':configPath:',
360
366
  new Array(countNestedFolders(embeddedStudioRouteFilePath.slice(workDir.length)))
361
367
  .join('../')
@@ -445,11 +451,11 @@ export default async function initSanity(
445
451
  }
446
452
 
447
453
  if (chosen === 'npm') {
448
- await execa('npm', ['install', 'next-sanity@9'], execOptions)
454
+ await execa('npm', ['install', 'next-sanity@7'], execOptions)
449
455
  } else if (chosen === 'yarn') {
450
- await execa('npx', ['install-peerdeps', '--yarn', 'next-sanity@9'], execOptions)
456
+ await execa('npx', ['install-peerdeps', '--yarn', 'next-sanity@7'], execOptions)
451
457
  } else if (chosen === 'pnpm') {
452
- await execa('pnpm', ['install', 'next-sanity@9'], execOptions)
458
+ await execa('pnpm', ['install', 'next-sanity@7'], execOptions)
453
459
  }
454
460
 
455
461
  print(
@@ -8,6 +8,14 @@ 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
+
11
19
  export function promptForStudioPath(prompt: CliPrompter): Promise<string> {
12
20
  return prompt.single({
13
21
  type: 'input',
@@ -1,8 +1,6 @@
1
1
  import {blogSchemaFolder, blogSchemaJS, blogSchemaTS} from './schemaTypes/blog'
2
2
 
3
- export const sanityConfigTemplate = `'use client'
4
-
5
- /**
3
+ export const sanityConfigTemplate = `/**
6
4
  * This configuration is used to for the Sanity Studio that’s mounted on the \`:route:\` route
7
5
  */
8
6
 
@@ -41,7 +39,27 @@ const dataset = process.env.NEXT_PUBLIC_SANITY_DATASET
41
39
  export default defineCliConfig({ api: { projectId, dataset } })
42
40
  `
43
41
 
44
- export const sanityStudioTemplate = `/**
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
+ /**
45
63
  * This route is responsible for the built-in authoring environment using Sanity Studio.
46
64
  * All routes under your studio path is handled by this file using Next.js' catch-all routes:
47
65
  * https://nextjs.org/docs/routing/dynamic-routes#catch-all-routes
@@ -53,14 +71,12 @@ export const sanityStudioTemplate = `/**
53
71
  import { NextStudio } from 'next-sanity/studio'
54
72
  import config from ':configPath:'
55
73
 
56
- export const dynamic = 'force-static'
57
-
58
- export { metadata, viewport } from 'next-sanity/studio'
59
-
60
74
  export default function StudioPage() {
61
75
  return <NextStudio config={config} />
62
76
  }`
63
77
 
78
+ export const sanityStudioAppLayoutTemplate = `export {metadata} from 'next-sanity/studio'`
79
+
64
80
  // Format today's date like YYYY-MM-DD
65
81
  const envTS = `export const apiVersion =
66
82
  process.env.NEXT_PUBLIC_SANITY_API_VERSION || '${new Date().toISOString().split('T')[0]}'
@@ -111,11 +127,10 @@ const client = `import { createClient } from 'next-sanity'
111
127
  import { apiVersion, dataset, projectId, useCdn } from '../env'
112
128
 
113
129
  export const client = createClient({
114
- projectId,
115
- dataset,
116
130
  apiVersion,
131
+ dataset,
132
+ projectId,
117
133
  useCdn,
118
- perspective: 'published',
119
134
  })
120
135
  `
121
136