@sanity/runtime-cli 17.7.1 → 17.8.0-blueprinit.g0993fa5

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 (67) hide show
  1. package/README.md +26 -21
  2. package/dist/actions/blueprinit/manifest.d.ts +34 -0
  3. package/dist/actions/blueprinit/manifest.js +107 -0
  4. package/dist/actions/blueprinit/studio.d.ts +6 -0
  5. package/dist/actions/blueprinit/studio.js +43 -0
  6. package/dist/actions/blueprinit/templates.d.ts +73 -0
  7. package/dist/actions/blueprinit/templates.js +138 -0
  8. package/dist/actions/blueprinit/workspace.d.ts +24 -0
  9. package/dist/actions/blueprinit/workspace.js +146 -0
  10. package/dist/actions/blueprints/stacks.d.ts +2 -0
  11. package/dist/actions/blueprints/stacks.js +1 -0
  12. package/dist/actions/sanity/datasets.d.ts +15 -0
  13. package/dist/actions/sanity/datasets.js +26 -0
  14. package/dist/actions/sanity/projects.d.ts +11 -0
  15. package/dist/actions/sanity/projects.js +48 -22
  16. package/dist/baseCommands.d.ts +6 -0
  17. package/dist/baseCommands.js +9 -1
  18. package/dist/commands/blueprints/stacks.d.ts +2 -1
  19. package/dist/commands/blueprints/stacks.js +14 -6
  20. package/dist/commands/init.d.ts +20 -0
  21. package/dist/commands/init.js +72 -0
  22. package/dist/constants.d.ts +2 -0
  23. package/dist/constants.js +5 -0
  24. package/dist/cores/blueprinit/adopt.d.ts +6 -0
  25. package/dist/cores/blueprinit/adopt.js +154 -0
  26. package/dist/cores/blueprinit/finish.d.ts +15 -0
  27. package/dist/cores/blueprinit/finish.js +73 -0
  28. package/dist/cores/blueprinit/fresh.d.ts +3 -0
  29. package/dist/cores/blueprinit/fresh.js +173 -0
  30. package/dist/cores/blueprinit/preview.d.ts +24 -0
  31. package/dist/cores/blueprinit/preview.js +97 -0
  32. package/dist/cores/blueprinit/prompts.d.ts +15 -0
  33. package/dist/cores/blueprinit/prompts.js +43 -0
  34. package/dist/cores/blueprinit/selection.d.ts +15 -0
  35. package/dist/cores/blueprinit/selection.js +90 -0
  36. package/dist/cores/blueprinit/stack-name.d.ts +39 -0
  37. package/dist/cores/blueprinit/stack-name.js +56 -0
  38. package/dist/cores/blueprinit/target.d.ts +33 -0
  39. package/dist/cores/blueprinit/target.js +80 -0
  40. package/dist/cores/blueprinit/types.d.ts +18 -0
  41. package/dist/cores/blueprinit/types.js +1 -0
  42. package/dist/cores/blueprinit.d.ts +7 -0
  43. package/dist/cores/blueprinit.js +55 -0
  44. package/dist/cores/blueprints/stacks.d.ts +8 -3
  45. package/dist/cores/blueprints/stacks.js +282 -85
  46. package/dist/cores/functions/test.d.ts +2 -19
  47. package/dist/cores/functions/test.js +55 -111
  48. package/dist/server/app.js +4 -6
  49. package/dist/server/static/components/payload-panel.js +1 -1
  50. package/dist/utils/display/intro.d.ts +6 -0
  51. package/dist/utils/display/intro.js +63 -0
  52. package/dist/utils/display/prompt.d.ts +4 -1
  53. package/dist/utils/display/prompt.js +16 -2
  54. package/dist/utils/external/npmjs.d.ts +7 -0
  55. package/dist/utils/external/npmjs.js +10 -0
  56. package/dist/utils/functions/child-process-wrapper.js +18 -6
  57. package/dist/utils/functions/child-runtime/durable.d.ts +18 -0
  58. package/dist/utils/functions/child-runtime/durable.js +46 -0
  59. package/dist/utils/functions/invoke/local.js +26 -9
  60. package/dist/utils/functions/invoke/resolve-invoke-type.d.ts +51 -0
  61. package/dist/utils/functions/invoke/resolve-invoke-type.js +131 -0
  62. package/dist/utils/progress.js +6 -3
  63. package/dist/utils/types.d.ts +46 -2
  64. package/oclif.manifest.json +155 -5
  65. package/package.json +1 -1
  66. package/skills/blueprints-stacks.md +14 -2
  67. package/skills/init.md +170 -0
