@sanity/cli 3.92.1-next.9.9ecd386f43 → 3.93.1-bump-pkg-utils.10.412e2ab170

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 (47) hide show
  1. package/codemods/partsTypeDirective.js +1 -2
  2. package/lib/_chunks-cjs/cli.js +214 -134
  3. package/lib/_chunks-cjs/cli.js.map +1 -1
  4. package/lib/_chunks-cjs/cliWorker.js.map +1 -1
  5. package/lib/_chunks-cjs/getCliConfig.js +4 -2
  6. package/lib/_chunks-cjs/getCliConfig.js.map +1 -1
  7. package/lib/_chunks-cjs/journeyConfig.js.map +1 -1
  8. package/lib/_chunks-cjs/loadEnv.js +10 -5
  9. package/lib/_chunks-cjs/loadEnv.js.map +1 -1
  10. package/lib/cli.d.ts +6 -10
  11. package/lib/index.d.mts +331 -418
  12. package/lib/index.d.ts +331 -418
  13. package/lib/index.mjs.map +1 -1
  14. package/lib/run.d.ts +1 -1
  15. package/lib/workers/getAndWriteJourneySchema.d.ts +1 -1
  16. package/lib/workers/getCliConfig.d.ts +1 -1
  17. package/lib/workers/typegenGenerate.d.ts +35 -42
  18. package/lib/workers/typegenGenerate.js +3 -4
  19. package/lib/workers/typegenGenerate.js.map +1 -1
  20. package/package.json +17 -15
  21. package/src/actions/codemod/codemodAction.ts +1 -1
  22. package/src/actions/codemod/mods/reactIconsV3.ts +1 -1
  23. package/src/actions/init-plugin/bootstrapFromTemplate.ts +2 -3
  24. package/src/actions/init-project/bootstrapLocalTemplate.ts +2 -2
  25. package/src/actions/init-project/git.ts +4 -4
  26. package/src/actions/init-project/initProject.ts +25 -13
  27. package/src/actions/init-project/readPackageJson.ts +1 -2
  28. package/src/actions/versions/findSanityModuleVersions.ts +1 -1
  29. package/src/cli.ts +3 -0
  30. package/src/commands/blueprints/addBlueprintsCommand.ts +32 -2
  31. package/src/commands/blueprints/initBlueprintsCommand.ts +23 -2
  32. package/src/commands/init/initCommand.ts +1 -1
  33. package/src/packageManager/installPackages.ts +33 -21
  34. package/src/util/cliWorker.ts +1 -1
  35. package/src/util/clientWrapper.ts +2 -2
  36. package/src/util/getCliConfig.ts +3 -3
  37. package/src/util/getLocalVersion.ts +1 -1
  38. package/src/util/journeyConfig.ts +2 -2
  39. package/src/util/remoteTemplate.ts +2 -2
  40. package/src/workers/typegenGenerate.ts +0 -1
  41. package/templates/blog/README.md +1 -1
  42. package/templates/clean/README.md +1 -1
  43. package/templates/ecommerce/README.md +1 -1
  44. package/templates/get-started/README.md +1 -1
  45. package/templates/moviedb/README.md +1 -1
  46. package/templates/quickstart/README.md +1 -1
  47. package/templates/.eslintrc +0 -8
@@ -25,6 +25,9 @@ Examples:
25
25
  # Add a Function with a specific type
26
26
  sanity blueprints add function --fn-type document-publish
27
27
 
28
+ # Add a Function using an example
29
+ sanity blueprints add function --example example-name
30
+
28
31
  # Add a JavaScript Function
29
32
  sanity blueprints add function --js
30
33
 
