![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
@prezly/contentful-typescript-codegen
Advanced tools
Generate TypeScript types from your Contentful environment.
Generate typings from your Contentful environment.
At Prezly, we use this in our marketing site to increase developer confidence and productivity, ensure that breaking changes to our Content Types don't cause an outage, and because it's neat.
npm i -D @prezly/contentful-typescript-codegen
Then, add the following to your package.json
:
{
// ...
"scripts": {
"contentful-typescript-codegen": "contentful-typescript-codegen --output @types/generated/contentful.d.ts"
}
}
Feel free to change the output path to whatever you like.
Next, the codegen will expect you to have created a file called getContentfulEnvironment.js
in the
root of your project directory, and it should export a promise that resolves with your Contentful
environment.
The reason for this is that you can do whatever you like to set up your Contentful Management Client. Here's an example:
const contentfulManagement = require("contentful-management")
module.exports = function() {
const contentfulClient = contentfulManagement.createClient({
accessToken: process.env.CONTENTFUL_MANAGEMENT_API_ACCESS_TOKEN,
})
return contentfulClient
.getSpace(process.env.CONTENTFUL_SPACE_ID)
.then(space => space.getEnvironment(process.env.CONTENTFUL_ENVIRONMENT))
}
Optionally, you can add a file called getContentfulFieldOverrides.js
in the root of your project, which should export two functions:
getImports
which should return an array of import declarations (as strings) required for your overriden types.getOverridenContentTypes
that returns an object of OverridenContentTypes
type (see example), which will indicate which fields for which content types should be overriden with the type name you provided.Example:
function getImports() {
return [
"import { SomeLibraryType } from '@some-library';"
]
}
function getOverridenContentTypes() {
return {
'myContentTypeId': {
'overridenField': 'SomeLibraryType'
}
}
}
module.exports = {
getImports,
getOverridenContentTypes,
}
Usage
$ contentful-typescript-codegen --output <file> <options>
Options
--output, -o Where to write to
--poll, -p Continuously refresh types
--interval N, -i The interval in seconds at which to poll (defaults to 15)
Here's an idea of what the output will look like for a Content Type:
interface BlogPostFields {
/** Title */
title: string
/** Body */
body: Document
/** Author link */
author: Author
/** Image */
image: Asset
/** Published? */
published: boolean | null
/** Tags */
tags: string[]
/** Blog CTA variant */
ctaVariant: "new-cta" | "old-cta"
}
/**
* A blog post.
*/
export interface BlogPost extends Entry<BlogPostFields> {}
You can see that a few things are handled for you:
author
, are resolved to other TypeScript interfaces.| null
appended to their type.FAQs
Generate TypeScript types from your Contentful environment.
The npm package @prezly/contentful-typescript-codegen receives a total of 1 weekly downloads. As such, @prezly/contentful-typescript-codegen popularity was classified as not popular.
We found that @prezly/contentful-typescript-codegen demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.