package/README.md CHANGED
@@ -90,7 +90,7 @@ EXAMPLES
90
90
  $ sanity-run blueprints add function --name my-function --fn-type document-create --fn-type document-update --lang js
91
91
  ```
92
92
 
93
- _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.7.1/src/commands/blueprints/add.ts)_
93
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.8.0-blueprinit.g0993fa5/src/commands/blueprints/add.ts)_
94
94
 
95
95
  ## `sanity-run blueprints config`
96
96
 
@@ -127,7 +127,7 @@ EXAMPLES
127
127
  $ sanity-run blueprints config --edit --project-id <projectId> --stack <name-or-id>
128
128
  ```
129
129
 
130
- _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v17.7.1/src/commands/blueprints/config.ts)_
130
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v17.8.0-blueprinit.g0993fa5/src/commands/blueprints/config.ts)_
131
131
 
132
132
  ## `sanity-run blueprints deploy`
133
133
 
@@ -183,7 +183,7 @@ EXAMPLES
183
183
  $ sanity-run blueprints deploy --new-stack-name <new-name>
184
184
  ```
185
185
 
186
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.7.1/src/commands/blueprints/deploy.ts)_
186
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.8.0-blueprinit.g0993fa5/src/commands/blueprints/deploy.ts)_
187
187
 
188
188
  ## `sanity-run blueprints destroy`
189
189
 
@@ -221,7 +221,7 @@ EXAMPLES
221
221
  $ sanity-run blueprints destroy --stack <name-or-id> --project-id <projectId> --force --no-wait
222
222
  ```
223
223
 
224
- _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.7.1/src/commands/blueprints/destroy.ts)_
224
+ _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.8.0-blueprinit.g0993fa5/src/commands/blueprints/destroy.ts)_
225
225
 
226
226
  ## `sanity-run blueprints doctor`
227
227
 
@@ -253,7 +253,7 @@ EXAMPLES
253
253
  $ sanity-run blueprints doctor --fix
254
254
  ```
255
255
 
256
- _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v17.7.1/src/commands/blueprints/doctor.ts)_
256
+ _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v17.8.0-blueprinit.g0993fa5/src/commands/blueprints/doctor.ts)_
257
257
 
258
258
  ## `sanity-run blueprints info`
259
259
 
@@ -291,7 +291,7 @@ EXAMPLES
291
291
  $ sanity-run blueprints info --organization-id <orgId> --stack <name-or-id>
292
292
  ```
293
293
 
294
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v17.7.1/src/commands/blueprints/info.ts)_
294
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v17.8.0-blueprinit.g0993fa5/src/commands/blueprints/info.ts)_
295
295
 
296
296
  ## `sanity-run blueprints init [DIR]`
297
297
 
@@ -355,7 +355,7 @@ EXAMPLES
355
355
  $ sanity-run blueprints init old-stack --type <json|js|ts> --project-id <projectId> --stack-id <existingStackId>
356
356
  ```
357
357
 
358
- _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v17.7.1/src/commands/blueprints/init.ts)_
358
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v17.8.0-blueprinit.g0993fa5/src/commands/blueprints/init.ts)_
359
359
 
360
360
  ## `sanity-run blueprints logs`
361
361
 
@@ -401,7 +401,7 @@ EXAMPLES
401
401
  $ sanity-run blueprints logs --before 2026-05-01T00:00:00Z
402
402
  ```
403
403
 
404
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.7.1/src/commands/blueprints/logs.ts)_
404
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.8.0-blueprinit.g0993fa5/src/commands/blueprints/logs.ts)_
405
405
 
406
406
  ## `sanity-run blueprints mint-deploy-token`
407
407
 
@@ -446,7 +446,7 @@ EXAMPLES
446
446
  $ sanity-run blueprints mint-deploy-token --organization-id <orgId>
