Skip to content

Commit

Permalink
style(generators): normalize, simplify, colorize and/or fix phrasing …
Browse files Browse the repository at this point in the history
…of options and questions

Factor out generators` descriptions.
  • Loading branch information
cueedee committed Aug 29, 2016
1 parent 8a6aad6 commit 5ca66f2
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 72 deletions.
75 changes: 46 additions & 29 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ var AppGenerator = generators.Base.extend(
{
generators.Base.apply( this, arguments );

this.description = this._description( 'project and barebones app' );

this.argument(
'packageName'
, {
type: String
, required: false
, desc: 'The name of the webapp to create.'
, desc: 'The name of the app to create.'
}
);

Expand All @@ -49,7 +51,7 @@ var AppGenerator = generators.Base.extend(
'packageName'
, {
type: String
, desc: 'The name of the webapp to create.'
, desc: 'The name of the app to create.'
, default: this.packageName
, hide: true
}
Expand All @@ -61,55 +63,55 @@ var AppGenerator = generators.Base.extend(
'description'
, {
type: String
, desc: 'The purpose of the webapp to create.'
, desc: 'The purpose of this app.'
}
);

this.option(
'authorName'
, {
type: String
, desc: 'The name of the main author creating the webapp.'
, desc: 'The name of the main author creating this app.'
}
);

this.option(
'authorEmail'
, {
type: String
, desc: 'The email address of the main author creating the webapp.'
, desc: 'The email address of this author.'
}
);

this.option(
'authorUrl'
, {
type: String
, desc: 'A website url identifying the main author creating the webapp.'
, desc: 'An optional website URL identifying this author.'
}
);

this.option(
'copyrightOwner'
, {
type: String
, desc: 'The full name of the webapp\'s copyright owner.'
, desc: 'The full name of the copyright owner of this app.'
}
);

this.option(
'i18n'
, {
type: Boolean
, desc: 'Specify whether internationalisation support is needed.'
, desc: 'Whether this app should support internationalisation'
}
);

this.option(
'i18nLocaleDefault'
, {
type: Boolean
, desc: 'Specify the default locale.'
, desc: 'The default locale for this app.'
, alias: 'locale'
}
);
Expand All @@ -118,26 +120,19 @@ var AppGenerator = generators.Base.extend(
'ie8'
, {
type: Boolean
, desc: 'Specify whether internet explorer version 8 support is needed.'
, desc: 'Whether this app should still support IE8.'
}
);

this.option(
'demo'
, {
type: Boolean
, desc: 'Specify whether the demonstration app should also be included.'
, desc: 'Whether the demonstration app should also be included.'
}
);
}

, description:
chalk.bold(
'This is the ' + chalk.cyan( 'project and barebones app' )
+ ' generator for BAT, the Backbone Application Template'
+ ' created by ' + chalk.blue( 'marv' ) + chalk.red( 'iq' ) + '.'
)

, initializing: function ()
{
// Load the BAT generator's 'package.json'.
Expand All @@ -162,7 +157,7 @@ var AppGenerator = generators.Base.extend(
{
type: 'input'
, name: 'packageName'
, message: 'What is the name of this webapp you so desire?'
, message: 'What is the name of this app you so desire?'
, default:
(
youtil.definedToString( this.options.packageName )
Expand All @@ -173,38 +168,38 @@ var AppGenerator = generators.Base.extend(
, {
type: 'input'
, name: 'description'
, message: 'What is the purpose (description) of this webapp?'
, message: 'What is the purpose (description) of this app?'
, default: youtil.definedToString( this.options.description )
, validate: youtil.isNonBlank
, filter: youtil.sentencify
}
, {
type: 'input'
, name: 'authorName'
, message: 'What is the main author\'s name?'
, message: 'What is the name of the main author creating this app?'
, default: ( youtil.definedToString( this.options.auhorName ) || youtil.definedToString( this.user.git.name() ))
, validate: youtil.isNonBlank
, filter: clean
}
, {
type: 'input'
, name: 'authorEmail'
, message: 'What is the main author\'s email address?'
, message: 'What is the email address of this author?'
, default: ( youtil.definedToString( this.options.auhorEmail ) || youtil.definedToString( this.user.git.email() ))
, validate: youtil.isNonBlank
, filter: _.trim
}
, {
type: 'input'
, name: 'authorUrl'
, message: 'If any, what is the main author\'s website url?'
, message: 'If any, what is the website URL identifying this author?'
, default: ( youtil.definedToString( this.options.auhorUrl ) || '' )
, filter: _.trim
}
, {
type: 'input'
, name: 'copyrightOwner'
, message: 'What is the full name of the copyright owner of this webapp?'
, message: 'What is the full name of the copyright owner of this app?'
, default: function ( answers )
{
return (
Expand All @@ -220,13 +215,23 @@ var AppGenerator = generators.Base.extend(
, {
type: 'confirm'
, name: 'i18n'
, message: 'Do you need internationalisation support?'
, message: 'Should this app support internationalisation?'
, default: false
}
, {
type: 'input'
, name: 'i18nLocaleDefault'
, message: 'What should the default locale be? (Please use a valid [BCP 47 language tag](https://tools.ietf.org/html/bcp47#section-2))'
, message: ( 'What is the default locale for this app?'
+ chalk.gray(
' - please use a valid '
+ chalk.cyan( '[' )
+ 'BCP 47 language tag'
+ chalk.cyan( '](' )
+ chalk.blue( 'https://tools.ietf.org/html/bcp47#section-2' )
+ chalk.cyan( ')' )
+ '.'
)
)
, default: ( youtil.definedToString( this.options.i18nLocaleDefault ) || 'en-US' )
, validate: tags.check
, filter: function ( value )
Expand All @@ -241,19 +246,31 @@ var AppGenerator = generators.Base.extend(
, {
type: 'confirm'
, name: 'jqueryCdn'
, message: 'Would you like your app to load jQuery from a CDN (googleapis.com) instead of bundling it?'
, message: (
'Should this app load jQuery from a CDN '
+ chalk.gray( '(googleapis.com)' )
+ ' instead of bundling it?'
)
, default: false
}
, {
type: 'confirm'
, name: 'ie8'
, message: 'Do you need IE8 and lower support? (affects the jQuery version and shims HTML5 and media query support)'
, message: (
'Should this app still support IE8?'
+ chalk.gray( ' - affects the jQuery version and shims HTML5 and media query support.' )
)
, default: false
}
, {
type: 'confirm'
, name: 'demo'
, message: 'Would you like the demo app now? (If not, you can always get it later through `yo bat:demo`)'
, message: (
'Would you like the demo app now?'
+ chalk.gray( ' - if not, you can always get it later through `' )
+ chalk.yellow( 'yo bat:demo ' )
+ chalk.gray( '`.' )
)
, default: false
}
]
Expand Down
22 changes: 8 additions & 14 deletions generators/collection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
var generators = require( 'yeoman-generator' )
, yosay = require( 'yosay' )
, youtil = require( './../../lib/youtil.js' )
, chalk = require( 'chalk' )
, _ = require( 'lodash' )
;

