-
Notifications
You must be signed in to change notification settings - Fork 19
Extract typings-generator into separate package #168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iobuhov
wants to merge
4
commits into
mendix:master
Choose a base branch
from
iobuhov:extract-widget-typings-generator
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| function beforePacking(pkg) { | ||
| // Remove bundled dependency from published package | ||
| delete pkg.dependencies['@mendix/widget-typings-generator']; | ||
|
|
||
| console.log('✓ Removed bundled dependency from package.json'); | ||
|
|
||
| return pkg; | ||
| } | ||
|
|
||
| module.exports = { | ||
| hooks: { | ||
| beforePacking | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
packages/pluggable-widgets-tools/configs/rollup-plugin-widget-typing.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { nodeResolve } from '@rollup/plugin-node-resolve'; | ||
| import commonjs from '@rollup/plugin-commonjs'; | ||
|
|
||
| export default [ | ||
| { | ||
| treeshake: false, | ||
| input: 'node_modules/@mendix/widget-typings-generator/dist/index.js', | ||
| output: { | ||
| file: 'dist/widget-typings-generator.js', | ||
| format: 'cjs', | ||
| exports: 'named', | ||
| sourcemap: false | ||
| }, | ||
| plugins: [ | ||
| commonjs(), | ||
| nodeResolve({ | ||
| preferBuiltins: true | ||
| }), | ||
| ] | ||
| } | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| export * from "./common"; | ||
| export * from "./native/common"; | ||
| export * from "./web/common"; | ||
| export * from "./utils/typings"; | ||
| export * from "./utils"; | ||
| export * from "./utils/typings"; | ||
| export * from "./web/common"; | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| # @mendix/widget-typings-generator | ||
|
|
||
| TypeScript typings generator for Mendix Pluggable Widgets. | ||
|
|
||
| ## Overview | ||
|
|
||
| Generates TypeScript definition files (`.d.ts`) from Mendix widget XML schema files, providing type-safe development experience for widget creators. | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Basic Usage | ||
|
|
||
| ```typescript | ||
| import { transformPackage } from "@mendix/widget-typings-generator"; | ||
| import { readFile } from "fs/promises"; | ||
|
|
||
| // Read your widget's package.xml | ||
| const packageXml = await readFile("./src/{WidgetName}.xml", "utf-8"); | ||
|
|
||
| // Generate TypeScript definitions | ||
| await transformPackage(packageXml, "./src"); | ||
| ``` | ||
|
|
||
| This will: | ||
| 1. Parse `{WidgetName}.xml` to find all widget XML files | ||
| 2. Generate TypeScript interfaces for each widget | ||
| 3. Create `.d.ts` files in `../typings/{WidgetName}.xml/` directory | ||
|
|
||
| ### Generated Types | ||
|
|
||
| For a widget named `MyWidget`, it generates: | ||
| - **Web:** `MyWidgetContainerProps` (runtime) and `MyWidgetPreviewProps` (Studio Pro) | ||
| - **Native:** `MyWidgetProps<Style>` (runtime) and `MyWidgetPreviewProps` (Studio Pro) | ||
|
|
||
| ### Integration with Rollup | ||
|
|
||
| ```javascript | ||
| import { transformPackage } from "@mendix/widget-typings-generator"; | ||
| import { readFile } from "fs/promises"; | ||
|
|
||
| export function widgetTypingPlugin({ sourceDir }) { | ||
| return { | ||
| name: "widget-typing", | ||
| async buildStart() { | ||
| const packageXml = await readFile(`${sourceDir}/package.xml`, "utf-8"); | ||
| await transformPackage(packageXml, sourceDir); | ||
| } | ||
| }; | ||
| } | ||
| ``` | ||
|
|
||
| ## API | ||
|
|
||
| ### `transformPackage(content: string, basePath: string): Promise<void>` | ||
|
|
||
| Parses package.xml and generates TypeScript definitions for all widgets. | ||
|
|
||
| **Parameters:** | ||
| - `content` - XML content of package.xml file | ||
| - `basePath` - Base directory path for resolving widget XML files | ||
|
|
||
| **Returns:** Promise that resolves when all type files are generated | ||
|
|
||
| **Throws:** Error if XML parsing fails or widget structure is invalid | ||
|
|
||
| ## Supported Property Types | ||
|
|
||
| The generator supports all Mendix widget property types: | ||
| - Actions (single, list, with variables) | ||
| - Attributes (string, boolean, integer, decimal, datetime, etc.) | ||
| - Associations (reference, reference set) | ||
| - Datasources (with filtering, sorting) | ||
| - Expressions (with type validation) | ||
| - Objects (nested properties) | ||
| - Icons, Images, Files | ||
| - Enumerations, Selections | ||
| - Text templates, Widgets (containment) | ||
|
|
||
| ## License | ||
|
|
||
| Apache-2.0 © Mendix Technology BV 2026. All rights reserved. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { build } from 'esbuild'; | ||
| import { execSync } from 'child_process'; | ||
|
|
||
| await build({ | ||
| entryPoints: ['src/index.ts'], | ||
| bundle: true, | ||
| platform: 'node', | ||
| target: 'node20', | ||
| format: 'esm', | ||
| outfile: 'dist/index.js', | ||
| external: ['xml2js'], | ||
| sourcemap: false, | ||
| minify: false | ||
| }); | ||
|
|
||
| console.log('✓ Bundled with esbuild'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| export default { | ||
| preset: "ts-jest/presets/default-esm", | ||
| testEnvironment: "node", | ||
| testMatch: ["**/__tests__/**/*.spec.ts"], | ||
| extensionsToTreatAsEsm: [".ts"], | ||
| moduleNameMapper: { | ||
| "^(\\.{1,2}/.*)\\.js$": "$1" | ||
| }, | ||
| transform: { | ||
| "^.+\\.tsx?$": [ | ||
| "ts-jest", | ||
| { | ||
| useESM: true | ||
| } | ||
| ] | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| { | ||
| "name": "@mendix/widget-typings-generator", | ||
| "version": "1.0.0", | ||
| "description": "TypeScript typings generator for Mendix Pluggable Widgets", | ||
| "type": "module", | ||
| "engines": { | ||
| "node": ">=20" | ||
| }, | ||
| "main": "dist/index.js", | ||
| "types": "dist/index.d.ts", | ||
| "scripts": { | ||
| "test": "jest", | ||
| "build": "premove dist && node build.mjs" | ||
| }, | ||
| "files": [ | ||
| "dist", | ||
| "src" | ||
| ], | ||
| "dependencies": { | ||
| "xml2js": "^0.6.2" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/jest": "^30.0.0", | ||
| "@types/node": "^16.18.126", | ||
| "@types/xml2js": "^0.4.5", | ||
| "esbuild": "^0.24.2", | ||
| "jest": "^29.4.1", | ||
| "premove": "^4.0.0", | ||
| "ts-jest": "^29.2.5", | ||
| "typescript": "^5.6.3" | ||
| }, | ||
| "keywords": [ | ||
| "mendix", | ||
| "widgets", | ||
| "typescript", | ||
| "typings", | ||
| "generator", | ||
| "pluggable-widgets" | ||
| ], | ||
| "license": "Apache-2.0", | ||
| "copyright": "© Mendix Technology BV 2026. All rights reserved.", | ||
| "homepage": "https://github.com/mendix/widgets-tools/tree/master/packages/widget-typings-generator", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/mendix/widgets-tools/" | ||
| } | ||
| } |
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "ES2020", | ||
| "module": "ES2020", | ||
| "lib": ["ES2020"], | ||
| "moduleResolution": "node", | ||
| "outDir": "./dist", | ||
| "rootDir": "./src", | ||
| "declaration": true, | ||
| "declarationMap": true, | ||
| "sourceMap": true, | ||
| "strict": true, | ||
| "esModuleInterop": true, | ||
| "skipLibCheck": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "resolveJsonModule": true, | ||
| "allowSyntheticDefaultImports": true | ||
| }, | ||
| "include": ["src/**/*"], | ||
| "exclude": ["src/**/*.spec.ts", "src/**/__tests__"] | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello Ilia 👋 Why do we need the
nullhere?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDK, probably just to avoid ts error.