447
447
  ```
448
448
 
449
- _See code: [src/commands/blueprints/mint-deploy-token.ts](https://github.com/sanity-io/runtime-cli/blob/v17.7.1/src/commands/blueprints/mint-deploy-token.ts)_
449
+ _See code: [src/commands/blueprints/mint-deploy-token.ts](https://github.com/sanity-io/runtime-cli/blob/v17.8.0-blueprinit.g0993fa5/src/commands/blueprints/mint-deploy-token.ts)_
450
450
 
451
451
  ## `sanity-run blueprints plan`
452
452
 
@@ -479,7 +479,7 @@ EXAMPLES
479
479
  $ sanity-run blueprints plan --organization-id <orgId> --stack <name-or-id>
480
480
  ```
481
481
 
482
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v17.7.1/src/commands/blueprints/plan.ts)_
482
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v17.8.0-blueprinit.g0993fa5/src/commands/blueprints/plan.ts)_
483
483
 
484
484
  ## `sanity-run blueprints promote`
485
485
 
@@ -515,7 +515,7 @@ EXAMPLES
515
515
  $ sanity-run blueprints promote --new-stack-name <new-name>
516
516
  ```
517
517
 
518
- _See code: [src/commands/blueprints/promote.ts](https://github.com/sanity-io/runtime-cli/blob/v17.7.1/src/commands/blueprints/promote.ts)_
518
+ _See code: [src/commands/blueprints/promote.ts](https://github.com/sanity-io/runtime-cli/blob/v17.8.0-blueprinit.g0993fa5/src/commands/blueprints/promote.ts)_
519
519
 
520
520
  ## `sanity-run blueprints stacks`
521
521
 
@@ -523,9 +523,11 @@ List remote Stack deployments for your project or organization
523
523
 
524
524
  ```
525
525
  USAGE
526
- $ sanity-run blueprints stacks [--json] [--project-id <value> | --organization-id <value> | --include-projects]
526
+ $ sanity-run blueprints stacks [--json] [--project-id <value> | --organization-id <value> | --include-projects |
527
+ --all]
527
528
 
528
529
  FLAGS
530
+ --all List Stacks from every organization and project you have access to
529
531
  --include-projects Include Stacks from all projects within the organization. Requires --organization-id.
530
532
  --json Format output as json
531
533
  --organization-id=<value> Sanity organization ID used to scope Blueprint and Stack
@@ -539,11 +541,14 @@ DESCRIPTION
539
541
  Use this to discover existing Stacks you can scope a local Blueprint to (using 'blueprints config --edit'), or to
540
542
  audit what's deployed across your project.
541
543
 
542
- Use --include-projects with --organization-id to also list Stacks from all projects within the organization.
544
+ Without a scope, prompts for an organization or project. Use --all to list Stacks across every organization and
545
+ project you can access, or --include-projects with --organization-id for one organization and its projects.
543
546
 
544
547
  EXAMPLES
545
548
  $ sanity-run blueprints stacks
546
549
 
550
+ $ sanity-run blueprints stacks --all
551
+
547
552
  $ sanity-run blueprints stacks --project-id <projectId>
548
553
 
549
554
  $ sanity-run blueprints stacks --organization-id <organizationId>
@@ -551,7 +556,7 @@ EXAMPLES
551
556
  $ sanity-run blueprints stacks --organization-id <organizationId> --include-projects
552
557
  ```
553
558
 
554
- _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v17.7.1/src/commands/blueprints/stacks.ts)_
559
+ _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v17.8.0-blueprinit.g0993fa5/src/commands/blueprints/stacks.ts)_
555
560
 
556
561
  ## `sanity-run functions add`
557
562
 
@@ -603,7 +608,7 @@ EXAMPLES
603
608
  $ sanity-run functions add --name my-function --type document-create --type document-update --lang js
604
609
  ```
605
610
 
606
- _See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.7.1/src/commands/functions/add.ts)_
611
+ _See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.8.0-blueprinit.g0993fa5/src/commands/functions/add.ts)_
607
612
 
608
613
  ## `sanity-run functions dev`
609
614
 
@@ -638,7 +643,7 @@ EXAMPLES
638
643
  $ sanity-run functions dev --timeout 60
639
644
  ```
640
645
 
641
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v17.7.1/src/commands/functions/dev.ts)_
646
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v17.8.0-blueprinit.g0993fa5/src/commands/functions/dev.ts)_
642
647
 
643
648
  ## `sanity-run functions env add NAME KEY VALUE`
644
649
 
@@ -671,7 +676,7 @@ EXAMPLES
671
676
  $ sanity-run functions env add --stack <name-or-id> MyFunction API_URL https://api.example.com/
672
677
  ```
