Merge pull request #116 from KevinGuancheDarias/master

Allow to define property visibility, by using --pv
This commit is contained in:
Kononnable 2018-11-01 19:17:33 +01:00 committed by GitHub
commit 6623c93e09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 871 deletions

View File

@ -1,5 +1,8 @@
# Changelog
## 0.2.24
* Allow to define property visibility, by using --pv
## 0.2.23
* added column type to generated `@PrimaryGeneratedColumn` decorator

861
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,8 @@
"test": "istanbul cover ./node_modules/mocha/bin/_mocha dist/test/**/*.test.js -- -R spec",
"posttest": "remap-istanbul -i ./coverage/coverage.json -o ./coverage/coverage-remapped.json && codecov --file=./coverage/coverage-remapped.json ",
"clean": "rimraf dist coverage output",
"prettier": "prettier --write ./src/*.ts ./src/**/*.ts"
"prettier": "prettier --write ./src/*.ts ./src/**/*.ts",
"prepack": "npm run compile"
},
"repository": {
"type": "git",

View File

@ -151,6 +151,13 @@ export class Engine {
}
return retStr;
});
Handlebars.registerHelper(
"printPropertyVisibility",
() =>
this.Options.propertyVisibility !== "none"
? this.Options.propertyVisibility + " "
: ""
);
Handlebars.registerHelper("toPropertyName", str => {
let retStr = "";
switch (this.Options.convertCaseProperty) {
@ -276,6 +283,7 @@ export interface EngineOptions {
convertCaseFile: "pascal" | "param" | "camel" | "none";
convertCaseEntity: "pascal" | "camel" | "none";
convertCaseProperty: "pascal" | "camel" | "none";
propertyVisibility: "public" | "protected" | "private" | "none";
lazy: boolean;
constructor: boolean;
namingStrategy: AbstractNamingStrategy;

View File

@ -23,12 +23,12 @@ import {Index,Entity, PrimaryColumn, PrimaryGeneratedColumn, Column, OneToOne, O
array:{{is_array}},{{/is_array}}
name:"{{sqlName}}"
})
{{toPropertyName tsName}}:{{ts_type}}{{#is_nullable}} | null{{/is_nullable}};
{{printPropertyVisibility}}{{toPropertyName tsName}}:{{ts_type}}{{#is_nullable}} | null{{/is_nullable}};
{{/relations}}{{#relations}}
@{{relationType}}(type=>{{toEntityName relatedTable}}, {{toEntityName relatedTable}}=>{{toEntityName relatedTable}}.{{#if isOwner}}{{toPropertyName ownerColumn}},{ {{#../isPrimary}}primary:true,{{/../isPrimary}}{{^../is_nullable}} nullable:false,{{/../is_nullable}}{{#actionOnDelete}}onDelete: '{{.}}',{{/actionOnDelete}}{{#actionOnUpdate}}onUpdate: '{{.}}'{{/actionOnUpdate}} }{{else}}{{toPropertyName relatedColumn}}{{#if (or actionOnDelete actionOnUpdate ) }}{{#actionOnDelete}},{ onDelete: '{{.}}' ,{{/actionOnDelete}}{{#actionOnUpdate}}onUpdate: '{{.}}'{{/actionOnUpdate}} }{{/if}}{{/if}}){{#isOwner}}
{{#if isManyToMany}}@JoinTable(){{else}}@JoinColumn({ name:'{{ ../sqlName}}'}){{/if}}{{/isOwner}}
{{#if (or isOneToMany isManyToMany)}}{{toPropertyName ../tsName}}:{{toLazy (concat (toEntityName relatedTable) "[]")}};
{{else}}{{toPropertyName ../tsName}}:{{toLazy (concat (toEntityName relatedTable) ' | null')}};
{{#if (or isOneToMany isManyToMany)}}{{printPropertyVisibility}} {{toPropertyName ../tsName}}:{{toLazy (concat (toEntityName relatedTable) "[]")}};
{{else}}{{printPropertyVisibility}} {{toPropertyName ../tsName}}:{{toLazy (concat (toEntityName relatedTable) ' | null')}};
{{/if}}
{{#if relationIdField }}

View File

@ -81,6 +81,12 @@ var argv = Yargs.usage(
choices: ["pascal", "camel", "none"],
default: "none"
})
.option("pv", {
alias: "property-visibility",
describe: "Defines which visibility should have the generated property",
choices: ["public", "protected", "private", "none"],
default: "none"
})
.option("lazy", {
describe: "Generate lazy relations",
boolean: true,
@ -162,6 +168,7 @@ let engine = new Engine(driver, {
convertCaseFile: argv.cf,
convertCaseEntity: argv.ce,
convertCaseProperty: argv.cp,
propertyVisibility: argv.pv,
lazy: argv.lazy,
constructor: argv.generateConstructor,
relationIds: argv.relationIds,

View File

@ -65,10 +65,11 @@ export async function createMSSQLModels(filesOrgPath: string, resultsPath: strin
convertCaseEntity: 'none',
convertCaseFile: 'none',
convertCaseProperty: 'none',
propertyVisibility: 'none',
lazy: false,
constructor: false,
namingStrategy: namingStrategy,
relationIds:false
relationIds: false
});
conn = await createConnection(connOpt)
@ -133,8 +134,9 @@ export async function createPostgresModels(filesOrgPath: string, resultsPath: st
convertCaseEntity: 'none',
convertCaseFile: 'none',
convertCaseProperty: 'none',
propertyVisibility: 'none',
lazy: false,
constructor:false,
constructor: false,
namingStrategy: namingStrategy,
relationIds: false
});
@ -193,8 +195,9 @@ export async function createSQLiteModels(filesOrgPath: string, resultsPath: stri
convertCaseEntity: 'none',
convertCaseFile: 'none',
convertCaseProperty: 'none',
propertyVisibility: 'none',
lazy: false,
constructor:false,
constructor: false,
namingStrategy: namingStrategy,
relationIds: false
});
@ -251,8 +254,9 @@ export async function createMysqlModels(filesOrgPath: string, resultsPath: strin
convertCaseEntity: 'none',
convertCaseFile: 'none',
convertCaseProperty: 'none',
propertyVisibility: 'none',
lazy: false,
constructor:false,
constructor: false,
namingStrategy: namingStrategy,
relationIds: false
});
@ -302,8 +306,9 @@ export async function createMariaDBModels(filesOrgPath: string, resultsPath: str
convertCaseEntity: 'none',
convertCaseFile: 'none',
convertCaseProperty: 'none',
propertyVisibility: 'none',
lazy: false,
constructor:false,
constructor: false,
namingStrategy: namingStrategy,
relationIds: false
});
@ -356,8 +361,9 @@ export async function createOracleDBModels(filesOrgPath: string, resultsPath: st
convertCaseEntity: 'none',
convertCaseFile: 'none',
convertCaseProperty: 'none',
propertyVisibility: 'none',
lazy: false,
constructor:false,
constructor: false,
namingStrategy: namingStrategy,
relationIds: false
});