@@ -3,7 +3,7 @@ import _ from "lodash";
33import path from "path" ;
44import util from "util" ;
55import { FKSpec , TableData } from "." ;
6- import { AutoOptions , CaseFileOption , CaseOption , LangOption , pluralize , qNameSplit , recase , Relation } from "./types" ;
6+ import { AutoOptions , CaseFileOption , CaseOption , LangOption , makeTableName , pluralize , qNameSplit , recase , Relation } from "./types" ;
77const mkdirp = require ( 'mkdirp' ) ;
88
99/** Writes text into files from TableData.text, and writes init-models */
@@ -72,8 +72,6 @@ export class AutoWriter {
7272 return this . createTsInitString ( tableNames , assoc ) ;
7373 case 'esm' :
7474 return this . createESMInitString ( tableNames , assoc ) ;
75- case 'esmd' :
76- return this . createESMDInitString ( tableNames , assoc ) ;
7775 case 'es6' :
7876 return this . createES5InitString ( tableNames , assoc , "const" ) ;
7977 default :
@@ -127,7 +125,7 @@ export class AutoWriter {
127125 // import statements
128126 tables . forEach ( t => {
129127 const fileName = recase ( this . options . caseFile , t , this . options . singularize ) ;
130- const modelName = recase ( this . options . caseModel , t , this . options . singularize ) ;
128+ const modelName = makeTableName ( this . options . caseModel , t , this . options . singularize , this . options . lang ) ;
131129 modelNames . push ( modelName ) ;
132130 str += `import { ${ modelName } as _${ modelName } } from "./${ fileName } ";\n` ;
133131 str += `import type { ${ modelName } Attributes, ${ modelName } CreationAttributes } from "./${ fileName } ";\n` ;
@@ -174,7 +172,7 @@ export class AutoWriter {
174172 // import statements
175173 tables . forEach ( t => {
176174 const fileName = recase ( this . options . caseFile , t , this . options . singularize ) ;
177- const modelName = recase ( this . options . caseModel , t , this . options . singularize ) ;
175+ const modelName = makeTableName ( this . options . caseModel , t , this . options . singularize , this . options . lang ) ;
178176 modelNames . push ( modelName ) ;
179177 str += `${ vardef } _${ modelName } = require("./${ fileName } ");\n` ;
180178 } ) ;
@@ -200,34 +198,7 @@ export class AutoWriter {
200198 str += 'module.exports.default = initModels;\n' ;
201199 return str ;
202200 }
203- // create the ES6 init-models file to load all the models (with define-syntax instead of classes) into Sequelize
204- createESMDInitString ( tables : string [ ] , assoc : string ) {
205- let str = 'import _sequelize from "sequelize";\n' ;
206- str += 'const DataTypes = _sequelize.DataTypes;\n' ;
207- const modelNames : string [ ] = [ ] ;
208- // import statements
209- tables . forEach ( t => {
210- const fileName = recase ( this . options . caseFile , t , this . options . singularize ) ;
211- const modelName = recase ( this . options . caseModel , t , this . options . singularize ) ;
212- modelNames . push ( modelName ) ;
213- str += `import _${ modelName } from "./${ fileName } .js";\n` ;
214- } ) ;
215- // create the initialization function
216- str += '\nexport default function initModels(sequelize) {\n' ;
217- modelNames . forEach ( m => {
218- str += ` const ${ m } = _${ m } (sequelize, DataTypes);\n` ;
219- } ) ;
220- // add the asociations
221- str += "\n" + assoc ;
222- // return the models
223- str += "\n return {\n" ;
224- modelNames . forEach ( m => {
225- str += ` ${ m } ,\n` ;
226- } ) ;
227- str += ' };\n' ;
228- str += '}\n' ;
229- return str ;
230- }
201+
231202 // create the ESM init-models file to load all the models into Sequelize
232203 private createESMInitString ( tables : string [ ] , assoc : string ) {
233204 let str = 'import _sequelize from "sequelize";\n' ;
@@ -236,18 +207,17 @@ export class AutoWriter {
236207 // import statements
237208 tables . forEach ( t => {
238209 const fileName = recase ( this . options . caseFile , t , this . options . singularize ) ;
239- const modelName = recase ( this . options . caseModel , t , this . options . singularize ) ;
210+ const modelName = makeTableName ( this . options . caseModel , t , this . options . singularize , this . options . lang ) ;
240211 modelNames . push ( modelName ) ;
241212 str += `import _${ modelName } from "./${ fileName } .js";\n` ;
242213 } ) ;
243-
244214 // create the initialization function
245215 str += '\nexport default function initModels(sequelize) {\n' ;
246216 modelNames . forEach ( m => {
247217 str += ` const ${ m } = _${ m } .init(sequelize, DataTypes);\n` ;
248218 } ) ;
249219
250- // add the asociations
220+ // add the associations
251221 str += "\n" + assoc ;
252222
253223 // return the models
0 commit comments