@sanity/cli 3.93.0 → 3.93.1-bump-pkg-utils.34.5d0c0b3d22

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 (160) hide show
  1. package/lib/_chunks-cjs/cli.js +5 -5
  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.map +1 -1
  6. package/lib/_chunks-cjs/journeyConfig.js.map +1 -1
  7. package/lib/_chunks-cjs/loadEnv.js.map +1 -1
  8. package/lib/index.js.map +1 -1
  9. package/lib/index.mjs.map +1 -1
  10. package/lib/run.js.map +1 -1
  11. package/lib/workers/getAndWriteJourneySchema.js.map +1 -1
  12. package/lib/workers/getCliConfig.js.map +1 -1
  13. package/lib/workers/typegenGenerate.js.map +1 -1
  14. package/package.json +6 -7
  15. package/templates/blog/README.md +1 -1
  16. package/templates/clean/README.md +1 -1
  17. package/templates/ecommerce/README.md +1 -1
  18. package/templates/get-started/README.md +1 -1
  19. package/templates/moviedb/README.md +1 -1
  20. package/templates/quickstart/README.md +1 -1
  21. package/src/CommandRunner.ts +0 -219
  22. package/src/__telemetry__/cli.telemetry.ts +0 -29
  23. package/src/__telemetry__/init.telemetry.ts +0 -95
  24. package/src/actions/codemod/codemodAction.ts +0 -109
  25. package/src/actions/codemod/mods/deskRename.ts +0 -19
  26. package/src/actions/codemod/mods/index.ts +0 -9
  27. package/src/actions/codemod/mods/partsTypeDirective.ts +0 -28
  28. package/src/actions/codemod/mods/reactIconsV3.ts +0 -54
  29. package/src/actions/codemod/types.ts +0 -10
  30. package/src/actions/init-plugin/bootstrapFromTemplate.ts +0 -196
  31. package/src/actions/init-project/bootstrapLocalTemplate.ts +0 -201
  32. package/src/actions/init-project/bootstrapRemoteTemplate.ts +0 -118
  33. package/src/actions/init-project/createAppCliConfig.ts +0 -24
  34. package/src/actions/init-project/createCliConfig.ts +0 -31
  35. package/src/actions/init-project/createPackageManifest.ts +0 -102
  36. package/src/actions/init-project/createStudioConfig.ts +0 -53
  37. package/src/actions/init-project/determineAppTemplate.ts +0 -13
  38. package/src/actions/init-project/fsUtils.ts +0 -40
  39. package/src/actions/init-project/git.ts +0 -59
  40. package/src/actions/init-project/initProject.ts +0 -1708
  41. package/src/actions/init-project/processTemplate.ts +0 -55
  42. package/src/actions/init-project/promptForDatasetName.ts +0 -68
  43. package/src/actions/init-project/prompts/index.ts +0 -51
  44. package/src/actions/init-project/prompts/nextjs.ts +0 -59
  45. package/src/actions/init-project/readPackageJson.ts +0 -17
  46. package/src/actions/init-project/templates/appQuickstart.ts +0 -23
  47. package/src/actions/init-project/templates/appSanityUi.ts +0 -25
  48. package/src/actions/init-project/templates/blog.ts +0 -5
  49. package/src/actions/init-project/templates/clean.ts +0 -5
  50. package/src/actions/init-project/templates/getStarted.ts +0 -37
  51. package/src/actions/init-project/templates/index.ts +0 -24
  52. package/src/actions/init-project/templates/moviedb.ts +0 -35
  53. package/src/actions/init-project/templates/nextjs/index.ts +0 -238
  54. package/src/actions/init-project/templates/nextjs/schemaTypes/blog.ts +0 -252
  55. package/src/actions/init-project/templates/quickstart.ts +0 -5
  56. package/src/actions/init-project/templates/shopify.ts +0 -78
  57. package/src/actions/init-project/templates/shopifyOnline.ts +0 -50
  58. package/src/actions/init-project/updateInitialTemplateMetadata.ts +0 -24
  59. package/src/actions/login/login.telemetry.ts +0 -18
  60. package/src/actions/login/login.ts +0 -350
  61. package/src/actions/login/types.ts +0 -19
  62. package/src/actions/project/createProject.ts +0 -36
  63. package/src/actions/telemetry/setTelemetryConsent.ts +0 -101
  64. package/src/actions/typegen/generate.telemetry.ts +0 -20
  65. package/src/actions/typegen/generateAction.ts +0 -210
  66. package/src/actions/versions/findSanityModuleVersions.ts +0 -185
  67. package/src/actions/yarn/events.ts +0 -73
  68. package/src/cli.ts +0 -350
  69. package/src/cliClient.ts +0 -62
  70. package/src/commands/blueprints/addBlueprintsCommand.ts +0 -155
  71. package/src/commands/blueprints/blueprintsGroup.ts +0 -10
  72. package/src/commands/blueprints/configBlueprintsCommand.ts +0 -86
  73. package/src/commands/blueprints/deployBlueprintsCommand.ts +0 -63
  74. package/src/commands/blueprints/destroyBlueprintsCommand.ts +0 -78
  75. package/src/commands/blueprints/infoBlueprintsCommand.ts +0 -55
  76. package/src/commands/blueprints/initBlueprintsCommand.ts +0 -99
  77. package/src/commands/blueprints/logsBlueprintsCommand.ts +0 -66
  78. package/src/commands/blueprints/planBlueprintsCommand.ts +0 -51
  79. package/src/commands/blueprints/stacksBlueprintsCommand.ts +0 -66
  80. package/src/commands/codemod/codemodCommand.ts +0 -32
  81. package/src/commands/debug/debugCommand.ts +0 -26
  82. package/src/commands/debug/printDebugInfo.ts +0 -243
  83. package/src/commands/docs/docsCommand.ts +0 -20
  84. package/src/commands/functions/devFunctionsCommand.ts +0 -73
  85. package/src/commands/functions/envFunctionsCommand.ts +0 -105
  86. package/src/commands/functions/functionsGroup.ts +0 -10
  87. package/src/commands/functions/logsFunctionsCommand.ts +0 -94
  88. package/src/commands/functions/testFunctionsCommand.ts +0 -93
  89. package/src/commands/help/helpCommand.ts +0 -21
  90. package/src/commands/help/showHelp.ts +0 -58
  91. package/src/commands/index.ts +0 -72
  92. package/src/commands/init/initCommand.ts +0 -123
  93. package/src/commands/install/installCommand.ts +0 -38
  94. package/src/commands/learn/learnCommand.ts +0 -20
  95. package/src/commands/login/loginCommand.ts +0 -29
  96. package/src/commands/logout/logoutCommand.ts +0 -52
  97. package/src/commands/manage/manageCommand.ts +0 -24
  98. package/src/commands/projects/listProjectsCommand.ts +0 -62
  99. package/src/commands/projects/projectsGroup.ts +0 -10
  100. package/src/commands/telemetry/disableTelemetryCommand.ts +0 -19
  101. package/src/commands/telemetry/enableTelemetryCommand.ts +0 -19
  102. package/src/commands/telemetry/telemetryGroup.ts +0 -10
  103. package/src/commands/telemetry/telemetryStatusCommand.ts +0 -89
  104. package/src/commands/typegen/generateTypesCommand.ts +0 -56
  105. package/src/commands/typegen/typegenGroup.ts +0 -10
  106. package/src/commands/versions/printVersionResult.ts +0 -51
  107. package/src/commands/versions/versionsCommand.ts +0 -13
  108. package/src/config.ts +0 -14
  109. package/src/debug.ts +0 -3
  110. package/src/index.ts +0 -6
  111. package/src/outputters/cliOutputter.ts +0 -47
  112. package/src/packageManager/getInstallCommand.ts +0 -26
  113. package/src/packageManager/getUpgradeCommand.ts +0 -52
  114. package/src/packageManager/index.ts +0 -33
  115. package/src/packageManager/installPackages.ts +0 -99
  116. package/src/packageManager/packageManagerChoice.ts +0 -204
  117. package/src/packageManager/uninstallPackages.ts +0 -44
  118. package/src/packageManager/yarnStub.ts +0 -22
  119. package/src/prompters/cliPrompter.ts +0 -9
  120. package/src/run.ts +0 -8
  121. package/src/studioDependencies.ts +0 -25
  122. package/src/types.ts +0 -387
  123. package/src/util/canLaunchBrowser.ts +0 -12
  124. package/src/util/cliWorker.ts +0 -34
  125. package/src/util/clientWrapper.ts +0 -119
  126. package/src/util/copy.ts +0 -50
  127. package/src/util/createExpiringConfig.ts +0 -80
  128. package/src/util/createTelemetryStore.ts +0 -204
  129. package/src/util/detectRuntime.ts +0 -12
  130. package/src/util/dynamicRequire.ts +0 -17
  131. package/src/util/frameworkPort.ts +0 -63
  132. package/src/util/generateCommandsDocumentation.ts +0 -62
  133. package/src/util/getCliConfig.ts +0 -172
  134. package/src/util/getCliVersion.ts +0 -22
  135. package/src/util/getLocalVersion.ts +0 -35
  136. package/src/util/getProjectDefaults.ts +0 -103
  137. package/src/util/getProviderName.ts +0 -9
  138. package/src/util/getUserConfig.ts +0 -15
  139. package/src/util/isCi.ts +0 -7
  140. package/src/util/isCommandGroup.ts +0 -7
  141. package/src/util/isInteractive.ts +0 -3
  142. package/src/util/isTrueish.ts +0 -8
  143. package/src/util/journeyConfig.ts +0 -280
  144. package/src/util/loadEnv.ts +0 -110
  145. package/src/util/mergeCommands.ts +0 -78
  146. package/src/util/neatStack.ts +0 -30
  147. package/src/util/noSuchCommandText.ts +0 -91
  148. package/src/util/parseArguments.ts +0 -76
  149. package/src/util/pathExists.ts +0 -14
  150. package/src/util/readJson.ts +0 -6
  151. package/src/util/readdirRecursive.ts +0 -26
  152. package/src/util/remoteTemplate.ts +0 -320
  153. package/src/util/resolveLatestVersions.ts +0 -24
  154. package/src/util/resolveRootDir.ts +0 -59
  155. package/src/util/telemetryDisclosure.ts +0 -45
  156. package/src/util/updateNotifier.ts +0 -158
  157. package/src/util/writeJson.ts +0 -6
  158. package/src/workers/getAndWriteJourneySchema.ts +0 -7
  159. package/src/workers/getCliConfig.ts +0 -14
  160. package/src/workers/typegenGenerate.ts +0 -228