673
678
 
674
- _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.7.1/src/commands/functions/env/add.ts)_
679
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.8.0-blueprinit.g0993fa5/src/commands/functions/env/add.ts)_
675
680
 
676
681
  ## `sanity-run functions env list NAME`
677
682
 
@@ -701,7 +706,7 @@ EXAMPLES
701
706
  $ sanity-run functions env list --stack <name-or-id> MyFunction
702
707
  ```
703
708
 
704
- _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v17.7.1/src/commands/functions/env/list.ts)_
709
+ _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v17.8.0-blueprinit.g0993fa5/src/commands/functions/env/list.ts)_
705
710
 
706
711
  ## `sanity-run functions env remove NAME KEY`
707
712
 
@@ -733,7 +738,7 @@ EXAMPLES
733
738
  $ sanity-run functions env remove --stack <name-or-id> MyFunction API_URL
734
739
  ```
735
740
 
736
- _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v17.7.1/src/commands/functions/env/remove.ts)_
741
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v17.8.0-blueprinit.g0993fa5/src/commands/functions/env/remove.ts)_
737
742
 
738
743
  ## `sanity-run functions logs [NAME]`
739
744
 
@@ -773,7 +778,7 @@ EXAMPLES
773
778
  $ sanity-run functions logs <name> --delete
774
779
  ```
775
780
 
776
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.7.1/src/commands/functions/logs.ts)_
781
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.8.0-blueprinit.g0993fa5/src/commands/functions/logs.ts)_
777
782
 
778
783
  ## `sanity-run functions test [NAME]`
779
784
 
@@ -830,7 +835,7 @@ EXAMPLES
830
835
  $ sanity-run functions test <name> --event update --data-before '{ "title": "before" }' --data-after '{ "title": "after" }'
831
836
  ```
832
837
 
833
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v17.7.1/src/commands/functions/test.ts)_
838
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v17.8.0-blueprinit.g0993fa5/src/commands/functions/test.ts)_
834
839
 
835
840
  ## `sanity-run help [COMMAND]`
836
841
 
