Skip to content

Commit

Permalink
Use appname from bower.json if set
Browse files Browse the repository at this point in the history
  • Loading branch information
p-m-p committed Jan 11, 2014
1 parent dbd0a43 commit d28d75e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var fileLogger = { write: noop, warn: noop };
* @property {String} resolved - the path to the current generator
* @property {String} generatorName
* @property {String} description - Used in `--help` output
* @property {String} appname - Application name determine from the CWD folder
* @property {String} appname - The application name
* @property {Storage} config - `.yo-rc` config file manager
* @property {Object} src - File util instance scoped to `sourceRoot`
* @property {Object} dest - File util instance scoped to `destinationRoot`
Expand Down Expand Up @@ -121,7 +121,19 @@ var Base = module.exports = function Base(args, options) {
this._options = [];
this._hooks = [];
this._conflicts = [];
this.appname = path.basename(process.cwd()).replace(/[^\w\s]+?/g, ' ');

// Get the application name by either:
// - Looking in bower.json if already setup
// - Argv if supplied
// - Current working directory
try {
this.appname = require(path.join(process.cwd(), 'bower.json')).name;
}
catch (e) {
this.argument('appname', { type: String, required: false });
this.appname || (this.appname = path.basename(process.cwd()));
}
this.appname = this._.slugify(this._.humanize(this.appname));

this.option('help', {
alias: 'h',
Expand Down

0 comments on commit d28d75e

Please sign in to comment.