Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/studio manifests #6458

Draft
wants to merge 29 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b171373
feat(sanity): allow `extractSchema` worker to emit schemas for all wo…
juice49 Apr 19, 2024
bd8486f
feat(sanity): include workspace and dataset names when extracting schema
juice49 Apr 22, 2024
5d6d98a
feat(cli): add `manifest` commands
juice49 Apr 22, 2024
11ca414
feat(manifest): add `@sanity/manifest` package
juice49 Apr 22, 2024
37e7b31
refactor(sanity): use manifest schemas from `@sanity/manifest`
juice49 Apr 22, 2024
eb68732
chore: format files
juice49 Apr 23, 2024
04df37f
feat(schema): include `title`, `description`, and `deprecated` attrib…
juice49 Apr 23, 2024
1526173
feat(sanity): add `direct` schema format to schema extractor
juice49 Apr 24, 2024
45f81a5
Revert "feat(schema): include `title`, `description`, and `deprecated…
juice49 Apr 24, 2024
03df4ed
feat(sanity): export `ConcreteRuleClass` class
juice49 Apr 26, 2024
568d925
feat(sanity): include validation rules in manifests
juice49 Apr 26, 2024
aad87f3
refactor(sanity): move manifest extraction code
juice49 Apr 27, 2024
9aa3a2b
feat(sanity): extract manifest during build
juice49 Apr 28, 2024
e99e860
feat(sanity): adopt `.studioschema.json` filename suffix for manifest…
juice49 Apr 28, 2024
13a817b
refactor(sanity): rename manifest extraction functions (remove plural)
juice49 Apr 29, 2024
9d688b5
fix(sanity): remove redundant success message
juice49 Apr 29, 2024
cd1917e
fix(sanity): stop build spinner before starting manifest extraction
juice49 Apr 29, 2024
74a504f
feat(sanity): add `unstable_extractManifestOnBuild` CLI config option
juice49 Apr 29, 2024
6956375
feat(test-studio): enable `unstable_extractManifestOnBuild`
juice49 Apr 29, 2024
99f8fc4
fix(sanity): switch to node crypto for node 18 compatibility
juice49 Apr 29, 2024
74fd877
feat(cli): add `unstable_staticAssetsPath` CLI configuration option
juice49 Apr 29, 2024
ef5478a
chore(cli): refine `unstable_extractManifestOnBuild` CLI configuratio…
juice49 Apr 29, 2024
deecb68
feat(sanity): remove extraneous `types` wrapper from manifests
juice49 Apr 30, 2024
a65d6f1
debug(test-studio): remove Mux plugin to unblock typegen
juice49 May 23, 2024
1d7132b
feat(embedded-studio): enable manifest extraction
juice49 May 23, 2024
6766c53
feat(starter-next-studio): enable manifest extraction
juice49 May 23, 2024
d5aae73
wip
juice49 May 23, 2024
69b34a1
feat(sanity): normalize type constraints in manifest validation
juice49 May 24, 2024
cd5f1f0
wip
juice49 Jun 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,7 @@ packages/sanity/src/core/studio/upsell/ @sanity-io/studio-ex
/packages/sanity/src/structure/panes/documentList/PaneContainer.tsx @sanity-io/ecosystem @sanity-io/studio-dx
/packages/sanity/src/structure/StructureToolProvider.tsx @sanity-io/ecosystem @sanity-io/studio-dx
/packages/sanity/src/structure/types.ts @sanity-io/ecosystem @sanity-io/studio-dx

# -- Manifest --
/packages/@sanity/manifest @sanity-io/studio-dx

