0

Is there a way to hook into the Sanity Studio initialise step? Or perhaps start the Studio from a js module so I can wrap it in some logic?

My motive is, in development it can be confusing which Project Instance, Dataset or Project name I'm on. When running npm start I get the following output

⠹ Compiling...webpack built d689d86d2ed85bc7df76 in 3970ms
✔ Compiling...
Content Studio successfully compiled! Go to http://localhost:3333

But I'd like to add an additional line to this to dump

ProjectName: $Name ProjectId: $ID Dataset: $Dataset 

There is a .env file but these values can also be overridden by config in sanity.json.

Logging these values for a sanity check would be very handy in dev.

Lex
  • 4,749
  • 3
  • 45
  • 66

1 Answers1

0

Ok so there is a command on the cli to execute a script with the Sanity context. sanity exec the page here mentions it but doesn't mention how to consume it in a script.

Making this info.ts file

import client from 'part:@sanity/base/client'

console.log(client.config())

Which imports the sanity part client. And from here we can dump the config to console.

Adding this to the package config enables npm run info

"info": "sanity exec info.ts"

As it's initialising Sanity it's a little slow to include in a start command npm run info && npm run start because this initialises Sanity twice. But handy to run once off to check, including this in the cli would be better.

Lex
  • 4,749
  • 3
  • 45
  • 66