Content-type-to-typescript
This is a tool to convert Contentful Models (Content Types) to the TS Definitions. Provides a way to automate TS Definitions generation. Could be used as a library or cli tool.
Installation
$ npm install content-type-to-typescript --save
Usage
- As CLI
$ ./node_modules/.bin/content-type-to-typescript --access-token <token> --space <space> --output <filepath>
This command will generate TS Definition file. Could also be used as a npm script.
package.json:
"scripts":
Usage:
npm run sync-contentful-types
- As a library using JSON preview from Web App
Copy JSON Preview from Contentful Web App
; const category = name: 'Category' description: null fields: id: 'title' name: 'Title' type: 'Text' required: true omitted: false const typings = await ; console;
compileFromContentTypes contentTypes: Array<Partial<ContentType>>, options?: Partial<Options>: Promise<string>
ContentType
The structure of the Content Type is described here Contentful data model.
Options
Property | Type | Required? | Description |
---|---|---|---|
bannerComment | String | A comment at the top of the response |
Example
Input:
Output:
Built with
License
MIT License - fork, modify and use however you want.