@sanity/cli 3.87.1 → 3.88.1-typegen-experimental.0

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 (39) hide show
  1. package/lib/_chunks-cjs/cli.js +58780 -56791
  2. package/lib/_chunks-cjs/cli.js.map +1 -1
  3. package/lib/_chunks-cjs/generateAction.js +113 -111
  4. package/lib/_chunks-cjs/generateAction.js.map +1 -1
  5. package/lib/_chunks-cjs/loadEnv.js +3 -3
  6. package/lib/_chunks-cjs/loadEnv.js.map +1 -1
  7. package/lib/_chunks-cjs/workerChannel.js +84 -0
  8. package/lib/_chunks-cjs/workerChannel.js.map +1 -0
  9. package/lib/workers/typegenGenerate.d.ts +144 -33
  10. package/lib/workers/typegenGenerate.js +83 -112
  11. package/lib/workers/typegenGenerate.js.map +1 -1
  12. package/package.json +20 -22
  13. package/src/actions/init-project/templates/appQuickstart.ts +2 -2
  14. package/src/actions/init-project/templates/appSanityUi.ts +2 -2
  15. package/src/actions/typegen/generate.telemetry.ts +9 -3
  16. package/src/actions/typegen/generateAction.ts +159 -152
  17. package/src/cli.ts +0 -0
  18. package/src/commands/blueprints/addBlueprintsCommand.ts +52 -56
  19. package/src/commands/blueprints/blueprintsGroup.ts +0 -1
  20. package/src/commands/blueprints/configBlueprintsCommand.ts +50 -74
  21. package/src/commands/blueprints/deployBlueprintsCommand.ts +41 -133
  22. package/src/commands/blueprints/destroyBlueprintsCommand.ts +76 -0
  23. package/src/commands/blueprints/infoBlueprintsCommand.ts +29 -51
  24. package/src/commands/blueprints/initBlueprintsCommand.ts +55 -73
  25. package/src/commands/blueprints/logsBlueprintsCommand.ts +43 -81
  26. package/src/commands/blueprints/planBlueprintsCommand.ts +26 -36
  27. package/src/commands/blueprints/stacksBlueprintsCommand.ts +43 -51
  28. package/src/commands/functions/devFunctionsCommand.ts +1 -2
  29. package/src/commands/functions/envFunctionsCommand.ts +55 -46
  30. package/src/commands/functions/functionsGroup.ts +1 -2
  31. package/src/commands/functions/logsFunctionsCommand.ts +101 -58
  32. package/src/commands/functions/testFunctionsCommand.ts +56 -36
  33. package/src/commands/index.ts +6 -4
  34. package/src/commands/projects/listProjectsCommand.ts +0 -0
  35. package/src/commands/projects/projectsGroup.ts +0 -0
  36. package/src/util/__tests__/workerChannel.test.ts +222 -0
  37. package/src/util/workerChannel.ts +312 -0
  38. package/src/workers/typegenGenerate.ts +181 -183
  39. package/templates/app-sanity-ui/src/ExampleComponent.tsx +1 -1
@@ -1,163 +1,71 @@
1
1
  import {type CliCommandDefinition} from '../../types'
2
2
 
3
3
  const helpText = `
4
- Examples
4
+ Options
5
+ --no-wait Do not wait for deployment to complete
6
+
7
+ Examples:
5
8
  # Deploy the current blueprint
6
9
  sanity blueprints deploy
10
+
11
+ # Deploy the current blueprint without waiting for completion
12
+ sanity blueprints deploy --no-wait
7
13
  `
8
14
 
