breeze-entity-generator
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -13,2 +13,6 @@ // tslint:disable:no-trailing-whitespace | ||
/// <module-code> Place module level code between <module-code> tags | ||
{{{modulecode}}} | ||
/// </module-code> | ||
export class {{shortName}} {{#baseClass}}extends {{.}} {{/baseClass}} { | ||
@@ -22,5 +26,5 @@ | ||
{{#properties}} | ||
{{name}}: {{dataType}}; | ||
{{name}}{{#if isNullable}}?{{/if}}: {{dataType}}; | ||
{{/properties}} | ||
} | ||
{ | ||
"name": "breeze-entity-generator", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Generate TypeScript modules for entities from Breeze metadata", | ||
@@ -12,15 +12,23 @@ "repository": { | ||
}, | ||
"keywords": [ "breeze", "entity", "generator", "breeze-client", "typescript", "metadata", "angular"], | ||
"keywords": [ | ||
"breeze", | ||
"entity", | ||
"generator", | ||
"breeze-client", | ||
"typescript", | ||
"metadata", | ||
"angular" | ||
], | ||
"author": "IdeaBlade, Inc.", | ||
"license": "MIT", | ||
"dependencies": { | ||
"handlebars": "^4.1.2", | ||
"lodash": "^4.17.15" | ||
"handlebars": ">=4.1.2", | ||
"lodash": "^4.17.21" | ||
}, | ||
"devDependencies": { | ||
"breeze-client": ">=2.0.0-alpha.13" | ||
"breeze-client": ">=2.0.0" | ||
}, | ||
"peerDependencies": { | ||
"breeze-client": ">=2.0.0-alpha.13" | ||
"breeze-client": ">=2.0.0" | ||
} | ||
} |
@@ -56,12 +56,6 @@ # Breeze Entity Generator | ||
### Custom code and custom references | ||
### Custom code and imports | ||
The typescript generator preserves two special sections for each class when regenerating the code. Those sections are `<code-reference>` and `<code>`. The `<code-reference>` section is for custom references and the `<code>` section is for custom methods etc. Following is an example of a class after it got generated showing the two sections. Everything between the opening and closing tags is preserved. | ||
The typescript generator preserves three special sections for each class when regenerating the code. Those sections are `<code-import>`, `<code>` and `<module-code>`. The `<code-import>` section is for custom imports, the `<code>` section is for custom methods, etc and `<module-code>` section is for module level code eg functions. Following is an example of a class after it got generated showing the three sections. Everything between the opening and closing tags is preserved. | ||
`/// <reference path="Order.ts" />` | ||
`/// <code-reference> Place custom references between code-reference tags` | ||
`/// </code-reference>` | ||
``` | ||
@@ -75,2 +69,6 @@ import { EntityBase } from './EntityBase'; | ||
/// <module-code> Place module level code between <module-code> tags | ||
/// </module-code> | ||
export class InternationalOrder extends EntityBase { | ||
@@ -77,0 +75,0 @@ |
var fs = require('fs'); | ||
var path = require('path'); | ||
var backing = require('breeze-client/bundles/breeze-client-adapter-model-library-backing-store.umd'); | ||
var breeze = require('breeze-client/bundles/breeze-client.umd'); | ||
var backing; // breeze-client/adapter-model-library-backing-store | ||
var breeze; // breeze-client | ||
var handlebars = require('handlebars'); | ||
@@ -22,3 +22,25 @@ var _ = require('lodash'); | ||
*/ | ||
function generate(config) { | ||
async function generate(config) { | ||
try { | ||
// try importing as modules; else use require | ||
backing = await import('breeze-client/adapter-model-library-backing-store'); | ||
breeze = await import('breeze-client'); | ||
} catch { | ||
backing = require('breeze-client/adapter-model-library-backing-store'); | ||
breeze = require('breeze-client'); | ||
} | ||
generateCore(config); | ||
} | ||
/** Generate the TypeScript entity files from Breeze metadata | ||
* @param {Object} config | ||
* @param {string} config.inputFileName: Breeze metadata file | ||
* @param {string} config.outputFolder: Where to write TypeScript files (defaults to current folder) | ||
* @param {string} config.sourceFilesFolder: Location of existing TS entity files (defaults to outputFolder) | ||
* @param {string} config.baseClassName: Base class for TS entities | ||
* @param {boolean} config.camelCase: Whether to use camelCase for TS property names | ||
* @param {boolean} config.kebabCaseFileNames: Whether to kebab-case-file-names.ts (otherwise PascalCaseFileNames.ts) | ||
* @param {boolean} config.useEnumTypes: Whether to output Enums.ts (if the input metadata contains an "enumTypes" section) | ||
*/ | ||
function generateCore(config) { | ||
console.log(config); | ||
@@ -154,3 +176,3 @@ if (!config.inputFileName || !fs.existsSync(config.inputFileName)) { | ||
entityType.properties = properties.map(function (property) { | ||
return { name: property.name, dataType: convertDataType(metadataStore, property, config.useEnumTypes) }; | ||
return { name: property.name, dataType: convertDataType(metadataStore, property, config.useEnumTypes), isNullable: property.isNullable}; | ||
}); | ||
@@ -188,2 +210,3 @@ if (entityType.baseEntityType) { | ||
entityType.codeimport = extractSection(ts, 'code-import', entityType.shortName); | ||
entityType.modulecode = extractSection(ts, 'module-code', entityType.shortName); | ||
// entityType.codereference = extractSection(ts, 'code-reference'); | ||
@@ -190,0 +213,0 @@ entityType.code = extractSection(ts, 'code', entityType.shortName); |
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
29084
366
103
Updatedhandlebars@>=4.1.2
Updatedlodash@^4.17.21