@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
package/src/cli.ts DELETED
@@ -1,350 +0,0 @@
1
- /* eslint-disable no-console, no-process-exit, no-sync */
2
- import {existsSync} from 'node:fs'
3
- import os from 'node:os'
4
- import path from 'node:path'
5
-
6
- import chalk from 'chalk'
7
- import dotenv from 'dotenv'
8
- import resolveFrom from 'resolve-from'
9
-
10
- import {CliCommand} from './__telemetry__/cli.telemetry'
11
- import {getCliRunner} from './CommandRunner'
12
- import {baseCommands} from './commands'
13
- import {debug} from './debug'
14
- import {getInstallCommand} from './packageManager'
15
- import {type CommandRunnerOptions, type TelemetryUserProperties} from './types'
16
- import {createTelemetryStore} from './util/createTelemetryStore'
17
- import {detectRuntime} from './util/detectRuntime'
18
- import {type CliConfigResult, getCliConfig} from './util/getCliConfig'
19
- import {loadEnv} from './util/loadEnv'
20
- import {mergeCommands} from './util/mergeCommands'
21
- import {neatStack} from './util/neatStack'
22
- import {parseArguments} from './util/parseArguments'
23
- import {resolveRootDir} from './util/resolveRootDir'
24
- import {telemetryDisclosure} from './util/telemetryDisclosure'
25
- import {runUpdateCheck} from './util/updateNotifier'
26
-
27
- const sanityEnv = process.env.SANITY_INTERNAL_ENV || 'production' // eslint-disable-line no-process-env
28
- const knownEnvs = ['development', 'staging', 'production']
29
-
30
- function wait(ms: number) {
31
- return new Promise((resolve) => setTimeout(resolve, ms))
32
- }
33
-
34
- function installProcessExitHack(finalTask: () => Promise<unknown>) {
35
- const originalProcessExit = process.exit
36
-
37
- // @ts-expect-error ignore TS2534
38
- process.exit = (exitCode?: number | undefined): never => {
39
- finalTask().finally(() => originalProcessExit(exitCode))
40
- }
41
- }
42
-
43
- export async function runCli(cliRoot: string, {cliVersion}: {cliVersion: string}): Promise<void> {
44
- installUnhandledRejectionsHandler()
45
-
46
- const pkg = {name: '@sanity/cli', version: cliVersion}
47
-
48
- const args = parseArguments()
49
- const isInit = args.groupOrCommand === 'init' && args.argsWithoutOptions[0] !== 'plugin'
50
- const cwd = getCurrentWorkingDirectory()
51
- let workDir: string | undefined
52
- try {
53
- workDir = isInit ? process.cwd() : resolveRootDir(cwd)
54
- } catch (err) {
55
- console.error(chalk.red(err.message))
56
- process.exit(1)
57
- }
58
-
59
- // Check if there are updates available for the CLI, and notify if there is
60
- await runUpdateCheck({pkg, cwd, workDir}).notify()
61
-
62
- // If the telemetry disclosure message has not yet been shown, show it.
63
- telemetryDisclosure()
64
-
65
- // Try to figure out if we're in a v2 or v3 context by finding a config
66
- debug(`Reading CLI config from "${workDir}"`)
67
- let cliConfig = await getCliConfig(workDir, {forked: true})
68
- if (!cliConfig) {
69
- debug('No CLI config found')
70
- }
71
-
72
- // Figure out if the app is a studio or an app from the CLI config
73
- const isApp = Boolean(cliConfig && 'app' in cliConfig)
74
- // Load the environment variables from
75
- loadAndSetEnvFromDotEnvFiles({workDir, cmd: args.groupOrCommand, isApp})
76
- maybeFixMissingWindowsEnvVar()
77
-
78
- // Reload the the cli config so env vars can work.
79
- cliConfig = await getCliConfig(workDir, {forked: true})
80
-
81
- const {logger: telemetry, flush: flushTelemetry} = createTelemetryStore<TelemetryUserProperties>({
82
- projectId: cliConfig?.config?.api?.projectId,
83
- env: process.env,
84
- })
85
-
86
- // UGLY HACK: process.exit(<code>) causes abrupt exit, we want to flush telemetry before exiting
87
- installProcessExitHack(() =>
88
- // When process.exit() is called, flush telemetry events first, but wait no more than x amount of ms before exiting process
89
- Promise.race([wait(2000), flushTelemetry()]),
90
- )
91
-
92
- telemetry.updateUserProperties({
93
- runtimeVersion: process.version,
94
- runtime: detectRuntime(),
95
- cliVersion: pkg.version,
96
- machinePlatform: process.platform,
97
- cpuArchitecture: process.arch,
98
- projectId: cliConfig?.config?.api?.projectId,
99
- dataset: cliConfig?.config?.api?.dataset,
100
- })
101
-
102
- const options: CommandRunnerOptions = {
103
- cliRoot: cliRoot,
104
- workDir: workDir,
105
- corePath: await getCoreModulePath(workDir, cliConfig),
106
- cliConfig,
107
- telemetry,
108
- }
109
-
110
- warnOnNonProductionEnvironment()
111
- warnOnInferredProjectDir(isInit, cwd, workDir)
112
-
113
- const core = args.coreOptions
114
- const commands = await mergeCommands(baseCommands, options.corePath, {cliVersion, cwd, workDir})
115
-
116
- if (core.v || core.version) {
117
- console.log(`${pkg.name} version ${pkg.version}`)
118
- process.exit()
119
- }
120
-
121
- // Translate `sanity -h <command>` to `sanity help <command>`
122
- if (core.h || core.help) {
123
- if (args.groupOrCommand) {
124
- args.argsWithoutOptions.unshift(args.groupOrCommand)
125
- }
126
-
127
- args.groupOrCommand = 'help'
128
- }
129
-
130
- if (args.groupOrCommand === 'logout') {
131
- // flush telemetry events before logging out
132
- await flushTelemetry()
133
- }
134
-
135
- const cliRunner = getCliRunner(commands)
136
- const cliCommandTrace = telemetry.trace(CliCommand, {
137
- groupOrCommand: args.groupOrCommand,
138
- extraArguments: args.extraArguments,
139
- commandArguments: args.argsWithoutOptions.slice(0, 10),
140
- coreOptions: {
141
- help: args.coreOptions.help || undefined,
142
- version: args.coreOptions.help || undefined,
143
- debug: args.coreOptions.help || undefined,
144
- },
145
- ...(!args.groupOrCommand && {emptyCommand: true}), // user did not entry a command
146
- })
147
-
148
- cliCommandTrace.start()
149
- cliRunner
150
- .runCommand(args.groupOrCommand, args, {
151
- ...options,
152
- telemetry: cliCommandTrace.newContext(args.groupOrCommand),
153
- })
154
- .then(() => cliCommandTrace.complete())
155
- .catch(async (err) => {
156
- await flushTelemetry()
157
- const error = typeof err.details === 'string' ? err.details : err
158
- // eslint-disable-next-line no-console
159
- console.error(`\n${error.stack ? neatStack(err) : error}`)
160
- if (err.cause) {
161
- console.error(`\nCaused by:\n\n${err.cause.stack ? neatStack(err.cause) : err.cause}`)
162
- }
163
- // eslint-disable-next-line no-process-exit
164
- cliCommandTrace.error(error)
165
- process.exit(1)
166
- })
167
- }
168
-
169
- async function getCoreModulePath(
170
- workDir: string,
171
- cliConfig: CliConfigResult | null,
172
- ): Promise<string | undefined> {
173
- const corePath = resolveFrom.silent(workDir, '@sanity/core')
174
- const sanityPath = resolveFrom.silent(workDir, 'sanity/_internal')
175
-
176
- if (corePath && sanityPath) {
177
- const closest = corePath.startsWith(workDir) ? corePath : sanityPath
178
- const assumedVersion = closest === corePath ? 'v2' : 'v3'
179
-
180
- console.warn(
181
- chalk.yellow(
182
- `Both \`@sanity/core\` AND \`sanity\` installed - assuming Sanity ${assumedVersion} project.`,
183
- ),
184
- )
185
-
186
- return closest
187
- }
188
-
189
- if (sanityPath) {
190
- // On v3 and everything installed
191
- return sanityPath
192
- }
193
-
194
- if (corePath && cliConfig && cliConfig?.version < 3) {
195
- // On v2 and everything installed
196
- return corePath
197
- }
198
-
199
- const isInstallCommand = process.argv.indexOf('install') === -1
200
-
201
- if (cliConfig && cliConfig?.version < 3 && !corePath && !isInstallCommand) {
202
- const installCmd = await getInstallCommand({workDir})
203
- console.warn(
204
- chalk.yellow(
205
- [
206
- 'The `@sanity/core` module is not installed in current project',
207
- `Project-specific commands not available until you run \`${installCmd}\``,
208
- ].join('\n'),
209
- ),
210
- )
211
- }
212
-
213
- if (cliConfig && cliConfig.version >= 3 && !sanityPath) {
214
- const installCmd = await getInstallCommand({workDir})
215
- console.warn(
216
- chalk.yellow(
217
- [
218
- 'The `sanity` module is not installed in current project',
219
- `Project-specific commands not available until you run \`${installCmd}\``,
220
- ].join('\n'),
221
- ),
222
- )
223
- }
224
-
225
- return undefined
226
- }
227
-
228
- /**
229
- * Returns the current working directory, but also handles a weird edge case where
230
- * the folder the terminal is currently in has been removed
231
- */
232
- function getCurrentWorkingDirectory(): string {
233
- let pwd
234
- try {
235
- pwd = process.cwd()
236
- } catch (err) {
237
- if (err.code === 'ENOENT') {
238
- console.error('[ERR] Could not resolve working directory, does the current folder exist?')
239
- process.exit(1)
240
- } else {
241
- throw err
242
- }
243
- }
244
-
245
- return pwd
246
- }
247
-
248
- function installUnhandledRejectionsHandler() {
249
- process.on('unhandledRejection', (reason) => {
250
- if (rejectionHasStack(reason)) {
251
- console.error('Unhandled rejection:', reason.stack)
252
- } else {
253
- console.error('Unhandled rejection\n', reason)
254
- }
255
- })
256
- }
257
-
258
- function rejectionHasStack(reason: unknown): reason is {stack: string} {
259
- return Boolean(
260
- reason && typeof reason === 'object' && 'stack' in reason && typeof reason.stack === 'string',
261
- )
262
- }
263
-
264
- function warnOnInferredProjectDir(isInit: boolean, cwd: string, workDir: string): void {
265
- if (isInit || cwd === workDir) {
266
- return
267
- }
268
-
269
- console.log(`Not in project directory, assuming context of project at ${workDir}`)
270
- }
271
-
272
- function warnOnNonProductionEnvironment(): void {
273
- if (sanityEnv === 'production') {
274
- return
275
- }
276
-
277
- console.warn(
278
- chalk.yellow(
279
- knownEnvs.includes(sanityEnv)
280
- ? `[WARN] Running in ${sanityEnv} environment mode\n`
281
- : `[WARN] Running in ${chalk.red('UNKNOWN')} "${sanityEnv}" environment mode\n`,
282
- ),
283
- )
284
- }
285
-
286
- function loadAndSetEnvFromDotEnvFiles({
287
- workDir,
288
- cmd,
289
- isApp,
290
- }: {
291
- workDir: string
292
- cmd: string
293
- isApp: boolean
294
- }) {
295
- /* eslint-disable no-process-env */
296
-
297
- // Do a cheap lookup for a sanity.json file. If there is one, assume it is a v2 project,
298
- // and apply the old behavior for environment variables. Otherwise, use the Vite-style
299
- // behavior. We need to do this "cheap" lookup because when loading the v3 config, env vars
300
- // may be used in the configuration file, meaning we'd have to load the config twice.
301
- if (existsSync(path.join(workDir, 'sanity.json'))) {
302
- // v2
303
- debug('sanity.json exists, assuming v2 project and loading .env files using old behavior')
304
- const env = process.env.SANITY_ACTIVE_ENV || process.env.NODE_ENV || 'development'
305
- debug('Loading environment files using %s mode', env)
306
- dotenv.config({path: path.join(workDir, `.env.${env}`)})
307
- return
308
- }
309
-
310
- // v3+
311
- debug('No sanity.json exists, assuming v3 project and loading .env files using new behavior')
312
-
313
- // Use `production` for `sanity build` / `sanity deploy`,
314
- // but default to `development` for everything else unless `SANITY_ACTIVE_ENV` is set
315
- const isProdCmd = ['build', 'deploy'].includes(cmd)
316
- let mode = process.env.SANITY_ACTIVE_ENV
317
- if (!mode && (isProdCmd || process.env.NODE_ENV === 'production')) {
318
- mode = 'production'
319
- } else if (!mode) {
320
- mode = 'development'
321
- }
322
-
323
- if (mode === 'production' && !isProdCmd) {
324
- console.warn(chalk.yellow(`[WARN] Running in ${sanityEnv} environment mode\n`))
325
- }
326
-
327
- debug('Loading environment files using %s mode', mode)
328
-
329
- const studioEnv = loadEnv(mode, workDir, [isApp ? 'SANITY_APP_' : 'SANITY_STUDIO_'])
330
- process.env = {...process.env, ...studioEnv}
331
- /* eslint-disable no-process-env */
332
- }
333
-
334
- /**
335
- * Apparently, Windows environment variables are supposed to be case-insensitive,
336
- * (https://nodejs.org/api/process.html#processenv). However, it seems they are not?
337
- * `process.env.SYSTEMROOT` is sometimes `undefined`, whereas `process.env.SystemRoot` is _NOT_.
338
- *
339
- * The `open` npm module uses the former to open a browser on Powershell, and Sindre seems
340
- * unwilling to fix it (https://github.com/sindresorhus/open/pull/299#issuecomment-1447587598),
341
- * so this is a (temporary?) workaround in order to make opening browsers on windows work,
342
- * which several commands does (`sanity login`, `sanity docs` etc)
343
- */
344
- function maybeFixMissingWindowsEnvVar() {
345
- /* eslint-disable no-process-env */
346
- if (os.platform() === 'win32' && !('SYSTEMROOT' in process.env) && 'SystemRoot' in process.env) {
347
- process.env.SYSTEMROOT = process.env.SystemRoot
348
- }
349
- /* eslint-enable no-process-env */
350
- }
package/src/cliClient.ts DELETED
@@ -1,62 +0,0 @@
1
- import {createClient, type SanityClient} from '@sanity/client'
2
-
3
- import {getCliConfigSync} from './util/getCliConfig'
4
- import {resolveRootDir} from './util/resolveRootDir'
5
-
6
- export interface CliClientOptions {
7
- cwd?: string
8
-
9
- projectId?: string
10
- dataset?: string
11
- useCdn?: boolean
12
- token?: string
13
- apiVersion?: string
14
- }
15
-
16
- export function getCliClient(options: CliClientOptions = {}): SanityClient {
17
- if (typeof process !== 'object') {
18
- throw new Error('getCliClient() should only be called from node.js scripts')
19
- }
20
-
21
- const {
22
- // eslint-disable-next-line no-process-env
23
- cwd = process.env.SANITY_BASE_PATH || process.cwd(),
24
- useCdn = false,
25
- apiVersion = '2022-06-06',
26
- projectId,
27
- dataset,
28
- token = getCliClient.__internal__getToken(),
29
- } = options
30
-
31
- if (projectId && dataset) {
32
- return createClient({projectId, dataset, apiVersion, useCdn, token})
33
- }
34
-
35
- const rootDir = resolveRootDir(cwd)
36
- const {config} = getCliConfigSync(rootDir) || {}
37
- if (!config) {
38
- throw new Error('Unable to resolve CLI configuration')
39
- }
40
-
41
- const apiConfig = config?.api || {}
42
- if (!apiConfig.projectId || !apiConfig.dataset) {
43
- throw new Error('Unable to resolve project ID/dataset from CLI configuration')
44
- }
45
-
46
- return createClient({
47
- projectId: apiConfig.projectId,
48
- dataset: apiConfig.dataset,
49
- apiVersion,
50
- useCdn,
51
- token,
52
- })
53
- }
54
-
55
- /* eslint-disable camelcase */
56
- /**
57
- * @internal
58
- * @deprecated This is only for INTERNAL use, and should not be relied upon outside of official Sanity modules
59
- * @returns A token to use when constructing a client without a `token` explicitly defined, or undefined
60
- */
61
- getCliClient.__internal__getToken = (): string | undefined => undefined
62
- /* eslint-enable camelcase */
@@ -1,155 +0,0 @@
1
- import {type CliCommandDefinition} from '../../types'
2
-
3
- const helpText = `
4
- Arguments
5
- <type> Type of Resource to add (currently only 'function' is supported)
6
-
7
- Options
8
- --name, -n <name> Name of the Resource
9
- --fn-type <type> Type of Function to add (e.g. document-publish)
10
- --fn-language, --lang <ts|js> Language of the Function. Default: "ts"
11
- --js, --javascript Shortcut for --fn-language=js
12
- --fn-helpers, --helpers Add helpers to the Function
13
- --no-fn-helpers Do not add helpers to the Function
14
- --fn-installer, Package manager to use for Function helpers
15
- --installer <npm|pnpm|yarn> sets --fn-helpers to true
16
- --install, -i Shortcut for --fn-installer=npm
17
-
18
- Examples:
19
- # Add a Function (TypeScript by default)
20
- sanity blueprints add function
21
-
22
- # Add a Function with a specific name and install helpers with npm
23
- sanity blueprints add function --name my-function -i
24
-
25
- # Add a Function with a specific type
26
- sanity blueprints add function --fn-type document-publish
27
-
28
- # Add a Function using an example
29
- sanity blueprints add function --example example-name
30
-
31
- # Add a JavaScript Function
32
- sanity blueprints add function --js
33
-
34
- # Add a Function without helpers
35
- sanity blueprints add function --no-fn-helpers
36
-
37
- # Add a document-publish .js Function with helpers and install with npm
38
- sanity blueprints add function -n roboto --fn-type document-publish --js -i
39
- `
40
-
41
- export interface BlueprintsAddFlags {
42
- 'example'?: string
43
-
44
- 'name'?: string
45
- 'n'?: string
46
-
47
- 'fn-type'?: string
48
-
49
- 'fn-language'?: string
50
- 'lang'?: string
51
-
52
- 'javascript'?: boolean
53
- 'js'?: boolean
54
-
55
- 'fn-helpers'?: boolean
56
- 'helpers'?: boolean
57
- 'no-fn-helpers'?: boolean
58
-
59
- 'fn-installer'?: string
60
- 'installer'?: string
61
-
62
- 'install'?: boolean
63
- 'i'?: boolean
64
- }
65
-
66
- const defaultFlags: BlueprintsAddFlags = {
67
- 'fn-language': 'ts',
68
- // 'fn-helpers': true, // ask, for now
69
- }
70
-
71
- const addBlueprintsCommand: CliCommandDefinition<BlueprintsAddFlags> = {
72
- name: 'add',
73
- group: 'blueprints',
74
- helpText,
75
- signature:
76
- '<type> [--name <name>] [--fn-type <document-publish>] [--fn-lang <ts|js>] [--javascript]',
77
- description: 'Add a Resource to a Blueprint',
78
-
79
- async action(args, context) {
80
- const {output, apiClient} = context
81
- const {extOptions} = args
82
-
83
- if (extOptions.example) {
84
- // example is exclusive to 'name', 'fn-type', 'fn-language', 'javascript', 'fn-helpers', 'fn-installer'
85
- // check before merging default flags
86
- const conflictingFlags: (keyof BlueprintsAddFlags)[] = [
87
- 'name',
88
- 'n',
89
- 'fn-type',
90
- 'fn-language',
91
- 'lang',
92
- 'javascript',
93
- 'js',
94
- 'fn-helpers',
95
- 'helpers',
96
- 'fn-installer',
97
- 'installer',
98
- ]
99
- const foundConflict = conflictingFlags.find((key) => extOptions[key])
100
- if (foundConflict) {
101
- throw new Error(`--example can't be used with --${foundConflict}`)
102
- }
103
- }
104
-
105
- const flags = {...defaultFlags, ...extOptions}
106
-
107
- const client = apiClient({
108
- requireUser: true,
109
- requireProject: false,
110
- })
111
- const {token} = client.config()
112
-
113
- if (!token) throw new Error('No API token found. Please run `sanity login`.')
114
-
115
- const [resourceType] = args.argsWithoutOptions
116
-
117
- if (!resourceType) {
118
- output.error('Resource type is required. Available types: function')
119
- return
120
- }
121
-
122
- const {initBlueprintConfig} = await import('@sanity/runtime-cli/cores')
123
- const {blueprintAddCore} = await import('@sanity/runtime-cli/cores/blueprints')
124
-
125
- const cmdConfig = await initBlueprintConfig({
126
- bin: 'sanity',
127
- log: (message) => output.print(message),
128
- token,
129
- })
130
-
131
- if (!cmdConfig.ok) throw new Error(cmdConfig.error)
132
-
133
- let userWantsFnHelpers = flags.helpers || flags['fn-helpers']
134
- if (flags['no-fn-helpers'] === true) userWantsFnHelpers = false // override
135
-
136
- const {success, error} = await blueprintAddCore({
137
- ...cmdConfig.value,
138
- args: {type: resourceType},
139
- flags: {
140
- 'example': flags.example,
141
- 'name': flags.n ?? flags.name,
142
- 'fn-type': flags['fn-type'],
143
- 'language': flags.lang ?? flags['fn-language'],
144
- 'javascript': flags.js || flags.javascript,
145
- 'fn-helpers': userWantsFnHelpers,
146
- 'fn-installer': flags.installer ?? flags['fn-installer'],
147
- 'install': flags.i || flags.install,
148
- },
149
- })
150
-
151
- if (!success) throw new Error(error)
152
- },
153
- }
154
-
155
- export default addBlueprintsCommand
@@ -1,10 +0,0 @@
1
- import {type CliCommandGroupDefinition} from '../../types'
2
-
3
- const blueprintsGroup: CliCommandGroupDefinition = {
4
- name: 'blueprints',
5
- signature: '[COMMAND]',
6
- isGroupRoot: true,
7
- description: 'Deploy and manage Sanity Blueprints and Stacks (IaC)',
8
- }
9
-
10
- export default blueprintsGroup
@@ -1,86 +0,0 @@
1
- import {type CliCommandDefinition} from '../../types'
2
-
3
- const helpText = `
4
- Options
5
- --edit, -e Edit the configuration
6
- --test, -t Test the configuration
7
- --project-id <id> Project ID to use
8
-
9
- Examples:
10
- # View current configuration
11
- sanity blueprints config
12
-
13
- # Edit configuration
14
- sanity blueprints config --edit
15
-
16
- # Test configuration
17
- sanity blueprints config --test
18
-
19
- # Edit and test configuration
20
- sanity blueprints config -et
21
- `
22
-
23
- export interface BlueprintsConfigFlags {
24
- 'test-config'?: boolean
25
- 'test'?: boolean
26
- 't'?: boolean
27
- 'edit'?: boolean
28
- 'e'?: boolean
29
- 'project-id'?: string
30
- 'projectId'?: string
31
- 'project'?: string
32
- 'stack-id'?: string
33
- 'stackId'?: string
34
- 'stack'?: string
35
- }
36
-
37
- const defaultFlags: BlueprintsConfigFlags = {
38
- //
39
- }
40
-
41
- const configBlueprintsCommand: CliCommandDefinition<BlueprintsConfigFlags> = {
42
- name: 'config',
43
- group: 'blueprints',
44
- helpText,
45
- signature: '[--edit] [-e] [--test] [-t] [--project-id <id>]',
46
- description: 'View or edit local Blueprints configuration',
47
-
48
- async action(args, context) {
49
- const {apiClient, output} = context
50
- const flags = {...defaultFlags, ...args.extOptions}
51
-
52
- const client = apiClient({
53
- requireUser: true,
54
- requireProject: false,
55
- })
56
- const {token} = client.config()
57
-
58
- if (!token) throw new Error('No API token found. Please run `sanity login`.')
59
-
60
- const {initBlueprintConfig} = await import('@sanity/runtime-cli/cores')
61
- const {blueprintConfigCore} = await import('@sanity/runtime-cli/cores/blueprints')
62
-
63
- const cmdConfig = await initBlueprintConfig({
64
- bin: 'sanity',
65
- log: (message) => output.print(message),
66
- token,
67
- })
68
-
69
- if (!cmdConfig.ok) throw new Error(cmdConfig.error)
70
-
71
- const {success, error} = await blueprintConfigCore({
72
- ...cmdConfig.value,
73
- token,
74
- flags: {
75
- 'project-id': flags['project-id'] ?? flags.projectId ?? flags.project,
76
- 'stack-id': flags['stack-id'] ?? flags.stackId ?? flags.stack,
77
- 'test-config': flags['test-config'] ?? flags.test ?? flags.t,
78
- 'edit': flags.edit ?? flags.e,
79
- },
80
- })
81
-
82
- if (!success) throw new Error(error)
83
- },
84
- }
85
-
86
- export default configBlueprintsCommand