Skip to content

Commit fcee2d0

Browse files
committed
style(gen): various small code style changes
1 parent 1d8d283 commit fcee2d0

File tree

1 file changed

+55
-97
lines changed

1 file changed

+55
-97
lines changed

Diff for: app/generator.js

+55-97
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import insight from '../insight-init';
99
import {exec} from 'child_process';
1010

1111
export default class Generator extends Base {
12-
1312
constructor(...args) {
1413
super(...args);
1514

@@ -48,7 +47,6 @@ export default class Generator extends Base {
4847
return cb();
4948
}
5049
},
51-
5250
info: function () {
5351
insight.track('generator', this.rootGeneratorVersion());
5452
insight.track('node', process.version);
@@ -61,7 +59,6 @@ export default class Generator extends Base {
6159
this.log(this.yoWelcome);
6260
this.log('Out of the box I create an AngularJS app with an Express server.\n');
6361
},
64-
6562
checkForConfig: function() {
6663
var cb = this.async();
6764
var existingFilters = this.config.get('filters');
@@ -72,7 +69,7 @@ export default class Generator extends Base {
7269
name: 'skipConfig',
7370
message: 'Existing .yo-rc configuration found, would you like to use it?',
7471
default: true,
75-
}], function (answers) {
72+
}], answers => {
7673
this.skipConfig = answers.skipConfig;
7774

7875
if(this.skipConfig) {
@@ -94,7 +91,7 @@ export default class Generator extends Base {
9491
}
9592

9693
cb();
97-
}.bind(this));
94+
});
9895
} else {
9996
cb();
10097
}
@@ -104,7 +101,6 @@ export default class Generator extends Base {
104101

105102
get prompting() {
106103
return {
107-
108104
clientPrompts: function() {
109105
if(this.skipConfig) return;
110106
var cb = this.async();
@@ -127,21 +123,21 @@ export default class Generator extends Base {
127123
name: 'markup',
128124
message: 'What would you like to write markup with?',
129125
choices: ['HTML', 'Jade'],
130-
filter: function( val ) { return val.toLowerCase(); }
126+
filter: val => val.toLowerCase()
131127
}, {
132128
type: 'list',
133129
name: 'stylesheet',
134130
default: 1,
135131
message: 'What would you like to write stylesheets with?',
136-
choices: [ 'CSS', 'Sass', 'Stylus', 'Less'],
137-
filter: function( val ) { return val.toLowerCase(); }
132+
choices: ['CSS', 'Sass', 'Stylus', 'Less'],
133+
filter: val => val.toLowerCase()
138134
}, {
139135
type: 'list',
140136
name: 'router',
141137
default: 1,
142138
message: 'What Angular router would you like to use?',
143-
choices: [ 'ngRoute', 'uiRouter'],
144-
filter: function( val ) { return val.toLowerCase(); }
139+
choices: ['ngRoute', 'uiRouter'],
140+
filter: val => val.toLowerCase()
145141
}, {
146142
type: 'confirm',
147143
name: 'bootstrap',
@@ -150,10 +146,8 @@ export default class Generator extends Base {
150146
type: 'confirm',
151147
name: 'uibootstrap',
152148
message: 'Would you like to include UI Bootstrap?',
153-
when: function (answers) {
154-
return answers.bootstrap;
155-
}
156-
}], function (answers) {
149+
when: answers => answers.bootstrap
150+
}], answers => {
157151
this.filters.js = true;
158152
this.filters[answers.transpiler] = true;
159153
insight.track('transpiler', answers.transpiler);
@@ -180,9 +174,8 @@ export default class Generator extends Base {
180174
this.styleExt = styleExt ? styleExt : answers.stylesheet;
181175

182176
cb();
183-
}.bind(this));
177+
});
184178
},
185-
186179
serverPrompts: function() {
187180
if(this.skipConfig) return;
188181
var cb = this.async();
@@ -194,70 +187,53 @@ export default class Generator extends Base {
194187
type: 'checkbox',
195188
name: 'odms',
196189
message: 'What would you like to use for data modeling?',
197-
choices: [
198-
{
199-
value: 'mongoose',
200-
name: 'Mongoose (MongoDB)',
201-
checked: true
202-
},
203-
{
204-
value: 'sequelize',
205-
name: 'Sequelize (MySQL, SQLite, MariaDB, PostgreSQL)',
206-
checked: false
207-
}
208-
]
190+
choices: [{
191+
value: 'mongoose',
192+
name: 'Mongoose (MongoDB)',
193+
checked: true
194+
}, {
195+
value: 'sequelize',
196+
name: 'Sequelize (MySQL, SQLite, MariaDB, PostgreSQL)',
197+
checked: false
198+
}]
209199
}, {
210200
type: 'list',
211201
name: 'models',
212202
message: 'What would you like to use for the default models?',
213203
choices: [ 'Mongoose', 'Sequelize' ],
214-
filter: function( val ) {
215-
return val.toLowerCase();
216-
},
217-
when: function(answers) {
218-
return answers.odms && answers.odms.length > 1;
219-
}
204+
filter: val => val.toLowerCase(),
205+
when: answers => answers.odms && answers.odms.length > 1
220206
}, {
221207
type: 'confirm',
222208
name: 'auth',
223209
message: 'Would you scaffold out an authentication boilerplate?',
224-
when: function (answers) {
225-
return answers.odms && answers.odms.length !== 0;
226-
}
210+
when: answers => answers.odms && answers.odms.length !== 0
227211
}, {
228212
type: 'checkbox',
229213
name: 'oauth',
230214
message: 'Would you like to include additional oAuth strategies?',
231-
when: function (answers) {
232-
return answers.auth;
233-
},
234-
choices: [
235-
{
236-
value: 'googleAuth',
237-
name: 'Google',
238-
checked: false
239-
},
240-
{
241-
value: 'facebookAuth',
242-
name: 'Facebook',
243-
checked: false
244-
},
245-
{
246-
value: 'twitterAuth',
247-
name: 'Twitter',
248-
checked: false
249-
}
250-
]
215+
when: answers => answers.auth,
216+
choices: [{
217+
value: 'googleAuth',
218+
name: 'Google',
219+
checked: false
220+
}, {
221+
value: 'facebookAuth',
222+
name: 'Facebook',
223+
checked: false
224+
}, {
225+
value: 'twitterAuth',
226+
name: 'Twitter',
227+
checked: false
228+
}]
251229
}, {
252230
type: 'confirm',
253231
name: 'socketio',
254232
message: 'Would you like to use socket.io?',
255233
// to-do: should not be dependent on ODMs
256-
when: function (answers) {
257-
return answers.odms && answers.odms.length !== 0;
258-
},
234+
when: answers => answers.odms && answers.odms.length !== 0,
259235
default: true
260-
}], function (answers) {
236+
}], answers => {
261237
if(answers.socketio) this.filters.socketio = true;
262238
insight.track('socketio', !!answers.socketio);
263239

@@ -273,9 +249,9 @@ export default class Generator extends Base {
273249
}
274250
this.filters.models = true;
275251
this.filters[models + 'Models'] = true;
276-
answers.odms.forEach(function(odm) {
252+
answers.odms.forEach(odm => {
277253
this.filters[odm] = true;
278-
}.bind(this));
254+
});
279255
insight.track('oauth', !!answers.oauth);
280256
} else {
281257
this.filters.noModels = true;
@@ -288,19 +264,18 @@ export default class Generator extends Base {
288264

289265
if(answers.oauth) {
290266
if(answers.oauth.length) this.filters.oauth = true;
291-
answers.oauth.forEach(function(oauthStrategy) {
267+
answers.oauth.forEach(oauthStrategy => {
292268
this.filters[oauthStrategy] = true;
293-
}.bind(this));
269+
});
294270
}
295271
insight.track('oauth', !!this.filters.oauth);
296272
insight.track('google-oauth', !!this.filters['googleAuth']);
297273
insight.track('facebook-oauth', !!this.filters['facebookAuth']);
298274
insight.track('twitter-oauth', !!this.filters['twitterAuth']);
299275

300276
cb();
301-
}.bind(this));
277+
});
302278
},
303-
304279
projectPrompts: function() {
305280
if(this.skipConfig) return;
306281
var cb = this.async();
@@ -320,54 +295,46 @@ export default class Generator extends Base {
320295
name: 'testing',
321296
message: 'What would you like to write tests with?',
322297
choices: [ 'Jasmine', 'Mocha + Chai + Sinon'],
323-
filter: function( val ) {
324-
var filterMap = {
298+
filter: function(val) {
299+
return {
325300
'Jasmine': 'jasmine',
326301
'Mocha + Chai + Sinon': 'mocha'
327-
};
328-
329-
return filterMap[val];
302+
}[val];
330303
}
331304
}, {
332305
type: 'list',
333306
name: 'chai',
334307
message: 'What would you like to write Chai assertions with?',
335308
choices: ['Expect', 'Should'],
336-
filter: function( val ) {
337-
return val.toLowerCase();
338-
},
339-
when: function( answers ) {
340-
return answers.testing === 'mocha';
341-
}
342-
}], function (answers) {
309+
filter: val => val.toLowerCase(),
310+
when: answers => answers.testing === 'mocha'
311+
}], answers => {
343312
this.filters[answers.buildtool] = true;
344313
insight.track('buildtool', answers.buildtool);
345314

346315
this.filters[answers.testing] = true;
347316
insight.track('testing', answers.testing);
348-
if (answers.testing === 'mocha') {
317+
if(answers.testing === 'mocha') {
349318
this.filters.jasmine = false;
350319
this.filters.should = false;
351320
this.filters.expect = false;
352321
this.filters[answers.chai] = true;
353322
insight.track('chai-assertions', answers.chai);
354323
}
355-
if (answers.testing === 'jasmine') {
324+
if(answers.testing === 'jasmine') {
356325
this.filters.mocha = false;
357326
this.filters.should = false;
358327
this.filters.expect = false;
359328
}
360329

361330
cb();
362-
}.bind(this));
331+
});
363332
}
364-
365333
};
366334
}
367335

