@@ -4,7 +4,6 @@ var fs = require('fs');
44var path = require ( 'path' ) ;
55var Sequelize = require ( 'sequelize' ) ;
66
7-
87/**
98 * Register sequelize as a Hapi plugin
109 * @param plugin
@@ -13,44 +12,47 @@ var Sequelize = require('sequelize');
1312 */
1413exports . register = function ( plugin , options , next ) {
1514
15+ var db = { } ;
1616 var dir = [ ] ;
17- var logging = process . env . NODE_ENV === 'production' ? false : console . log ;
18-
19- dir = Array . isArray ( options . models ) ? options . models : dir . push ( options . models ) ;
17+ Array . isArray ( options . models ) ? dir = options . models : dir . push ( options . models ) ;
2018
2119 dir . forEach ( function ( folder , index , arr ) {
2220 arr [ index ] = path . join ( process . cwd ( ) , folder ) ;
2321 } ) ;
2422
23+
2524 var sequelize = new Sequelize ( options . database , options . user , options . pass , {
2625 host : options . host || 'localhost' ,
2726 dialect : options . dialect || 'mysql' ,
2827 port : options . port || 3306 ,
29- define : options . defaults || { } ,
30- logging : logging
28+ storage : options . storage || '' ,
29+ define : options . defaults || { }
3130 } ) ;
3231
33- var db = { } ;
3432
35- // recursively get all models in 'models' directory, and all nested sub-directories
36- var getModels = function ( folder ) {
37- var fileContents = fs . readdirSync ( folder )
33+ //recursively get all models in 'models' directory, and all nested sub-directories
34+ var getJSModels = function ( folder ) {
35+ var fileContents = fs . readdirSync ( folder ) ,
36+ stats ;
3837
39- fileContents . forEach ( function ( fileName ) {
40- var stats = fs . lstatSync ( folder + '/' + fileName ) ;
38+ fileContents . forEach ( function ( fileName ) {
39+ stats = fs . lstatSync ( folder + '/' + fileName ) ;
4140
4241 if ( stats . isDirectory ( ) ) {
43- getModels ( folder + '/' + fileName )
44- } else if ( fileName . indexOf ( '.' ) !== 0 ) {
45- var filePath = path . join ( folder , fileName ) ;
46- var model = sequelize . import ( filePath ) ;
47- db [ model . name ] = model ;
42+ getJSModels ( folder + '/' + fileName )
43+ } else {
44+ if ( fileName . indexOf ( '.' ) !== 0 ) {
45+ var filePath = path . join ( folder , fileName ) ;
46+ var model = sequelize . import ( filePath ) ;
47+ db [ model . name ] = model ;
48+ }
4849 }
4950 } ) ;
50- }
51+
52+ } ;
5153
5254 dir . forEach ( function ( folder ) {
53- getModels ( folder ) ;
55+ getJSModels ( folder ) ;
5456 } ) ;
5557
5658 Object . keys ( db ) . forEach ( function ( modelName ) {
@@ -64,10 +66,9 @@ exports.register = function(plugin, options, next) {
6466
6567 plugin . expose ( 'db' , db ) ;
6668
67- return next ( ) ;
68-
69+ next ( ) ;
6970} ;
7071
7172exports . register . attributes = {
7273 pkg : require ( '../package.json' )
73- } ;
74+ } ;
0 commit comments