breeze-entity-generator
Advanced tools
Comparing version 1.3.4 to 1.4.0
@@ -24,6 +24,6 @@ // tslint:disable:no-trailing-whitespace | ||
// Generated code. Do not place code below this line. | ||
{{#properties}} | ||
{{name}}{{#if isNullable}}?{{else}}!{{/if}}: {{dataType}}; | ||
{{/properties}} | ||
{{#properties}}{{#if comment}} /** {{comment}} */ | ||
{{/if}} {{name}}{{#if isNullable}}?{{else}}!{{/if}}: {{dataType}}; | ||
{{/properties}} | ||
} | ||
{ | ||
"name": "breeze-entity-generator", | ||
"version": "1.3.4", | ||
"version": "1.4.0", | ||
"description": "Generate TypeScript modules for entities from Breeze metadata", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -21,3 +21,4 @@ # Breeze Entity Generator | ||
codePrefix: 'MyProject', | ||
useEnumTypes: true | ||
useEnumTypes: true, | ||
propertyComments: true | ||
}); | ||
@@ -56,2 +57,10 @@ ``` | ||
`propertyComments`: Optionally include metadata comments on data properties, indicating original datatype and key relationships, e.g.: | ||
```ts | ||
/** String(50) */ | ||
productName!: string; | ||
/** Int32 FK supplier */ | ||
supplierId!: number; | ||
``` | ||
## Description | ||
@@ -122,1 +131,2 @@ At the core of the typescript generator sits [handlebars](http://handlebarsjs.com/) which is responsible for generating the actual TypeScript source code. The output that handlebars generate can be customized by modifying the templates. | ||
1.3.4 - Fix class name of RegistrationHelper; Fix include path to base complex type | ||
1.4.0 - Add property comments indicating type, maxlength, key, and fk |
@@ -17,3 +17,4 @@ const tsGen = require('../tsgen-core'); | ||
codePrefix: 'Test', | ||
useEnumTypes: true | ||
useEnumTypes: true, | ||
propertyComments: true, | ||
}); |
@@ -22,2 +22,3 @@ var fs = require('fs'); | ||
* @param {boolean} config.useEnumTypes: Whether to output Enums.ts (if the input metadata contains an "enumTypes" section) | ||
* @param {boolean} config.propertyComments: Whether to add comments to each data property | ||
*/ | ||
@@ -46,2 +47,3 @@ async function generate(config) { | ||
* @param {boolean} config.useEnumTypes: Whether to output Enums.ts (if the input metadata contains an "enumTypes" section) | ||
* @param {boolean} config.propertyComments: Whether to add comments to each data property | ||
*/ | ||
@@ -67,2 +69,3 @@ function generateCore(config) { | ||
console.log('useEnumTypes: ' + !!config.useEnumTypes); | ||
console.log('propertyComments: ' + !!config.propertyComments); | ||
@@ -185,4 +188,6 @@ handlebars.registerHelper('camelCase', function(str) { | ||
entityType.properties = properties.map(function (property) { | ||
return { name: property.name, dataType: convertDataType(metadataStore, property, config.useEnumTypes), isNullable: property.isNullable}; | ||
return { name: property.name, dataType: convertDataType(metadataStore, property, config.useEnumTypes), isNullable: property.isNullable, | ||
comment: config.propertyComments && getPropertyComment(property) }; | ||
}); | ||
if (entityType.baseEntityType) { | ||
@@ -301,2 +306,26 @@ // entityType.baseClass = entityType.baseEntityType.namespace + '.' + entityType.baseEntityType.shortName; | ||
/** Get a data type comment for the given property */ | ||
function getPropertyComment(property) { | ||
if (property.isDataProperty) { | ||
var com = property.enumType ? 'Enum' : property.isComplexProperty ? 'Complex' : property.dataType.name; | ||
if (property.maxLength) { | ||
com += '(' + property.maxLength + ')'; | ||
} | ||
if (property.isPartOfKey) { | ||
com += ' key'; | ||
} | ||
if (property.relatedNavigationProperty) { | ||
com += ' FK ' + property.relatedNavigationProperty.name; | ||
} | ||
return com; | ||
} else if (property.isNavigationProperty) { | ||
if (property.foreignKeyNames.length && property.foreignKeyNames.length) { | ||
return 'FK ' + property.foreignKeyNames.join(','); | ||
} else { | ||
return 'Inv FK ' + property.invForeignKeyNames.join(','); | ||
} | ||
} | ||
} | ||
/** Get the EntityType of the given name */ | ||
@@ -303,0 +332,0 @@ function getEntityType(metadataStore, name) { |
41413
983
129