disabled mustache char escaping; couple fixes in mustache template

This commit is contained in:
Kononnable 2017-04-26 19:23:22 +02:00
parent 7ef9bb109c
commit dd2399f4fe
2 changed files with 17 additions and 14 deletions

View File

@ -1,6 +1,6 @@
import { MssqlDriver } from './drivers/MssqlDriver'
import { AbstractDriver } from "./drivers/AbstractDriver";
import {DatabaseModel} from './models/DatabaseModel'
import { DatabaseModel } from './models/DatabaseModel'
import * as Mustache from 'mustache'
import fs = require('fs');
import path = require('path')
@ -21,16 +21,16 @@ export class Engine {
return true;
}
private async getEntitiesInfo(database: string, server: string, port: number, user: string, password: string): Promise<DatabaseModel> {
return await this.driver.GetDataFromServer(database, server, port, user, password)
return await this.driver.GetDataFromServer(database, server, port, user, password)
}
private createModelFromMetadata(databaseModel: DatabaseModel) {
let templatePath = path.resolve(__dirname,'entity.mst')
let template = fs.readFileSync(templatePath,'UTF-8');
let templatePath = path.resolve(__dirname, 'entity.mst')
let template = fs.readFileSync(templatePath, 'UTF-8');
//TODO:get results path to argvs, check if dir exists before
let resultPath = path.resolve(__dirname,'../results')
let resultPath = path.resolve(__dirname, '../results')
//TODO:Refactor to new method
fs.writeFileSync(path.resolve(resultPath,'tsconfig.json'),`{"compilerOptions": {
fs.writeFileSync(path.resolve(resultPath, 'tsconfig.json'), `{"compilerOptions": {
"lib": ["es5", "es6"],
"target": "es6",
"module": "commonjs",
@ -38,12 +38,15 @@ export class Engine {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true
}}`,{encoding:'UTF-8',flag:'w'});
//TODO:Create ormconfig file
}}`, { encoding: 'UTF-8', flag: 'w' });
//TODO:Create ormconfig file
Mustache.escape = function (value) {
return value;
};
databaseModel.entities.forEach(element => {
let resultFilePath = path.resolve(resultPath,element.EntityName+'.ts');
let rendered = Mustache.render(template, element);
fs.writeFileSync(resultFilePath,rendered,{encoding:'UTF-8',flag:'w'})
let resultFilePath = path.resolve(resultPath, element.EntityName + '.ts');
let rendered = Mustache.render(template, element);
fs.writeFileSync(resultFilePath, rendered, { encoding: 'UTF-8', flag: 'w' })
});
}
}

View File

@ -1,5 +1,5 @@
import {Index,Entity, PrimaryColumn, Column, OneToOne, OneToMany, ManyToOne, JoinTable} from "typeorm";
{{{relationImports}}}
{{relationImports}}
@Entity()
{{#Indexes}}{{^isPrimaryKey}}@Index("{{name}}",[{{#columns}}"{{name}}",{{/columns}}]{{#isUnique}},{unique:true}{{/isUnique}})
@ -7,7 +7,7 @@ import {Index,Entity, PrimaryColumn, Column, OneToOne, OneToMany, ManyToOne, Joi
{{#Columns}}
@Column("{{sql_type}}",{ {{#is_nullable}}nullable:true,{{/is_nullable}}{{#char_max_lenght}}length:{{char_max_lenght}},{{/char_max_lenght}}{{#default}}default:{{default}},{{/default}}{{#numericPrecision}}precision:{numericPrecision},{{/numericPrecision}}{{#numericScale}}scale:{{numericScale}},{{/numericScale}}{{#isPrimary}}primary:{{isPrimary}},{{/isPrimary}}}){{#relations}}
@Column("{{sql_type}}",{ {{#is_nullable}}nullable:true,{{/is_nullable}}{{#char_max_lenght}}length:{{char_max_lenght}},{{/char_max_lenght}}{{#default}}default:{{default}},{{/default}}{{#numericPrecision}}precision:{{numericPrecision}},{{/numericPrecision}}{{#numericScale}}scale:{{numericScale}},{{/numericScale}}{{#isPrimary}}primary:{{isPrimary}},{{/isPrimary}}}){{#relations}}
@{{relationType}}(type=>{{relatedTable}},x=>x.{{relatedColumn}}){{#isOwner}}
@JoinTable(){{/isOwner}}{{/relations}}
{{name}}:{{ts_type}};