Skip to content

Commit 17c8a28

Browse files
committed
style(gen:endpoint):
1 parent 58d4bac commit 17c8a28

File tree

1 file changed

+26
-28
lines changed

1 file changed

+26
-28
lines changed

src/generators/endpoint/index.js

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {Base} from 'yeoman-generator';
55
import {genNamedBase} from '../generator-base';
66

77
export class Generator extends Base {
8-
98
constructor(...args) {
109
super(...args);
1110

@@ -33,69 +32,68 @@ export class Generator extends Base {
3332
}
3433

3534
prompting() {
36-
var promptCb = (props) => {
35+
let promptCb = props => {
3736
if(props.route.charAt(0) !== '/') {
38-
props.route = '/' + props.route;
37+
props.route = `/${props.route}`;
3938
}
4039

4140
this.route = props.route;
4241

43-
if (props.models) {
42+
if(props.models) {
4443
delete this.filters.mongoose;
4544
delete this.filters.mongooseModels;
4645
delete this.filters.sequelize;
4746
delete this.filters.sequelizeModels;
4847

4948
this.filters[props.models] = true;
50-
this.filters[props.models + 'Models'] = true;
49+
this.filters[`${props.models}Models`] = true;
5150
}
5251
};
5352

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);
5956
} 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;
6360
return promptCb(this.options);
6461
}
6562
}
6663

6764
var name = this.name;
6865

6966
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}/`;
7269
}
7370

7471
// 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`;
7774
}
7875

7976
var prompts = [{
8077
name: 'route',
8178
message: 'What will the url of your endpoint be?',
82-
default: base + name
79+
default: `${base}${name}`
8380
}, {
8481
type: 'list',
8582
name: 'models',
8683
message: 'What would you like to use for the endpoint\'s models?',
87-
choices: [ 'Mongoose', 'Sequelize' ],
84+
choices: ['Mongoose', 'Sequelize'],
8885
default: this.filters.sequelizeModels ? 1 : 0,
89-
filter: (val) => val.toLowerCase(),
86+
filter: val => val.toLowerCase(),
9087
when: () => this.filters.mongoose && this.filters.sequelize
9188
}];
9289

9390
return this.prompt(prompts).then(promptCb);
9491
}
9592

9693
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);
9997
}
10098

10199
writing() {
@@ -111,34 +109,34 @@ export class Generator extends Base {
111109
file: routesFile,
112110
needle: this.config.get('routesNeedle'),
113111
splicable: [
114-
"app.use(\'" + this.route +"\', require(\'" + reqPath + "\'));"
112+
`app.use('${this.route}', require('${reqPath}'));`
115113
]
116114
};
117115
this.rewriteFile(routeConfig);
118116
}
119117

120-
if (this.filters.socketio && this.config.get('insertSockets')) {
118+
if(this.filters.socketio && this.config.get('insertSockets')) {
121119
var socketsFile = this.config.get('registerSocketsFile');
122120
var reqPath = this.relativeRequire(this.routeDest + '/' + this.basename +
123121
'.socket', socketsFile);
124122
var socketConfig = {
125123
file: socketsFile,
126124
needle: this.config.get('socketsNeedle'),
127125
splicable: [
128-
"require(\'" + reqPath + "\').register(socket);"
126+
`require('${reqPath}').register(socket);`
129127
]
130128
};
131129
this.rewriteFile(socketConfig);
132130
}
133131

134-
if (this.filters.sequelize && this.config.get('insertModels')) {
132+
if(this.filters.sequelize && this.config.get('insertModels')) {
135133
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);
137135
var modelConfig = {
138136
file: modelsFile,
139137
needle: this.config.get('modelsNeedle'),
140138
splicable: [
141-
"db." + this.classedName + " = db.sequelize.import(\'" + reqPath +"\');"
139+
`db.${this.classedName} = db.sequelize.import('${reqPath}');`
142140
]
143141
};
144142
this.rewriteFile(modelConfig);

0 commit comments

Comments
 (0)