@sanity/cli 3.77.3-server-side-schemas.26 → 3.77.3-server-side-schemas.36

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 (32) hide show
  1. package/bin/xdg-open +1066 -0
  2. package/lib/_chunks-cjs/cli.js +384 -195
  3. package/lib/_chunks-cjs/cli.js.map +1 -1
  4. package/lib/_chunks-cjs/loadEnv.js +5 -5
  5. package/lib/_chunks-cjs/loadEnv.js.map +1 -1
  6. package/lib/index.d.mts +2 -3
  7. package/lib/index.d.ts +2 -3
  8. package/lib/index.esm.js +5 -5
  9. package/lib/index.esm.js.map +1 -1
  10. package/lib/index.mjs +5 -5
  11. package/lib/index.mjs.map +1 -1
  12. package/package.json +12 -11
  13. package/src/actions/init-project/bootstrapLocalTemplate.ts +10 -10
  14. package/src/actions/init-project/{createCoreAppCliConfig.ts → createAppCliConfig.ts} +4 -4
  15. package/src/actions/init-project/{determineCoreAppTemplate.ts → determineAppTemplate.ts} +3 -3
  16. package/src/actions/init-project/initProject.ts +125 -48
  17. package/src/actions/init-project/templates/{coreApp.ts → appQuickstart.ts} +7 -8
  18. package/src/actions/init-project/templates/index.ts +2 -2
  19. package/src/cli.ts +4 -14
  20. package/src/commands/functions/devFunctionsCommand.ts +42 -0
  21. package/src/commands/functions/functionsGroup.ts +11 -0
  22. package/src/commands/functions/logsFunctionsCommand.ts +46 -0
  23. package/src/commands/functions/testFunctionsCommand.ts +62 -0
  24. package/src/commands/index.ts +8 -0
  25. package/src/commands/init/initCommand.ts +0 -1
  26. package/src/types.ts +2 -3
  27. package/src/util/clientWrapper.ts +1 -1
  28. package/src/util/resolveRootDir.ts +5 -5
  29. package/templates/core-app/src/App.css +18 -0
  30. package/templates/core-app/src/App.tsx +15 -17
  31. package/templates/core-app/src/ExampleComponent.css +26 -0
  32. package/templates/core-app/src/ExampleComponent.tsx +15 -4
@@ -1,9 +1,9 @@
1
1
  import {type ProjectTemplate} from '../initProject'
2
2
 