@@ -36,6 +39,8 @@ Examples:
36
39
  `
37
40
 
38
41
  export interface BlueprintsAddFlags {
42
+ 'example'?: string
43
+
39
44
  'name'?: string
40
45
  'n'?: string
41
46
 
@@ -44,8 +49,8 @@ export interface BlueprintsAddFlags {
44
49
  'fn-language'?: string
45
50
  'lang'?: string
46
51
 
47
- 'js'?: boolean
48
52
  'javascript'?: boolean
53
+ 'js'?: boolean
49
54
 
50
55
  'fn-helpers'?: boolean
51
56
  'helpers'?: boolean
@@ -73,7 +78,31 @@ const addBlueprintsCommand: CliCommandDefinition<BlueprintsAddFlags> = {
73
78
 
74
79
  async action(args, context) {
75
80
  const {output, apiClient} = context
76
- const flags = {...defaultFlags, ...args.extOptions}
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}
77
106
 
78
107
  const client = apiClient({
79
108
  requireUser: true,
@@ -108,6 +137,7 @@ const addBlueprintsCommand: CliCommandDefinition<BlueprintsAddFlags> = {
108
137
  ...cmdConfig.value,
109
138
  args: {type: resourceType},
110
139
  flags: {
140
+ 'example': flags.example,
111
141
  'name': flags.n ?? flags.name,
112
142
  'fn-type': flags['fn-type'],
113
143
  'language': flags.lang ?? flags['fn-language'],
@@ -9,14 +9,18 @@ Options
9
9
  --project-id <id> Project ID to use
10
10
 
11
11
  Examples:
12
- # Create a new Blueprint manifest file in the current directory
12
+ # Create a new Blueprint project in the current directory
13
13
  sanity blueprints init
14
14
 
15
- # Create a new Blueprint manifest file in a specific directory
15
+ # Create a new Blueprint project in a specific directory
16
16
  sanity blueprints init my-sanity-project --type json
17
+
18
+ # Create a new Blueprint project in a specific directory with an example
19
+ sanity blueprints init --example example-name
17
20
  `
18
21
 
