Skip to content

Commit b3d09f0

Browse files
refactor(gen): read bower.json once
1 parent 8ccf8c6 commit b3d09f0

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

script-base.js

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,31 @@ var chalk = require('chalk');
88
var Generator = module.exports = function Generator() {
99
yeoman.generators.NamedBase.apply(this, arguments);
1010

11+
var bowerJson = {};
12+
1113
try {
12-
this.appname = require(path.join(process.cwd(), 'bower.json')).name;
13-
} catch (e) {
14+
bowerJson = require(path.join(process.cwd(), 'bower.json'));
15+
} catch (e) {}
16+
17+
if (bowerJson.name) {
18+
this.appname = bowerJson.name;
19+
} else {
1420
this.appname = path.basename(process.cwd());
1521
}
16-
this.appname = this._.slugify(this._.humanize(this.appname));
1722

18-
try {
19-
this.scriptAppName = require(path.join(process.cwd(), 'bower.json')).moduleName;
20-
} catch (e) {}
23+
this.appname = this._.slugify(this._.humanize(this.appname));
2124

22-
this.scriptAppName = this.scriptAppName || this._.camelize(this.appname) + angularUtils.appName(this);
25+
this.scriptAppName = bowerJson.moduleName || this._.camelize(this.appname) + angularUtils.appName(this);
2326

2427
this.cameledName = this._.camelize(this.name);
2528
this.classedName = this._.classify(this.name);
2629

2730
if (typeof this.env.options.appPath === 'undefined') {
28-
this.env.options.appPath = this.options.appPath;
29-
30-
if (!this.env.options.appPath) {
31-
try {
32-
this.env.options.appPath = require(path.join(process.cwd(), 'bower.json')).appPath;
33-
} catch (e) {}
34-
}
35-
this.env.options.appPath = this.env.options.appPath || 'app';
31+
this.env.options.appPath = this.options.appPath || bowerJson.appPath || 'app';
3632
this.options.appPath = this.env.options.appPath;
3733
}
3834

39-
if (typeof this.env.options.testPath === 'undefined') {
40-
try {
41-
this.env.options.testPath = require(path.join(process.cwd(), 'bower.json')).testPath;
42-
} catch (e) {}
43-
this.env.options.testPath = this.env.options.testPath || 'test/spec';
44-
}
35+
this.env.options.testPath = this.env.options.testPath || bowerJson.testPath || 'test/spec';
4536

4637
this.env.options.coffee = this.options.coffee;
4738
if (typeof this.env.options.coffee === 'undefined') {

0 commit comments

Comments
 (0)