Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@repixelcorp/hyper-pwt",
"version": "0.3.1",
"version": "0.3.2",
"description": "A faster, more modern, superior alternative for Mendix PWT.",
"repository": {
"type": "git",
Expand Down
17 changes: 16 additions & 1 deletion src/commands/start/web/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import getViteUserConfiguration from '../../../utils/getViteUserConfiguration';
import { generateTypesFromFile } from '../../../type-generator';
import { mendixHotreloadReactPlugin } from '../../../configurations/vite/plugins/mendix-hotreload-react-plugin';
import { mendixPatchViteClientPlugin } from '../../../configurations/vite/plugins/mendix-patch-vite-client-plugin';
import typescript from 'rollup-plugin-typescript2';

const generateTyping = async () => {
const widgetName = await getWidgetName();
Expand Down Expand Up @@ -71,6 +72,20 @@ const startWebCommand = async () => {
},
},
plugins: [
typescript({
tsconfig: path.join(PROJECT_DIRECTORY, 'tsconfig.json'),
tsconfigOverride: {
compilerOptions: {
jsx: 'preserve',
preserveConstEnums: false,
isolatedModules: false,
declaration: false
}
},
include: ["src/**/*.ts", "src/**/*.tsx"],
exclude: ["node_modules/**", "src/**/*.d.ts"],
check: false,
}),
...resultViteConfig.plugins as PluginOption[],
mendixHotreloadReactPlugin(),
mendixPatchViteClientPlugin(),
Expand All @@ -84,7 +99,7 @@ const startWebCommand = async () => {
});
}
},
]
],
});

await viteServer.listen();
Expand Down
46 changes: 29 additions & 17 deletions src/type-generator/mendix-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ export function mapPropertyToMendixType(property: Property, platform: GenerateTa

function mapAttributeToMendixType(property: Property, imports: Set<string>): string {
const baseType = getAttributeBaseType(property.attributeTypes || []);


if (baseType.includes('Big')) {
imports.add('Big');
}

if (property.dataSource) {
imports.add('ListAttributeValue');

Expand All @@ -194,7 +198,11 @@ function mapAttributeToMendixType(property: Property, imports: Set<string>): str

function mapExpressionToMendixType(property: Property, imports: Set<string>): string {
const baseType = property.returnType ? mapReturnTypeToTS(property.returnType.type) : 'string';


if (baseType.includes('Big')) {
imports.add('Big');
}

if (property.dataSource) {
imports.add('ListExpressionValue');

Expand Down Expand Up @@ -268,7 +276,7 @@ function mapSelectionToMendixType(property: Property, imports: Set<string>): str

function getAttributeBaseType(attributeTypes: AttributeType[]): string {
if (attributeTypes.length === 0) return 'any';

const types = attributeTypes.map(type => {
switch (type) {
case 'String':
Expand All @@ -280,11 +288,11 @@ function getAttributeBaseType(attributeTypes: AttributeType[]): string {
case 'Integer':
case 'Long':
case 'AutoNumber':
case 'Float':
case 'Currency':
return 'number';
case 'Decimal':
return 'Big';
case 'Float':
return 'number';
case 'DateTime':
return 'Date';
case 'Binary':
Expand All @@ -305,10 +313,12 @@ function mapReturnTypeToTS(returnType: string): string {
case 'Boolean':
return 'boolean';
case 'Integer':
case 'Float':
return 'number';
case 'Long':
case 'AutoNumber':
case 'Decimal':
return 'Big';
case 'Float':
return 'number';
case 'DateTime':
return 'Date';
case 'String':
Expand All @@ -326,22 +336,24 @@ function generateObjectInterface(property: Property): string {

export function generateMendixImports(imports: string[]): string {
if (imports.length === 0) return '';

const mendixImports = imports.filter(imp =>
!['ReactNode'].includes(imp)
);


const reactImports = imports.filter(imp => imp === 'ReactNode');

const bigJsImports = imports.filter(imp => imp === 'Big');
const mendixImports = imports.filter(imp => imp !== 'ReactNode' && imp !== 'Big');

let output = '';

if (reactImports.length > 0) {
output += `import { ${reactImports.join(', ')} } from 'react';\n`;
}

if (mendixImports.length > 0) {
output += `import { ${mendixImports.join(', ')} } from 'mendix';\n`;
}


if (bigJsImports.length > 0) {
output += `import { ${bigJsImports.join(', ')} } from 'big.js';\n`;
}

return output;
}
}
98 changes: 51 additions & 47 deletions src/type-generator/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,57 @@ export function mapPropertyTypeToTS(property: Property, target?: GenerateTargetP
return mapping.type;
}

export function mapAttributeTypeToTS(attributeType: AttributeType): string {
switch (attributeType) {
case 'String':
case 'HashString':
case 'Enum':
return 'string';
case 'Boolean':
return 'boolean';
case 'Integer':
case 'Long':
case 'AutoNumber':
case 'Float':
case 'Currency':
case 'Decimal':
return 'number';
export function mapAttributeTypeToTS(attributeType: AttributeType): string {
switch (attributeType) {
case 'String':
case 'HashString':
case 'Enum':
return 'string';
case 'Boolean':
return 'boolean';
case 'Integer':
case 'Long':
case 'AutoNumber':
case 'Currency':
case 'Decimal':
return 'Big';
case 'Float':
return 'number';

case 'DateTime':
return 'Date | string';

case 'Binary':
return 'Blob | string';

default:
return 'any';
}
}

case 'DateTime':
return 'Date | string';

case 'Binary':
return 'Blob | string';

default:
return 'any';
}
}

export function mapReturnTypeToTS(returnType: string): string {
switch (returnType) {
case 'Void':
return 'void';
case 'Boolean':
return 'boolean';
case 'Integer':
case 'Float':
case 'Decimal':
return 'number';
case 'DateTime':
return 'Date | string';
case 'String':
return 'string';
case 'Object':
return 'object';
default:
return 'any';
}
}
export function mapReturnTypeToTS(returnType: string): string {
switch (returnType) {
case 'Void':
return 'void';
case 'Boolean':
return 'boolean';
case 'Integer':
case 'Long':
case 'AutoNumber':
case 'Decimal':
return 'Big';
case 'Float':
return 'number';
case 'DateTime':
return 'Date | string';
case 'String':
return 'string';
case 'Object':
return 'object';
default:
return 'any';
}
}

export function ensureArray<T>(value: T | T[] | undefined): T[] {
if (!value) return [];
Expand Down Expand Up @@ -85,4 +89,4 @@ export function formatDescription(description: string): string {
.map(line => line.trim())
.filter(line => line.length > 0)
.join(' ');
}
}
Loading