9
- const deployBlueprintsCommand: CliCommandDefinition = {
15
+ export interface BlueprintsDeployFlags {
16
+ 'no-wait'?: boolean
17
+ }
18
+
19
+ const defaultFlags: BlueprintsDeployFlags = {
20
+ //
21
+ }
22
+
23
+ const deployBlueprintsCommand: CliCommandDefinition<BlueprintsDeployFlags> = {
10
24
  name: 'deploy',
11
25
  group: 'blueprints',
12
26
  helpText,
13
- signature: '',
27
+ signature: '[--no-wait]',
14
28
  description: 'Deploy a Blueprint to create or update a Stack',
15
- hideFromHelp: true,
16
- /* eslint-disable-next-line complexity, max-statements */
29
+
17
30
  async action(args, context) {
18
- const {apiClient, output, prompt} = context
19
- const {print} = output
31
+ const {apiClient, output} = context
32
+ const flags = {...defaultFlags, ...args.extOptions}
20
33
 
21
34
  const client = apiClient({
22
35
  requireUser: true,
23
36
  requireProject: false,
24
37
  })
25
38
  const {token} = client.config()
26
- const {
27
- blueprint: blueprintAction,
28
- stacks: stacksAction,
29
- assets: assetsAction,
30
- } = await import('@sanity/runtime-cli/actions/blueprints')
31
- const {display} = await import('@sanity/runtime-cli/utils')
32
-
33
- if (!token) {
34
- print('No API token found. Please run `sanity login` first.')
35
- return
36
- }
37
-
38
- let blueprint = null
39
- try {
40
- blueprint = await blueprintAction.readBlueprintOnDisk({getStack: true, token})
41
- } catch (error) {
42
- print('Unable to read Blueprint manifest file. Run `sanity blueprints init`')
43
- return
44
- }
45
-
46
- if (!blueprint) {
47
- print('Unable to read Blueprint manifest file. Run `sanity blueprints init`')
48
- return
49
- }
50
-
51
- const {
52
- errors,
53
- projectId: configuredProjectId,
54
- stackId,
55
- parsedBlueprint,
56
- deployedStack,
57
- } = blueprint
58
-
59
- if (errors && errors.length > 0) {
60
- print(errors)
61
- return
62
- }
63
-
64
- if (stackId && !deployedStack) {
65
- print('Stack specified in config, but deployed Stack not found.')
66
- return
67
- }
68
-
69
- const resources = parsedBlueprint.resources || []
39
+ if (!token) throw new Error('No API token found. Please run `sanity login`.')
70
40
 
71
- let projectId = configuredProjectId
72
- if (!projectId) {
73
- print('No Sanity Project context found in Blueprint configuration.')
74
-
75
- const maybeProjectId = await prompt.single({
76
- type: 'input',
77
- message: 'Enter Sanity Project ID:',
78
- })
41
+ const {blueprintDeployCore} = await import('@sanity/runtime-cli/cores/blueprints')
42
+ const {getBlueprintAndStack} = await import('@sanity/runtime-cli/actions/blueprints')
43
+ const {display} = await import('@sanity/runtime-cli/utils')
79
44
 
80
- projectId = maybeProjectId
81
- }
45
+ const {localBlueprint, deployedStack, issues} = await getBlueprintAndStack({token})
82
46
 
83
- if (!projectId) {
84
- print('Sanity Project context is required')
85
- print('To configure this Blueprint, run `sanity blueprints config`')
86
- return
47
+ if (issues) {
48
+ output.print(display.errors.presentBlueprintIssues(issues))
49
+ throw new Error('Unable to parse Blueprint file.')
87
50
  }
88
51
 
52
+ const {projectId, stackId} = localBlueprint
89
53
  const auth = {token, projectId}
90
54
 
91
- let name = deployedStack?.name
92
- if (!name) {
93
- const stackName = await prompt.single({
94
- type: 'input',
95
- message: 'Enter stack name:',
96
- validate: (input) => input.length > 0 || 'Stack name is required',
97
- })
98
-
99
- name = stackName
100
- }
101
-
102
- if (!name) {
103
- print('Stack name is required')
104
- return
105
- }
106
-
107
- const validResources = resources?.filter((r) => r.type)
108
- const functionResources = validResources?.filter((r) => r.type.startsWith('sanity.function.'))
109
-
110
- if (functionResources?.length) {
111
- for (const resource of functionResources) {
112
- print(`Processing ${resource.name}...`)
113
- const result = await assetsAction.stashAsset({resource, auth})
114
-
115
- if (result.success && result.assetId) {
116
- const src = resource.src
117
- resource.src = result.assetId // ! this will change! for now, the API expects the assetId
118
- const {yellow} = display.colors
119
- print(`${resource.name} <${yellow(result.assetId)}>`)
120
- print(` Source: ${src}`)
121
- } else {
122
- print(` Error: ${result.error}`)
123
- throw new Error(`Failed to process ${resource.name}`)
124
- }
125
- }
126
- }
127
-
128
- const stackPayload = {
129
- name,
55
+ const {success, error} = await blueprintDeployCore({
56
+ bin: 'sanity',
57
+ log: (message) => output.print(message),
58
+ auth,
130
59
  projectId,
131
- document: {resources: validResources},
132
- }
133
-
134
- print('Deploying stack...')
135
-
136
- const {
137
- ok: deployOk,
138
- stack,
139
- error: deployError,
140
- } = deployedStack
141
- ? await stacksAction.updateStack({stackId: deployedStack.id, stackPayload, auth})
142
- : await stacksAction.createStack({stackPayload, auth})
143
-
144
- if (deployOk) {
145
- const {green, bold, yellow} = display.colors
146
- print(
147
- `${green('Success!')} Stack "${bold(stack.name)}" ${deployedStack ? 'updated' : 'created'} <${yellow(stack.id)}>`,
148
- )
149
-
150
- blueprintAction.writeConfigFile({
151
- projectId,
152
- stackId: stack.id,
153
- })
60
+ stackId,
61
+ deployedStack,
62
+ blueprint: localBlueprint,
63
+ flags: {
64
+ 'no-wait': flags['no-wait'],
65
+ },
66
+ })
154
67
 
155
- print('\nUse `sanity blueprints info` to check deployment status')
156
- } else {
157
- const {red} = display.colors
158
- print(`${red('Failed')} to ${deployedStack ? 'update' : 'create'} stack`)
159
- print(`Error: ${deployError || JSON.stringify(stack, null, 2) || 'Unknown error'}`)
160
- }
68
+ if (!success) throw new Error(error)
161
69
  },
162
70
  }
163
71
 
@@ -0,0 +1,76 @@
1
+ import {type CliCommandDefinition} from '../../types'
2
+
3
+ const helpText = `
4
+ Options
5
+ --force, -f Force destroy without confirmation
6
+ --no-wait Do not wait for destroy to complete
7
+
8
+ Examples:
9
+ # Destroy the current deployment
10
+ sanity blueprints destroy
11
+
12
+ # Force destroy without confirmation
13
+ sanity blueprints destroy --force
14
+
15
+ # Destroy without waiting for completion
16
+ sanity blueprints destroy --no-wait
17
+ `
18
+
19
+ export interface BlueprintsDestroyFlags {
20
+ 'force'?: boolean
21
+ 'f'?: boolean
22
+ 'project-id'?: string
23
+ 'projectId'?: string
24
+ 'project'?: string
25
+ 'stack-id'?: string
26
+ 'stackId'?: string
27
+ 'stack'?: string
28
+ 'no-wait'?: boolean
29
+ }
30
+
31
+ const defaultFlags: BlueprintsDestroyFlags = {
32
+ //
33
+ }
34
+
35
+ const destroyBlueprintsCommand: CliCommandDefinition<BlueprintsDestroyFlags> = {
36
+ name: 'destroy',
37
+ group: 'blueprints',
38
+ helpText,
39
+ signature: '[--force] [-f] [--no-wait]',
40
+ description: 'Destroy a Blueprint deployment',
41
+ hideFromHelp: true,
42
+
43
+ async action(args, context) {
44
+ const {apiClient, output} = context
45
+ const flags = {...defaultFlags, ...args.extOptions}
46
+
47
+ const client = apiClient({
48
+ requireUser: true,
49
+ requireProject: false,
50
+ })
51
+ const {token} = client.config()
52
+ if (!token) throw new Error('No API token found. Please run `sanity login`.')
53
+
54
+ const {blueprintDestroyCore} = await import('@sanity/runtime-cli/cores/blueprints')
55
+ const {getBlueprintAndStack} = await import('@sanity/runtime-cli/actions/blueprints')
56
+
57
+ const {localBlueprint} = await getBlueprintAndStack({token})
58
+
59
+ const {success, error} = await blueprintDestroyCore({
60
+ bin: 'sanity',
61
+ log: (message) => output.print(message),
62
+ token,
63
+ blueprint: localBlueprint,
64
+ flags: {
65
+ 'no-wait': flags['no-wait'],
66
+ 'force': flags.force ?? flags.f,
67
+ 'project-id': flags['project-id'] ?? flags.projectId ?? flags.project,
68
+ 'stack-id': flags['stack-id'] ?? flags.stackId ?? flags.stack,
69
+ },
70
+ })
71
+
72
+ if (!success) throw new Error(error)
73
+ },
74
+ }
75
+
76
+ export default destroyBlueprintsCommand
@@ -1,29 +1,28 @@
1
1
  import {type CliCommandDefinition} from '../../types'
2
2
 
3
3
  const helpText = `
4
- Options
5
- --id, -i Stack ID
6
-
7
- Examples
4
+ Examples:
8
5
  # Retrieve information about the current Stack
9
6
  sanity blueprints info
10
-
11
- # Retrieve information about a specific Stack
12
- sanity blueprints info --id <stack-id>
13
7
  `
14
8
 
15
- const defaultFlags = {id: undefined}
9
+ export interface BlueprintsInfoFlags {
10
+ id?: string
11
+ }
12
+
13
+ const defaultFlags: BlueprintsInfoFlags = {
14
+ //
15
+ }
16
16
 
17
- const infoBlueprintsCommand: CliCommandDefinition = {
17
+ const infoBlueprintsCommand: CliCommandDefinition<BlueprintsInfoFlags> = {
18
18
  name: 'info',
19
19
  group: 'blueprints',
20
20
  helpText,
21
21
  signature: '',
22
22
  description: 'Retrieve information about a Blueprint Stack',
23
- hideFromHelp: true,
23
+
24
24
  async action(args, context) {
25
25
  const {apiClient, output} = context
26
- const {print} = output
27
26
  const flags = {...defaultFlags, ...args.extOptions}
28
27
 
29
28
  const client = apiClient({
@@ -31,53 +30,32 @@ const infoBlueprintsCommand: CliCommandDefinition = {
31
30
  requireProject: false,
32
31
  })
33
32
  const {token} = client.config()
34
- const {blueprint: blueprintAction, stacks: stacksAction} = await import(
35
- '@sanity/runtime-cli/actions/blueprints'
36
- )
33
+ if (!token) throw new Error('No API token found. Please run `sanity login`.')
34
+
35
+ const {blueprintInfoCore} = await import('@sanity/runtime-cli/cores/blueprints')
36
+ const {getBlueprintAndStack} = await import('@sanity/runtime-cli/actions/blueprints')
37
37
  const {display} = await import('@sanity/runtime-cli/utils')
38
38
 
39
- let blueprint = null
40
- try {
41
- blueprint = await blueprintAction.readBlueprintOnDisk({token})
42
- } catch (error) {
43
- print('Unable to read Blueprint manifest file. Run `sanity blueprints init`')
44
- return
45
- }
39
+ const {localBlueprint, deployedStack, issues} = await getBlueprintAndStack({token})
46
40
 
47
- if (!blueprint) {
48
- print('Unable to read Blueprint manifest file. Run `sanity blueprints init`')
49
- return
41
+ if (issues) {
42
+ output.print(display.errors.presentBlueprintIssues(issues))
43
+ throw new Error('Unable to parse Blueprint file.')
50
44
  }
51
45
 
52
- const {errors, deployedStack, projectId} = blueprint
53
-
54
- if (errors && errors.length > 0) {
55
- print(errors)
56
- return
57
- }
46
+ const {projectId, stackId} = localBlueprint
47
+ const auth = {token, projectId}
58
48
 
59
- if (token && projectId) {
60
- const auth = {token, projectId}
61
- let result
62
- if (flags.id) {
63
- const {stack, error, ok} = await stacksAction.getStack({stackId: flags.id, auth})
64
- if (ok) {
65
- result = stack
66
- } else {
67
- print(error)
68
- }
69
- } else {
70
- result = deployedStack
71
- }
49
+ const {success, error} = await blueprintInfoCore({
50
+ bin: 'sanity',
51
+ log: (message) => output.print(message),
52
+ auth,
53
+ stackId,
54
+ deployedStack,
55
+ flags,
56
+ })
72
57
 
73
- if (result) {
74
- print(display.blueprintsFormatting.formatStackInfo(result))
75
- } else {
76
- print('No Stack found')
77
- }
78
- } else {
79
- print('Cannot retrieve information for Blueprint: missing API token or Project ID')
80
- }
58
+ if (!success) throw new Error(error)
81
59
  },
82
60
  }
83
61
 
@@ -1,95 +1,77 @@
1
- import {join} from 'node:path'
2
- import {cwd} from 'node:process'
3
-
4
1
  import {type CliCommandDefinition} from '../../types'
5
2
 
6
3
  const helpText = `
7
- Examples
8
- # Create a new Blueprint manifest file
4
+ Arguments
5
+ [dir] Path to initialize the Blueprint in
6
+
7
+ Options
8
+ --blueprint-type, --type <json> Type of Blueprint to create
9
+ --project-id <id> Project ID to use
10
+
11
+ Examples:
12
+ # Create a new Blueprint manifest file in the current directory
9
13
  sanity blueprints init
14
+
15
+ # Create a new Blueprint manifest file in a specific directory
16
+ sanity blueprints init my-sanity-project --type json
10
17
  `
11
18
 
12
- const initBlueprintsCommand: CliCommandDefinition = {
19
+ export interface BlueprintsInitFlags {
20
+ 'dir'?: string
21
+ 'blueprint-type'?: string
22
+ 'type'?: string
23
+ 'project-id'?: string
24
+ 'projectId'?: string
25
+ 'project'?: string
26
+ 'stack-id'?: string
27
+ 'stackId'?: string
28
+ 'stack'?: string
29
+ 'stack-name'?: string
30
+ 'name'?: string
31
+ }
32
+
33
+ const defaultFlags: BlueprintsInitFlags = {
34
+ //
35
+ }
36
+
37
+ const initBlueprintsCommand: CliCommandDefinition<BlueprintsInitFlags> = {
13
38
  name: 'init',
14
39
  group: 'blueprints',
15
40
  helpText,
16
- signature: '',
41
+ signature: '[dir] [--blueprint-type <type>] [--project-id <id>]',
17
42
  description: 'Initialize a new Blueprint manifest file',
18
- hideFromHelp: true,
43
+
19
44
  async action(args, context) {
20
- const {apiClient, output, prompt} = context
21
- const {print} = output
45
+ const {apiClient, output} = context
46
+ const flags = {...defaultFlags, ...args.extOptions}
47
+
48
+ const [dir] = args.argsWithoutOptions
22
49
 
23
50
  const client = apiClient({
24
51
  requireUser: true,
25
52
  requireProject: false,
26
53
  })
27
54
  const {token} = client.config()
28
-
29
- if (!token) {
30
- print('No API token found. Please run `sanity login` first.')
31
- return
32
- }
33
-
34
- const {blueprint: blueprintAction, projects: projectsAction} = await import(
35
- '@sanity/runtime-cli/actions/blueprints'
36
- )
37
-
38
- const existingBlueprint = blueprintAction.findBlueprintFile()
39
-
40
- if (existingBlueprint) {
41
- print(`A blueprint file already exists: ${existingBlueprint.fileName}`)
42
- return
43
- }
44
-
45
- const blueprintExtension = await prompt.single({
46
- type: 'list',
47
- message: 'Choose a Blueprint manifest file type:',
48
- choices: [
49
- {value: 'json', name: 'JSON (Recommended)'},
50
- {value: 'js', name: 'JavaScript (Available soon)', disabled: true},
51
- {value: 'ts', name: 'TypeScript (Available soon)', disabled: true},
52
- ],
55
+ if (!token) throw new Error('No API token found. Please run `sanity login`.')
56
+
57
+ const {blueprintInitCore} = await import('@sanity/runtime-cli/cores/blueprints')
58
+
59
+ const {success, error} = await blueprintInitCore({
60
+ bin: 'sanity',
61
+ log: (message) => output.print(message),
62
+ token,
63
+ args: {
64
+ dir: dir ?? flags.dir,
65
+ },
66
+ flags: {
67
+ 'blueprint-type': flags['blueprint-type'] ?? flags.type,
68
+ 'project-id': flags['project-id'] ?? flags.projectId ?? flags.project,
69
+ 'stack-id': flags['stack-id'] ?? flags.stackId ?? flags.stack,
70
+ 'stack-name': flags['stack-name'] ?? flags.name,
71
+ },
53
72
  })
54
73
 
55
- const {ok, projects, error} = await projectsAction.listProjects({token})
56
-
57
- if (!ok) {
58
- print(error)
59
- return
60
- }
61
-
62
- if (!projects || projects.length === 0) {
63
- print('No Projects found. Please create a Project in Sanity.io first.')
64
- return
65
- }
66
-
67
- const projectChoices = projects.map(({displayName, id}) => ({
68
- value: id,
69
- name: `${displayName} <${id}>`,
70
- }))
71
-
72
- const projectId = await prompt.single({
73
- type: 'list',
74
- message: 'Select your Sanity Project:',
75
- choices: projectChoices,
76
- })
77
-
78
- const fileName = `blueprint.${blueprintExtension}`
79
- const filePath = join(cwd(), fileName)
80
-
81
- blueprintAction.writeBlueprintToDisk({
82
- path: filePath,
83
- fileType: blueprintExtension as 'json' | 'js' | 'ts',
84
- })
85
-
86
- blueprintAction.writeConfigFile({projectId})
87
-
88
- print(`Created new blueprint: ./${fileName}`)
89
-
90
- if (blueprintExtension === 'ts') {
91
- print('\nNote: TypeScript support requires "tsx" to be installed. Run: npm install -D tsx')
92
- }
74
+ if (!success) throw new Error(error)
93
75
  },
94
76
  }
95
77