Espen Hovlandsdal
Open-sourceror @ Sanity.io
A script to validate that your schema is free of errors and warnings
This schema is for an older version of Sanity Studio (v2), which is deprecated.
Learn how to migrate to the new Studio v3 →// Run this file like this:
// npx sanity exec schema-check.js --mock-browser-env -- --strict
import schema from 'part:@sanity/base/schema'
let hasErrors = false
let hasWarnings = false
for (const item of schema._validation) {
const path = item.path.map(segment => segment.name).join(' → ')
console.log(`${path}:`)
for (const problem of item.problems) {
if (problem.severity === 'error') {
hasErrors = true
console.error(` - [error] ${problem.message}`)
} else if (problem.severity === 'warning') {
hasWarnings = true
console.warn(` - [warning] ${problem.message}`)
}
}
console.warn('')
}
if (hasErrors) {
process.exit(1)
}
if (hasWarnings && process.argv.includes('--strict')) {
process.exit(2)
}
This script is useful to run before deploying a Studio, for example as part of a build pipeline, where you can stop a deployment if there are errors or optionally warnings in the schema.
npx sanity exec schema-check.js --mock-browser-env -- --strict && do-your-deploy
Open-sourceror @ Sanity.io
I find solutions
🚫 MyFile / ✅ MyFile.pdf
Go to Add extensions to asset original filenamesDrop this into your Studio to let editors know when there's a more recent version of your Studio available, making sure they have the latest fields and validations.
Go to Auto-reload Studio when changes are deployedShow different document lists based on a user's role
Go to Desk structure with custom rolesHow to group documents by their publishedAt year using the Structure Builder API
Go to Group documents by year