3
- const coreAppTemplate: ProjectTemplate = {
3
+ const appTemplate: ProjectTemplate = {
4
4
  dependencies: {
5
- '@sanity/sdk': '^0.0.0-alpha',
6
- '@sanity/sdk-react': '^0.0.0-alpha',
5
+ '@sanity/sdk': '^0.0.0-rc',
6
+ '@sanity/sdk-react': '^0.0.0-rc',
7
7
  'react': '^19',
8
8
  'react-dom': '^19',
9
9
  },
@@ -21,11 +21,10 @@ const coreAppTemplate: ProjectTemplate = {
21
21
  },
22
22
  appLocation: './src/App.tsx',
23
23
  scripts: {
24
- // this will eventually run a concurrently process with another in-flight utility
25
- dev: 'sanity app dev',
26
- build: 'sanity app build',
27
- start: 'sanity app start',
24
+ dev: 'sanity dev',
25
+ build: 'sanity build',
26
+ start: 'sanity start',
28
27
  },
29
28
  }
30
29
 
31
- export default coreAppTemplate
30
+ export default appTemplate
@@ -1,7 +1,7 @@
1
1
  import {type ProjectTemplate} from '../initProject'
2
+ import appTemplate from './appQuickstart'
2
3
  import blog from './blog'
3
4
  import clean from './clean'
4
- import coreAppTemplate from './coreApp'
5
5
  import getStartedTemplate from './getStarted'
6
6
  import moviedb from './moviedb'
7
7
  import quickstart from './quickstart'
@@ -11,7 +11,7 @@ import shopifyOnline from './shopifyOnline'
11
11
  const templates: Record<string, ProjectTemplate | undefined> = {
12
12
  blog,
13
13
  clean,
14
- 'core-app': coreAppTemplate,
14
+ 'app-quickstart': appTemplate,
15
15
  'get-started': getStartedTemplate,
16
16
  moviedb,
17
17
  shopify,
package/src/cli.ts CHANGED
@@ -47,17 +47,16 @@ export async function runCli(cliRoot: string, {cliVersion}: {cliVersion: string}
47
47
 
48
48
  const args = parseArguments()
49
49
  const isInit = args.groupOrCommand === 'init' && args.argsWithoutOptions[0] !== 'plugin'
50
- const isCoreApp = args.groupOrCommand === 'app'
51
50
  const cwd = getCurrentWorkingDirectory()
52
51
  let workDir: string | undefined
53
52
  try {
54
- workDir = isInit ? process.cwd() : resolveRootDir(cwd, isCoreApp)
53
+ workDir = isInit ? process.cwd() : resolveRootDir(cwd)
55
54
  } catch (err) {
56
55
  console.error(chalk.red(err.message))
57
56
  process.exit(1)
58
57
  }
59
58
 
60
- loadAndSetEnvFromDotEnvFiles({workDir, cmd: args.groupOrCommand, isCoreApp})
59
+ loadAndSetEnvFromDotEnvFiles({workDir, cmd: args.groupOrCommand})
61
60
  maybeFixMissingWindowsEnvVar()
62
61
 
63
62
  // Check if there are updates available for the CLI, and notify if there is
@@ -100,7 +99,6 @@ export async function runCli(cliRoot: string, {cliVersion}: {cliVersion: string}
100
99
  corePath: await getCoreModulePath(workDir, cliConfig),
101
100
  cliConfig,
102
101
  telemetry,
103
- isCoreApp,
104
102
  }
105
103
 
106
104
  warnOnNonProductionEnvironment()
@@ -276,15 +274,7 @@ function warnOnNonProductionEnvironment(): void {
276
274
  )
277
275
  }
278
276
 
279
- function loadAndSetEnvFromDotEnvFiles({
280
- workDir,
281
- cmd,
282
- isCoreApp,
283
- }: {
284
- workDir: string
285
- cmd: string
286
- isCoreApp: boolean
287
- }) {
277
+ function loadAndSetEnvFromDotEnvFiles({workDir, cmd}: {workDir: string; cmd: string}) {
288
278
  /* eslint-disable no-process-env */
289
279
 
290
280
  // Do a cheap lookup for a sanity.json file. If there is one, assume it is a v2 project,
@@ -319,7 +309,7 @@ function loadAndSetEnvFromDotEnvFiles({
319
309
 
320
310
  debug('Loading environment files using %s mode', mode)
321
311
 
322
- const studioEnv = loadEnv(mode, workDir, isCoreApp ? ['VITE_'] : ['SANITY_STUDIO_'])
312
+ const studioEnv = loadEnv(mode, workDir, ['SANITY_STUDIO_'])
323
313
  process.env = {...process.env, ...studioEnv}
324
314
  /* eslint-disable no-process-env */
325
315
  }
@@ -0,0 +1,42 @@
1
+ import open from 'open'
2
+
3
+ import {type CliCommandDefinition} from '../../types'
4
+
5
+ const helpText = `
6
+ Options
7
+ --port <port> Port to start emulator on
8
+
9
+ Examples
10
+ # Start dev server on default port
11
+ sanity functions dev
12
+
13
+ # Start dev server on specific port
14
+ sanity functions dev --port 3333
15
+ `
16
+
17
+ const defaultFlags = {
18
+ port: 8080,
19
+ }
20
+
21
+ const devFunctionsCommand: CliCommandDefinition = {
22
+ name: 'dev',
23
+ group: 'functions',
24
+ helpText,
25
+ signature: '',
26
+ description: 'Start the Sanity Function emulator',
27
+ hideFromHelp: true,
28
+ async action(args, context) {
29
+ const {output} = context
30
+ const {print} = output
31
+ const flags = {...defaultFlags, ...args.extOptions}
32
+
33
+ const {devAction} = await import('@sanity/runtime-cli')
34
+
35
+ devAction(flags.port)
36
+
37
+ print(`Server is running on port ${flags.port}\n`)
38
+ open(`http://localhost:${flags.port}`)
39
+ },
40
+ }
41
+
42
+ export default devFunctionsCommand
@@ -0,0 +1,11 @@
1
+ import {type CliCommandGroupDefinition} from '../../types'
2
+
3
+ const functionsGroup: CliCommandGroupDefinition = {
4
+ name: 'functions',
5
+ signature: '[COMMAND]',
6
+ isGroupRoot: true,
7
+ description: 'Test Sanity Functions locally and retrieve logs',
8
+ hideFromHelp: true,
9
+ }
10
+
11
+ export default functionsGroup
@@ -0,0 +1,46 @@
1
+ import {type CliCommandDefinition} from '../../types'
2
+
3
+ const helpText = `
4
+ Options
5
+ --id <id> The ID of the function to retrieve logs for
6
+
7
+ Examples
8
+ # Retrieve logs for Sanity Function abcd1234
9
+ sanity functions logs --id abcd1234
10
+ `
11
+
12
+ const defaultFlags = {
13
+ id: undefined,
14
+ }
15
+
16
+ const logsFunctionsCommand: CliCommandDefinition = {
17
+ name: 'logs',
18
+ group: 'functions',
19
+ helpText,
20
+ signature: '',
21
+ description: 'Retrieve logs for a Sanity Function',
22
+ hideFromHelp: true,
23
+ async action(args, context) {
24
+ const {apiClient, output} = context
25
+ const {print} = output
26
+ const flags = {...defaultFlags, ...args.extOptions}
27
+
28
+ const client = apiClient({
29
+ requireUser: true,
30
+ requireProject: false,
31
+ })
32
+
33
+ if (flags.id) {
34
+ const token = client.config().token
35
+ if (token) {
36
+ const {logsAction} = await import('@sanity/runtime-cli')
37
+ const result = await logsAction(flags.id, token)
38
+ print(JSON.stringify(result, null, 2))
39
+ }
40
+ } else {
41
+ print('You must provide a function ID')
42
+ }
43
+ },
44
+ }
45
+
46
+ export default logsFunctionsCommand
@@ -0,0 +1,62 @@
1
+ import {type CliCommandDefinition} from '../../types'
2
+
3
+ const helpText = `
4
+ Options
5
+ --data <data> Data to send to the function
6
+ --file <file> Read data from file and send to the function
7
+ --path <path> Path to your Sanity Function code
8
+ --timeout <timeout> Execution timeout value in seconds
9
+
10
+ Examples
11
+ # Test function passing event data on command line
12
+ sanity functions test --path ./test.ts --data '{ "id": 1 }'
13
+
14
+ # Test function passing event data via a file
15
+ sanity functions test -path ./test.js --file 'payload.json'
16
+
17
+ # Test function passing event data on command line and cap execution time to 60 seconds
18
+ sanity functions test -path ./test.ts --data '{ "id": 1 }' --timeout 60
19
+ `
20
+
21
+ const defaultFlags = {
22
+ data: undefined,
23
+ file: undefined,
24
+ path: undefined,
25
+ timeout: 5, // seconds
26
+ }
27
+
28
+ const testFunctionsCommand: CliCommandDefinition = {
29
+ name: 'test',
30
+ group: 'functions',
31
+ helpText,
32
+ signature: '',
33
+ description: 'Invoke a local Sanity Function',
34
+ hideFromHelp: true,
35
+ async action(args, context) {
36
+ const {output} = context
37
+ const {print} = output
38
+ const flags = {...defaultFlags, ...args.extOptions}
39
+
40
+ if (flags.path) {
41
+ const {testAction} = await import('@sanity/runtime-cli')
42
+ const {json, logs, error} = await testAction(flags.path, {
43
+ data: flags.data,
44
+ file: flags.file,
45
+ timeout: flags.timeout,
46
+ })
47
+
48
+ if (error) {
49
+ print(error.toString())
50
+ } else {
51
+ print('Logs:')
52
+ print(logs)
53
+ print('Response:')
54
+ print(JSON.stringify(json, null, 2))
55
+ }
56
+ } else {
57
+ print('You must provide a path to the Sanity Function code')
58
+ }
59
+ },
60
+ }
61
+
62
+ export default testFunctionsCommand
@@ -2,6 +2,10 @@ import {type CliCommandDefinition, type CliCommandGroupDefinition} from '../type
2
2
  import codemodCommand from './codemod/codemodCommand'
3
3
  import debugCommand from './debug/debugCommand'
4
4
  import docsCommand from './docs/docsCommand'
5
+ import devfunctionsCommand from './functions/devFunctionsCommand'
6
+ import functionsGroup from './functions/functionsGroup'
7
+ import logsfunctionsCommand from './functions/logsFunctionsCommand'
8
+ import testfunctionsCommand from './functions/testFunctionsCommand'
5
9
  import helpCommand from './help/helpCommand'
6
10
  import initCommand from './init/initCommand'
7
11
  import installCommand from './install/installCommand'
@@ -39,4 +43,8 @@ export const baseCommands: (CliCommandDefinition | CliCommandGroupDefinition)[]
39
43
  telemetryStatusCommand,
40
44
  generateTypegenCommand,
41
45
  typegenGroup,
46
+ functionsGroup,
47
+ devfunctionsCommand,
48
+ logsfunctionsCommand,
49
+ testfunctionsCommand,
42
50
  ]
@@ -101,7 +101,6 @@ export const initCommand: CliCommandDefinition<InitFlags> = {
101
101
  description: 'Initializes a new Sanity Studio and/or project',
102
102
  helpText,
103
103
  action: async (args, context) => {
104
- const {output, chalk} = context
105
104
  const [type] = args.argsWithoutOptions
106
105
 
107
106
  // `sanity init whatever`
package/src/types.ts CHANGED
@@ -147,7 +147,6 @@ export interface CommandRunnerOptions {
147
147
  workDir: string
148
148
  corePath: string | undefined
149
149
  telemetry: TelemetryLogger<TelemetryUserProperties>
150
- isCoreApp: boolean
151
150
  }
152
151
 
153
152
  export interface CliOutputter {
@@ -352,8 +351,8 @@ export interface CliConfig {
352
351
  * Signals to `sanity` commands that this is not a studio.
353
352
  * @internal
354
353
  */
355
- __experimental_coreAppConfiguration?: {
356
- organizationId?: string
354
+ __experimental_appConfiguration?: {
355
+ organizationId: string
357
356
  appLocation?: string
358
357
  appId?: string
359
358
  }
@@ -15,7 +15,7 @@ import {getUserConfig} from './getUserConfig'
15
15
 
16
16
  const apiHosts: Record<string, string | undefined> = {
17
17
  staging: 'https://api.sanity.work',
18
- development: 'http://api.sanity.wtf',
18
+ development: 'http://api.sanity.local',
19
19
  }
20
20
 
21
21
  /**
@@ -7,9 +7,9 @@ import {debug} from '../debug'
7
7
  /**
8
8
  * Resolve project root directory, falling back to cwd if it cannot be found
9
9
  */
10
- export function resolveRootDir(cwd: string, isCoreApp = false): string {
10
+ export function resolveRootDir(cwd: string): string {
11
11
  try {
12
- return resolveProjectRoot(cwd, 0, isCoreApp) || cwd
12
+ return resolveProjectRoot(cwd) || cwd
13
13
  } catch (err) {
14
14
  throw new Error(`Error occurred trying to resolve project root:\n${err.message}`)
15
15
  }
@@ -25,8 +25,8 @@ function hasSanityConfig(basePath: string, configName: string): boolean {
25
25
  return buildConfigs.some(Boolean)
26
26
  }
27
27
 
28
- function resolveProjectRoot(basePath: string, iterations = 0, isCoreApp = false): string | false {
29
- const configName = isCoreApp ? 'sanity.cli' : 'sanity.config'
28
+ function resolveProjectRoot(basePath: string, iterations = 0): string | false {
29
+ const configName = 'sanity.config'
30
30
  if (hasSanityConfig(basePath, configName)) {
31
31
  return basePath
32
32
  }
@@ -37,7 +37,7 @@ function resolveProjectRoot(basePath: string, iterations = 0, isCoreApp = false)
37
37
  return false
38
38
  }
39
39
 
40
- return resolveProjectRoot(parentDir, iterations + 1, isCoreApp)
40
+ return resolveProjectRoot(parentDir, iterations + 1)
41
41
  }
42
42
 
43
43
  function isSanityV2StudioRoot(basePath: string): boolean {
@@ -0,0 +1,18 @@
1
+ /* Container styling for the app */
2
+ .app-container {
3
+ max-width: 1200px;
4
+ margin: 0 auto;
5
+ padding: 2rem;
6
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
7
+ }
8
+
9
+ /* Basic reset */
10
+ * {
11
+ box-sizing: border-box;
12
+ }
13
+
14
+ body {
15
+ margin: 0;
16
+ padding: 0;
17
+ background-color: #f9f9f9;
18
+ }
@@ -1,27 +1,25 @@
1
1
  import {type SanityConfig} from '@sanity/sdk'
2
- import {SanityApp} from '@sanity/sdk-react/components'
2
+ import {SanityApp} from '@sanity/sdk-react'
3
3
  import {ExampleComponent} from './ExampleComponent'
4
+ import './App.css'
4
5
 
5
6
  export function App() {
6
-
7
- const sanityConfig: SanityConfig = {
8
- auth: {
9
- authScope: 'global'
7
+ // apps can access many different projects or other sources of data
8
+ const sanityConfigs: SanityConfig[] = [
9
+ {
10
+ projectId: 'project-id',
11
+ dataset: 'dataset-name',
10
12
  }
11
- /*
12
- * Apps can access several different projects!
13
- * Add the below configuration if you want to connect to a specific project.
14
- */
15
- // projectId: 'my-project-id',
16
- // dataset: 'my-dataset',
17
- }
13
+ ]
18
14
 
19
15
  return (
20
- <SanityApp sanityConfig={sanityConfig}>
21
- {/* add your own components here! */}
22
- <ExampleComponent />
23
- </SanityApp>
16
+ <div className="app-container">
17
+ <SanityApp sanityConfigs={sanityConfigs} fallback={<div>Loading...</div>}>
18
+ {/* add your own components here! */}
19
+ <ExampleComponent />
20
+ </SanityApp>
21
+ </div>
24
22
  )
25
23
  }
26
24
 
27
- export default App
25
+ export default App
@@ -0,0 +1,26 @@
1
+ .example-container {
2
+ background-color: white;
3
+ border-radius: 8px;
4
+ padding: 2rem;
5
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
6
+ }
7
+
8
+ .example-heading {
9
+ color: #333;
10
+ margin-top: 0;
11
+ font-size: 1.8rem;
12
+ }
13
+
14
+ .example-text {
15
+ color: #666;
16
+ line-height: 1.6;
17
+ }
18
+
19
+ .code-hint {
20
+ background-color: #f5f5f5;
21
+ padding: 1rem;
22
+ border-radius: 4px;
23
+ font-family: monospace;
24
+ margin-top: 1.5rem;
25
+ border-left: 3px solid #e0e0e0;
26
+ }
@@ -1,11 +1,22 @@
1
+ import './ExampleComponent.css'
2
+
1
3
  export function ExampleComponent() {
2
4
  return (
3
- <div>
4
- <h1>Welcome to Your Sanity App!</h1>
5
- <p>
5
+ <div className="example-container">
6
+ <h1 className="example-heading">Welcome to your Sanity App!</h1>
7
+ <p className="example-text">
6
8
  This is an example component. You can replace this with your own content
7
9
  by creating a new component and importing it in App.tsx.
8
10
  </p>
11
+ <div className="code-hint">
12
+ <p>Quick tip: Create new components in separate files and import them like this in App.tsx / App.jsx:</p>
13
+ <pre>{`import {YourComponent} from './YourComponent'
14
+
15
+ // Then use it in your JSX
16
+ <SanityApp sanityConfigs={sanityConfigs}>
17
+ <YourComponent />
18
+ </SanityApp>`}</pre>
19
+ </div>
9
20
  </div>
10
21
  )
11
- }
22
+ }