Skip to content

Commit c2dd94c

Browse files
Broccofilipesilva
authored andcommitted
feat(generate): specify class type via dot notation (#2707)
Closes #2155 BREAKING CHANGE: The ability to specify a class type via an additional arg has been replaced by combining the name and type args separated by a dot
1 parent e562579 commit c2dd94c

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

packages/angular-cli/blueprints/class/index.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@ const getFiles = Blueprint.prototype.files;
66
module.exports = {
77
description: '',
88

9-
anonymousOptions: [
10-
'<class-type>'
11-
],
12-
139
availableOptions: [
1410
{ name: 'spec', type: Boolean }
1511
],
1612

1713
normalizeEntityName: function (entityName) {
18-
var parsedPath = dynamicPathParser(this.project, entityName);
14+
var parsedPath = dynamicPathParser(this.project, entityName.split('.')[0]);
1915

2016
this.dynamicPath = parsedPath;
2117
return parsedPath.name;
2218
},
2319

2420
locals: function (options) {
25-
var classType = options.args [2]
21+
const rawName = options.args[1];
22+
const nameParts = rawName.split('.')
23+
.filter(part => part.length !== 0);
24+
25+
const classType = nameParts[1];
2626
this.fileName = stringUtils.dasherize(options.entity.name);
2727
if (classType) {
28-
this.fileName += '.' + classType;
28+
this.fileName += '.' + classType.toLowerCase();
2929
}
3030

3131
options.spec = options.spec !== undefined ?

tests/acceptance/generate-class.spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ describe('Acceptance: ng generate class', function () {
4343
});
4444
});
4545

46-
it('ng generate class my-class model', function () {
47-
return ng(['generate', 'class', 'my-class', 'model']).then(() => {
46+
it('ng generate class my-class.model', function () {
47+
return ng(['generate', 'class', 'my-class.model']).then(() => {
4848
expect(existsSync(path.join(testPath, 'my-class.model.ts'))).to.equal(true);
4949
});
5050
});
@@ -55,8 +55,8 @@ describe('Acceptance: ng generate class', function () {
5555
});
5656
});
5757

58-
it(`ng generate class shared${path.sep}my-class model`, function () {
59-
return ng(['generate', 'class', 'shared/my-class', 'model']).then(() => {
58+
it(`ng generate class shared${path.sep}my-class.model`, function () {
59+
return ng(['generate', 'class', 'shared/my-class.model']).then(() => {
6060
expect(existsSync(path.join(testPath, 'shared', 'my-class.model.ts'))).to.equal(true);
6161
});
6262
});

0 commit comments

Comments
 (0)