Skip to content

Commit 09f0f7b

Browse files
committed
feat(gen): allow app names to have custom suffix
Allow app names to have a custom suffix with app-suffix option. By default, it uses 'App' Breaks existing app names that began with a capital letter
1 parent 889befb commit 09f0f7b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+194
-165
lines changed

app/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22
var path = require('path');
33
var util = require('util');
4+
var angularUtils = require('../util.js');
45
var spawn = require('child_process').spawn;
56
var yeoman = require('yeoman-generator');
67

@@ -9,6 +10,14 @@ var Generator = module.exports = function Generator(args, options) {
910
yeoman.generators.Base.apply(this, arguments);
1011
this.argument('appname', { type: String, required: false });
1112
this.appname = this.appname || path.basename(process.cwd());
13+
this.appname = this._.camelize(this._.slugify(this._.humanize(this.appname)));
14+
15+
this.option('app-suffix', {
16+
desc: 'Allow a custom suffix to be added to the module name',
17+
type: String,
18+
required: 'false'
19+
});
20+
this.scriptAppName = this.appname + angularUtils.appName(this);
1221

1322
args = ['main'];
1423

route/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Generator.prototype.rewriteAppJs = function () {
2323
needle: '.otherwise',
2424
splicable: [
2525
" templateUrl: 'views/" + this.name + ".html'" + (coffee ? "" : "," ),
26-
" controller: '" + this._.classify(this.name) + "Ctrl'"
26+
" controller: '" + this.classedName + "Ctrl'"
2727
]
2828
};
2929

script-base.js

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ var Generator = module.exports = function Generator() {
1212
} catch (e) {
1313
this.appname = path.basename(process.cwd());
1414
}
15+
this.appname = this._.slugify(this._.humanize(this.appname));
16+
this.scriptAppName = this._.camelize(this.appname) + angularUtils.appName(this);
17+
18+
this.cameledName = this._.camelize(this.name);
19+
this.classedName = this._.classify(this.name);
1520

1621
if (typeof this.env.options.appPath === 'undefined') {
1722
try {

templates/coffeescript-min/app.coffee

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App', [<%= angularModules %>])
3+
angular.module('<%= scriptAppName %>', [<%= angularModules %>])
44
.config ['$routeProvider', ($routeProvider) ->
55
$routeProvider
66
.when '/',

templates/coffeescript-min/controller.coffee

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App')
4-
.controller '<%= _.classify(name) %>Ctrl', ['$scope', ($scope) ->
3+
angular.module('<%= scriptAppName %>')
4+
.controller '<%= classedName %>Ctrl', ['$scope', ($scope) ->
55
$scope.awesomeThings = [
66
'HTML5 Boilerplate'
77
'AngularJS'
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

3-
angular.module("<%= _.camelize(appname) %>App").config ["$provide", ($provide) ->
4-
$provide.decorator "<%= _.camelize(name) %>", ($delegate) ->
3+
angular.module("<%= scriptAppName").config ["$provide", ($provide) ->
4+
$provide.decorator "<%= cameledName %>", ($delegate) ->
55
# decorate the $delegate
66
$delegate
77
]
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App')
4-
.directive '<%= _.camelize(name) %>', [->
3+
angular.module('<%= scriptAppName %>')
4+
.directive '<%= cameledName %>', [->
55
template: '<div></div>'
66
restrict: 'E'
77
link: (scope, element, attrs) ->
8-
element.text 'this is the <%= _.camelize(name) %> directive'
8+
element.text 'this is the <%= cameledName %> directive'
99
]
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App')
4-
.filter '<%= _.camelize(name) %>', [() ->
3+
angular.module('<%= scriptAppName %>')
4+
.filter '<%= cameledName %>', [() ->
55
(input) ->
6-
'<%= _.camelize(name) %> filter: ' + input
6+
'<%= cameledName %> filter: ' + input
77
]
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App')
4-
.constant '<%= _.camelize(name) %>', 42
3+
angular.module('<%= scriptAppName %>')
4+
.constant '<%= cameledName %>', 42

templates/coffeescript-min/service/factory.coffee

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App')
4-
.factory '<%= _.camelize(name) %>', [() ->
3+
angular.module('<%= scriptAppName %>')
4+
.factory '<%= cameledName %>', [() ->
55
# Service logic
66
# ...
77

templates/coffeescript-min/service/provider.coffee

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App')
4-
.provider '<%= _.camelize(name) %>', [->
3+
angular.module('<%= scriptAppName %>')
4+
.provider '<%= cameledName %>', [->
55

66
# Private variables
77
salutation = 'Hello'
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App')
4-
.service '<%= _.classify(name) %>', () ->
3+
angular.module('<%= scriptAppName %>')
4+
.service '<%= classedName %>', () ->
55
# AngularJS will instantiate a singleton by calling "new" on this function
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App')
4-
.value '<%= _.camelize(name) %>', 42
3+
angular.module('<%= scriptAppName %>')
4+
.value '<%= cameledName %>', 42

templates/coffeescript-min/spec/controller.coffee

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
'use strict'
22

3-
describe 'Controller: <%= _.classify(name) %>Ctrl', () ->
3+
describe 'Controller: <%= classedName %>Ctrl', () ->
44

55
# load the controller's module
6-
beforeEach module '<%= _.camelize(appname) %>App'
6+
beforeEach module '<%= scriptAppName %>'
77

8-
<%= _.classify(name) %>Ctrl = {}
8+
<%= classedName %>Ctrl = {}
99
scope = {}
1010

1111
# Initialize the controller and a mock scope
1212
beforeEach inject ($controller, $rootScope) ->
1313
scope = $rootScope.$new()
14-
<%= _.classify(name) %>Ctrl = $controller '<%= _.classify(name) %>Ctrl', {
14+
<%= classedName %>Ctrl = $controller '<%= classedName %>Ctrl', {
1515
$scope: scope
1616
}
1717

Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict'
22

3-
describe 'Directive: <%= _.camelize(name) %>', () ->
3+
describe 'Directive: <%= cameledName %>', () ->
44

55
# load the directive's module
6-
beforeEach module '<%= _.camelize(appname) %>App'
6+
beforeEach module '<%= scriptAppName %>'
77

88
scope = {}
99

@@ -13,4 +13,4 @@ describe 'Directive: <%= _.camelize(name) %>', () ->
1313
it 'should make hidden element visible', inject ($compile) ->
1414
element = angular.element '<<%= _.dasherize(name) %>></<%= _.dasherize(name) %>>'
1515
element = $compile(element) scope
16-
expect(element.text()).toBe 'this is the <%= _.camelize(name) %> directive'
16+
expect(element.text()).toBe 'this is the <%= cameledName %> directive'
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
'use strict'
22

3-
describe 'Filter: <%= _.camelize(name) %>', () ->
3+
describe 'Filter: <%= cameledName %>', () ->
44

55
# load the filter's module
6-
beforeEach module '<%= _.camelize(appname) %>App'
6+
beforeEach module '<%= scriptAppName %>'
77

88
# initialize a new instance of the filter before each test
9-
<%= _.camelize(name) %> = {}
9+
<%= cameledName %> = {}
1010
beforeEach inject ($filter) ->
11-
<%= _.camelize(name) %> = $filter '<%= _.camelize(name) %>'
11+
<%= cameledName %> = $filter '<%= cameledName %>'
1212

13-
it 'should return the input prefixed with "<%= _.camelize(name) %> filter:"', () ->
13+
it 'should return the input prefixed with "<%= cameledName %> filter:"', () ->
1414
text = 'angularjs'
15-
expect(<%= _.camelize(name) %> text).toBe ('<%= _.camelize(name) %> filter: ' + text)
15+
expect(<%= cameledName %> text).toBe ('<%= cameledName %> filter: ' + text)
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict'
22

3-
describe 'Service: <%= _.classify(name) %>', () ->
3+
describe 'Service: <%= classedName %>', () ->
44

55
# load the service's module
6-
beforeEach module '<%= _.classify(appname) %>App'
6+
beforeEach module '<%= scriptAppName %>App'
77

88
# instantiate service
9-
<%= _.classify(name) %> = {}
10-
beforeEach inject (_<%= _.classify(name) %>_) ->
11-
<%= _.classify(name) %> = _<%= _.classify(name) %>_
9+
<%= classedName %> = {}
10+
beforeEach inject (_<%= classedName %>_) ->
11+
<%= classedName %> = _<%= classedName %>_
1212

1313
it 'should do something', () ->
14-
expect(!!<%= _.classify(name) %>).toBe true
14+
expect(!!<%= classedName %>).toBe true

templates/coffeescript/app.coffee

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App', [<%= angularModules %>])
3+
angular.module('<%= scriptAppName %>', [<%= angularModules %>])
44
.config ($routeProvider) ->
55
$routeProvider
66
.when '/',

templates/coffeescript/controller.coffee

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App')
4-
.controller '<%= _.classify(name) %>Ctrl', ($scope) ->
3+
angular.module('<%= scriptAppName %>')
4+
.controller '<%= classedName %>Ctrl', ($scope) ->
55
$scope.awesomeThings = [
66
'HTML5 Boilerplate'
77
'AngularJS'
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
angular.module("<%= _.camelize(appname) %>App").config ($provide) ->
4-
$provide.decorator "<%= _.camelize(name) %>", ($delegate) ->
3+
angular.module("<%= scriptAppName").config ($provide) ->
4+
$provide.decorator "<%= cameledName %>", ($delegate) ->
55
# decorate the $delegate
66
$delegate
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App')
4-
.directive('<%= _.camelize(name) %>', () ->
3+
angular.module('<%= scriptAppName %>')
4+
.directive('<%= cameledName %>', () ->
55
template: '<div></div>'
66
restrict: 'E'
77
link: (scope, element, attrs) ->
8-
element.text 'this is the <%= _.camelize(name) %> directive'
8+
element.text 'this is the <%= cameledName %> directive'
99
)

templates/coffeescript/filter.coffee

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App')
4-
.filter '<%= _.camelize(name) %>', () ->
3+
angular.module('<%= scriptAppName %>')
4+
.filter '<%= cameledName %>', () ->
55
(input) ->
6-
'<%= _.camelize(name) %> filter: ' + input
6+
'<%= cameledName %> filter: ' + input
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App')
4-
.constant '<%= _.camelize(name) %>', 42
3+
angular.module('<%= scriptAppName %>')
4+
.constant '<%= cameledName %>', 42

templates/coffeescript/service/factory.coffee

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App')
4-
.factory '<%= _.camelize(name) %>', () ->
3+
angular.module('<%= scriptAppName %>')
4+
.factory '<%= cameledName %>', () ->
55
# Service logic
66
# ...
77

templates/coffeescript/service/provider.coffee

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App')
4-
.provider '<%= _.camelize(name) %>', [->
3+
angular.module('<%= scriptAppName %>')
4+
.provider '<%= cameledName %>', [->
55

66
# Private variables
77
salutation = 'Hello'
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App')
4-
.service '<%= _.classify(name) %>', () ->
3+
angular.module('<%= scriptAppName %>')
4+
.service '<%= classedName %>', () ->
55
# AngularJS will instantiate a singleton by calling "new" on this function
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
'use strict'
22

3-
angular.module('<%= _.camelize(appname) %>App')
4-
.value '<%= _.camelize(name) %>', 42
3+
angular.module('<%= scriptAppName %>')
4+
.value '<%= cameledName %>', 42

templates/coffeescript/spec/controller.coffee

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
'use strict'
22

3-
describe 'Controller: <%= _.classify(name) %>Ctrl', () ->
3+
describe 'Controller: <%= classedName %>Ctrl', () ->
44

55
# load the controller's module
6-
beforeEach module '<%= _.camelize(appname) %>App'
6+
beforeEach module '<%= scriptAppName %>'
77

8-
<%= _.classify(name) %>Ctrl = {}
8+
<%= classedName %>Ctrl = {}
99
scope = {}
1010

1111
# Initialize the controller and a mock scope
1212
beforeEach inject ($controller, $rootScope) ->
1313
scope = $rootScope.$new()
14-
<%= _.classify(name) %>Ctrl = $controller '<%= _.classify(name) %>Ctrl', {
14+
<%= classedName %>Ctrl = $controller '<%= classedName %>Ctrl', {
1515
$scope: scope
1616
}
1717

Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict'
22

3-
describe 'Directive: <%= _.camelize(name) %>', () ->
3+
describe 'Directive: <%= cameledName %>', () ->
44

55
# load the directive's module
6-
beforeEach module '<%= _.camelize(appname) %>App'
6+
beforeEach module '<%= scriptAppName %>'
77

88
scope = {}
99

@@ -13,4 +13,4 @@ describe 'Directive: <%= _.camelize(name) %>', () ->
1313
it 'should make hidden element visible', inject ($compile) ->
1414
element = angular.element '<<%= _.dasherize(name) %>></<%= _.dasherize(name) %>>'
1515
element = $compile(element) scope
16-
expect(element.text()).toBe 'this is the <%= _.camelize(name) %> directive'
16+
expect(element.text()).toBe 'this is the <%= cameledName %> directive'
+6-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
'use strict'
22

3-
describe 'Filter: <%= _.camelize(name) %>', () ->
3+
describe 'Filter: <%= cameledName %>', () ->
44

55
# load the filter's module
6-
beforeEach module '<%= _.camelize(appname) %>App'
6+
beforeEach module '<%= scriptAppName %>'
77

88
# initialize a new instance of the filter before each test
9-
<%= _.camelize(name) %> = {}
9+
<%= cameledName %> = {}
1010
beforeEach inject ($filter) ->
11-
<%= _.camelize(name) %> = $filter '<%= _.camelize(name) %>'
11+
<%= cameledName %> = $filter '<%= cameledName %>'
1212

13-
it 'should return the input prefixed with "<%= _.camelize(name) %> filter:"', () ->
13+
it 'should return the input prefixed with "<%= cameledName %> filter:"', () ->
1414
text = 'angularjs'
15-
expect(<%= _.camelize(name) %> text).toBe ('<%= _.camelize(name) %> filter: ' + text)
15+
expect(<%= cameledName %> text).toBe ('<%= cameledName %> filter: ' + text)
+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict'
22

3-
describe 'Service: <%= _.classify(name) %>', () ->
3+
describe 'Service: <%= classedName %>', () ->
44

55
# load the service's module
6-
beforeEach module '<%= _.classify(appname) %>App'
6+
beforeEach module '<%= scriptAppName %>App'
77

88
# instantiate service
9-
<%= _.classify(name) %> = {}
10-
beforeEach inject (_<%= _.classify(name) %>_) ->
11-
<%= _.classify(name) %> = _<%= _.classify(name) %>_
9+
<%= classedName %> = {}
10+
beforeEach inject (_<%= classedName %>_) ->
11+
<%= classedName %> = _<%= classedName %>_
1212

1313
it 'should do something', () ->
14-
expect(!!<%= _.classify(name) %>).toBe true
14+
expect(!!<%= classedName %>).toBe true

0 commit comments

Comments
 (0)