@sanity/runtime-cli 17.21.6-blueprinit.gc247877 → 17.21.6-next.g34627a4
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/README.md +19 -19
- package/dist/actions/blueprints/assets.d.ts +2 -1
- package/dist/actions/blueprints/assets.js +8 -2
- package/dist/actions/blueprints/pre-deploy.d.ts +1 -1
- package/dist/actions/blueprints/pre-deploy.js +38 -5
- package/dist/actions/blueprints/process-assets.d.ts +3 -0
- package/dist/actions/blueprints/process-assets.js +13 -4
- package/dist/cores/blueprints/deploy.js +2 -1
- package/dist/utils/bundles/prepare-asset.d.ts +6 -2
- package/dist/utils/bundles/prepare-asset.js +10 -2
- package/dist/utils/bundles/resolve-resource-bindings.d.ts +10 -0
- package/dist/utils/bundles/resolve-resource-bindings.js +37 -0
- package/dist/utils/functions/blocked-modules.d.ts +14 -0
- package/dist/utils/functions/blocked-modules.js +41 -0
- package/dist/utils/functions/prepare-asset.js +5 -0
- package/dist/utils/functions/transpile/function.js +4 -1
- package/dist/utils/icons/prepare-asset.d.ts +10 -0
- package/dist/utils/icons/prepare-asset.js +40 -0
- package/dist/utils/types.d.ts +17 -2
- package/oclif.manifest.json +1 -152
- package/package.json +3 -3
- package/dist/actions/blueprinit/manifest.d.ts +0 -52
- package/dist/actions/blueprinit/manifest.js +0 -139
- package/dist/actions/blueprinit/quote.d.ts +0 -6
- package/dist/actions/blueprinit/quote.js +0 -8
- package/dist/actions/blueprinit/studio.d.ts +0 -6
- package/dist/actions/blueprinit/studio.js +0 -43
- package/dist/actions/blueprinit/templates.d.ts +0 -73
- package/dist/actions/blueprinit/templates.js +0 -143
- package/dist/actions/blueprinit/versions.d.ts +0 -8
- package/dist/actions/blueprinit/versions.js +0 -11
- package/dist/actions/blueprinit/workspace.d.ts +0 -36
- package/dist/actions/blueprinit/workspace.js +0 -174
- package/dist/actions/sanity/create-project.d.ts +0 -19
- package/dist/actions/sanity/create-project.js +0 -32
- package/dist/actions/sanity/datasets.d.ts +0 -15
- package/dist/actions/sanity/datasets.js +0 -26
- package/dist/commands/init.d.ts +0 -21
- package/dist/commands/init.js +0 -82
- package/dist/cores/blueprinit/adopt.d.ts +0 -6
- package/dist/cores/blueprinit/adopt.js +0 -137
- package/dist/cores/blueprinit/columns.d.ts +0 -26
- package/dist/cores/blueprinit/columns.js +0 -27
- package/dist/cores/blueprinit/finish.d.ts +0 -15
- package/dist/cores/blueprinit/finish.js +0 -72
- package/dist/cores/blueprinit/fresh.d.ts +0 -3
- package/dist/cores/blueprinit/fresh.js +0 -230
- package/dist/cores/blueprinit/naming.d.ts +0 -27
- package/dist/cores/blueprinit/naming.js +0 -43
- package/dist/cores/blueprinit/preview.d.ts +0 -34
- package/dist/cores/blueprinit/preview.js +0 -118
- package/dist/cores/blueprinit/project-choice.d.ts +0 -28
- package/dist/cores/blueprinit/project-choice.js +0 -82
- package/dist/cores/blueprinit/prompts.d.ts +0 -13
- package/dist/cores/blueprinit/prompts.js +0 -42
- package/dist/cores/blueprinit/results.d.ts +0 -8
- package/dist/cores/blueprinit/results.js +0 -4
- package/dist/cores/blueprinit/selection.d.ts +0 -15
- package/dist/cores/blueprinit/selection.js +0 -90
- package/dist/cores/blueprinit/stack-name.d.ts +0 -39
- package/dist/cores/blueprinit/stack-name.js +0 -56
- package/dist/cores/blueprinit/target.d.ts +0 -33
- package/dist/cores/blueprinit/target.js +0 -80
- package/dist/cores/blueprinit/types.d.ts +0 -20
- package/dist/cores/blueprinit/types.js +0 -1
- package/dist/cores/blueprinit.d.ts +0 -7
- package/dist/cores/blueprinit.js +0 -64
- package/dist/utils/display/intro.d.ts +0 -6
- package/dist/utils/display/intro.js +0 -63
- package/skills/init.md +0 -199
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { readImageFile } from '@sanity/cli-core/images';
|
|
3
|
+
/**
|
|
4
|
+
* Reads the image at `resource[iconKey]`. The returned `assetParameter` is `iconKey`, so once
|
|
5
|
+
* the bytes are stashed that property is rewritten from the path to the asset ID.
|
|
6
|
+
*/
|
|
7
|
+
export async function prepareIconAsset({ blueprintFileDir, resolvedResource, iconKey, workDir, }) {
|
|
8
|
+
const { resource } = resolvedResource;
|
|
9
|
+
const cleanup = async () => { };
|
|
10
|
+
const icon = String(resource[iconKey]);
|
|
11
|
+
const baseDir = workDir ?? blueprintFileDir;
|
|
12
|
+
const iconPath = path.resolve(baseDir, icon);
|
|
13
|
+
// Defence in depth alongside blueprints-node's own check, as for 'root'
|
|
14
|
+
if (workDir && (path.isAbsolute(icon) || path.relative(workDir, iconPath).startsWith('..'))) {
|
|
15
|
+
return {
|
|
16
|
+
success: false,
|
|
17
|
+
cleanup,
|
|
18
|
+
error: `Property '${iconKey}' on resource '${resource.name}' must be a path inside "${path.relative(blueprintFileDir, workDir) || '.'}", such as './${iconKey}.png'.`,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const { image } = await readImageFile(iconPath);
|
|
23
|
+
return {
|
|
24
|
+
success: true,
|
|
25
|
+
cleanup,
|
|
26
|
+
outputBuffer: image,
|
|
27
|
+
// the provider derives the image's Content-Type from the stashed filename's extension
|
|
28
|
+
fileExtension: path.extname(iconPath).slice(1).toLowerCase(),
|
|
29
|
+
assetParameter: iconKey,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
34
|
+
return {
|
|
35
|
+
success: false,
|
|
36
|
+
cleanup,
|
|
37
|
+
error: `Unable to read '${iconKey}' on resource '${resource.name}': ${msg}`,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
package/dist/utils/types.d.ts
CHANGED
|
@@ -395,14 +395,25 @@ export type AssetPrepResult = {
|
|
|
395
395
|
export type PrepAssetFn<R extends BlueprintResource> = (options: {
|
|
396
396
|
resolvedResource: ResolvedResource<R>;
|
|
397
397
|
blueprintFileDir: string;
|
|
398
|
+
stackId: string;
|
|
399
|
+
auth: AuthParams;
|
|
398
400
|
installer?: InstallerType;
|
|
399
|
-
/** Deploy auth; the agent prep uses `auth.scopeId` for the manifest `sanityID`. */
|
|
400
|
-
auth?: AuthParams;
|
|
401
401
|
}) => Promise<AssetPrepResult>;
|
|
402
402
|
export type PrepResourceFn<R extends BlueprintResource> = (options: {
|
|
403
403
|
resource: R;
|
|
404
404
|
blueprintFileDir: string;
|
|
405
405
|
}) => Promise<void>;
|
|
406
|
+
/** Where a resource's icon image is, so it can be stashed as its own asset. */
|
|
407
|
+
export type IconInfo = {
|
|
408
|
+
/** The resource property holding the icon's path, such as `icon`. It's replaced with the asset ID. */
|
|
409
|
+
iconKey: string;
|
|
410
|
+
/** The directory the path is relative to, and must stay inside. Defaults to the blueprint file directory, without that limit. */
|
|
411
|
+
workDir?: string;
|
|
412
|
+
};
|
|
413
|
+
export type GetIconInfoFn<R extends BlueprintResource> = (options: {
|
|
414
|
+
resolvedResource: ResolvedResource<R>;
|
|
415
|
+
blueprintFileDir: string;
|
|
416
|
+
}) => IconInfo | undefined;
|
|
406
417
|
export type PreDeployConfig = {
|
|
407
418
|
/** The resource type this config applies to or a function that returns true if this config applies to the given type. */
|
|
408
419
|
resourceType: string | ((type: string) => boolean);
|
|
@@ -410,10 +421,14 @@ export type PreDeployConfig = {
|
|
|
410
421
|
prepareAsset?: PrepAssetFn<BlueprintResource>;
|
|
411
422
|
/** Function that mutates the resource before the pre-deploy is executed. */
|
|
412
423
|
prepareResource?: PrepResourceFn<BlueprintResource>;
|
|
424
|
+
/** Function that says where the resource's icon is, or returns nothing when it has none. */
|
|
425
|
+
getIconInfo?: GetIconInfoFn<BlueprintResource>;
|
|
413
426
|
};
|
|
414
427
|
export type AssetResource<R extends BlueprintResource> = {
|
|
415
428
|
resource: ResolvedResource<R>;
|
|
416
429
|
prepareAsset: PrepAssetFn<R>;
|
|
430
|
+
/** The asset is the resource's icon, not its source. */
|
|
431
|
+
isIcon?: boolean;
|
|
417
432
|
};
|
|
418
433
|
export type Warning = {
|
|
419
434
|
code: string;
|
package/oclif.manifest.json
CHANGED
|
@@ -1,156 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"commands": {
|
|
3
|
-
"init": {
|
|
4
|
-
"aliases": [],
|
|
5
|
-
"args": {
|
|
6
|
-
"directory": {
|
|
7
|
-
"description": "Directory to initialize. Interactive runs are asked for one instead.",
|
|
8
|
-
"name": "directory",
|
|
9
|
-
"required": false
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
"description": "Scaffolds a Blueprint, Studio, and starter function around a Sanity project.\n\nUse a project you already have, or create one with --create-project. A new project has no\ndatasets, so the Blueprint creates the dataset rather than attaching it.\n\nPass a directory to scaffold into it. Without one, an interactive run asks where the files go.\n\nThis hidden command is an experiment; its interface and generated files are not stable.",
|
|
13
|
-
"examples": [
|
|
14
|
-
"<%= config.bin %> <%= command.id %>",
|
|
15
|
-
"<%= config.bin %> <%= command.id %> ./my-workspace",
|
|
16
|
-
"<%= config.bin %> <%= command.id %> --yes",
|
|
17
|
-
"<%= config.bin %> <%= command.id %> --project-id <id> --dataset <name> --yes",
|
|
18
|
-
"<%= config.bin %> <%= command.id %> --create-project \"My Shop\" --yes"
|
|
19
|
-
],
|
|
20
|
-
"flags": {
|
|
21
|
-
"json": {
|
|
22
|
-
"description": "Format output as json",
|
|
23
|
-
"name": "json",
|
|
24
|
-
"allowNo": false,
|
|
25
|
-
"type": "boolean"
|
|
26
|
-
},
|
|
27
|
-
"path": {
|
|
28
|
-
"aliases": [
|
|
29
|
-
"blueprint-path"
|
|
30
|
-
],
|
|
31
|
-
"char": "p",
|
|
32
|
-
"description": "Path to a Blueprint file or directory containing one",
|
|
33
|
-
"env": "SANITY_BLUEPRINT_PATH",
|
|
34
|
-
"hidden": true,
|
|
35
|
-
"name": "path",
|
|
36
|
-
"hasDynamicHelp": false,
|
|
37
|
-
"multiple": false,
|
|
38
|
-
"type": "option"
|
|
39
|
-
},
|
|
40
|
-
"trace": {
|
|
41
|
-
"description": "Trace output",
|
|
42
|
-
"hidden": true,
|
|
43
|
-
"name": "trace",
|
|
44
|
-
"allowNo": false,
|
|
45
|
-
"type": "boolean"
|
|
46
|
-
},
|
|
47
|
-
"validate-resources": {
|
|
48
|
-
"description": "Validate resources",
|
|
49
|
-
"hidden": true,
|
|
50
|
-
"name": "validate-resources",
|
|
51
|
-
"allowNo": true,
|
|
52
|
-
"type": "boolean"
|
|
53
|
-
},
|
|
54
|
-
"verbose": {
|
|
55
|
-
"description": "Verbose output",
|
|
56
|
-
"hidden": true,
|
|
57
|
-
"name": "verbose",
|
|
58
|
-
"allowNo": false,
|
|
59
|
-
"type": "boolean"
|
|
60
|
-
},
|
|
61
|
-
"llms": {
|
|
62
|
-
"aliases": [
|
|
63
|
-
"skill"
|
|
64
|
-
],
|
|
65
|
-
"description": "Show agent-oriented guidance for this command",
|
|
66
|
-
"hidden": true,
|
|
67
|
-
"name": "llms",
|
|
68
|
-
"allowNo": false,
|
|
69
|
-
"type": "boolean"
|
|
70
|
-
},
|
|
71
|
-
"yes": {
|
|
72
|
-
"char": "y",
|
|
73
|
-
"description": "Skip confirmation prompts",
|
|
74
|
-
"name": "yes",
|
|
75
|
-
"allowNo": false,
|
|
76
|
-
"type": "boolean"
|
|
77
|
-
},
|
|
78
|
-
"organization-id": {
|
|
79
|
-
"aliases": [
|
|
80
|
-
"organization",
|
|
81
|
-
"organizationId",
|
|
82
|
-
"org"
|
|
83
|
-
],
|
|
84
|
-
"description": "Organization to use when the account has several",
|
|
85
|
-
"name": "organization-id",
|
|
86
|
-
"hasDynamicHelp": false,
|
|
87
|
-
"multiple": false,
|
|
88
|
-
"type": "option"
|
|
89
|
-
},
|
|
90
|
-
"project-id": {
|
|
91
|
-
"aliases": [
|
|
92
|
-
"project",
|
|
93
|
-
"projectId"
|
|
94
|
-
],
|
|
95
|
-
"description": "Project to use when the organization has several",
|
|
96
|
-
"name": "project-id",
|
|
97
|
-
"hasDynamicHelp": false,
|
|
98
|
-
"multiple": false,
|
|
99
|
-
"type": "option"
|
|
100
|
-
},
|
|
101
|
-
"create-project": {
|
|
102
|
-
"aliases": [
|
|
103
|
-
"createProject",
|
|
104
|
-
"new-project"
|
|
105
|
-
],
|
|
106
|
-
"description": "Create a project with this display name instead of using an existing one",
|
|
107
|
-
"exclusive": [
|
|
108
|
-
"project-id"
|
|
109
|
-
],
|
|
110
|
-
"name": "create-project",
|
|
111
|
-
"hasDynamicHelp": false,
|
|
112
|
-
"multiple": false,
|
|
113
|
-
"type": "option"
|
|
114
|
-
},
|
|
115
|
-
"dataset": {
|
|
116
|
-
"description": "Dataset to attach, or to create alongside a new project",
|
|
117
|
-
"name": "dataset",
|
|
118
|
-
"hasDynamicHelp": false,
|
|
119
|
-
"multiple": false,
|
|
120
|
-
"type": "option"
|
|
121
|
-
},
|
|
122
|
-
"stack-name": {
|
|
123
|
-
"description": "Name for the new organization-scoped Stack, and the hosted Studio slug",
|
|
124
|
-
"name": "stack-name",
|
|
125
|
-
"hasDynamicHelp": false,
|
|
126
|
-
"multiple": false,
|
|
127
|
-
"type": "option"
|
|
128
|
-
},
|
|
129
|
-
"studio-name": {
|
|
130
|
-
"description": "Blueprint-local name for the Studio resource and its directory",
|
|
131
|
-
"name": "studio-name",
|
|
132
|
-
"hasDynamicHelp": false,
|
|
133
|
-
"multiple": false,
|
|
134
|
-
"type": "option"
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
"hasDynamicHelp": false,
|
|
138
|
-
"hidden": true,
|
|
139
|
-
"hiddenAliases": [],
|
|
140
|
-
"id": "init",
|
|
141
|
-
"pluginAlias": "@sanity/runtime-cli",
|
|
142
|
-
"pluginName": "@sanity/runtime-cli",
|
|
143
|
-
"pluginType": "core",
|
|
144
|
-
"strict": true,
|
|
145
|
-
"summary": "Experimental blueprints-first project init",
|
|
146
|
-
"enableJsonFlag": true,
|
|
147
|
-
"isESM": true,
|
|
148
|
-
"relativePath": [
|
|
149
|
-
"dist",
|
|
150
|
-
"commands",
|
|
151
|
-
"init.js"
|
|
152
|
-
]
|
|
153
|
-
},
|
|
154
3
|
"blueprints:add": {
|
|
155
4
|
"aliases": [],
|
|
156
5
|
"args": {
|
|
@@ -3301,5 +3150,5 @@
|
|
|
3301
3150
|
]
|
|
3302
3151
|
}
|
|
3303
3152
|
},
|
|
3304
|
-
"version": "17.21.6-
|
|
3153
|
+
"version": "17.21.6-next.g34627a4"
|
|
3305
3154
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/runtime-cli",
|
|
3
3
|
"description": "Sanity's Runtime CLI for Blueprints and Functions",
|
|
4
|
-
"version": "17.21.6-
|
|
4
|
+
"version": "17.21.6-next.g34627a4",
|
|
5
5
|
"author": "Sanity Runtime Team",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
"@sanity-labs/oclif-plugin-skills-flag": "^0.2.1",
|
|
73
73
|
"@sanity/blueprints": "^0.34.1",
|
|
74
74
|
"@sanity/blueprints-parser": "^0.5.0",
|
|
75
|
-
"@sanity/cli-build": "^7.
|
|
76
|
-
"@sanity/cli-core": "^3.
|
|
75
|
+
"@sanity/cli-build": "^7.4.0",
|
|
76
|
+
"@sanity/cli-core": "^3.16.0",
|
|
77
77
|
"@sanity/client": "^8.16.0",
|
|
78
78
|
"adm-zip": "^0.6.1",
|
|
79
79
|
"array-treeify": "^0.2.0",
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
export declare const STARTER_DOCUMENT_TYPE = "post";
|
|
2
|
-
/** Where `sanity dev` serves the generated Studio. */
|
|
3
|
-
export declare const LOCAL_STUDIO_ORIGIN = "http://localhost:3333";
|
|
4
|
-
export declare const STARTER_FUNCTION_NAME = "set-slug";
|
|
5
|
-
export declare const DEFAULT_STUDIO_NAME = "studio";
|
|
6
|
-
/**
|
|
7
|
-
* Whether the Blueprint takes ownership of an existing dataset or makes a new one.
|
|
8
|
-
*
|
|
9
|
-
* A project this command just created has no datasets, so its Blueprint creates one.
|
|
10
|
-
* A project the user already had has the dataset they picked, so its Blueprint attaches.
|
|
11
|
-
*/
|
|
12
|
-
export type DatasetAction = 'attach' | 'create';
|
|
13
|
-
export interface BlueprintManifestOptions {
|
|
14
|
-
projectName: string;
|
|
15
|
-
displayName: string;
|
|
16
|
-
projectId: string;
|
|
17
|
-
datasetName: string;
|
|
18
|
-
datasetAction: DatasetAction;
|
|
19
|
-
studioName: string;
|
|
20
|
-
studioSlug: string;
|
|
21
|
-
studioRoot: string;
|
|
22
|
-
studioOrigin: string;
|
|
23
|
-
withFunction: boolean;
|
|
24
|
-
/** Declare the dev server's origin too. Set when the project is new and has none. */
|
|
25
|
-
withLocalCors: boolean;
|
|
26
|
-
}
|
|
27
|
-
export declare function renderBlueprint(options: BlueprintManifestOptions): string;
|
|
28
|
-
export declare function hostedStudioOrigin(studioName: string, sanityEnv?: string): string;
|
|
29
|
-
/**
|
|
30
|
-
* The Blueprint-local name for the attached project.
|
|
31
|
-
*
|
|
32
|
-
* Kept apart from the Stack name so a default Stack name can never collide with a
|
|
33
|
-
* resource name, and suffixed so a reference states which resource it reads.
|
|
34
|
-
*/
|
|
35
|
-
export declare function projectResourceName(baseName: string): string;
|
|
36
|
-
/** The Blueprint-local name for the Studio's credentialed CORS origin. */
|
|
37
|
-
export declare function corsResourceName(studioName: string): string;
|
|
38
|
-
/** The Blueprint-local name for the dev server's credentialed CORS origin. */
|
|
39
|
-
export declare function devCorsResourceName(studioName: string): string;
|
|
40
|
-
/** Where a fresh scaffold puts the Studio, relative to the Blueprint. */
|
|
41
|
-
export declare function studioSourcePath(studioName: string): string;
|
|
42
|
-
/**
|
|
43
|
-
* The default name for the new Stack, which is also the hosted Studio slug.
|
|
44
|
-
*
|
|
45
|
-
* A Studio slug must be unique across every Sanity organization and no API can report
|
|
46
|
-
* whether one is free, so the default carries both the project and the dataset to make
|
|
47
|
-
* an accidental match unlikely.
|
|
48
|
-
*/
|
|
49
|
-
export declare function defaultStackName(baseName: string, datasetName: string): string;
|
|
50
|
-
/** The slug form of a project display name, falling back to its ID. */
|
|
51
|
-
export declare function projectBaseName(displayName: string, projectId: string): string;
|
|
52
|
-
export declare function slugify(value: string): string;
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { quote } from './quote.js';
|
|
2
|
-
export const STARTER_DOCUMENT_TYPE = 'post';
|
|
3
|
-
/** Where `sanity dev` serves the generated Studio. */
|
|
4
|
-
export const LOCAL_STUDIO_ORIGIN = 'http://localhost:3333';
|
|
5
|
-
export const STARTER_FUNCTION_NAME = 'set-slug';
|
|
6
|
-
export const DEFAULT_STUDIO_NAME = 'studio';
|
|
7
|
-
export function renderBlueprint(options) {
|
|
8
|
-
const { projectName, displayName, projectId, datasetName, datasetAction, studioName, studioSlug, studioRoot, studioOrigin, withFunction, withLocalCors, } = options;
|
|
9
|
-
const definers = [
|
|
10
|
-
'defineBlueprint',
|
|
11
|
-
'defineCorsOrigin',
|
|
12
|
-
'defineDataset',
|
|
13
|
-
'defineProject',
|
|
14
|
-
'defineStudio',
|
|
15
|
-
];
|
|
16
|
-
if (withFunction)
|
|
17
|
-
definers.splice(3, 0, 'defineDocumentFunction');
|
|
18
|
-
const project = quote(`$.resources.${projectName}.id`);
|
|
19
|
-
// A project this command just created has no CORS origins, so `sanity dev` could not sign in
|
|
20
|
-
// until one existed. Declaring it keeps local development in the file the reader is reading.
|
|
21
|
-
const localCorsResource = withLocalCors
|
|
22
|
-
? ` defineCorsOrigin({
|
|
23
|
-
project: ${project},
|
|
24
|
-
name: ${quote(devCorsResourceName(studioName))},
|
|
25
|
-
origin: ${quote(LOCAL_STUDIO_ORIGIN)},
|
|
26
|
-
allowCredentials: true,
|
|
27
|
-
}),
|
|
28
|
-
`
|
|
29
|
-
: '';
|
|
30
|
-
// `retain` is spelled out on both paths. The coordinator defaults to `allow`, and neither
|
|
31
|
-
// the dataset nor the project provider overrides that, so a created dataset would
|
|
32
|
-
// otherwise be deleted, with its content, by `blueprints destroy`.
|
|
33
|
-
const datasetLifecycle = datasetAction === 'attach'
|
|
34
|
-
? ` lifecycle: {
|
|
35
|
-
deletionPolicy: 'retain',
|
|
36
|
-
ownershipAction: {
|
|
37
|
-
type: 'attach',
|
|
38
|
-
id: ${quote(datasetName)},
|
|
39
|
-
projectId: ${project},
|
|
40
|
-
},
|
|
41
|
-
},`
|
|
42
|
-
: ` lifecycle: {deletionPolicy: 'retain'},`;
|
|
43
|
-
const inlineImport = `import {${definers.join(', ')}} from '@sanity/blueprints'`;
|
|
44
|
-
const imports = inlineImport.length > 100
|
|
45
|
-
? `import {\n${definers.map((definer) => ` ${definer},`).join('\n')}\n} from '@sanity/blueprints'`
|
|
46
|
-
: inlineImport;
|
|
47
|
-
const functionResource = withFunction
|
|
48
|
-
? ` defineDocumentFunction({
|
|
49
|
-
name: ${quote(STARTER_FUNCTION_NAME)},
|
|
50
|
-
displayName: 'Set slug',
|
|
51
|
-
project: ${project},
|
|
52
|
-
event: {
|
|
53
|
-
on: ['create', 'update'],
|
|
54
|
-
filter: "_type == '${STARTER_DOCUMENT_TYPE}' && !defined(slug.current)",
|
|
55
|
-
projection: '{_id, title, slug}',
|
|
56
|
-
},
|
|
57
|
-
}),
|
|
58
|
-
`
|
|
59
|
-
: '';
|
|
60
|
-
return `${imports}
|
|
61
|
-
|
|
62
|
-
export default defineBlueprint({
|
|
63
|
-
resources: [
|
|
64
|
-
defineProject({
|
|
65
|
-
name: ${quote(projectName)},
|
|
66
|
-
displayName: ${quote(displayName)},
|
|
67
|
-
lifecycle: {
|
|
68
|
-
deletionPolicy: 'retain',
|
|
69
|
-
ownershipAction: {type: 'attach', id: ${quote(projectId)}},
|
|
70
|
-
},
|
|
71
|
-
}),
|
|
72
|
-
defineDataset({
|
|
73
|
-
project: ${project},
|
|
74
|
-
name: ${quote(datasetName)},
|
|
75
|
-
${datasetLifecycle}
|
|
76
|
-
}),
|
|
77
|
-
defineCorsOrigin({
|
|
78
|
-
project: ${project},
|
|
79
|
-
name: ${quote(corsResourceName(studioName))},
|
|
80
|
-
origin: ${quote(studioOrigin)},
|
|
81
|
-
allowCredentials: true,
|
|
82
|
-
}),
|
|
83
|
-
${localCorsResource}
|
|
84
|
-
defineStudio({
|
|
85
|
-
project: ${project},
|
|
86
|
-
name: ${quote(studioName)},
|
|
87
|
-
slug: ${quote(studioSlug)},
|
|
88
|
-
title: ${quote(displayName)},
|
|
89
|
-
root: ${quote(studioRoot)},
|
|
90
|
-
}),
|
|
91
|
-
${functionResource} ],
|
|
92
|
-
})
|
|
93
|
-
`;
|
|
94
|
-
}
|
|
95
|
-
export function hostedStudioOrigin(studioName, sanityEnv) {
|
|
96
|
-
const hostname = sanityEnv?.toLowerCase() === 'staging' ? 'studio.sanity.work' : 'sanity.studio';
|
|
97
|
-
return `https://${studioName}.${hostname}`;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* The Blueprint-local name for the attached project.
|
|
101
|
-
*
|
|
102
|
-
* Kept apart from the Stack name so a default Stack name can never collide with a
|
|
103
|
-
* resource name, and suffixed so a reference states which resource it reads.
|
|
104
|
-
*/
|
|
105
|
-
export function projectResourceName(baseName) {
|
|
106
|
-
return `${baseName}-project`;
|
|
107
|
-
}
|
|
108
|
-
/** The Blueprint-local name for the Studio's credentialed CORS origin. */
|
|
109
|
-
export function corsResourceName(studioName) {
|
|
110
|
-
return `${studioName}-cors`;
|
|
111
|
-
}
|
|
112
|
-
/** The Blueprint-local name for the dev server's credentialed CORS origin. */
|
|
113
|
-
export function devCorsResourceName(studioName) {
|
|
114
|
-
return `${studioName}-dev-cors`;
|
|
115
|
-
}
|
|
116
|
-
/** Where a fresh scaffold puts the Studio, relative to the Blueprint. */
|
|
117
|
-
export function studioSourcePath(studioName) {
|
|
118
|
-
return `studios/${studioName}`;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* The default name for the new Stack, which is also the hosted Studio slug.
|
|
122
|
-
*
|
|
123
|
-
* A Studio slug must be unique across every Sanity organization and no API can report
|
|
124
|
-
* whether one is free, so the default carries both the project and the dataset to make
|
|
125
|
-
* an accidental match unlikely.
|
|
126
|
-
*/
|
|
127
|
-
export function defaultStackName(baseName, datasetName) {
|
|
128
|
-
return `${baseName}-${datasetName}`;
|
|
129
|
-
}
|
|
130
|
-
/** The slug form of a project display name, falling back to its ID. */
|
|
131
|
-
export function projectBaseName(displayName, projectId) {
|
|
132
|
-
return slugify(displayName) || projectId;
|
|
133
|
-
}
|
|
134
|
-
export function slugify(value) {
|
|
135
|
-
return value
|
|
136
|
-
.toLowerCase()
|
|
137
|
-
.replace(/[^a-z0-9]+/g, '-')
|
|
138
|
-
.replace(/^-+|-+$/g, '');
|
|
139
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A single-quoted TypeScript string literal, for the files this command generates.
|
|
3
|
-
*
|
|
4
|
-
* Both generators write source code, so both need the same escaping rules.
|
|
5
|
-
*/
|
|
6
|
-
export function quote(value) {
|
|
7
|
-
return `'${value.replaceAll('\\', '\\\\').replaceAll("'", "\\'")}'`;
|
|
8
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
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 // useCdn: false because this handler writes; the default warns and reads from the edge cache\n const client = createClient({\n apiVersion: '2025-05-01',\n useCdn: false,\n ...context.clientOptions,\n })\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
|
-
};
|