@@ -0,0 +1,34 @@
1
+ export declare const STARTER_DOCUMENT_TYPE = "post";
2
+ export declare const STARTER_FUNCTION_NAME = "set-slug";
3
+ export declare const DEFAULT_STUDIO_NAME = "studio";
4
+ export interface BlueprintManifestOptions {
5
+ projectName: string;
6
+ displayName: string;
7
+ projectId: string;
8
+ datasetName: string;
9
+ studioName: string;
10
+ studioSlug: string;
11
+ studioSrc: string;
12
+ studioOrigin: string;
13
+ withFunction: boolean;
14
+ }
15
+ export declare function renderBlueprint(options: BlueprintManifestOptions): string;
16
+ export declare function hostedStudioOrigin(studioName: string, sanityEnv?: string): string;
17
+ /**
18
+ * The Blueprint-local name for the attached project.
19
+ *
20
+ * Kept apart from the Stack name so a default Stack name can never collide with a
21
+ * resource name, and suffixed so a reference states which resource it reads.
22
+ */
23
+ export declare function projectResourceName(baseName: string): string;
24
+ /**
25
+ * The default name for the new Stack, which is also the hosted Studio slug.
26
+ *
27
+ * A Studio slug must be unique across every Sanity organization and no API can report
28
+ * whether one is free, so the default carries both the project and the dataset to make
29
+ * an accidental match unlikely.
30
+ */
31
+ export declare function defaultStackName(baseName: string, datasetName: string): string;
32
+ /** The slug form of a project display name, falling back to its ID. */
33
+ export declare function projectBaseName(displayName: string, projectId: string): string;
34
+ export declare function slugify(value: string): string;
@@ -0,0 +1,107 @@
1
+ const quote = (value) => `'${value.replaceAll('\\', '\\\\').replaceAll("'", "\\'")}'`;
2
+ export const STARTER_DOCUMENT_TYPE = 'post';
3
+ export const STARTER_FUNCTION_NAME = 'set-slug';
4
+ export const DEFAULT_STUDIO_NAME = 'studio';
5
+ export function renderBlueprint(options) {
6
+ const { projectName, displayName, projectId, datasetName, studioName, studioSlug, studioSrc, studioOrigin, withFunction, } = options;
7
+ const definers = [
8
+ 'defineBlueprint',
9
+ 'defineCorsOrigin',
10
+ 'defineDataset',
11
+ 'defineProject',
12
+ 'defineStudio',
13
+ ];
14
+ if (withFunction)
15
+ definers.splice(3, 0, 'defineDocumentFunction');
16
+ const project = quote(`$.resources.${projectName}.id`);
17
+ const inlineImport = `import {${definers.join(', ')}} from '@sanity/blueprints'`;
18
+ const imports = inlineImport.length > 100
19
+ ? `import {\n${definers.map((definer) => ` ${definer},`).join('\n')}\n} from '@sanity/blueprints'`
20
+ : inlineImport;
21
+ const functionResource = withFunction
22
+ ? ` defineDocumentFunction({
23
+ name: ${quote(STARTER_FUNCTION_NAME)},
24
+ displayName: 'Set slug',
25
+ project: ${project},
26
+ event: {
27
+ on: ['create', 'update'],
28
+ filter: "_type == '${STARTER_DOCUMENT_TYPE}' && !defined(slug.current)",
29
+ projection: '{_id, title, slug}',
30
+ },
31
+ }),
32
+ `
33
+ : '';
34
+ return `${imports}
35
+
36
+ export default defineBlueprint({
37
+ resources: [
38
+ defineProject({
39
+ name: ${quote(projectName)},
40
+ displayName: ${quote(displayName)},
41
+ lifecycle: {
42
+ deletionPolicy: 'retain',
43
+ ownershipAction: {type: 'attach', id: ${quote(projectId)}},
44
+ },
45
+ }),
46
+ defineDataset({
47
+ project: ${project},
48
+ name: ${quote(datasetName)},
49
+ lifecycle: {
50
+ deletionPolicy: 'retain',
51
+ ownershipAction: {
52
+ type: 'attach',
53
+ id: ${quote(datasetName)},
54
+ projectId: ${project},
55
+ },
56
+ },
57
+ }),
58
+ defineCorsOrigin({
59
+ project: ${project},
60
+ name: ${quote(`${studioName}-cors`)},
61
+ origin: ${quote(studioOrigin)},
62
+ allowCredentials: true,
63
+ }),
64
+ defineStudio({
65
+ project: ${project},
66
+ name: ${quote(studioName)},
67
+ slug: ${quote(studioSlug)},
68
+ title: ${quote(displayName)},
69
+ src: ${quote(studioSrc)},
70
+ }),
71
+ ${functionResource} ],
72
+ })
73
+ `;
74
+ }
75
+ export function hostedStudioOrigin(studioName, sanityEnv) {
76
+ const hostname = sanityEnv?.toLowerCase() === 'staging' ? 'studio.sanity.work' : 'sanity.studio';
77
+ return `https://${studioName}.${hostname}`;
78
+ }
79
+ /**
80
+ * The Blueprint-local name for the attached project.
81
+ *
82
+ * Kept apart from the Stack name so a default Stack name can never collide with a
83
+ * resource name, and suffixed so a reference states which resource it reads.
84
+ */
85
+ export function projectResourceName(baseName) {
86
+ return `${baseName}-project`;
87
+ }
88
+ /**
89
+ * The default name for the new Stack, which is also the hosted Studio slug.
90
+ *
91
+ * A Studio slug must be unique across every Sanity organization and no API can report
92
+ * whether one is free, so the default carries both the project and the dataset to make
93
+ * an accidental match unlikely.
94
+ */
95
+ export function defaultStackName(baseName, datasetName) {
96
+ return `${baseName}-${datasetName}`;
97
+ }
98
+ /** The slug form of a project display name, falling back to its ID. */
99
+ export function projectBaseName(displayName, projectId) {
100
+ return slugify(displayName) || projectId;
101
+ }
102
+ export function slugify(value) {
103
+ return value
104
+ .toLowerCase()
105
+ .replace(/[^a-z0-9]+/g, '-')
106
+ .replace(/^-+|-+$/g, '');
107
+ }
@@ -0,0 +1,6 @@
1
+ export interface DetectedStudio {
2
+ configFile: string;
3
+ projectId?: string;
4
+ dataset?: string;
5
+ }
6
+ export declare function detectStudio(dir: string): DetectedStudio | undefined;
@@ -0,0 +1,43 @@
1
+ import { readdirSync, readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ const STUDIO_CONFIG_PATTERN = /^sanity\.config\.[cm]?[jt]sx?$/;
4
+ const STUDIO_CLI_PATTERN = /^sanity\.cli\.[cm]?[jt]sx?$/;
5
+ export function detectStudio(dir) {
6
+ let entries;
7
+ try {
8
+ entries = readdirSync(dir, { withFileTypes: true })
9
+ .filter((entry) => entry.isFile())
10
+ .map((entry) => entry.name);
11
+ }
12
+ catch {
13
+ return undefined;
14
+ }
15
+ const configFile = entries.find((name) => STUDIO_CONFIG_PATTERN.test(name));
16
+ if (!configFile)
17
+ return undefined;
18
+ const detected = { configFile };
19
+ const cliFile = entries.find((name) => STUDIO_CLI_PATTERN.test(name));
20
+ for (const file of [configFile, cliFile]) {
21
+ if (!file)
22
+ continue;
23
+ const source = readSource(join(dir, file));
24
+ if (!source)
25
+ continue;
26
+ detected.projectId ??= extractLiteral(source, 'projectId');
27
+ detected.dataset ??= extractLiteral(source, 'dataset');
28
+ if (detected.projectId && detected.dataset)
29
+ break;
30
+ }
31
+ return detected;
32
+ }
33
+ function readSource(filePath) {
34
+ try {
35
+ return readFileSync(filePath, 'utf8');
36
+ }
37
+ catch {
38
+ return undefined;
39
+ }
40
+ }
41
+ function extractLiteral(source, key) {
42
+ return source.match(new RegExp(`\\b${key}\\s*:\\s*(['"\`])([^'"\`\\\\]+)\\1`))?.[2];
43
+ }
@@ -0,0 +1,73 @@
1
+ export declare function renderStudioConfig(options: {
2
+ displayName: string;
3
+ projectId: string;
4
+ datasetName: string;
5
+ }): string;
6
+ /**
7
+ * `sanity dev` and `sanity build` read the project and dataset from here, not from
8
+ * `sanity.config.ts`, and fail with `No CLI config found` when the file is absent.
9
+ *
10
+ * `sanity init` also writes a `deployment.autoUpdates` block. It is left out because it only
11
+ * affects `sanity deploy`, and the Blueprint's `defineStudio` already declares auto-updates.
12
+ */
13
+ export declare function renderStudioCliConfig(options: {
14
+ projectId: string;
15
+ datasetName: string;
16
+ }): string;
17
+ export declare const STUDIO_SCHEMA_TYPES = "import {post} from './post'\n\nexport const schemaTypes = [post]\n";
18
+ export declare const STUDIO_POST_TYPE = "import {defineField, defineType} from 'sanity'\n\nexport const post = defineType({\n name: 'post',\n title: 'Post',\n type: 'document',\n fields: [\n defineField({name: 'title', type: 'string', validation: (rule) => rule.required()}),\n // The set-slug function fills this when it is empty.\n defineField({name: 'slug', type: 'slug', options: {source: 'title'}}),\n defineField({name: 'publishedAt', title: 'Published at', type: 'datetime'}),\n defineField({name: 'body', type: 'text'}),\n ],\n})\n";
19
+ export declare const FUNCTION_SET_SLUG = "import {createClient} from '@sanity/client'\nimport {documentEventHandler} from '@sanity/functions'\n\nconst slugify = (title: string) =>\n title\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/^-+|-+$/g, '')\n .slice(0, 96)\n\nexport const handler = documentEventHandler(async ({context, event}) => {\n const {_id, title, slug} = event.data\n if (!title || slug?.current) return\n\n const client = createClient({apiVersion: '2025-05-01', ...context.clientOptions})\n const current = slugify(title)\n await client.patch(_id).set({slug: {_type: 'slug', current}}).commit()\n\n console.log(`Set slug for ${_id}: ${current}`)\n})\n";
20
+ export interface StudioVersions {
21
+ sanity: string;
22
+ vision: string;
23
+ }
24
+ export declare const studioPackageJson: (name: string, versions: StudioVersions) => {
25
+ name: string;
26
+ version: string;
27
+ private: boolean;
28
+ license: string;
29
+ keywords: string[];
30
+ scripts: {
31
+ dev: string;
32
+ build: string;
33
+ };
34
+ dependencies: {
35
+ '@sanity/vision': string;
36
+ react: string;
37
+ 'react-dom': string;
38
+ sanity: string;
39
+ 'styled-components': string;
40
+ };
41
+ devDependencies: {
42
+ '@types/react': string;
43
+ typescript: string;
44
+ };
45
+ };
46
+ /** Copied from `templates/shared/tsconfig.json` in `@sanity/cli`. */
47
+ export declare const STUDIO_TSCONFIG: {
48
+ compilerOptions: {
49
+ target: string;
50
+ lib: string[];
51
+ allowJs: boolean;
52
+ skipLibCheck: boolean;
53
+ strict: boolean;
54
+ forceConsistentCasingInFileNames: boolean;
55
+ module: string;
56
+ moduleDetection: string;
57
+ isolatedModules: boolean;
58
+ jsx: string;
59
+ incremental: boolean;
60
+ };
61
+ include: string[];
62
+ exclude: string[];
63
+ };
64
+ export declare const functionPackageJson: (name: string) => {
65
+ name: string;
66
+ version: string;
67
+ private: boolean;
68
+ type: string;
69
+ dependencies: {
70
+ '@sanity/client': string;
71
+ '@sanity/functions': string;
72
+ };
73
+ };
@@ -0,0 +1,138 @@
1
+ import { STARTER_DOCUMENT_TYPE, STARTER_FUNCTION_NAME } from './manifest.js';
2
+ const quote = (value) => `'${value.replaceAll('\\', '\\\\').replaceAll("'", "\\'")}'`;
3
+ export function renderStudioConfig(options) {
4
+ return `import {defineConfig} from 'sanity'
5
+ import {structureTool} from 'sanity/structure'
6
+ import {visionTool} from '@sanity/vision'
7
+ import {schemaTypes} from './schemaTypes'
8
+
9
+ export default defineConfig({
10
+ name: 'default',
11
+ title: ${quote(options.displayName)},
12
+ projectId: ${quote(options.projectId)},
13
+ dataset: ${quote(options.datasetName)},
14
+ plugins: [structureTool(), visionTool()],
15
+ schema: {types: schemaTypes},
16
+ })
17
+ `;
18
+ }
19
+ /**
20
+ * `sanity dev` and `sanity build` read the project and dataset from here, not from
21
+ * `sanity.config.ts`, and fail with `No CLI config found` when the file is absent.
22
+ *
23
+ * `sanity init` also writes a `deployment.autoUpdates` block. It is left out because it only
24
+ * affects `sanity deploy`, and the Blueprint's `defineStudio` already declares auto-updates.
25
+ */
26
+ export function renderStudioCliConfig(options) {
27
+ return `import {defineCliConfig} from 'sanity/cli'
28
+
29
+ export default defineCliConfig({
30
+ api: {
31
+ projectId: ${quote(options.projectId)},
32
+ dataset: ${quote(options.datasetName)},
33
+ },
34
+ })
35
+ `;
36
+ }
37
+ export const STUDIO_SCHEMA_TYPES = `import {post} from './post'
38
+
39
+ export const schemaTypes = [post]
40
+ `;
41
+ export const STUDIO_POST_TYPE = `import {defineField, defineType} from 'sanity'
42
+
43
+ export const post = defineType({
44
+ name: '${STARTER_DOCUMENT_TYPE}',
45
+ title: 'Post',
46
+ type: 'document',
47
+ fields: [
48
+ defineField({name: 'title', type: 'string', validation: (rule) => rule.required()}),
49
+ // The ${STARTER_FUNCTION_NAME} function fills this when it is empty.
50
+ defineField({name: 'slug', type: 'slug', options: {source: 'title'}}),
51
+ defineField({name: 'publishedAt', title: 'Published at', type: 'datetime'}),
52
+ defineField({name: 'body', type: 'text'}),
53
+ ],
54
+ })
55
+ `;
56
+ export const FUNCTION_SET_SLUG = `import {createClient} from '@sanity/client'
57
+ import {documentEventHandler} from '@sanity/functions'
58
+
59
+ const slugify = (title: string) =>
60
+ title
61
+ .toLowerCase()
62
+ .replace(/[^a-z0-9]+/g, '-')
63
+ .replace(/^-+|-+$/g, '')
64
+ .slice(0, 96)
65
+
66
+ export const handler = documentEventHandler(async ({context, event}) => {
67
+ const {_id, title, slug} = event.data
68
+ if (!title || slug?.current) return
69
+
70
+ const client = createClient({apiVersion: '2025-05-01', ...context.clientOptions})
71
+ const current = slugify(title)
72
+ await client.patch(_id).set({slug: {_type: 'slug', current}}).commit()
73
+
74
+ console.log(\`Set slug for \${_id}: \${current}\`)
75
+ })
76
+ `;
77
+ /**
78
+ * Versions `sanity init` pins itself, in `studioDependencies` in `@sanity/cli`.
79
+ *
80
+ * `sanity` and `@sanity/vision` are resolved at scaffold time instead, the way that command
81
+ * resolves them, so a Studio here matches the one `sanity init` would have written.
82
+ */
83
+ const REACT_VERSION = '^19.2.4';
84
+ const STYLED_COMPONENTS_VERSION = '^6.1.18';
85
+ const TYPES_REACT_VERSION = '^19.2.14';
86
+ const TYPESCRIPT_VERSION = '^5.8';
87
+ export const studioPackageJson = (name, versions) => ({
88
+ name,
89
+ version: '1.0.0',
90
+ private: true,
91
+ license: 'UNLICENSED',
92
+ keywords: ['sanity'],
93
+ // The Blueprint deploys this Studio, so there is no `sanity deploy` script.
94
+ // Running one would create a second hosted Studio that the Stack does not own.
95
+ scripts: {
96
+ dev: 'sanity dev',
97
+ build: 'sanity build',
98
+ },
99
+ dependencies: {
100
+ '@sanity/vision': versions.vision,
101
+ react: REACT_VERSION,
102
+ 'react-dom': REACT_VERSION,
103
+ sanity: versions.sanity,
104
+ 'styled-components': STYLED_COMPONENTS_VERSION,
105
+ },
106
+ devDependencies: {
107
+ '@types/react': TYPES_REACT_VERSION,
108
+ typescript: TYPESCRIPT_VERSION,
109
+ },
110
+ });
111
+ /** Copied from `templates/shared/tsconfig.json` in `@sanity/cli`. */
112
+ export const STUDIO_TSCONFIG = {
113
+ compilerOptions: {
114
+ target: 'ES2017',
115
+ lib: ['dom', 'dom.iterable', 'esnext'],
116
+ allowJs: true,
117
+ skipLibCheck: true,
118
+ strict: true,
119
+ forceConsistentCasingInFileNames: true,
120
+ module: 'Preserve',
121
+ moduleDetection: 'force',
122
+ isolatedModules: true,
123
+ jsx: 'preserve',
124
+ incremental: true,
125
+ },
126
+ include: ['**/*.ts', '**/*.tsx'],
127
+ exclude: ['node_modules'],
128
+ };
129
+ export const functionPackageJson = (name) => ({
130
+ name,
131
+ version: '0.1.0',
132
+ private: true,
133
+ type: 'module',
134
+ dependencies: {
135
+ '@sanity/client': '^8',
136
+ '@sanity/functions': '^1',
137
+ },
138
+ });
@@ -0,0 +1,24 @@
1
+ import { type StudioVersions } from './templates.js';
2
+ export interface WorkspaceOptions {
3
+ dir: string;
4
+ projectId: string;
5
+ displayName: string;
6
+ datasetName: string;
7
+ stackName: string;
8
+ /** Blueprint-local name for the attached project resource. */
9
+ projectName: string;
10
+ studioName: string;
11
+ studioSlug: string;
12
+ studioOrigin: string;
13
+ blueprintsVersion: string;
14
+ }
15
+ export interface ScaffoldOptions extends WorkspaceOptions {
16
+ /** Resolved at scaffold time, the way `sanity init` resolves its own Studio versions. */
17
+ studioVersions: StudioVersions;
18
+ }
19
+ export interface WorkspaceResult {
20
+ blueprintFilePath: string;
21
+ files: string[];
22
+ }
23
+ export declare function scaffoldWorkspace(options: ScaffoldOptions): WorkspaceResult;
24
+ export declare function adoptWorkspace(options: WorkspaceOptions): WorkspaceResult;