Skip to content

Commit

Permalink
Feat/studio manifests cont (#7403)
Browse files Browse the repository at this point in the history
* feat(sanity): allow `extractSchema` worker to emit schemas for all workspaces

* feat(sanity): include workspace and dataset names when extracting schema

* feat(cli): add `manifest` commands

* feat(manifest): add `@sanity/manifest` package

* refactor(sanity): use manifest schemas from `@sanity/manifest`

* chore: format files

* feat(schema): include `title`, `description`, and `deprecated` attributes when extracting schema

* feat(sanity): add `direct` schema format to schema extractor

* Revert "feat(schema): include `title`, `description`, and `deprecated` attributes when extracting schema"

This reverts commit 60cb576.

* feat(sanity): export `ConcreteRuleClass` class

* feat(sanity): include validation rules in manifests

* refactor(sanity): move manifest extraction code

* feat(sanity): extract manifest during build

* feat(sanity): adopt `.studioschema.json` filename suffix for manifest schemas

* refactor(sanity): rename manifest extraction functions (remove plural)

* fix(sanity): remove redundant success message

* fix(sanity): stop build spinner before starting manifest extraction

* feat(sanity): add `unstable_extractManifestOnBuild` CLI config option

* feat(test-studio): enable `unstable_extractManifestOnBuild`

* fix(sanity): switch to node crypto for node 18 compatibility

* feat(cli): add `unstable_staticAssetsPath` CLI configuration option

* chore(cli): refine `unstable_extractManifestOnBuild` CLI configuration option description

* feat(sanity): remove extraneous `types` wrapper from manifests

* debug(test-studio): remove Mux plugin to unblock typegen

* feat(embedded-studio): enable manifest extraction

* feat(starter-next-studio): enable manifest extraction

* wip

* feat(sanity): normalize type constraints in manifest validation

* wip

* chore: merge fix

* feat: serialize userland properties and validation rules in manifest

* fix: remove @sanity/manifest package

* chore: cleanup

* fix: serialize fieldsets

* fix: omit default titles on fields and array-members

* fix: ensure manifest schema is restoreble and supports cross dataset references

* chore: mergefix

* fix: serialization of type aliases no longer inlines fields and of props

* fix: removes double dot in filename

* feat: manifest command

* chore: tweaks

* chore: revert redundant changes

* fix: adds manifest group to CLI

* chore: wording change

* fix: adds a 2-minute timeout to manifest extract

* fix: ensures error code when mainfest extract fails and changes failed spinner message to info

* chore: use *ENABLED instead of *DISABLED for constant

* chore: defensive optional chaining for option extraction

* chore: reworded EXTRACT_FAILURE_MESSAGE

---------

Co-authored-by: Ash <[email protected]>
  • Loading branch information
snorrees and juice49 authored Oct 3, 2024
1 parent e7e7185 commit 1f57db4
Show file tree
Hide file tree
Showing 26 changed files with 2,797 additions and 96 deletions.
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.59.0",
"private": true,
"scripts": {
"build": "tsc && vite build",
"build": "tsc && vite build && sanity manifest extract",
"dev": "vite",
"preview": "vite preview"
},
Expand Down
8 changes: 8 additions & 0 deletions dev/embedded-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',
},
})
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
3 changes: 3 additions & 0 deletions dev/starter-next-studio/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.next

public/static/*.create-schema.json
public/static/create-manifest.json
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 --path public/static && 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',
},
],
},
],
},
})
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 @@ -18,6 +18,7 @@ const coreCommands = [
'graphql',
'hook',
'migration',
'manifest',
'preview',
'schema',
'start',
Expand Down
5 changes: 5 additions & 0 deletions packages/sanity/package.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export default defineConfig({
require: './lib/_internal/cli/threads/extractSchema.js',
runtime: 'node',
},
{
source: './src/_internal/cli/threads/extractManifest.ts',
require: './lib/_internal/cli/threads/extractManifest.js',
runtime: 'node',
},
],

extract: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export default async function buildSanityStudio(

spin.text = `Build Sanity Studio (${buildDuration.toFixed()}ms)`
spin.succeed()

trace.complete()
if (flags.stats) {
output.print('\nLargest module files:')
Expand Down
22 changes: 16 additions & 6 deletions packages/sanity/src/_internal/cli/actions/deploy/deployAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import tar from 'tar-fs'

import {shouldAutoUpdate} from '../../util/shouldAutoUpdate'
import buildSanityStudio, {type BuildSanityStudioCommandFlags} from '../build/buildAction'
import {extractManifestSafe} from '../manifest/extractManifestAction'
import {
checkDir,
createDeployment,
Expand Down Expand Up @@ -101,16 +102,25 @@ export default async function deployStudioAction(
// Always build the project, unless --no-build is passed
const shouldBuild = flags.build
if (shouldBuild) {
const buildArgs = [customSourceDir].filter(Boolean)
const {didCompile} = await buildSanityStudio(
{...args, extOptions: flags, argsWithoutOptions: buildArgs},
context,
{basePath: '/'},
)
const buildArgs = {
...args,
extOptions: flags,
argsWithoutOptions: [customSourceDir].filter(Boolean),
}
const {didCompile} = await buildSanityStudio(buildArgs, context, {basePath: '/'})

if (!didCompile) {
return
}

await extractManifestSafe(
{
...buildArgs,
extOptions: {},
extraArguments: [],
},
context,
)
}

// Ensure that the directory exists, is a directory and seems to have valid content
Expand Down
Loading

0 comments on commit 1f57db4

Please sign in to comment.