@sanity/cli 3.59.2-canary.33 → 3.59.2-corel-presentation-lcapi.562

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.
Files changed (48) hide show
  1. package/lib/_chunks-cjs/cli.js +34360 -26058
  2. package/lib/_chunks-cjs/cli.js.map +1 -1
  3. package/lib/_chunks-cjs/cliWorker.js.map +1 -1
  4. package/lib/_chunks-cjs/generateAction.js.map +1 -1
  5. package/lib/_chunks-cjs/getCliConfig.js +1 -1
  6. package/lib/_chunks-cjs/getCliConfig.js.map +1 -1
  7. package/lib/_chunks-cjs/journeyConfig.js.map +1 -1
  8. package/lib/_chunks-cjs/loadEnv.js +200 -202
  9. package/lib/_chunks-cjs/loadEnv.js.map +1 -1
  10. package/lib/index.d.mts +37 -1
  11. package/lib/index.d.ts +37 -1
  12. package/lib/index.esm.js +223 -224
  13. package/lib/index.esm.js.map +1 -1
  14. package/lib/index.js.map +1 -1
  15. package/lib/index.mjs +223 -224
  16. package/lib/index.mjs.map +1 -1
  17. package/lib/workers/getCliConfig.js.map +1 -1
  18. package/lib/workers/typegenGenerate.js.map +1 -1
  19. package/package.json +17 -19
  20. package/src/CommandRunner.ts +1 -2
  21. package/src/actions/init-project/{bootstrapTemplate.ts → bootstrapLocalTemplate.ts} +8 -21
  22. package/src/actions/init-project/bootstrapRemoteTemplate.ts +118 -0
  23. package/src/actions/init-project/git.ts +2 -2
  24. package/src/actions/init-project/initProject.ts +158 -146
  25. package/src/actions/init-project/readPackageJson.ts +18 -0
  26. package/src/actions/init-project/templates/nextjs/index.ts +16 -0
  27. package/src/actions/init-project/templates/nextjs/schemaTypes/blog.ts +2 -2
  28. package/src/actions/init-project/updateInitialTemplateMetadata.ts +24 -0
  29. package/src/actions/login/login.ts +2 -3
  30. package/src/actions/versions/findSanityModuleVersions.ts +0 -1
  31. package/src/commands/index.ts +2 -2
  32. package/src/commands/init/initCommand.ts +7 -67
  33. package/src/commands/learn/learnCommand.ts +20 -0
  34. package/src/commands/logout/logoutCommand.ts +1 -1
  35. package/src/outputters/cliOutputter.ts +21 -8
  36. package/src/studioDependencies.ts +1 -1
  37. package/src/types.ts +41 -1
  38. package/src/util/frameworkPort.ts +63 -0
  39. package/src/util/generateCommandsDocumentation.ts +7 -4
  40. package/src/util/getCliConfig.ts +1 -1
  41. package/src/util/getProviderName.ts +9 -0
  42. package/src/util/remoteTemplate.ts +320 -0
  43. package/templates/get-started/plugins/sanity-plugin-tutorial/GetStartedTutorial.tsx +4 -4
  44. package/src/actions/init-plugin/initPlugin.ts +0 -119
  45. package/src/actions/init-plugin/pluginTemplates.ts +0 -38
  46. package/src/actions/init-project/reconfigureV2Project.ts +0 -446
  47. package/src/commands/upgrade/upgradeCommand.ts +0 -38
  48. package/src/commands/upgrade/upgradeDependencies.ts +0 -289
@@ -5,6 +5,7 @@ import docsCommand from './docs/docsCommand'
5
5
  import helpCommand from './help/helpCommand'
6
6
  import initCommand from './init/initCommand'
7
7
  import installCommand from './install/installCommand'
8
+ import learnCommand from './learn/learnCommand'
8
9
  import loginCommand from './login/loginCommand'
9
10
  import logoutCommand from './logout/logoutCommand'
10
11
  import manageCommand from './manage/manageCommand'
@@ -16,7 +17,6 @@ import telemetryGroup from './telemetry/telemetryGroup'
16
17
  import telemetryStatusCommand from './telemetry/telemetryStatusCommand'
17
18
  import generateTypegenCommand from './typegen/generateTypesCommand'
18
19
  import typegenGroup from './typegen/typegenGroup'
19
- import upgradeCommand from './upgrade/upgradeCommand'
20
20
  import versionsCommand from './versions/versionsCommand'
