Various Shopify codegen tools
npm install shopify-codegenGenerate TypeScript types from Shopify Liquid section schemas.
``bash`
yarn add -D shopify-codegenor
npm install -D shopify-codegen
`bash`
shopify-codegen [sections-dir]
If sections-dir is not provided, it defaults to ./sections.
Example:
`bash`
shopify-codegen ./sections > src/types/shopify/liquid.types.ts
`typescript
import { generateTypes } from 'shopify-codegen'
const types = await generateTypes({
sectionsDir: './sections'
})
console.log(types)
`
The tool scans all .liquid files in the specified directory, extracts JSON schemas from {% schema %} blocks, and generates TypeScript interfaces for:
- Section types: Based on filename (e.g., video.liquid → Video)VideoSlide
- Block types: Prefixed with section name to avoid conflicts (e.g., )
- Settings types: With proper optionality based on defaults
- @app blocks are typed as generic BlockSettings since their structure is app-definedname
- Interface names are derived from filenames to avoid duplicates
- The property in interfaces preserves the original schema name (can be translation keys like t:sections.footer.name)
Given a sections/video.liquid file with a schema, the tool generates:
`typescript``
export interface Video extends ShopifySection {
name: 'Video'
tag: 'section'
settings: {
cover_text: string
video_url?: { id: string; type: string }
// ...
}
blocks: Block[]
}