@mgrdevport/simple-strapi-types
v0.0.6
Published
Simple typescript interface generator for Strapi 4 models
Downloads
56
Maintainers
Readme
simple-strapi-types
This is a stripped down version of @oak-digital/types-4-strapi-2
types-4-strapi-2 is a rewrite of francescolorenzetti/types-4-strapi written in TypeScript, with the goal of being much easier to extend and maintain.
Requirements
- Node
>=v16
Getting started
Install the script for your project:
# NPM
npm install --save-dev @mgrdevport/simple-strapi-types
# YARN
yarn add -D @mgrdevport/simple-strapi-types
Then set up a script in your package.json
// package.json
{
"scripts": {
"types": "st4s"
}
}
In some cases it is desirable to change the output directory which is ./types
by default.
This can be done with the --out
flag like in the following example.
// package.json
{
"scripts": {
"types": "st4s --out ../frontend/src/lib/types"
}
}
Features
- Generate TypeScript interfaces for all your api content-types and components
- Generate TypeScript interfaces for builtin types such as
Media
andMediaFormat
- Select input and output directory
- Prettier formatting and ability to use your own
.prettierrc
. - Generate types for plugins such as url-alias
- Population by generics
Planned features
- Support for localization
Flags
| Flag | Description | Default |
|-----------------------------|--------------------------------------------------------------------------------------|-------------|
| -i, --in | The src directory for strapi | ./src
|
| -o, --out | The output directory to output the types to | ./types
|
| --prefix | A prefix for all generated interfaces | I
|
| --component-prefix | A prefix for components | none |
| -D, --delete-old | CAUTION: This option is equivalent to running rm -rf
on the output directory first | false
|
| --prettier | The prettier config file to use for formatting TypeScript interfaces | none |
| --plugins <plugins...> | The plugins to use | none |
Using plugins
It is possible to generate types for plugins, for example url-alias gives a new field on your content types, so that plugin will automatically add that field to your types. You can see a list of builtin plugins below. Some plugins might not be fully featured.
It will be possible in the future to add your own plugins in later versions.
List of supported plugins
- url-alias
example of using plugins
$ st4s --plugins url-alias
Population
This stripped down version doesn't deal with population, just use the interfaces as they fall out of the generator.
Building
To build this project, use the following command
npm run build
Publishing
npm version # major | minor | patch
npm run build
npm publish