@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.
- package/lib/_chunks-cjs/cli.js +5 -5
- package/lib/_chunks-cjs/cli.js.map +1 -1
- package/lib/_chunks-cjs/cliWorker.js.map +1 -1
- package/lib/_chunks-cjs/generateAction.js.map +1 -1
- package/lib/_chunks-cjs/getCliConfig.js.map +1 -1
- package/lib/_chunks-cjs/journeyConfig.js.map +1 -1
- package/lib/_chunks-cjs/loadEnv.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/index.mjs.map +1 -1
- package/lib/run.js.map +1 -1
- package/lib/workers/getAndWriteJourneySchema.js.map +1 -1
- package/lib/workers/getCliConfig.js.map +1 -1
- package/lib/workers/typegenGenerate.js.map +1 -1
- package/package.json +6 -7
- package/templates/blog/README.md +1 -1
- package/templates/clean/README.md +1 -1
- package/templates/ecommerce/README.md +1 -1
- package/templates/get-started/README.md +1 -1
- package/templates/moviedb/README.md +1 -1
- package/templates/quickstart/README.md +1 -1
- package/src/CommandRunner.ts +0 -219
- package/src/__telemetry__/cli.telemetry.ts +0 -29
- package/src/__telemetry__/init.telemetry.ts +0 -95
- package/src/actions/codemod/codemodAction.ts +0 -109
- package/src/actions/codemod/mods/deskRename.ts +0 -19
- package/src/actions/codemod/mods/index.ts +0 -9
- package/src/actions/codemod/mods/partsTypeDirective.ts +0 -28
- package/src/actions/codemod/mods/reactIconsV3.ts +0 -54
- package/src/actions/codemod/types.ts +0 -10
- package/src/actions/init-plugin/bootstrapFromTemplate.ts +0 -196
- package/src/actions/init-project/bootstrapLocalTemplate.ts +0 -201
- package/src/actions/init-project/bootstrapRemoteTemplate.ts +0 -118
- package/src/actions/init-project/createAppCliConfig.ts +0 -24
- package/src/actions/init-project/createCliConfig.ts +0 -31
- package/src/actions/init-project/createPackageManifest.ts +0 -102
- package/src/actions/init-project/createStudioConfig.ts +0 -53
- package/src/actions/init-project/determineAppTemplate.ts +0 -13
- package/src/actions/init-project/fsUtils.ts +0 -40
- package/src/actions/init-project/git.ts +0 -59
- package/src/actions/init-project/initProject.ts +0 -1708
- package/src/actions/init-project/processTemplate.ts +0 -55
- package/src/actions/init-project/promptForDatasetName.ts +0 -68
- package/src/actions/init-project/prompts/index.ts +0 -51
- package/src/actions/init-project/prompts/nextjs.ts +0 -59
- package/src/actions/init-project/readPackageJson.ts +0 -17
- package/src/actions/init-project/templates/appQuickstart.ts +0 -23
- package/src/actions/init-project/templates/appSanityUi.ts +0 -25
- package/src/actions/init-project/templates/blog.ts +0 -5
- package/src/actions/init-project/templates/clean.ts +0 -5
- package/src/actions/init-project/templates/getStarted.ts +0 -37
- package/src/actions/init-project/templates/index.ts +0 -24
- package/src/actions/init-project/templates/moviedb.ts +0 -35
- package/src/actions/init-project/templates/nextjs/index.ts +0 -238
- package/src/actions/init-project/templates/nextjs/schemaTypes/blog.ts +0 -252
- package/src/actions/init-project/templates/quickstart.ts +0 -5
- package/src/actions/init-project/templates/shopify.ts +0 -78
- package/src/actions/init-project/templates/shopifyOnline.ts +0 -50
- package/src/actions/init-project/updateInitialTemplateMetadata.ts +0 -24
- package/src/actions/login/login.telemetry.ts +0 -18
- package/src/actions/login/login.ts +0 -350
- package/src/actions/login/types.ts +0 -19
- package/src/actions/project/createProject.ts +0 -36
- package/src/actions/telemetry/setTelemetryConsent.ts +0 -101
- package/src/actions/typegen/generate.telemetry.ts +0 -20
- package/src/actions/typegen/generateAction.ts +0 -210
- package/src/actions/versions/findSanityModuleVersions.ts +0 -185
- package/src/actions/yarn/events.ts +0 -73
- package/src/cli.ts +0 -350
- package/src/cliClient.ts +0 -62
- package/src/commands/blueprints/addBlueprintsCommand.ts +0 -155
- package/src/commands/blueprints/blueprintsGroup.ts +0 -10
- package/src/commands/blueprints/configBlueprintsCommand.ts +0 -86
- package/src/commands/blueprints/deployBlueprintsCommand.ts +0 -63
- package/src/commands/blueprints/destroyBlueprintsCommand.ts +0 -78
- package/src/commands/blueprints/infoBlueprintsCommand.ts +0 -55
- package/src/commands/blueprints/initBlueprintsCommand.ts +0 -99
- package/src/commands/blueprints/logsBlueprintsCommand.ts +0 -66
- package/src/commands/blueprints/planBlueprintsCommand.ts +0 -51
- package/src/commands/blueprints/stacksBlueprintsCommand.ts +0 -66
- package/src/commands/codemod/codemodCommand.ts +0 -32
- package/src/commands/debug/debugCommand.ts +0 -26
- package/src/commands/debug/printDebugInfo.ts +0 -243
- package/src/commands/docs/docsCommand.ts +0 -20
- package/src/commands/functions/devFunctionsCommand.ts +0 -73
- package/src/commands/functions/envFunctionsCommand.ts +0 -105
- package/src/commands/functions/functionsGroup.ts +0 -10
- package/src/commands/functions/logsFunctionsCommand.ts +0 -94
- package/src/commands/functions/testFunctionsCommand.ts +0 -93
- package/src/commands/help/helpCommand.ts +0 -21
- package/src/commands/help/showHelp.ts +0 -58
- package/src/commands/index.ts +0 -72
- package/src/commands/init/initCommand.ts +0 -123
- package/src/commands/install/installCommand.ts +0 -38
- package/src/commands/learn/learnCommand.ts +0 -20
- package/src/commands/login/loginCommand.ts +0 -29
- package/src/commands/logout/logoutCommand.ts +0 -52
- package/src/commands/manage/manageCommand.ts +0 -24
- package/src/commands/projects/listProjectsCommand.ts +0 -62
- package/src/commands/projects/projectsGroup.ts +0 -10
- package/src/commands/telemetry/disableTelemetryCommand.ts +0 -19
- package/src/commands/telemetry/enableTelemetryCommand.ts +0 -19
- package/src/commands/telemetry/telemetryGroup.ts +0 -10
- package/src/commands/telemetry/telemetryStatusCommand.ts +0 -89
- package/src/commands/typegen/generateTypesCommand.ts +0 -56
- package/src/commands/typegen/typegenGroup.ts +0 -10
- package/src/commands/versions/printVersionResult.ts +0 -51
- package/src/commands/versions/versionsCommand.ts +0 -13
- package/src/config.ts +0 -14
- package/src/debug.ts +0 -3
- package/src/index.ts +0 -6
- package/src/outputters/cliOutputter.ts +0 -47
- package/src/packageManager/getInstallCommand.ts +0 -26
- package/src/packageManager/getUpgradeCommand.ts +0 -52
- package/src/packageManager/index.ts +0 -33
- package/src/packageManager/installPackages.ts +0 -99
- package/src/packageManager/packageManagerChoice.ts +0 -204
- package/src/packageManager/uninstallPackages.ts +0 -44
- package/src/packageManager/yarnStub.ts +0 -22
- package/src/prompters/cliPrompter.ts +0 -9
- package/src/run.ts +0 -8
- package/src/studioDependencies.ts +0 -25
- package/src/types.ts +0 -387
- package/src/util/canLaunchBrowser.ts +0 -12
- package/src/util/cliWorker.ts +0 -34
- package/src/util/clientWrapper.ts +0 -119
- package/src/util/copy.ts +0 -50
- package/src/util/createExpiringConfig.ts +0 -80
- package/src/util/createTelemetryStore.ts +0 -204
- package/src/util/detectRuntime.ts +0 -12
- package/src/util/dynamicRequire.ts +0 -17
- package/src/util/frameworkPort.ts +0 -63
- package/src/util/generateCommandsDocumentation.ts +0 -62
- package/src/util/getCliConfig.ts +0 -172
- package/src/util/getCliVersion.ts +0 -22
- package/src/util/getLocalVersion.ts +0 -35
- package/src/util/getProjectDefaults.ts +0 -103
- package/src/util/getProviderName.ts +0 -9
- package/src/util/getUserConfig.ts +0 -15
- package/src/util/isCi.ts +0 -7
- package/src/util/isCommandGroup.ts +0 -7
- package/src/util/isInteractive.ts +0 -3
- package/src/util/isTrueish.ts +0 -8
- package/src/util/journeyConfig.ts +0 -280
- package/src/util/loadEnv.ts +0 -110
- package/src/util/mergeCommands.ts +0 -78
- package/src/util/neatStack.ts +0 -30
- package/src/util/noSuchCommandText.ts +0 -91
- package/src/util/parseArguments.ts +0 -76
- package/src/util/pathExists.ts +0 -14
- package/src/util/readJson.ts +0 -6
- package/src/util/readdirRecursive.ts +0 -26
- package/src/util/remoteTemplate.ts +0 -320
- package/src/util/resolveLatestVersions.ts +0 -24
- package/src/util/resolveRootDir.ts +0 -59
- package/src/util/telemetryDisclosure.ts +0 -45
- package/src/util/updateNotifier.ts +0 -158
- package/src/util/writeJson.ts +0 -6
- package/src/workers/getAndWriteJourneySchema.ts +0 -7
- package/src/workers/getCliConfig.ts +0 -14
- 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
|