sanity 3.72.2-coreui.15 → 3.72.2-server-side-schemas-1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/_internal.js +112 -69
- package/lib/_chunks-cjs/_internal.js.map +1 -1
- package/lib/_chunks-cjs/deployAction.js +10 -3
- package/lib/_chunks-cjs/deployAction.js.map +1 -1
- package/lib/_chunks-cjs/fetchSchemaAction.js +18 -0
- package/lib/_chunks-cjs/fetchSchemaAction.js.map +1 -0
- package/lib/_chunks-cjs/runtime.js +2 -6
- package/lib/_chunks-cjs/runtime.js.map +1 -1
- package/lib/_chunks-cjs/storeSchemasAction.js +52 -0
- package/lib/_chunks-cjs/storeSchemasAction.js.map +1 -0
- package/lib/_chunks-cjs/version.js +1 -1
- package/lib/_chunks-es/version.mjs +1 -1
- package/lib/_legacy/version.esm.js +1 -1
- package/package.json +10 -10
- package/src/_internal/cli/actions/deploy/deployAction.ts +12 -1
- package/src/_internal/cli/actions/schema/fetchSchemaAction.ts +35 -0
- package/src/_internal/cli/actions/schema/storeSchemasAction.ts +93 -0
- package/src/_internal/cli/commands/build/buildCommand.ts +2 -0
- package/src/_internal/cli/commands/deploy/deployCommand.ts +1 -0
- package/src/_internal/cli/commands/index.ts +4 -0
- package/src/_internal/cli/commands/schema/fetchSchemaCommand.ts +31 -0
- package/src/_internal/cli/commands/schema/storeSchemaCommand.ts +35 -0
- package/src/_internal/cli/server/renderDocument.tsx +0 -12
- package/src/_internal/cli/server/runtime.ts +9 -12
@@ -8,6 +8,7 @@ import tar from 'tar-fs'
|
|
8
8
|
import {shouldAutoUpdate} from '../../util/shouldAutoUpdate'
|
9
9
|
import buildSanityStudio, {type BuildSanityStudioCommandFlags} from '../build/buildAction'
|
10
10
|
import {extractManifestSafe} from '../manifest/extractManifestAction'
|
11
|
+
import storeManifestSchemas from '../schema/storeSchemasAction'
|
11
12
|
import {
|
12
13
|
checkDir,
|
13
14
|
createDeployment,
|
@@ -113,7 +114,7 @@ export default async function deployStudioAction(
|
|
113
114
|
return
|
114
115
|
}
|
115
116
|
|
116
|
-
await extractManifestSafe(
|
117
|
+
const extractManifestError = await extractManifestSafe(
|
117
118
|
{
|
118
119
|
...buildArgs,
|
119
120
|
extOptions: {},
|
@@ -121,6 +122,16 @@ export default async function deployStudioAction(
|
|
121
122
|
},
|
122
123
|
context,
|
123
124
|
)
|
125
|
+
|
126
|
+
const storeManifestSchemasArgs = {
|
127
|
+
...args,
|
128
|
+
extOptions: {
|
129
|
+
path: `${sourceDir}/static`,
|
130
|
+
},
|
131
|
+
extraArguments: [],
|
132
|
+
}
|
133
|
+
|
134
|
+
if (!extractManifestError) await storeManifestSchemas(storeManifestSchemasArgs, context)
|
124
135
|
}
|
125
136
|
|
126
137
|
// Ensure that the directory exists, is a directory and seems to have valid content
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import {type CliCommandArguments, type CliCommandContext} from '@sanity/cli'
|
2
|
+
|
3
|
+
import {type ManifestSchemaType} from '../../../manifest/manifestTypes'
|
4
|
+
|
5
|
+
export interface FetchSchemaFlags {
|
6
|
+
id: string
|
7
|
+
}
|
8
|
+
|
9
|
+
export default async function fetchSchemaAction(
|
10
|
+
args: CliCommandArguments<FetchSchemaFlags>,
|
11
|
+
context: CliCommandContext,
|
12
|
+
): Promise<void> {
|
13
|
+
const {apiClient, output} = context
|
14
|
+
const flags = args.extOptions
|
15
|
+
const schemaId = flags.id
|
16
|
+
const spinner = output.spinner({}).start('Fetching schema')
|
17
|
+
const client = apiClient({
|
18
|
+
requireUser: true,
|
19
|
+
requireProject: true,
|
20
|
+
}).withConfig({apiVersion: 'v2024-08-01'})
|
21
|
+
|
22
|
+
const projectId = client.config().projectId
|
23
|
+
const dataset = client.config().dataset
|
24
|
+
|
25
|
+
const schema = await client
|
26
|
+
.withConfig({
|
27
|
+
dataset: dataset,
|
28
|
+
projectId: projectId,
|
29
|
+
})
|
30
|
+
.fetch<ManifestSchemaType>(`*[_type == "sanity.workspace.schema" && _id == "${schemaId}"]`)
|
31
|
+
|
32
|
+
spinner.succeed('Schema fetched')
|
33
|
+
// print schema as json
|
34
|
+
output.success(JSON.stringify(schema, null, 2))
|
35
|
+
}
|
@@ -0,0 +1,93 @@
|
|
1
|
+
import {readFileSync} from 'node:fs'
|
2
|
+
import path, {join, resolve} from 'node:path'
|
3
|
+
|
4
|
+
import {type CliCommandArguments, type CliCommandContext} from '@sanity/cli'
|
5
|
+
|
6
|
+
import {
|
7
|
+
type CreateManifest,
|
8
|
+
type ManifestSchemaType,
|
9
|
+
type ManifestWorkspaceFile,
|
10
|
+
} from '../../../manifest/manifestTypes'
|
11
|
+
|
12
|
+
export interface StoreManifestSchemasFlags {
|
13
|
+
'path'?: string
|
14
|
+
'workspace'?: string
|
15
|
+
'custom-id'?: string
|
16
|
+
}
|
17
|
+
|
18
|
+
export default async function storeManifestSchemas(
|
19
|
+
args: CliCommandArguments<StoreManifestSchemasFlags>,
|
20
|
+
context: CliCommandContext,
|
21
|
+
): Promise<void> {
|
22
|
+
const flags = args.extOptions
|
23
|
+
const workspaceName = flags.workspace
|
24
|
+
const customId = flags['custom-id']
|
25
|
+
const {output, workDir, apiClient} = context
|
26
|
+
|
27
|
+
const defaultOutputDir = resolve(join(workDir, 'dist'))
|
28
|
+
|
29
|
+
const outputDir = resolve(defaultOutputDir)
|
30
|
+
const defaultStaticPath = join(outputDir, 'static')
|
31
|
+
|
32
|
+
const staticPath = flags.path ?? defaultStaticPath
|
33
|
+
|
34
|
+
try {
|
35
|
+
const manifestPath = path.resolve(process.cwd(), staticPath)
|
36
|
+
const client = apiClient({
|
37
|
+
requireUser: true,
|
38
|
+
requireProject: true,
|
39
|
+
}).withConfig({apiVersion: 'v2024-08-01'})
|
40
|
+
|
41
|
+
const projectId = client.config().projectId
|
42
|
+
|
43
|
+
const manifest: CreateManifest = JSON.parse(
|
44
|
+
readFileSync(`${manifestPath}/create-manifest.json`, 'utf-8'),
|
45
|
+
)
|
46
|
+
|
47
|
+
const saveSchema = async (workspace: ManifestWorkspaceFile) => {
|
48
|
+
const spinner = output.spinner({}).start('Storing schemas')
|
49
|
+
const id = customId || `sanity.workspace.schema.${workspace.name}`
|
50
|
+
try {
|
51
|
+
if (workspace.projectId !== projectId && workspaceName !== workspace.name) {
|
52
|
+
spinner.fail(
|
53
|
+
`Cannot store schema for ${workspace.name} because manifest projectId does not match: ${projectId} !== ${workspace.projectId}`,
|
54
|
+
)
|
55
|
+
return
|
56
|
+
}
|
57
|
+
const schema = JSON.parse(
|
58
|
+
readFileSync(`${manifestPath}/${workspace.schema}`, 'utf-8'),
|
59
|
+
) as ManifestSchemaType
|
60
|
+
await client
|
61
|
+
.withConfig({
|
62
|
+
dataset: workspace.dataset,
|
63
|
+
projectId: workspace.projectId,
|
64
|
+
})
|
65
|
+
.transaction()
|
66
|
+
.createOrReplace({_type: 'sanity.workspace.schema', _id: id, workspace, schema})
|
67
|
+
.commit()
|
68
|
+
spinner.succeed(
|
69
|
+
`Schema stored for workspace ${workspace.name} (shcemaId: ${id}, projectId: ${projectId}, dataset: ${workspace.dataset})`,
|
70
|
+
)
|
71
|
+
} catch (error) {
|
72
|
+
spinner.fail(`Error storing schema for workspace ${workspace.name}: ${error}`)
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
if (workspaceName) {
|
77
|
+
const schemaToSave = manifest.workspaces.find((workspace) => workspace.name === workspaceName)
|
78
|
+
if (schemaToSave) {
|
79
|
+
await saveSchema(schemaToSave)
|
80
|
+
} else {
|
81
|
+
output.error(`Workspace ${workspaceName} not found in manifest: projectID: ${projectId}`)
|
82
|
+
}
|
83
|
+
} else {
|
84
|
+
await Promise.all(
|
85
|
+
manifest.workspaces.map(async (workspace): Promise<void> => {
|
86
|
+
await saveSchema(workspace)
|
87
|
+
}),
|
88
|
+
)
|
89
|
+
}
|
90
|
+
} catch (err) {
|
91
|
+
output.error(err)
|
92
|
+
}
|
93
|
+
}
|
@@ -6,7 +6,9 @@ Options
|
|
6
6
|
--source-maps Enable source maps for built bundles (increases size of bundle)
|
7
7
|
--auto-updates / --no-auto-updates Enable/disable auto updates of studio versions
|
8
8
|
--no-minify Skip minifying built JavaScript (speeds up build, increases size of bundle)
|
9
|
+
--work
|
9
10
|
-y, --yes Unattended mode, answers "yes" to any "yes/no" prompt and otherwise uses defaults
|
11
|
+
--schema-path If you are storing your schemas in a different path than the default one, you need to specify it here.
|
10
12
|
|
11
13
|
Examples
|
12
14
|
sanity build
|
@@ -10,6 +10,7 @@ const helpText = `
|
|
10
10
|
Options
|
11
11
|
--source-maps Enable source maps for built bundles (increases size of bundle)
|
12
12
|
--auto-updates / --no-auto-updates Enable/disable auto updates of studio versions
|
13
|
+
--schema-path / path to schema folder if custom schema folder is used
|
13
14
|
--no-minify Skip minifying built JavaScript (speeds up build, increases size of bundle)
|
14
15
|
--no-build Don't build the studio prior to deploy, instead deploying the version currently in \`dist/\`
|
15
16
|
-y, --yes Unattended mode, answers "yes" to any "yes/no" prompt and otherwise uses defaults
|
@@ -47,7 +47,9 @@ import migrationGroup from './migration/migrationGroup'
|
|
47
47
|
import runMigrationCommand from './migration/runMigrationCommand'
|
48
48
|
import previewCommand from './preview/previewCommand'
|
49
49
|
import extractSchemaCommand from './schema/extractSchemaCommand'
|
50
|
+
import fetchSchemaCommand from './schema/fetchSchemaCommand'
|
50
51
|
import schemaGroup from './schema/schemaGroup'
|
52
|
+
import storeSchemaCommand from './schema/storeSchemaCommand'
|
51
53
|
import validateSchemaCommand from './schema/validateSchemaCommand'
|
52
54
|
import startCommand from './start/startCommand'
|
53
55
|
import inviteUserCommand from './users/inviteUserCommand'
|
@@ -105,6 +107,8 @@ const commands: (CliCommandDefinition | CliCommandGroupDefinition)[] = [
|
|
105
107
|
validateSchemaCommand,
|
106
108
|
extractSchemaCommand,
|
107
109
|
previewCommand,
|
110
|
+
fetchSchemaCommand,
|
111
|
+
storeSchemaCommand,
|
108
112
|
execCommand,
|
109
113
|
manifestGroup,
|
110
114
|
extractManifestCommand,
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import {type CliCommandArguments, type CliCommandDefinition} from '@sanity/cli'
|
2
|
+
|
3
|
+
import {type FetchSchemaFlags} from '../../actions/schema/fetchSchemaAction'
|
4
|
+
|
5
|
+
const description = 'Extracts a JSON representation of a Sanity schema within a Studio context.'
|
6
|
+
|
7
|
+
const helpText = `
|
8
|
+
**Note**: This command is experimental and subject to change.
|
9
|
+
|
10
|
+
Options
|
11
|
+
--id id of the schema to fetch
|
12
|
+
|
13
|
+
Examples
|
14
|
+
# Fetch the stored schema for the workspace 'default' in the dataset 'sanity-test'
|
15
|
+
sanity schema fetch --id sanity.workspace.schema.default
|
16
|
+
`
|
17
|
+
|
18
|
+
const fetchSchemaCommand = {
|
19
|
+
name: 'fetch',
|
20
|
+
group: 'schema',
|
21
|
+
signature: '',
|
22
|
+
description,
|
23
|
+
helpText,
|
24
|
+
action: async (args, context) => {
|
25
|
+
const mod = await import('../../actions/schema/fetchSchemaAction')
|
26
|
+
|
27
|
+
return mod.default(args as unknown as CliCommandArguments<FetchSchemaFlags>, context)
|
28
|
+
},
|
29
|
+
} satisfies CliCommandDefinition
|
30
|
+
|
31
|
+
export default fetchSchemaCommand
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import {type CliCommandArguments, type CliCommandDefinition} from '@sanity/cli'
|
2
|
+
|
3
|
+
import {type StoreManifestSchemasFlags} from '../../actions/schema/storeSchemasAction'
|
4
|
+
|
5
|
+
const description = ''
|
6
|
+
|
7
|
+
const helpText = `
|
8
|
+
**Note**: This command is experimental and subject to change.
|
9
|
+
|
10
|
+
Options:
|
11
|
+
--workspace The name of the workspace to fetch the stored schema for
|
12
|
+
--path If you are not using the default static file path, you can specify it here.
|
13
|
+
--custom-id you can specify a custom id for the schema. Useful if you want to store the schema in a different path than the default one.
|
14
|
+
|
15
|
+
Examples
|
16
|
+
# if no options are provided all workspace schemas will be stored
|
17
|
+
sanity schema store
|
18
|
+
# Store the schema for only the workspace 'default'
|
19
|
+
sanity schema store --workspace default
|
20
|
+
`
|
21
|
+
|
22
|
+
const storeSchemaCommand = {
|
23
|
+
name: 'store',
|
24
|
+
group: 'schema',
|
25
|
+
signature: '',
|
26
|
+
description,
|
27
|
+
helpText,
|
28
|
+
action: async (args, context) => {
|
29
|
+
const mod = await import('../../actions/schema/storeSchemasAction')
|
30
|
+
|
31
|
+
return mod.default(args as unknown as CliCommandArguments<StoreManifestSchemasFlags>, context)
|
32
|
+
},
|
33
|
+
} satisfies CliCommandDefinition
|
34
|
+
|
35
|
+
export default storeSchemaCommand
|
@@ -111,18 +111,6 @@ export function decorateIndexWithAutoGeneratedWarning(template: string): string
|
|
111
111
|
return template.replace(/<head/, `\n<!--\n${autoGeneratedWarning}\n-->\n<head`)
|
112
112
|
}
|
113
113
|
|
114
|
-
/**
|
115
|
-
* Decorates the given HTML template with a script
|
116
|
-
* tag that loads the bridge component to communicate
|
117
|
-
* with core-ui.
|
118
|
-
*/
|
119
|
-
export function decorateIndexWithBridgeScript(template: string): string {
|
120
|
-
return template.replace(
|
121
|
-
'</head>',
|
122
|
-
'<script src="https://core.sanity-cdn.com/bridge.js" async type="module"></script>\n</head>',
|
123
|
-
)
|
124
|
-
}
|
125
|
-
|
126
114
|
export function getPossibleDocumentComponentLocations(studioRootPath: string): string[] {
|
127
115
|
return [path.join(studioRootPath, '_document.js'), path.join(studioRootPath, '_document.tsx')]
|
128
116
|
}
|
@@ -7,7 +7,6 @@ import {debug as serverDebug} from './debug'
|
|
7
7
|
import {getEntryModule} from './getEntryModule'
|
8
8
|
import {
|
9
9
|
decorateIndexWithAutoGeneratedWarning,
|
10
|
-
decorateIndexWithBridgeScript,
|
11
10
|
getPossibleDocumentComponentLocations,
|
12
11
|
renderDocument,
|
13
12
|
} from './renderDocument'
|
@@ -45,17 +44,15 @@ export async function writeSanityRuntime({
|
|
45
44
|
|
46
45
|
async function renderAndWriteDocument() {
|
47
46
|
debug('Rendering document template')
|
48
|
-
const indexHtml =
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
}),
|
58
|
-
),
|
47
|
+
const indexHtml = decorateIndexWithAutoGeneratedWarning(
|
48
|
+
await renderDocument({
|
49
|
+
studioRootPath: cwd,
|
50
|
+
monorepo,
|
51
|
+
props: {
|
52
|
+
entryPath: `/${path.relative(cwd, path.join(runtimeDir, 'app.js'))}`,
|
53
|
+
basePath: basePath || '/',
|
54
|
+
},
|
55
|
+
}),
|
59
56
|
)
|
60
57
|
|
61
58
|
debug('Writing index.html to runtime directory')
|