@@ -5,7 +5,6 @@ import {Base} from 'yeoman-generator';
5
5
import { genNamedBase } from '../generator-base' ;
6
6
7
7
export class Generator extends Base {
8
-
9
8
constructor ( ...args ) {
10
9
super ( ...args ) ;
11
10
@@ -33,69 +32,68 @@ export class Generator extends Base {
33
32
}
34
33
35
34
prompting ( ) {
36
- var promptCb = ( props ) => {
35
+ let promptCb = props => {
37
36
if ( props . route . charAt ( 0 ) !== '/' ) {
38
- props . route = '/' + props . route ;
37
+ props . route = `/ ${ props . route } ` ;
39
38
}
40
39
41
40
this . route = props . route ;
42
41
43
- if ( props . models ) {
42
+ if ( props . models ) {
44
43
delete this . filters . mongoose ;
45
44
delete this . filters . mongooseModels ;
46
45
delete this . filters . sequelize ;
47
46
delete this . filters . sequelizeModels ;
48
47
49
48
this . filters [ props . models ] = true ;
50
- this . filters [ props . models + ' Models' ] = true ;
49
+ this . filters [ ` ${ props . models } Models` ] = true ;
51
50
}
52
51
} ;
53
52
54
- if ( this . options . route ) {
55
- if ( this . filters . mongoose && this . filters . sequelize ) {
56
- if ( this . options . models ) {
57
- return promptCb ( this . options ) ;
58
- }
53
+ if ( this . options . route ) {
54
+ if ( this . filters . mongoose && this . filters . sequelize && this . options . models ) {
55
+ return promptCb ( this . options ) ;
59
56
} else {
60
- if ( this . filters . mongooseModels ) { this . options . models = 'mongoose' ; }
61
- else if ( this . filters . sequelizeModels ) { this . options . models = 'sequelize' ; }
62
- else { delete this . options . models ; }
57
+ if ( this . filters . mongooseModels ) this . options . models = 'mongoose' ;
58
+ else if ( this . filters . sequelizeModels ) this . options . models = 'sequelize' ;
59
+ else delete this . options . models ;
63
60
return promptCb ( this . options ) ;
64
61
}
65
62
}
66
63
67
64
var name = this . name ;
68
65
69
66
var base = this . config . get ( 'routesBase' ) || '/api/' ;
70
- if ( base . charAt ( base . length - 1 ) !== '/' ) {
71
- base = base + '/' ;
67
+ if ( base . charAt ( base . length - 1 ) !== '/' ) {
68
+ base = ` ${ base } /` ;
72
69
}
73
70
74
71
// pluralization defaults to true for backwards compat
75
- if ( this . config . get ( 'pluralizeRoutes' ) !== false ) {
76
- name = name + 's' ;
72
+ if ( this . config . get ( 'pluralizeRoutes' ) !== false ) {
73
+ name = ` ${ name } s` ;
77
74
}
78
75
79
76
var prompts = [ {
80
77
name : 'route' ,
81
78
message : 'What will the url of your endpoint be?' ,
82
- default : base + name
79
+ default : ` ${ base } ${ name } `
83
80
} , {
84
81
type : 'list' ,
85
82
name : 'models' ,
86
83
message : 'What would you like to use for the endpoint\'s models?' ,
87
- choices : [ 'Mongoose' , 'Sequelize' ] ,
84
+ choices : [ 'Mongoose' , 'Sequelize' ] ,
88
85
default : this . filters . sequelizeModels ? 1 : 0 ,
89
- filter : ( val ) => val . toLowerCase ( ) ,
86
+ filter : val => val . toLowerCase ( ) ,
90
87
when : ( ) => this . filters . mongoose && this . filters . sequelize
91
88
} ] ;
92
89
93
90
return this . prompt ( prompts ) . then ( promptCb ) ;
94
91
}
95
92
96
93
configuring ( ) {
97
- this . routeDest = path . join ( this . options . endpointDirectory ||
98
- this . config . get ( 'endpointDirectory' ) || 'server/api/' , this . name ) ;
94
+ this . routeDest = path . join ( this . options . endpointDirectory
95
+ || this . config . get ( 'endpointDirectory' )
96
+ || 'server/api/' , this . name ) ;
99
97
}
100
98
101
99
writing ( ) {
@@ -111,34 +109,34 @@ export class Generator extends Base {
111
109
file : routesFile ,
112
110
needle : this . config . get ( 'routesNeedle' ) ,
113
111
splicable : [
114
- " app.use(\'" + this . route + "\ ', require(\'" + reqPath + "\ '));"
112
+ ` app.use(' ${ this . route } ', require(' ${ reqPath } '));`
115
113
]
116
114
} ;
117
115
this . rewriteFile ( routeConfig ) ;
118
116
}
119
117
120
- if ( this . filters . socketio && this . config . get ( 'insertSockets' ) ) {
118
+ if ( this . filters . socketio && this . config . get ( 'insertSockets' ) ) {
121
119
var socketsFile = this . config . get ( 'registerSocketsFile' ) ;
122
120
var reqPath = this . relativeRequire ( this . routeDest + '/' + this . basename +
123
121
'.socket' , socketsFile ) ;
124
122
var socketConfig = {
125
123
file : socketsFile ,
126
124
needle : this . config . get ( 'socketsNeedle' ) ,
127
125
splicable : [
128
- " require(\'" + reqPath + "\ ').register(socket);"
126
+ ` require(' ${ reqPath } ').register(socket);`
129
127
]
130
128
} ;
131
129
this . rewriteFile ( socketConfig ) ;
132
130
}
133
131
134
- if ( this . filters . sequelize && this . config . get ( 'insertModels' ) ) {
132
+ if ( this . filters . sequelize && this . config . get ( 'insertModels' ) ) {
135
133
var modelsFile = this . config . get ( 'registerModelsFile' ) ;
136
- var reqPath = this . relativeRequire ( this . routeDest + '/' + this . basename + ' .model' , modelsFile ) ;
134
+ var reqPath = this . relativeRequire ( ` ${ this . routeDest } / ${ this . basename } .model` , modelsFile ) ;
137
135
var modelConfig = {
138
136
file : modelsFile ,
139
137
needle : this . config . get ( 'modelsNeedle' ) ,
140
138
splicable : [
141
- " db." + this . classedName + " = db.sequelize.import(\'" + reqPath + "\ ');"
139
+ ` db.${ this . classedName } = db.sequelize.import(' ${ reqPath } ');`
142
140
]
143
141
} ;
144
142
this . rewriteFile ( modelConfig ) ;
0 commit comments