1 change: 1 addition & 0 deletions dev/aliases.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const devAliases = {
'@sanity/mutator': './packages/@sanity/mutator/src',
'@sanity/portable-text-editor': './packages/@sanity/portable-text-editor/src',
'@sanity/schema': './packages/@sanity/schema/src/_exports',
'@sanity/manifest': './packages/@sanity/manifrst/src/_exports',
'@sanity/migrate': './packages/@sanity/migrate/src/_exports',
'@sanity/types': './packages/@sanity/types/src',
'@sanity/util': './packages/@sanity/util/src/_exports',
Expand Down
2 changes: 1 addition & 1 deletion dev/embedded-studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "3.43.0",
"private": true,
"scripts": {
"build": "tsc && vite build",
"build": "tsc && vite build && sanity manifest extract",
"dev": "vite",
"preview": "vite preview"
},
Expand Down
9 changes: 9 additions & 0 deletions dev/embedded-studio/sanity.cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {defineCliConfig} from 'sanity/cli'

export default defineCliConfig({
api: {
projectId: 'ppsg7ml5',
dataset: 'test',
},
unstable_staticAssetsPath: './dist/assets',
})
34 changes: 34 additions & 0 deletions dev/embedded-studio/sanity.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {defineConfig, defineType} from 'sanity'
import {structureTool} from 'sanity/structure'

const BLOG_POST_SCHEMA = defineType({
type: 'document',
name: 'blogPost',
title: 'Blog post',
fields: [
{
type: 'string',
name: 'title',
title: 'Title',
},
],
})

export const SCHEMA_TYPES = [BLOG_POST_SCHEMA]

export default defineConfig({
projectId: 'ppsg7ml5',
dataset: 'test',

document: {
unstable_comments: {
enabled: true,
},
},

schema: {
types: SCHEMA_TYPES,
},

plugins: [structureTool()],
})
42 changes: 2 additions & 40 deletions dev/embedded-studio/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,8 @@
import {Button, Card, Flex, studioTheme, ThemeProvider, usePrefersDark} from '@sanity/ui'
import {useCallback, useMemo, useState} from 'react'
import {
defineConfig,
defineType,
Studio,
StudioLayout,
StudioProvider,
type StudioThemeColorSchemeKey,
} from 'sanity'
import {structureTool} from 'sanity/structure'
import {Studio, StudioLayout, StudioProvider, type StudioThemeColorSchemeKey} from 'sanity'

const BLOG_POST_SCHEMA = defineType({
type: 'document',
name: 'blogPost',
title: 'Blog post',
fields: [
{
type: 'string',
name: 'title',
title: 'Title',
},
],
})

const SCHEMA_TYPES = [BLOG_POST_SCHEMA]

const config = defineConfig({
projectId: 'ppsg7ml5',
dataset: 'test',

document: {
unstable_comments: {
enabled: true,
},
},

schema: {
types: SCHEMA_TYPES,
},

plugins: [structureTool()],
})
import config from '../sanity.config'

export function App() {
const prefersDark = usePrefersDark()
Expand Down
36 changes: 4 additions & 32 deletions dev/starter-next-studio/components/Studio.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,13 @@
import {useMemo} from 'react'
import {defineConfig, Studio} from 'sanity'
import {structureTool} from 'sanity/structure'
import {Studio} from 'sanity'

import config from '../sanity.config'

const wrapperStyles = {height: '100vh', width: '100vw'}

export default function StudioRoot({basePath}: {basePath: string}) {
const config = useMemo(
() =>
defineConfig({
basePath,
plugins: [structureTool()],
title: 'Next.js Starter',
projectId: 'ppsg7ml5',
dataset: 'test',
schema: {
types: [
{
type: 'document',
name: 'post',
title: 'Post',
fields: [
{
type: 'string',
name: 'title',
title: 'Title',
},
],
},
],
},
}),
[basePath],
)

return (
<div style={wrapperStyles}>
<Studio config={config} />
<Studio config={{...config, basePath}} />
</div>
)
}
2 changes: 1 addition & 1 deletion dev/starter-next-studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "MIT",
"author": "Sanity.io <[email protected]>",
"scripts": {
"build": "next build",
"build": "sanity manifest extract && next build",
"dev": "next dev",
"start": "next start"
},
Expand Down
8 changes: 8 additions & 0 deletions dev/starter-next-studio/sanity.cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {defineCliConfig} from 'sanity/cli'

export default defineCliConfig({
api: {
projectId: 'ppsg7ml5',
dataset: 'test',
},
})
25 changes: 25 additions & 0 deletions dev/starter-next-studio/sanity.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {defineConfig} from 'sanity'
import {structureTool} from 'sanity/structure'

export default defineConfig({
plugins: [structureTool()],
title: 'Next.js Starter',
projectId: 'ppsg7ml5',
dataset: 'test',
schema: {
types: [
{
type: 'document',
name: 'post',
title: 'Post',
fields: [
{
type: 'string',
name: 'title',
title: 'Title',
},
],
},
],
},
})
2 changes: 2 additions & 0 deletions dev/test-studio/sanity.cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export default defineCliConfig({
dataset: 'test',
},

unstable_extractManifestOnBuild: true,

// Can be overriden by:
// A) `SANITY_STUDIO_REACT_STRICT_MODE=false pnpm dev`
// B) creating a `.env` file locally that sets the same env variable as above
Expand Down
3 changes: 0 additions & 3 deletions dev/test-studio/sanity.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {defineConfig, definePlugin, type WorkspaceOptions} from 'sanity'
import {presentationTool} from 'sanity/presentation'
import {structureTool} from 'sanity/structure'
import {imageHotspotArrayPlugin} from 'sanity-plugin-hotspot-array'
import {muxInput} from 'sanity-plugin-mux-input'

import {imageAssetSource} from './assetSources'
import {
Expand Down Expand Up @@ -130,8 +129,6 @@ const sharedSettings = definePlugin({
visionTool({
defaultApiVersion: '2022-08-08',
}),
// eslint-disable-next-line camelcase
muxInput({mp4_support: 'standard'}),
imageHotspotArrayPlugin(),
presenceTool(),
routerDebugTool(),
Expand Down
2 changes: 0 additions & 2 deletions dev/test-studio/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ import {virtualizationInObject} from './debug/virtualizationInObject'
import {demos3d} from './demos/3d'
import {v3docs} from './docs/v3'
import markdown from './externalPlugins/markdown'
import mux from './externalPlugins/mux'
import playlist from './playlist'
import playlistTrack from './playlistTrack'
import code from './plugins/code'
Expand Down Expand Up @@ -261,7 +260,6 @@ export const schemaTypes = [

// Test documents with 3rd party plugin inputs
markdown,
mux,

// Other documents
author,
Expand Down
2 changes: 2 additions & 0 deletions dev/tsconfig.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"@sanity/cli": ["./packages/@sanity/cli/src/index.ts"],
"@sanity/codegen": ["./packages/@sanity/codegen/src/_exports/index.ts"],
"@sanity/mutator": ["./packages/@sanity/mutator/src/index.ts"],
"@sanity/manifest/*": ["./packages/@sanity/manifest/src/_exports/*"],
"@sanity/manifest": ["./packages/@sanity/manifest/src/_exports/index.ts"],
"@sanity/portable-text-editor": ["./packages/@sanity/portable-text-editor/src/index.ts"],
"@sanity/schema/*": ["./packages/@sanity/schema/src/_exports/*"],
"@sanity/schema": ["./packages/@sanity/schema/src/_exports/index.ts"],
Expand Down
2 changes: 2 additions & 0 deletions examples/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"@sanity/cli": ["./packages/@sanity/cli/src/index.ts"],
"@sanity/codegen": ["./packages/@sanity/codegen/src/_exports/index.ts"],
"@sanity/mutator": ["./packages/@sanity/mutator/src/index.ts"],
"@sanity/manifest/*": ["./packages/@sanity/manifest/src/_exports/*"],
"@sanity/manifest": ["./packages/@sanity/manifest/src/_exports/index.ts"],
"@sanity/portable-text-editor": ["./packages/@sanity/portable-text-editor/src/index.ts"],
"@sanity/schema/*": ["./packages/@sanity/schema/src/_exports/*"],
"@sanity/schema": ["./packages/@sanity/schema/src/_exports/index.ts"],
Expand Down
1 change: 1 addition & 0 deletions packages/@repo/test-exports/.depcheckrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"@sanity/cli",
"@sanity/codegen",
"@sanity/diff",
"@sanity/manifest",
"@sanity/migrate",
"@sanity/mutator",
"@sanity/portable-text-editor",
Expand Down
1 change: 1 addition & 0 deletions packages/@repo/test-exports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@sanity/cli": "workspace:*",
"@sanity/codegen": "workspace:*",
"@sanity/diff": "workspace:*",
"@sanity/manifest": "workspace:*",
"@sanity/migrate": "workspace:*",
"@sanity/mutator": "workspace:*",
"@sanity/portable-text-editor": "workspace:*",
Expand Down
20 changes: 20 additions & 0 deletions packages/@sanity/cli/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,26 @@ export interface CliConfig {
graphql?: GraphQLAPIConfig[]

vite?: UserViteConfig

/**
* Whether or not to extract a Studio Manifest to the static assets directory when building
* (or deploying) the project.
*
* Optional, defaults to `false`.
*/
unstable_extractManifestOnBuild?: boolean

/**
* The path Sanity CLI will write static assets (such as the Studio Manifest) to when used inside
* an embedded Studio project. Relative to the CLI config file.
*
* Sanity CLI will attempt to create this path if it does not exist.
*
* You should not define a value if your Studio is not embedded.
*
* Optional, defaults to `dist/static`.
*/
unstable_staticAssetsPath?: string
}

export type UserViteConfig =
Expand Down
1 change: 1 addition & 0 deletions packages/@sanity/cli/src/util/noSuchCommandText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const coreCommands = [
'exec',
'graphql',
'hook',
'manifest',
'migration',
'preview',
'schema',
Expand Down
3 changes: 3 additions & 0 deletions packages/@sanity/manifest/.depcheckrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignores": ["@repo/tsconfig", "@sanity/pkg-utils"]
}
11 changes: 11 additions & 0 deletions packages/@sanity/manifest/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict'

const path = require('path')

const ROOT_PATH = path.resolve(__dirname, '../../..')

module.exports = {
rules: {
'import/no-extraneous-dependencies': ['error', {packageDir: [ROOT_PATH, __dirname]}],
},
}
15 changes: 15 additions & 0 deletions packages/@sanity/manifest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Logs
/logs
*.log

# Coverage directory used by tools like istanbul
/coverage

# Dependency directories
/node_modules

# Compiled code
/lib

# Legacy exports
/_internal.js
1 change: 1 addition & 0 deletions packages/@sanity/manifest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Sanity Manifest
8 changes: 8 additions & 0 deletions packages/@sanity/manifest/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict'

const {createJestConfig} = require('../../../test/config.cjs')

module.exports = createJestConfig({
displayName: require('./package.json').name,
testEnvironment: 'node',
})
4 changes: 4 additions & 0 deletions packages/@sanity/manifest/package.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import baseConfig from '@repo/package.config'
import {defineConfig} from '@sanity/pkg-utils'

export default defineConfig(baseConfig)
Loading
Loading