Skip to content

Commit

Permalink
Try package.json if bower.json not found
Browse files Browse the repository at this point in the history
  • Loading branch information
p-m-p committed Jan 11, 2014
1 parent 8215494 commit 5c96344
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ var Base = module.exports = function Base(args, options) {
this.appname = require(path.join(process.cwd(), 'bower.json')).name;
}
catch (e) {
this.appname = this.args[0] || path.basename(process.cwd());
try {
this.appname = require(path.join(process.cwd(), 'package.json')).name;
}
catch (e) {
this.appname = this.args[0] || path.basename(process.cwd());
}
}
this.appname = this.appname.replace(/[^\w\s]+?/g, ' ');

Expand Down
9 changes: 9 additions & 0 deletions test/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ describe('yeoman.generators.Base', function () {
delete require.cache[path.join(process.cwd(), 'bower.json')];
});

it('should pull app name from package.json', function () {
fs.writeFileSync('package.json', '{ "name": "package_app-name" }');
this.dummy = this.createDummyGenerator();
assert.equal(this.dummy.appname, 'package_app name');

fs.unlinkSync('package.json');
delete require.cache[path.join(process.cwd(), 'package.json')];
});

it('should be set with the project directory', function () {
this.dummy = this.createDummyGenerator();
assert.equal(this.dummy.appname, 'temp dev');
Expand Down

0 comments on commit 5c96344

Please sign in to comment.