{"id":15707111,"url":"https://github.com/fabiankaegy/block-json-to-typescript-webpack-plugin","last_synced_at":"2025-05-12T19:27:13.296Z","repository":{"id":206929133,"uuid":"718014454","full_name":"fabiankaegy/block-json-to-typescript-webpack-plugin","owner":"fabiankaegy","description":"Automatically generate typings for block edit functions based on the content of the block.json file for any block.","archived":false,"fork":false,"pushed_at":"2023-11-14T22:23:31.000Z","size":147,"stargazers_count":10,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-15T06:03:53.246Z","etag":null,"topics":["gutenberg","webpack","wordpress"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/block-json-to-typescript-webpack-plugin","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fabiankaegy.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-13T07:31:50.000Z","updated_at":"2025-01-01T16:01:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"18210aab-0cca-4117-a62f-8ac585cbe610","html_url":"https://github.com/fabiankaegy/block-json-to-typescript-webpack-plugin","commit_stats":null,"previous_names":["fabiankaegy/block-json-to-typescript-webpack-plugin"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiankaegy%2Fblock-json-to-typescript-webpack-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiankaegy%2Fblock-json-to-typescript-webpack-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiankaegy%2Fblock-json-to-typescript-webpack-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiankaegy%2Fblock-json-to-typescript-webpack-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fabiankaegy","download_url":"https://codeload.github.com/fabiankaegy/block-json-to-typescript-webpack-plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253807496,"owners_count":21967374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gutenberg","webpack","wordpress"],"created_at":"2024-10-03T20:36:44.028Z","updated_at":"2025-05-12T19:27:13.270Z","avatar_url":"https://github.com/fabiankaegy.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Block.json to TypeScript - Webpack Plugin\n\nAutomatically generate typings for block edit functions based on the content of the `block.json` file for any block.\n\n## Usage\n\n```js\n// webpack.config.js\nconst path = require('path');\nconst BlockJsonToTypescriptWebpackPlugin = require('block-json-to-typescript-webpack-plugin');\n\nmodule.exports = {\n plugins: [\n  new BlockJsonToTypescriptWebpackPlugin({\n   sourceDirectory: path.resolve(__dirname, 'includes/blocks/'),\n   distDirectory: path.resolve(__dirname, 'dist/blocks/'),\n  }),\n ]\n}\n```\n\nWith this added any `block.json` file located in the source folder will get an additional `types.d.ts` file added to its dist location with interfaces for the block attributes, context, and general properties passed into the blocks edit function.\n\n```json\n{\n  \"apiVersion\": 3,\n  \"name\": \"namespace/example\",\n  \"title\": \"Example Block\",\n  \"attributes\": {\n    \"title\": {\n      \"type\": \"string\"\n    }\n  },\n  \"supports\": {\n    \"align\": [\n      \"wide\",\n      \"full\"\n    ],\n  },\n  \"usesContext\": [\n    \"postType\",\n    \"postId\"\n  ],\n}\n```\n\nturns to:\n\n```ts\ninterface NamespaceExampleAttributes {\n    readonly title: string;\n    readonly style?: Record\u003cstring, any\u003e;\n    readonly align?: string;\n}\n\ninterface NamespaceExampleContext {\n    readonly postType: string;\n    readonly postId: number;\n}\n\ninterface NamespaceExampleProps {\n    readonly name: string;\n    readonly isSelected: boolean;\n    readonly isSelectionEnabled: boolean;\n    readonly clientId: string;\n    readonly attributes: NamespaceExampleAttributes;\n    readonly context: NamespaceExampleContext;\n    setAttributes(attributes: Partial\u003cNamespaceExampleAttributes\u003e): void;\n    insertBlocksAfter(block: any): void;\n    mergeBlocks(blocks: Array\u003cany\u003e): void;\n    onRemove(callback: any): void;\n    onReplace(callback: any): void;\n    toggleSelection(): void;\n    [key: string]: any;\n}\n```\n\nIn order for these types to get picked up correctly, the `dist/blocks/` folder needs to get added to the `typeRoots` in the `tsconfig`.\n\n```json\n{\n  \"compilerOptions\": {\n    \"typeRoots\": [\n      \"node_modules/@types\",\n      \"dist/blocks\"\n    ]\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabiankaegy%2Fblock-json-to-typescript-webpack-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffabiankaegy%2Fblock-json-to-typescript-webpack-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabiankaegy%2Fblock-json-to-typescript-webpack-plugin/lists"}