changed from mustache.js to handlebars.js
This commit is contained in:
parent
126d9ce185
commit
3ca6707a80
@ -22,14 +22,15 @@
|
||||
},
|
||||
"homepage": "https://github.com/Kononnable/typeorm-model-generator#readme",
|
||||
"dependencies": {
|
||||
"handlebars": "^4.0.10",
|
||||
"mssql": "^3.3.0",
|
||||
"mustache": "^2.3.0",
|
||||
"reflect-metadata": "^0.1.10",
|
||||
"typeorm": "0.0.10",
|
||||
"typescript": "^2.3.2",
|
||||
"yargs": "^7.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/handlebars": "^4.0.32",
|
||||
"@types/chai": "^3.5.2",
|
||||
"@types/chai-as-promised": "0.0.30",
|
||||
"@types/chai-subset": "^1.3.0",
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { MssqlDriver } from './drivers/MssqlDriver'
|
||||
import { AbstractDriver } from "./drivers/AbstractDriver";
|
||||
import { DatabaseModel } from './models/DatabaseModel'
|
||||
import * as Mustache from 'mustache'
|
||||
import * as Handlebars from 'handlebars'
|
||||
import fs = require('fs');
|
||||
import path = require('path')
|
||||
/**
|
||||
@ -32,15 +32,13 @@ export class Engine {
|
||||
fs.mkdirSync(resultPath);
|
||||
this.createTsConfigFile(resultPath)
|
||||
this.createTypeOrm(resultPath)
|
||||
Mustache.escape = function (value) {
|
||||
return value;
|
||||
};
|
||||
let entitesPath = path.resolve(resultPath, './entities')
|
||||
if (!fs.existsSync(entitesPath))
|
||||
fs.mkdirSync(entitesPath);
|
||||
let compliedTemplate = Handlebars.compile(template,{noEscape:true})
|
||||
databaseModel.entities.forEach(element => {
|
||||
let resultFilePath = path.resolve(entitesPath, element.EntityName + '.ts');
|
||||
let rendered = Mustache.render(template, element);
|
||||
let rendered =compliedTemplate(element)
|
||||
fs.writeFileSync(resultFilePath, rendered, { encoding: 'UTF-8', flag: 'w' })
|
||||
});
|
||||
}
|
||||
|
@ -7,7 +7,16 @@ import {Index,Entity, PrimaryColumn, Column, OneToOne, OneToMany, ManyToOne, Joi
|
||||
|
||||
{{#Columns}}
|
||||
|
||||
@Column("{{sql_type}}",{ {{#is_generated}}generated:true,{{/is_generated}}{{#is_nullable}}nullable:true,{{/is_nullable}}{{^is_nullable}}nullable:false,{{/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_generated}}
|
||||
generated:true,{{/is_generated}}{{#is_nullable}}
|
||||
nullable:true,{{/is_nullable}}{{^is_nullable}}
|
||||
nullable:false,{{/is_nullable}}{{#char_max_lenght}}
|
||||
length:{{.}},{{/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}};
|
||||
|
@ -1,11 +1,8 @@
|
||||
import { MssqlDriver } from './drivers/MssqlDriver';
|
||||
import * as Mustache from 'mustache'
|
||||
import { Engine } from './Engine'
|
||||
import * as Yargs from 'yargs'
|
||||
import { AbstractDriver } from "./drivers/AbstractDriver";
|
||||
import path = require('path')
|
||||
// var x = Mustache.render("{{a}}", { a: 'test' });
|
||||
// console.log(x);
|
||||
|
||||
|
||||
|
||||
|
@ -6,8 +6,8 @@ export class EntityFileToJson {
|
||||
if (decoratorParameters.search(',') > 0) {
|
||||
col.columnType = decoratorParameters.substring(0, decoratorParameters.indexOf(',')).trim()
|
||||
let badJSON = decoratorParameters.substring(decoratorParameters.indexOf(',') + 1).trim()
|
||||
if (badJSON.lastIndexOf(',') == badJSON.length - 2) {
|
||||
badJSON = badJSON.slice(0, badJSON.length - 2) + badJSON[badJSON.length - 1]
|
||||
if (badJSON.lastIndexOf(',') == badJSON.length - 3) {
|
||||
badJSON = badJSON.slice(0, badJSON.length - 3) + badJSON[badJSON.length - 2] + badJSON[badJSON.length - 1]
|
||||
}
|
||||
col.columnOptions = JSON.parse(badJSON.replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g, '"$2": '))
|
||||
} else {
|
||||
@ -15,8 +15,8 @@ export class EntityFileToJson {
|
||||
col.columnType = decoratorParameters
|
||||
} else {
|
||||
let badJSON = decoratorParameters.substring(decoratorParameters.indexOf(',') + 1).trim()
|
||||
if (badJSON.lastIndexOf(',') == badJSON.length - 2) {
|
||||
badJSON = badJSON.slice(0, badJSON.length - 2) + badJSON[badJSON.length - 1]
|
||||
if (badJSON.lastIndexOf(',') == badJSON.length - 3) {
|
||||
badJSON = badJSON.slice(0, badJSON.length - 3) + badJSON[badJSON.length - 2] + badJSON[badJSON.length - 1]
|
||||
}
|
||||
col.columnOptions = JSON.parse(badJSON.replace(/(['"])?([a-z0-9A-Z_]+)(['"])?:/g, '"$2": '))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user