21
21
 
22
22
  export const baseCommands: (CliCommandDefinition | CliCommandGroupDefinition)[] = [
@@ -24,13 +24,13 @@ export const baseCommands: (CliCommandDefinition | CliCommandGroupDefinition)[]
24
24
  loginCommand,
25
25
  logoutCommand,
26
26
  installCommand,
27
- upgradeCommand,
28
27
  versionsCommand,
29
28
  docsCommand,
30
29
  manageCommand,
31
30
  debugCommand,
32
31
  helpCommand,
33
32
  projectsGroup,
33
+ learnCommand,
34
34
  listProjectsCommand,
35
35
  codemodCommand,
36
36
  telemetryGroup,
@@ -1,7 +1,6 @@
1
1
  import {type Framework, frameworks} from '@vercel/frameworks'
2
2
  import {detectFrameworkRecord, LocalFileSystemDetector} from '@vercel/fs-detectors'
3
3
 
4
- import initPlugin from '../../actions/init-plugin/initPlugin'
5
4
  import initProject from '../../actions/init-project/initProject'
6
5
  import {
7
6
  allowedPackageManagersString,
@@ -58,6 +57,11 @@ export interface InitFlags {
58
57
  'project'?: string
59
58
  'dataset'?: string
60
59
  'template'?: string
60
+ /**
61
+ * Used for accessing private GitHub repo templates
62
+ * @beta
63
+ */
64
+ 'template-token'?: string
61
65
 
62
66
  'visibility'?: string
63
67
  'typescript'?: boolean
@@ -97,87 +101,23 @@ export const initCommand: CliCommandDefinition<InitFlags> = {
97
101
  description: 'Initializes a new Sanity Studio and/or project',
98
102
  helpText,
99
103
  action: async (args, context) => {
100
- const {output, chalk, prompt} = context
104
+ const {output, chalk} = context
101
105
  const [type] = args.argsWithoutOptions
102
- const unattended = args.extOptions.y || args.extOptions.yes
103
-
104
- const warn = (msg: string) => output.warn(chalk.yellow.bgBlack(msg))
105
-
106
- // `sanity init plugin`
107
- if (type === 'plugin') {
108
- return context.sanityMajorVersion === 2
109
- ? // don't bother with telemetry here, as it's not supported in v3
110
- initPlugin(args, context)
111
- : Promise.reject(new Error(`'sanity init plugin' is not available in modern studios`))
112
- }
113
106
 
114
107
  // `sanity init whatever`
115
108
  if (type) {
116
109
  return Promise.reject(new Error(`Unknown init type "${type}"`))
117
110
  }
118
111
 
119
- // `npm create sanity` (regular v3 init)
120
-
121
112
  const detectedFramework: Framework | null = await detectFrameworkRecord({
122
113
  fs: new LocalFileSystemDetector(process.cwd()),
123
114
  frameworkList: frameworks as readonly Framework[],
124
115
  })
125
116
 
126
- if (
127
- args.argv.includes('--from-create') ||
128
- args.argv.includes('--env') ||
129
- args.argv.includes('--bare') ||
130
- detectedFramework?.slug === 'nextjs'
131
- ) {
132
- return initProject(args, {
133
- ...context,
134
- detectedFramework,
135
- })
136
- }
137
-
138
- // `sanity init` (v2 style)
139
- warn('╭────────────────────────────────────────────────────────────╮')
140
- warn('│ │')
141
- warn("│ Welcome to Sanity! It looks like you're following │")
142
- warn('│ instructions for Sanity Studio v2, but the version you │')
143
- warn('│ have installed is the latest - Sanity Studio v3. │')
144
- warn('│ │')
145
- warn('│ In Sanity Studio v3, new projects are created by running │')
146
- warn('│ [npm create sanity@latest]. For more information, see │')
147
- warn('│ https://www.sanity.io/help/studio-v2-vs-v3 │')
148
- warn('│ │')
149
- warn('╰────────────────────────────────────────────────────────────╯')
150
- warn('') // Newline to separate from other output
151
- const continueV3Init = unattended
152
- ? true
153
- : await prompt.single({
154
- message: 'Continue creating a Sanity Studio v3 project?',
155
- type: 'confirm',
156
- })
157
-
158
- // Fall back
159
- if (!continueV3Init) {
160
- // Indicate that the operation did not succeed as expected
161
- // eslint-disable-next-line no-process-exit
162
- process.exit(1)
163
- }
164
-
165
- const returnVal = await initProject(args, {
117
+ return initProject(args, {
166
118
  ...context,
167
119
  detectedFramework,
168
- }).catch((err) => {
169
- return Promise.reject(err)
170
120
  })
171
-
172
- warn('╭────────────────────────────────────────────────────────────╮')
173
- warn('│ │')
174
- warn('│ To learn how commands have changed from Studio v2 to v3, │')
175
- warn('│ see https://www.sanity.io/help/studio-v2-vs-v3 │')
176
- warn('│ │')
177
- warn('╰────────────────────────────────────────────────────────────╯')
178
- warn('') // Newline to separate from other output
179
-
180
- return returnVal
181
121
  },
182
122
  }
183
123
 
@@ -0,0 +1,20 @@
1
+ import open from 'open'
2
+
3
+ import {type CliCommandDefinition} from '../../types'
4
+
5
+ const learnCommand: CliCommandDefinition = {
6
+ name: 'learn',
7
+ helpText: '',
8
+ signature: 'learn',
9
+ description: 'Opens Sanity Learn in your web browser',
10
+ async action(args, context) {
11
+ const {output} = context
12
+ const {print} = output
13
+ const url = 'https://www.sanity.io/learn'
14
+
15
+ print(`Opening ${url}`)
16
+ await open(url)
17
+ },
18
+ }
19
+
20
+ export default learnCommand
@@ -45,7 +45,7 @@ const logoutCommand: CliCommandDefinition = {
45
45
  // Clear cached telemetry consent
46
46
  cfg.delete(TELEMETRY_CONSENT_CONFIG_KEY)
47
47
 
48
- output.print(chalk.green('Logged out'))
48
+ output.success('Logged out')
49
49
  },
50
50
  }
51
51
 
@@ -2,6 +2,10 @@
2
2
  import chalk from 'chalk'
3
3
  import ora, {type Options, type Ora} from 'ora'
4
4
 
5
+ const SYMBOL_CHECK = chalk.green('✓')
6
+ const SYMBOL_WARN = chalk.yellow('⚠')
7
+ const SYMBOL_FAIL = chalk.red('✗')
8
+
5
9
  let isFirstClear = true
6
10
 
7
11
  export default {
@@ -9,15 +13,19 @@ export default {
9
13
  console.log(...args)
10
14
  },
11
15
 
12
- warn(...args: unknown[]): void {
13
- console.warn(...args)
16
+ success(firstPartOfMessage: unknown, ...args: unknown[]): void {
17
+ console.log(`${SYMBOL_CHECK} ${firstPartOfMessage}`, ...args)
18
+ },
19
+
20
+ warn(firstPartOfMessage: unknown, ...args: unknown[]): void {
21
+ console.warn(`${SYMBOL_WARN} ${firstPartOfMessage}`, ...args)
14
22
  },
15
23
 
16
- error(...args: unknown[]): void {
17
- if (args[0] instanceof Error) {
18
- console.error(chalk.red(args[0].stack))
24
+ error(firstPartOfMessage: unknown, ...args: unknown[]): void {
25
+ if (firstPartOfMessage instanceof Error) {
26
+ console.error(`${SYMBOL_FAIL} ${chalk.red(firstPartOfMessage.stack)}`)
19
27
  } else {
20
- console.error(...args)
28
+ console.error(`${SYMBOL_FAIL} ${firstPartOfMessage}`, ...args)
21
29
  }
22
30
  },
23
31
 
@@ -28,7 +36,12 @@ export default {
28
36
  isFirstClear = false
29
37
  },
30
38
 
31
- spinner(options: Options | string): Ora {
32
- return ora(options)
39
+ spinner(options: Options): Ora {
40
+ const spinner = ora(options)
41
+ // Override the default status methods to use custom symbols instead of emojis
42
+ spinner.succeed = (text?: string) => spinner.stopAndPersist({text, symbol: SYMBOL_CHECK})
43
+ spinner.warn = (text?: string) => spinner.stopAndPersist({text, symbol: SYMBOL_WARN})
44
+ spinner.fail = (text?: string) => spinner.stopAndPersist({text, symbol: SYMBOL_FAIL})
45
+ return spinner
33
46
  },
34
47
  }
@@ -18,7 +18,7 @@ export const studioDependencies = {
18
18
  '@sanity/eslint-config-studio': 'latest',
19
19
  // When using typescript, we'll want the these types too, so might as well install them
20
20
  '@types/react': '^18.0.25',
21
- 'eslint': '^8.6.0',
21
+ 'eslint': '^9.9.0',
22
22
  'prettier': '^3.0.2',
23
23
  'typescript': '^5.1.6', // Peer dependency of eslint-config-studio (implicitly)
24
24
  },
package/src/types.ts CHANGED
@@ -82,7 +82,6 @@ export interface CliBaseCommandContext {
82
82
  output: CliOutputter
83
83
  prompt: CliPrompter
84
84
  apiClient: CliApiClient
85
- yarn: CliStubbedYarn
86
85
  sanityMajorVersion: 2 | 3
87
86
  cliConfigPath?: string
88
87
  cliRoot: string
@@ -151,6 +150,7 @@ export interface CommandRunnerOptions {
151
150
 
152
151
  export interface CliOutputter {
153
152
  print: (...args: unknown[]) => void
153
+ success: (...args: unknown[]) => void
154
154
  warn: (...args: unknown[]) => void
155
155
  error: (...args: unknown[]) => void
156
156
  clear: () => void
@@ -286,6 +286,30 @@ export interface GraphQLAPIConfig {
286
286
  filterSuffix?: string
287
287
  }
288
288
 
289
+ /**
290
+ * Until these types are on npm: https://github.com/facebook/react/blob/0bc30748730063e561d87a24a4617526fdd38349/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Options.ts#L39-L122
291
+ * @beta
292
+ */
293
+ export interface ReactCompilerConfig {
294
+ /**
295
+ * @see https://react.dev/learn/react-compiler#existing-projects
296
+ */
297
+ sources?: Array<string> | ((filename: string) => boolean) | null
298
+
299
+ /**
300
+ * The minimum major version of React that the compiler should emit code for. If the target is 19
301
+ * or higher, the compiler emits direct imports of React runtime APIs needed by the compiler. On
302
+ * versions prior to 19, an extra runtime package react-compiler-runtime is necessary to provide
303
+ * a userspace approximation of runtime APIs.
304
+ * @see https://react.dev/learn/react-compiler#using-react-compiler-with-react-17-or-18
305
+ */
306
+ target: '18' | '19'
307
+
308
+ panicThreshold?: 'ALL_ERRORS' | 'CRITICAL_ERRORS' | 'NONE'
309
+
310
+ compilationMode?: 'infer' | 'syntax' | 'annotation' | 'all'
311
+ }
312
+
289
313
  export interface CliConfig {
290
314
  api?: CliApiConfig
291
315
 
@@ -301,6 +325,13 @@ export interface CliConfig {
301
325
  */
302
326
  reactStrictMode?: boolean
303
327
 
328
+ /**
329
+ * The React Compiler is currently in beta, and is disabled by default.
330
+ * @see https://react.dev/learn/react-compiler
331
+ * @beta
332
+ */
333
+ reactCompiler?: ReactCompilerConfig
334
+
304
335
  server?: {
305
336
  hostname?: string
306
337
  port?: number
@@ -318,3 +349,12 @@ export interface CliConfig {
318
349
  export type UserViteConfig =
319
350
  | InlineConfig
320
351
  | ((config: InlineConfig, env: ConfigEnv) => InlineConfig | Promise<InlineConfig>)
352
+
353
+ export type SanityUser = {
354
+ id: string
355
+ name: string
356
+ email: string
357
+ profileImage?: string
358
+ tosAcceptedAt?: string
359
+ provider: 'google' | 'github' | 'sanity' | `saml-${string}`
360
+ }
@@ -0,0 +1,63 @@
1
+ const FALLBACK_PORT = 3000
2
+
3
+ const portMap: Record<string, number> = {
4
+ 'nextjs': 3000,
5
+ 'blitzjs': 3000,
6
+ 'gatsby': 8000,
7
+ 'remix': 3000,
8
+ 'astro': 3000,
9
+ 'hexo': 4000,
10
+ 'eleventy': 8080,
11
+ 'docusaurus': 3000,
12
+ 'docusaurus-2': 3000,
13
+ 'preact': 8080,
14
+ 'solidstart': 3000,
15
+ 'solidstart-1': 3000,
16
+ 'dojo': 3000,
17
+ 'ember': 4200,
18
+ 'vue': 8080,
19
+ 'scully': 1668,
20
+ 'ionic-angular': 4200,
21
+ 'angular': 4200,
22
+ 'polymer': 8081,
23
+ 'svelte': 5000,
24
+ 'sveltekit': 5173,
25
+ 'sveltekit-1': 5173,
26
+ 'ionic-react': 3000,
27
+ 'create-react-app': 3000,
28
+ 'gridsome': 8080,
29
+ 'umijs': 8000,
30
+ 'saber': 3000,
31
+ 'stencil': 3333,
32
+ 'nuxtjs': 3000,
33
+ 'redwoodjs': 8910,
34
+ 'hugo': 1313,
35
+ 'jekyll': 4000,
36
+ 'brunch': 3333,
37
+ 'middleman': 4567,
38
+ 'zola': 1111,
39
+ 'hydrogen': 3000,
40
+ 'vite': 5173,
41
+ 'vitepress': 5173,
42
+ 'vuepress': 8080,
43
+ 'parcel': 1234,
44
+ 'fasthtml': 8000,
45
+ 'sanity': 3333,
46
+ 'sanity-v3': 3333,
47
+ 'storybook': 6006,
48
+ }
49
+
50
+ /**
51
+ * Returns the default development port for a given framework.
52
+ * Contains default ports for all frameworks supported by `@vercel/frameworks`.
53
+ * Falls back to port 3000 if framework is not found or not specified.
54
+ *
55
+ * @see https://github.com/vercel/vercel/blob/main/packages/frameworks/src/frameworks.ts
56
+ * for the complete list of supported frameworks
57
+ *
58
+ * @param frameworkSlug - The framework identifier from `@vercel/frameworks`
59
+ * @returns The default port number for the framework
60
+ */
61
+ export function getDefaultPortForFramework(frameworkSlug?: string | null): number {
62
+ return portMap[frameworkSlug ?? ''] ?? FALLBACK_PORT
63
+ }
@@ -22,12 +22,15 @@ export function generateCommandsDocumentation(
22
22
  const prefix = group === 'default' ? '' : ` ${group}`
23
23
 
24
24
  const rows = [
25
- `usage: sanity${prefix} [--default] [-v|--version] [-d|--debug] [-h|--help] <command> [<args>]`,
25
+ `usage: npx sanity${prefix} [--default] [-v|--version] [-d|--debug] [-h|--help] <command> [<args>]`,
26
26
  '',
27
27
  'Commands:',
28
28
  ]
29
29
  .concat(commands.map((cmd) => ` ${padEnd(cmd.name, cmdLength + 1)} ${cmd.description}`))
30
- .concat(['', `See 'sanity help${prefix} <command>' for specific information on a subcommand.`])
30
+ .concat([
31
+ '',
32
+ `See 'npx sanity help${prefix} <command>' for specific information on a subcommand.`,
33
+ ])
31
34
 
32
35
  return rows.join('\n')
33
36
  }
@@ -43,14 +46,14 @@ export function generateCommandDocumentation(
43
46
  if (!command) {
44
47
  throw new Error(
45
48
  subCommand
46
- ? `"${subCommand}" is not a subcommand of "${group}". See 'sanity help ${group}'`
49
+ ? `"${subCommand}" is not a subcommand of "${group}". See 'npx sanity help ${group}'`
47
50
  : getNoSuchCommandText(group || command),
48
51
  )
49
52
  }
50
53
 
51
54
  const cmdParts = [group || command.name, subCommand].filter(Boolean).join(' ')
52
55
  return [
53
- `usage: sanity ${cmdParts} ${command.signature}`,
56
+ `usage: npx sanity ${cmdParts} ${command.signature}`,
54
57
  '',
55
58
  ` ${command.description}`,
56
59
  '',
@@ -42,7 +42,7 @@ export async function getCliConfig(
42
42
 
43
43
  const {unregister} = __DEV__
44
44
  ? {unregister: () => undefined}
45
- : require('esbuild-register/dist/node').register()
45
+ : require('esbuild-register/dist/node').register({supported: {'dynamic-import': true}})
46
46
 
47
47
  try {
48
48
  const v3Config = getSanityCliConfig(cwd)
@@ -0,0 +1,9 @@
1
+ import {type SanityUser} from '../types'
2
+
3
+ export function getProviderName(provider: SanityUser['provider']) {
4
+ if (provider === 'google') return 'Google'
5
+ if (provider === 'github') return 'GitHub'
6
+ if (provider === 'sanity') return 'Email'
7
+ if (provider.startsWith('saml-')) return 'SAML'
8
+ return provider
9
+ }