@@ -1,243 +0,0 @@
1
- import os from 'node:os'
2
- import path from 'node:path'
3
- import util from 'node:util'
4
-
5
- import {type SanityProject, type SanityProjectMember} from '@sanity/client'
6
- import {omit, pick} from 'lodash'
7
- import promiseProps from 'promise-props-recursive'
8
- import xdgBasedir from 'xdg-basedir'
9
-
10
- import {
11
- findSanityModuleVersions,
12
- type ModuleVersionResult,
13
- } from '../../actions/versions/findSanityModuleVersions'
14
- import {
15
- type CliCommandAction,
16
- type CliCommandContext,
17
- type CliUserConfig,
18
- type SanityJson,
19
- } from '../../types'
20
- import {getCliToken} from '../../util/clientWrapper'
21
- import {getUserConfig} from '../../util/getUserConfig'
22
- import {printResult as printVersionsResult} from '../versions/printVersionResult'
23
-
24
- export const printDebugInfo: CliCommandAction = async (args, context) => {
25
- const flags = args.extOptions
26
- const {user, globalConfig, projectConfig, project, versions} = await gatherInfo(context)
27
- const {chalk} = context
28
-
29
- // User info
30
- context.output.print('\nUser:')
31
- if (user instanceof Error) {
32
- context.output.print(` ${chalk.red(user.message)}\n`)
33
- } else {
34
- printKeyValue(
35
- {
36
- ID: user.id,
37
- Name: user.name,
38
- Email: user.email,
39
- Roles: project ? project.userRoles : undefined,
40
- },
41
- context,
42
- )
43
- }
44
-
45
- // Project info (API-based)
46
- if (project) {
47
- context.output.print('Project:')
48
- printKeyValue(
49
- {
50
- 'ID': project.id,
51
- 'Display name': project.displayName,
52
- 'Studio URL': project.studioHostname,
53
- },
54
- context,
55
- )
56
- }
57
-
58
- // Auth info
59
- // eslint-disable-next-line no-process-env
60
- const authToken = process.env.SANITY_AUTH_TOKEN || globalConfig.authToken
61
- if (authToken) {
62
- context.output.print('Authentication:')
63
- printKeyValue(
64
- {
65
- 'User type': globalConfig.authType || 'normal',
66
- 'Auth token': flags.secrets ? authToken : `<redacted>`,
67
- },
68
- context,
69
- )
70
-
71
- if (!flags.secrets) {
72
- context.output.print(' (run with --secrets to reveal token)\n')
73
- }
74
- }
75
-
76
- // Global configuration (user home dir config file)
77
- context.output.print(`Global config (${chalk.yellow(getGlobalConfigLocation())}):`)
78
- const globalCfg = omit(globalConfig, ['authType', 'authToken'])
79
- context.output.print(` ${formatObject(globalCfg).replace(/\n/g, '\n ')}\n`)
80
-
81
- // Project configuration (projectDir/sanity.json)
82
- if (projectConfig) {
83
- const configLocation = context.cliConfigPath
84
- ? ` (${chalk.yellow(path.relative(process.cwd(), context.cliConfigPath))})`
85
- : ''
86
-
87
- context.output.print(`Project config${configLocation}:`)
88
- context.output.print(` ${formatObject(projectConfig).replace(/\n/g, '\n ')}`)
89
- }
90
-
91
- // Print installed package versions
92
- if (versions) {
93
- context.output.print('\nPackage versions:')
94
- printVersionsResult(versions, (line) => context.output.print(` ${line}`))
95
- context.output.print('')
96
- }
97
- }
98
-
99
- function formatObject(obj: Record<string, any>): string {
100
- return util.inspect(obj, {colors: true, depth: +Infinity})
101
- }
102
-
103
- function printKeyValue(obj: Record<string, any>, context: CliCommandContext): void {
104
- let printedLines = 0
105
- Object.keys(obj).forEach((key) => {
106
- if (typeof obj[key] !== 'undefined') {
107
- context.output.print(` ${key}: ${formatObject(obj[key])}`)
108
- printedLines++
109
- }
110
- })
111
-
112
- if (printedLines > 0) {
113
- context.output.print('')
114
- }
115
- }
116
-
117
- interface Configs {
118
- globalConfig: CliUserConfig
119
- projectConfig: SanityJson
120
- }
121
-
122
- interface UserInfo {
123
- id: string
124
- name: string
125
- email: string
126
- }
127
-
128
- interface ProjectInfo {
129
- id: string
130
- displayName: string
131
- studioHostname?: string | null
132
- userRoles: string[]
133
- }
134
-
135
- interface ConfigsWithUser extends Configs {
136
- user: UserInfo | Error
137
- }
138
-
139
- interface DebugInfo extends ConfigsWithUser {
140
- project: ProjectInfo
141
- versions: ModuleVersionResult[]
142
- }
143
-
144
- interface SanityRole {
145
- name: string
146
- title: string
147
- description: string
148
- }
149
-
150
- interface SanityProjectWithRoles extends SanityProject {
151
- members: (SanityProjectMember & {roles: SanityRole[]})[]
152
- }
153
-
154
- async function gatherInfo(context: CliCommandContext): Promise<DebugInfo> {
155
- const baseInfo = await promiseProps<Configs>({
156
- globalConfig: gatherGlobalConfigInfo(),
157
- projectConfig: gatherProjectConfigInfo(context),
158
- })
159
-
160
- const withUser: ConfigsWithUser = {
161
- ...baseInfo,
162
- user: await gatherUserInfo(context, {
163
- projectBased: Boolean(baseInfo.projectConfig && baseInfo.projectConfig.api),
164
- }),
165
- }
166
-
167
- return promiseProps<DebugInfo>({
168
- project: gatherProjectInfo(context, withUser),
169
- versions: findSanityModuleVersions(context, {target: 'latest'}),
170
- ...withUser,
171
- })
172
- }
173
-
174
- function getGlobalConfigLocation(): string {
175
- const user = (os.userInfo().username || 'user').replace(/\\/g, '')
176
- const configDir = xdgBasedir.config || path.join(os.tmpdir(), user, '.config')
177
- return path.join(configDir, 'sanity', 'config.json')
178
- }
179
-
180
- function gatherGlobalConfigInfo(): CliUserConfig {
181
- return getUserConfig().all
182
- }
183
-
184
- function gatherProjectConfigInfo(context: CliCommandContext): SanityJson | {error: string} | null {
185
- const {cliConfig} = context
186
- if (cliConfig?.api?.projectId) {
187
- return cliConfig
188
- }
189
-
190
- return {
191
- error: `Missing required "api.projectId" key`,
192
- }
193
- }
194
-
195
- async function gatherProjectInfo(
196
- context: CliCommandContext,
197
- baseInfo: ConfigsWithUser,
198
- ): Promise<ProjectInfo | null | Error> {
199
- const projectClient = context.apiClient({requireUser: false, requireProject: false})
200
- const projectId = projectClient.config().projectId
201
- const hasToken = Boolean(getCliToken())
202
- if (!projectId || !hasToken) {
203
- return null
204
- }
205
-
206
- const client = context
207
- .apiClient({requireUser: true, requireProject: false})
208
- .withConfig({apiVersion: '2023-06-06'})
209
-
210
- const projectInfo = await client.request<SanityProjectWithRoles>({url: `/projects/${projectId}`})
211
- if (!projectInfo) {
212
- return new Error(`Project specified in configuration (${projectId}) does not exist in API`)
213
- }
214
-
215
- const userId = baseInfo.user instanceof Error ? null : baseInfo.user.id
216
- const host = projectInfo.studioHost
217
- const member = (projectInfo.members || []).find((user) => user.id === userId)
218
- const hostname = host && `https://${host}.sanity.studio/`
219
- return {
220
- id: projectId,
221
- displayName: projectInfo.displayName,
222
- studioHostname: hostname,
223
- userRoles: member ? member.roles.map((role) => role.name) : ['<none>'],
224
- }
225
- }
226
-
227
- async function gatherUserInfo(
228
- context: CliCommandContext,
229
- options: {projectBased: boolean},
230
- ): Promise<UserInfo | Error> {
231
- const hasToken = Boolean(getCliToken())
232
- if (!hasToken) {
233
- return new Error('Not logged in')
234
- }
235
-
236
- const client = context.apiClient({requireUser: true, requireProject: options.projectBased})
237
- const userInfo = await client.users.getById('me')
238
- if (!userInfo) {
239
- return new Error('Token expired or invalid')
240
- }
241
-
242
- return pick(userInfo, ['id', 'name', 'email'])
243
- }
@@ -1,20 +0,0 @@
1
- import open from 'open'
2
-
3
- import {type CliCommandDefinition} from '../../types'
4
-
5
- const docsCommand: CliCommandDefinition = {
6
- name: 'docs',
7
- helpText: '',
8
- signature: 'docs',
9
- description: 'Opens Sanity Studio documentation in your web browser',
10
- async action(args, context) {
11
- const {output} = context
12
- const {print} = output
13
- const url = 'https://www.sanity.io/docs'
14
-
15
- print(`Opening ${url}`)
16
- await open(url)
17
- },
18
- }
19
-
20
- export default docsCommand
@@ -1,73 +0,0 @@
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
- --open Open dev server in a new browser tab
9
-
10
- Examples
11
- # Start dev server on default port
12
- sanity functions dev
13
-
14
- # Start dev server on specific port
15
- sanity functions dev --port 3333
16
-
17
- # Start dev server and open a new browser tab
18
- sanity functions dev --open
19
- `
20
-
21
- export interface FunctionsDevFlags {
22
- open?: boolean
23
- port?: number
24
- }
25
-
26
- const defaultFlags: FunctionsDevFlags = {
27
- open: false,
28
- port: 8080,
29
- }
30
-
31
- const devFunctionsCommand: CliCommandDefinition<FunctionsDevFlags> = {
32
- name: 'dev',
33
- group: 'functions',
34
- helpText,
35
- signature: '[--port <port> --open]',
36
- description: 'Start the Sanity Function emulator',
37
- async action(args, context) {
38
- const {apiClient, output} = context
39
- const flags = {...defaultFlags, ...args.extOptions}
40
- const {open: shouldOpen} = flags
41
-
42
- const client = apiClient({requireUser: true, requireProject: false})
43
- const {token} = client.config()
44
-
45
- if (!token) throw new Error('No API token found. Please run `sanity login`.')
46
-
47
- const {initBlueprintConfig} = await import('@sanity/runtime-cli/cores')
48
- const {functionDevCore} = await import('@sanity/runtime-cli/cores/functions')
49
-
50
- const cmdConfig = await initBlueprintConfig({
51
- bin: 'sanity',
52
- log: (message) => output.print(message),
53
- token,
54
- })
55
-
56
- if (!cmdConfig.ok) throw new Error(cmdConfig.error)
57
-
58
- const {success, error} = await functionDevCore({
59
- ...cmdConfig.value,
60
- flags: {
61
- port: flags.port,
62
- },
63
- })
64
-
65
- if (!success) throw new Error(error)
66
-
67
- if (shouldOpen) {
68
- open(`http://localhost:${flags.port}`)
69
- }
70
- },
71
- }
72
-
73
- export default devFunctionsCommand
@@ -1,105 +0,0 @@
1
- import {type CliCommandDefinition} from '../../types'
2
-
3
- const helpText = `
4
- Commands
5
- add Add or update an environment variable
6
- list List the environment variables
7
- remove Remove an environment variable
8
-
9
- Arguments
10
- <name> The name of the function
11
- <key> The name of the environment variable
12
- <value> The value of the environment variable
13
-
14
- Examples
15
- # Add or update an environment variable
16
- sanity functions env add echo API_URL https://api.example.com/
17
-
18
- # Remove an environment variable
19
- sanity functions env remove echo API_URL
20
-
21
- # List environment variables
22
- sanity functions env list echo
23
- `
24
-
25
- export interface FunctionsEnvFlags {
26
- //
27
- }
28
-
29
- const envFunctionsCommand: CliCommandDefinition<FunctionsEnvFlags> = {
30
- name: 'env',
31
- group: 'functions',
32
- helpText,
33
- signature: '<add|list|remove> <name> [key] [value]',
34
- description:
35
- 'Add or remove an environment variable or list environment variables for a Sanity function',
36
- async action(args, context) {
37
- const {apiClient, output} = context
38
- const [subCommand, name, key, value] = args.argsWithoutOptions
39
-
40
- if (!subCommand || !['add', 'list', 'remove'].includes(subCommand)) {
41
- throw new Error('You must specify if you want to list, add or remove')
42
- }
43
-
44
- if (subCommand === 'add' && (!key || !value)) {
45
- throw new Error('You must specify the name, key and value arguments')
46
- } else if (subCommand === 'remove' && !key) {
47
- throw new Error('You must specify the name and key arguments')
48
- }
49
-
50
- const client = apiClient({
51
- requireUser: true,
52
- requireProject: false,
53
- })
54
-
55
- if (!name) {
56
- throw new Error('You must provide a function name as the first argument')
57
- }
58
-
59
- const token = client.config().token
60
- if (!token) throw new Error('No API token found. Please run `sanity login`.')
61
-
62
- const {initDeployedBlueprintConfig} = await import('@sanity/runtime-cli/cores')
63
- const {functionEnvAddCore, functionEnvListCore, functionEnvRemoveCore} = await import(
64
- '@sanity/runtime-cli/cores/functions'
65
- )
66
-
67
- const cmdConfig = await initDeployedBlueprintConfig({
68
- bin: 'sanity',
69
- log: (message) => output.print(message),
70
- token,
71
- })
72
-
73
- if (!cmdConfig.ok) throw new Error(cmdConfig.error)
74
-
75
- let response
76
- switch (subCommand) {
77
- case 'add':
78
- response = await functionEnvAddCore({
79
- ...cmdConfig.value,
80
- args: {name, key, value},
81
- })
82
- break
83
- case 'list':
84
- response = await functionEnvListCore({
85
- ...cmdConfig.value,
86
- args: {name},
87
- })
88
- break
89
- case 'remove':
90
- response = await functionEnvRemoveCore({
91
- ...cmdConfig.value,
92
- args: {name, key},
93
- })
94
- break
95
- default:
96
- throw new Error(`Unknown subcommand: ${subCommand}`)
97
- }
98
-
99
- const {success, error} = response
100
-
101
- if (!success) throw new Error(error)
102
- },
103
- }
104
-
105
- export default envFunctionsCommand
@@ -1,10 +0,0 @@
1
- import {type CliCommandGroupDefinition} from '../../types'
2
-
3
- const functionsGroup: CliCommandGroupDefinition = {
4
- name: 'functions',
5
- signature: '[COMMAND]',
6
- isGroupRoot: true,
7
- description: 'Manage, test, and observe Sanity Functions',
8
- }
9
-
10
- export default functionsGroup
@@ -1,94 +0,0 @@
1
- import {type CliCommandDefinition} from '../../types'
2
-
3
- const helpText = `
4
- Arguments
5
- <name> The name of the Function to retrieve logs for
6
-
7
- Options
8
- --limit <limit> The number of log entries to retrieve [default 50]
9
- --json If set return json
10
- --utc Use UTC dates in logs
11
- --delete Delete all logs for the Function
12
- --force Force delete all logs for the Function
13
- --watch Watch for new logs (streaming mode)
14
-
15
- Examples
16
- # Retrieve logs for Sanity Function
17
- sanity functions logs echo
18
-
19
- # Retrieve the last two log entries for Sanity Function
20
- sanity functions logs echo --limit 2
21
-
22
- # Retrieve logs for Sanity Function in json format
23
- sanity functions logs echo --json
24
-
25
- # Delete all logs for Sanity Function
26
- sanity functions logs echo --delete
27
-
28
- # Watch for new logs (streaming mode)
29
- sanity functions logs echo --watch
30
- `
31
-
32
- export interface FunctionsLogsFlags {
33
- limit?: number
34
- json?: boolean
35
- utc?: boolean
36
- delete?: boolean
37
- force?: boolean
38
- watch?: boolean // undocumented for now
39
- }
40
-
41
- const defaultFlags = {
42
- limit: 50,
43
- json: false,
44
- utc: false,
45
- delete: false,
46
- force: false,
47
- watch: false,
48
- }
49
-
50
- const logsFunctionsCommand: CliCommandDefinition<FunctionsLogsFlags> = {
51
- name: 'logs',
52
- group: 'functions',
53
- helpText,
54
- signature: '<name> [--limit <number>] [--json] [--utc] [--delete [--force]] [--watch]',
55
- description: 'Retrieve or delete logs for a Sanity Function',
56
- async action(args, context) {
57
- const {apiClient, output} = context
58
- const [name] = args.argsWithoutOptions
59
- const flags = {...defaultFlags, ...args.extOptions}
60
-
61
- const client = apiClient({
62
- requireUser: true,
63
- requireProject: false,
64
- })
65
-
66
- if (!name) {
67
- throw new Error('You must provide a function name as the first argument')
68
- }
69
-
70
- const token = client.config().token
71
- if (!token) throw new Error('No API token found. Please run `sanity login`.')
72
-
73
- const {initDeployedBlueprintConfig} = await import('@sanity/runtime-cli/cores')
74
- const {functionLogsCore} = await import('@sanity/runtime-cli/cores/functions')
75
-
76
- const cmdConfig = await initDeployedBlueprintConfig({
77
- bin: 'sanity',
78
- log: (message) => output.print(message),
79
- token,
80
- })
81
-
82
- if (!cmdConfig.ok) throw new Error(cmdConfig.error)
83
-
84
- const {success, error} = await functionLogsCore({
85
- ...cmdConfig.value,
86
- args: {name},
87
- flags,
88
- })
89
-
90
- if (!success) throw new Error(error)
91
- },
92
- }
93
-
94
- export default logsFunctionsCommand
@@ -1,93 +0,0 @@
1
- import {type CliCommandDefinition} from '../../types'
2
-
3
- const helpText = `
4
- Arguments
5
- <name> The name of the Sanity Function
6
-
7
- Options
8
- --data <data> Data to send to the function
9
- --file <file> Read data from file and send to the function
10
- --timeout <timeout> Execution timeout value in seconds
11
- --api <version> Sanity API Version to use
12
- --dataset <dataset> The Sanity dataset to use
13
- --project-id <id> Sanity Project ID to use
14
-
15
-
16
- Examples
17
- # Test function passing event data on command line
18
- sanity functions test echo --data '{ "id": 1 }'
19
-
20
- # Test function passing event data via a file
21
- sanity functions test echo --file 'payload.json'
22
-
23
- # Test function passing event data on command line and cap execution time to 60 seconds
24
- sanity functions test echo --data '{ "id": 1 }' --timeout 60
25
- `
26
-
27
- export interface FunctionsTestFlags {
28
- 'data'?: string
29
- 'file'?: string
30
- 'timeout'?: number
31
- 'api'?: string
32
- 'dataset'?: string
33
- 'project-id'?: string
34
- }
35
-
36
- const defaultFlags: FunctionsTestFlags = {
37
- timeout: 10, // seconds
38
- }
39
-
40
- const testFunctionsCommand: CliCommandDefinition<FunctionsTestFlags> = {
41
- name: 'test',
42
- group: 'functions',
43
- helpText,
44
- signature:
45
- '<name> [--data <json>] [--file <filename>] [--timeout <seconds>] [--api <version>] [--dataset <name>] [--project-id] <id>]',
46
- description: 'Invoke a local Sanity Function',
47
- async action(args, context) {
48
- const {apiClient, output} = context
49
- const [name] = args.argsWithoutOptions
50
- const flags = {...defaultFlags, ...args.extOptions}
51
-
52
- const client = apiClient({
53
- requireUser: true,
54
- requireProject: false,
55
- })
56
- const {dataset, projectId, token} = client.config()
57
- const actualDataset = dataset === '~dummy-placeholder-dataset-' ? undefined : dataset
58
-
59
- if (!token) throw new Error('No API token found. Please run `sanity login`.')
60
-
61
- if (!name) {
62
- throw new Error('You must provide a function name as the first argument')
63
- }
64
-
65
- const {initBlueprintConfig} = await import('@sanity/runtime-cli/cores')
66
- const {functionTestCore} = await import('@sanity/runtime-cli/cores/functions')
67
-
68
- const cmdConfig = await initBlueprintConfig({
69
- bin: 'sanity',
70
- log: (message: string) => output.print(message),
71
- token,
72
- })
73
-
74
- if (!cmdConfig.ok) throw new Error(cmdConfig.error)
75
-
76
- const {success, error} = await functionTestCore({
77
- ...cmdConfig.value,
78
- args: {name},
79
- flags: {
80
- 'data': flags.data,
81
- 'file': flags.file,
82
- 'timeout': flags.timeout,
83
- 'api': flags.api,
84
- 'dataset': flags.dataset || actualDataset,
85
- 'project-id': flags['project-id'] || projectId,
86
- },
87
- })
88
-
89
- if (!success) throw new Error(error)
90
- },
91
- }
92
-
93
- export default testFunctionsCommand
@@ -1,21 +0,0 @@
1
- import {type CliCommandDefinition} from '../../types'
2
- import showHelp from './showHelp'
3
-
4
- const help = `
5
- With no options and no COMMAND given, the synopsis of the sanity command and a
6
- list of the most commonly used commands are printed on the standard output.
7
-
8
- If a command is given, the help page for that command is printed to standard
9
- output. This will usually be more in-depth than the brief description shown in
10
- the command list.
11
- `
12
-
13
- const command: CliCommandDefinition = {
14
- name: 'help',
15
- signature: '[COMMAND]',
16
- description: 'Displays help information about Sanity CLI commands',
17
- action: showHelp,
18
- helpText: help,
19
- }
20
-
21
- export default command