schema init
Fetches the current schema of a Storyblok space and writes it as TypeScript files using @storyblok/schema helpers. schema init is a one-time setup step for adopting an existing space in code.
The command generates the following files:
- One file per block, in subdirectories that follow the component group hierarchy
- One file per datasource
- One placeholder file per custom field plugin
- A
folders.tsfile for all component groups - A
schema.tsfile in the root that combines everything into a single exportedschemaobject.
.storyblok/└── schema/ ├── blocks/ │ ├── <block-name>.ts │ └── <group-slug>/ │ └── <block-name>.ts ├── datasources/ │ └── <datasource-slug>.ts ├── field-plugins/ │ └── <field-plugin-slug>.ts ├── folders.ts └── schema.tsThe command also registers the field plugins your blocks use. It imports official field plugins from @storyblok/schema and writes a placeholder file to field-plugins/ for every other field plugin. A placeholder accepts any value. To type the field plugin’s value, replace the placeholder’s value with a schema that implements Standard Schema.
After initialization, treat the local files as the source of truth and use schema push for further changes.
Prerequisites
Section titled “Prerequisites”The @storyblok/schema package must be installed in the target project: npm install @storyblok/schema.
storyblok schema init [flags]| Flag | Type | Description |
|---|---|---|
--space, -s |
integer | Required. The ID of the Storyblok space to read the schema from. |
--out-dir |
string | Optional. Output directory for generated files. Defaults to .storyblok/schema. |
Examples
Section titled “Examples”The following examples assume you defined a space in the configuration file.
# Bootstrap a local TypeScript schema from a spacestoryblok schema init
# Bootstrap into a custom output directorystoryblok schema init --out-dir src/schemaWas this page helpful?
This site uses reCAPTCHA and Google's Privacy Policy (opens in a new window).Terms of Service (opens in a new window) apply.
- Need help?Contact support (opens in a new window)
- Something isn’t right?Check system status (opens in a new window)
Get in touch with the Storyblok community