368336
get configuring() {
369337
return {
370-
371338
saveSettings: function() {
372339
if(this.skipConfig) return;
373340
this.config.set('endpointDirectory', 'server/api/');
@@ -389,7 +356,6 @@ export default class Generator extends Base {
389356
this.config.set('filters', this.filters);
390357
this.config.forceSave();
391358
},
392-
393359
ngComponent: function() {
394360
if(this.skipConfig) return;
395361
var appPath = 'client/app/';
@@ -401,7 +367,7 @@ export default class Generator extends Base {
401367
'mocha',
402368
'expect',
403369
'should'
404-
].filter(function(v) {return this.filters[v];}, this);
370+
].filter(v => this.filters[v]);
405371

406372
if(this.filters.ngroute) filters.push('ngroute');
407373
if(this.filters.uirouter) filters.push('uirouter');
@@ -430,7 +396,6 @@ export default class Generator extends Base {
430396
}
431397
}, { local: require.resolve('generator-ng-component/app/index.js') });
432398
},
433-
434399
ngModules: function() {
435400
var angModules = [
436401
`'${this.scriptAppName}.constants'`,
@@ -450,7 +415,6 @@ export default class Generator extends Base {
450415

451416
this.angularModules = '\n ' + angModules.join(',\n ') +'\n';
452417
}
453-
454418
};
455419
}
456420

@@ -460,7 +424,6 @@ export default class Generator extends Base {
460424

461425
get writing() {
462426
return {
463-
464427
generateProject: function() {
465428
let self = this;
466429
this.sourceRoot(path.join(__dirname, './templates'));
@@ -472,12 +435,11 @@ export default class Generator extends Base {
472435
return dest;
473436
});
474437
},
475-
476438
generateEndpoint: function() {
477439
var models;
478-
if (this.filters.mongooseModels) {
440+
if(this.filters.mongooseModels) {
479441
models = 'mongoose';
480-
} else if (this.filters.sequelizeModels) {
442+
} else if(this.filters.sequelizeModels) {
481443
models = 'sequelize';
482444
}
483445
this.composeWith('angular-fullstack:endpoint', {
@@ -488,24 +450,20 @@ export default class Generator extends Base {
488450
args: ['thing']
489451
});
490452
}
491-
492453
};
493454
}
494455

495456
get install() {
496457
return {
497-
498458
installDeps: function() {
499459
this.installDependencies({
500460
skipInstall: this.options['skip-install']
501461
});
502462
}
503-
504463
};
505464
}
506465

507466
get end() {
508467
return {};
509468
}
510-
511469
}

0 commit comments

Comments
 (0)