19
22
  export interface BlueprintsInitFlags {
23
+ 'example'?: string
20
24
  'dir'?: string
21
25
  'blueprint-type'?: string
22
26
  'type'?: string
@@ -56,6 +60,22 @@ const initBlueprintsCommand: CliCommandDefinition<BlueprintsInitFlags> = {
56
60
 
57
61
  const {blueprintInitCore} = await import('@sanity/runtime-cli/cores/blueprints')
58
62
 
63
+ if (flags.example) {
64
+ const conflictingFlags: (keyof BlueprintsInitFlags)[] = [
65
+ 'blueprint-type',
66
+ 'type',
67
+ 'stack-id',
68
+ 'stackId',
69
+ 'stack',
70
+ 'stack-name',
71
+ 'name',
72
+ ]
73
+ const foundConflict = conflictingFlags.find((key) => flags[key])
74
+ if (foundConflict) {
75
+ throw new Error(`--example can't be used with --${foundConflict}`)
76
+ }
77
+ }
78
+
59
79
  const {success, error} = await blueprintInitCore({
60
80
  bin: 'sanity',
61
81
  log: (message) => output.print(message),
@@ -64,6 +84,7 @@ const initBlueprintsCommand: CliCommandDefinition<BlueprintsInitFlags> = {
64
84
  dir: dir ?? flags.dir,
65
85
  },
66
86
  flags: {
87
+ 'example': flags.example,
67
88
  'blueprint-type': flags['blueprint-type'] ?? flags.type,
68
89
  'project-id': flags['project-id'] ?? flags.projectId ?? flags.project,
69
90
  'stack-id': flags['stack-id'] ?? flags.stackId ?? flags.stack,
@@ -95,7 +95,7 @@ export interface InitFlags {
95
95
  'package-manager'?: PackageManager
96
96
  }
97
97
 
98
- export const initCommand: CliCommandDefinition<InitFlags> = {
98
+ const initCommand: CliCommandDefinition<InitFlags> = {
99
99
  name: 'init',
100
100
  signature: '',
101
101
  description: 'Initializes a new Sanity Studio and/or project',
@@ -18,32 +18,44 @@ export async function installDeclaredPackages(
18
18
  encoding: 'utf8',
19
19
  env: getPartialEnvWithNpmPath(cwd),
20
20
  cwd,
21
- stdio: 'inherit',
21
+ stdio: 'pipe',
22
22
  }
23
23
 
24
- const npmArgs = ['install', '--legacy-peer-deps']
24
+ // results of running execa with the selected package manager
25
25
  let result: ExecaReturnValue<string> | undefined
26
- if (packageManager === 'npm') {
27
- output.print(`Running 'npm ${npmArgs.join(' ')}'`)
28
- result = await execa('npm', npmArgs, execOptions)
29
- } else if (packageManager === 'yarn') {
30
- const yarnArgs = ['install']
31
- output.print(`Running 'yarn ${yarnArgs.join(' ')}'`)
32
- result = await execa('yarn', yarnArgs, execOptions)
33
- } else if (packageManager === 'pnpm') {
34
- const pnpmArgs = ['install']
35
- output.print(`Running 'pnpm ${pnpmArgs.join(' ')}'`)
36
- result = await execa('pnpm', pnpmArgs, execOptions)
37
- } else if (packageManager === 'bun') {
38
- const bunArgs = ['install']
39
- output.print(`Running 'bun ${bunArgs.join(' ')}'`)
40
- result = await execa('bun', bunArgs, execOptions)
41
- } else if (packageManager === 'manual') {
42
- output.print(`Manual installation selected - run 'npm ${npmArgs.join(' ')}' or similar`)
26
+
27
+ type PackageManagerLibs = Exclude<PackageManager, 'manual'>
28
+ type InstallerArgs = {[key in PackageManagerLibs]: string[]}
29
+
30
+ const installerArgs: InstallerArgs = {
31
+ npm: ['install', '--legacy-peer-deps'],
32
+ yarn: ['install'],
33
+ pnpm: ['install'],
34
+ bun: ['install'],
43
35
  }
44
36
 
45
- if (result?.exitCode || result?.failed) {
46
- throw new Error('Dependency installation failed')
37
+ async function handleInstall(cmd: PackageManager, args: InstallerArgs[PackageManagerLibs]) {
38
+ // Start a spinner for the install process
39
+ const progress = output.spinner(`Running ${cmd} ${args.join(' ')}\n`).start()
40
+
41
+ // Perform the install command with execa
42
+ result = await execa(cmd, args, execOptions)
43
+
44
+ // If the install fails, log execa's stdout and throw…
45
+ if (result?.exitCode || result?.failed) {
46
+ progress.fail()
47
+ output.print(result.stdout)
48
+ throw new Error('Dependency installation failed')
49
+ } else {
50
+ // …otherwise, just mark the install as successful
51
+ progress.succeed()
52
+ }
53
+ }
54
+
55
+ if (packageManager === 'manual') {
56
+ output.print(`Manual installation selected — run 'npm ${installerArgs.npm} or equivalent'`)
57
+ } else {
58
+ await handleInstall(packageManager, installerArgs[packageManager])
47
59
  }
48
60
  }
49
61
 
@@ -28,7 +28,7 @@ export async function getCliWorkerPath(workerPath: string): Promise<string> {
28
28
  const resolvedPath = path.resolve(cliDir, 'lib', 'workers', workerPath)
29
29
  try {
30
30
  return require.resolve(resolvedPath)
31
- } catch (err) {
31
+ } catch {
32
32
  throw new Error(`Unable to resolve path for worker: ${workerPath}`)
33
33
  }
34
34
  }
@@ -86,8 +86,8 @@ export function getClientWrapper(
86
86
  const token = getCliToken()
87
87
  const apiHost = apiHosts[sanityEnv]
88
88
  const apiConfig = {
89
- ...(cliApiConfig || {}),
90
- ...(api || {}),
89
+ ...cliApiConfig,
90
+ ...api,
91
91
  }
92
92
 
93
93
  if (apiHost) {
@@ -35,14 +35,15 @@ export async function getCliConfig(
35
35
  if (forked) {
36
36
  try {
37
37
  return await getCliConfigForked(cwd)
38
- } catch (err) {
38
+ } catch {
39
39
  // Intentional noop - try unforked variant
40
40
  }
41
41
  }
42
42
 
43
43
  const {unregister} = __DEV__
44
44
  ? {unregister: () => undefined}
45
- : require('esbuild-register/dist/node').register({supported: {'dynamic-import': true}})
45
+ : // eslint-disable-next-line @typescript-eslint/no-require-imports
46
+ require('esbuild-register/dist/node').register({supported: {'dynamic-import': true}})
46
47
 
47
48
  try {
48
49
  const v3Config = getSanityCliConfig(cwd)
@@ -68,7 +69,6 @@ async function getCliConfigForked(cwd: string): Promise<CliConfigResult | null>
68
69
  return new Promise((resolve, reject) => {
69
70
  const worker = new Worker(workerPath, {
70
71
  workerData: cwd,
71
- // eslint-disable-next-line no-process-env
72
72
  env: process.env,
73
73
  })
74
74
  worker.on('message', (message) => {
@@ -29,7 +29,7 @@ function tryGetVersion(modulePath: string): string | undefined {
29
29
  const fileContent = readFileSync(modulePath, 'utf8')
30
30
  const manifest = JSON.parse(fileContent)
31
31
  return manifest.version
32
- } catch (err) {
32
+ } catch {
33
33
  return undefined
34
34
  }
35
35
  }
@@ -154,7 +154,7 @@ export async function fetchJourneyConfig(
154
154
  schemaUrl: response.schemaUrl,
155
155
  isFirstProject: true,
156
156
  }
157
- } catch (err) {
157
+ } catch {
158
158
  throw new Error(`Failed to fetch remote schema config: ${projectId}`)
159
159
  }
160
160
  }
@@ -169,7 +169,7 @@ async function fetchJourneySchema(schemaUrl: string): Promise<DocumentOrObject[]
169
169
  try {
170
170
  const response = await import(schemaUrl)
171
171
  return response.default
172
- } catch (err) {
172
+ } catch {
173
173
  throw new Error(`Failed to fetch remote schema: ${schemaUrl}`)
174
174
  }
175
175
  }
@@ -264,7 +264,7 @@ export async function applyEnvVariables(
264
264
  }
265
265
 
266
266
  await writeFile(join(root, targetName), envContent)
267
- } catch (err) {
267
+ } catch {
268
268
  throw new Error(
269
269
  'Failed to set environment variables. This could be due to file permissions or the .env file format. See https://www.sanity.io/docs/environment-variables for details on environment variable setup.',
270
270
  )
@@ -278,7 +278,7 @@ export async function tryApplyPackageName(root: string, name: string): Promise<v
278
278
  pkg.name = name
279
279
 
280
280
  await writeFile(join(root, 'package.json'), JSON.stringify(pkg, null, 2))
281
- } catch (err) {
281
+ } catch {
282
282
  // noop
283
283
  }
284
284
  }
@@ -12,7 +12,6 @@ import createDebug from 'debug'
12
12
  import {typeEvaluate, type TypeNode} from 'groq-js'
13
13
 
14
14
  const $info = createDebug('sanity:codegen:generate:info')
15
- const $warn = createDebug('sanity:codegen:generate:warn')
16
15
 
17
16
  export interface TypegenGenerateTypesWorkerData {
18
17
  workDir: string
@@ -7,5 +7,5 @@ Now you can do the following things:
7
7
  - [Read “getting started” in the docs](https://www.sanity.io/docs/introduction/getting-started?utm_source=readme)
8
8
  - Check out the example frontend: [React/Next.js](https://github.com/sanity-io/tutorial-sanity-blog-react-next)
9
9
  - [Read the blog post about this template](https://www.sanity.io/blog/build-your-own-blog-with-sanity-and-next-js?utm_source=readme)
10
- - [Join the community Slack](https://slack.sanity.io/?utm_source=readme)
10
+ - [Join the community Slack](https://snty.link/community/?utm_source=readme)
11
11
  - [Extend and build plugins](https://www.sanity.io/docs/content-studio/extending?utm_source=readme)
@@ -5,5 +5,5 @@ Congratulations, you have now installed the Sanity Content Studio, an open-sourc
5
5
  Now you can do the following things:
6
6
 
7
7
  - [Read “getting started” in the docs](https://www.sanity.io/docs/introduction/getting-started?utm_source=readme)
8
- - [Join the community Slack](https://slack.sanity.io/?utm_source=readme)
8
+ - [Join the community Slack](https://snty.link/community/?utm_source=readme)
9
9
  - [Extend and build plugins](https://www.sanity.io/docs/content-studio/extending?utm_source=readme)
@@ -7,5 +7,5 @@ Now you can do the following things:
7
7
  - [Read “getting started” in the docs](https://www.sanity.io/docs/introduction/getting-started?utm_source=readme)
8
8
  - Check out the example frontend: [Vue/Nuxt.js](https://github.com/sanity-io/example-ecommerce-snipcart-vue)
9
9
  - [Read the blog post about this template](https://www.sanity.io/blog/e-commerce-vue-nuxt-snipcart?uutm_source=readme)
10
- - [Join the community Slack](https://slack.sanity.io/?utm_source=readme)
10
+ - [Join the community Slack](https://snty.link/community/?utm_source=readme)
11
11
  - [Extend and build plugins](https://www.sanity.io/docs/content-studio/extending?utm_source=readme)
@@ -5,5 +5,5 @@ Congratulations, you have now installed the Sanity Content Studio, an open-sourc
5
5
  Now you can do the following things:
6
6
 
7
7
  - [Read “getting started” in the docs](https://www.sanity.io/docs/introduction/getting-started?utm_source=readme)
8
- - [Join the community Slack](https://slack.sanity.io/?utm_source=readme)
8
+ - [Join the community Slack](https://snty.link/community/?utm_source=readme)
9
9
  - [Extend and build plugins](https://www.sanity.io/docs/content-studio/extending?utm_source=readme)
@@ -6,5 +6,5 @@ Now you can do the following things:
6
6
 
7
7
  - [Read “getting started” in the docs](https://www.sanity.io/docs/introduction/getting-started?utm_source=readme)
8
8
  - Check out one of the example frontends: [React](https://github.com/sanity-io/example-frontend-next-js) | [React Native](https://github.com/sanity-io/example-app-react-native) | [Vue](https://github.com/sanity-io/example-frontend-vue-js) | [PHP](https://github.com/sanity-io/example-frontend-silex-twig)
9
- - [Join the community Slack](https://slack.sanity.io/?utm_source=readme)
9
+ - [Join the community Slack](https://snty.link/community/?utm_source=readme)
10
10
  - [Extend and build plugins](https://www.sanity.io/docs/content-studio/extending?utm_source=readme)
@@ -5,5 +5,5 @@ Congratulations, you have now installed Sanity Studio, an open-source real-time
5
5
  Now you can do the following things:
6
6
 
7
7
  - [Read “getting started” in the docs](https://www.sanity.io/docs/introduction/getting-started?utm_source=readme)
8
- - [Join the community Slack](https://slack.sanity.io/?utm_source=readme)
8
+ - [Join the community Slack](https://snty.link/community/?utm_source=readme)
9
9
  - [Extend and build plugins](https://www.sanity.io/docs/content-studio/extending?utm_source=readme)
@@ -1,8 +0,0 @@
1
- {
2
- "root": true,
3
- "extends": "@sanity/eslint-config-studio",
4
- "rules": {
5
- "import/no-unresolved": "off",
6
- "no-restricted-imports": "off"
7
- }
8
- }