Expand All @@ -19,6 +18,8 @@ var CollectionGenerator = generators.Base.extend(
{
generators.Base.apply( this, arguments );

this.description = this._description( 'backbone collection' );

this.argument(
'collectionName'
, {
Expand Down Expand Up @@ -47,42 +48,35 @@ var CollectionGenerator = generators.Base.extend(
'description'
, {
type: String
, desc: 'The purpose of the collection to create.'
, desc: 'The purpose of this collection.'
}
);

this.option(
'singleton'
, {
type: Boolean
, desc: 'Specify whether this collection should be a singleton (instance).'
, desc: 'Whether this collection should be a singleton (instance).'
}
);

this.option(
'modelName'
, {
type: String
, desc: 'The model name for the collection to create.'
, desc: 'The model name for this collection.'
}
);

this.option(
'createModel'
, {
type: Boolean
, desc: 'Specify whether to create the collection\'s model too.'
, desc: 'Whether to create this model too.'
}
);
}

, description:
chalk.bold(
'This is the ' + chalk.cyan( 'backbone collection' )
+ ' generator for BAT, the Backbone Application Template'
+ ' created by ' + chalk.blue( 'marv' ) + chalk.red( 'iq' ) + '.'
)

, initializing: function ()
{
this._assertBatApp();
Expand Down Expand Up @@ -122,7 +116,7 @@ var CollectionGenerator = generators.Base.extend(
, {
type: 'confirm'
, name: 'singleton'
, message: 'Should this collection be a singleton?'
, message: 'Should this collection be a singleton (instance)?'
, default: false
, validate: _.isBoolean
}
Expand All @@ -148,7 +142,7 @@ var CollectionGenerator = generators.Base.extend(
, {
type: 'confirm'
, name: 'createModel'
, message: 'Should i create this model now as well?'
, message: 'Should I create this model now as well?'
, default: true
, validate: _.isBoolean
}
Expand Down
10 changes: 2 additions & 8 deletions generators/demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//

var generators = require( 'yeoman-generator' )
, chalk = require( 'chalk' )
, tags = require( 'language-tags' )
, _ = require( 'lodash' )
;
Expand All @@ -24,6 +23,8 @@ var DemoGenerator = generators.Base.extend(
{
this._assertBatApp();

this.description = this._description( 'demo app' );

var npm = this.fs.readJSON( this.destinationPath( 'package.json' ));

// Container for template expansion data.
Expand All @@ -36,13 +37,6 @@ var DemoGenerator = generators.Base.extend(
;
}

, description:
chalk.bold(
'This is the ' + chalk.cyan( 'demo app' )
+ ' generator for BAT, the Backbone Application Template'
+ ' created by ' + chalk.blue( 'marv' ) + chalk.red( 'iq' ) + '.'
)

, configuring: function()
{
var config = this.config
Expand Down
15 changes: 5 additions & 10 deletions generators/model/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ var ModelGenerator = generators.Base.extend(
{
generators.Base.apply( this, arguments );

this.description = this._description( 'backbone model' );

this.argument(
'modelName'
, {
Expand Down Expand Up @@ -47,26 +49,19 @@ var ModelGenerator = generators.Base.extend(
'description'
, {
type: String
, desc: 'The purpose of the model to create.'
, desc: 'The purpose of this model.'
}
);

this.option(
'singleton'
, {
type: Boolean
, desc: 'Specify whether this model should be a singleton (instance).'
, desc: 'Whether this model should be a singleton (instance).'
}
);
}

, description:
chalk.bold(
'This is the ' + chalk.cyan( 'backbone model' )
+ ' generator for BAT, the Backbone Application Template'
+ ' created by ' + chalk.blue( 'marv' ) + chalk.red( 'iq' ) + '.'
)

, initializing: function ()
{
this._assertBatApp();
Expand Down Expand Up @@ -106,7 +101,7 @@ var ModelGenerator = generators.Base.extend(
, {
type: 'confirm'
, name: 'singleton'
, message: 'Should this model be a singleton?'
, message: 'Should this model be a singleton (instance)?'
, default: false
, validate: _.isBoolean
}
Expand Down
Loading

0 comments on commit 5ca66f2

Please sign in to comment.