Skip to content

Commit 0e103c8

Browse files
committed
chore: force component and route names to have dashes
1 parent e25844a commit 0e103c8

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

addon/ng2/blueprints/component/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ var dynamicPathParser = require('../../utilities/dynamic-path-parser');
44
var addBarrelRegistration = require('../../utilities/barrel-management');
55
var getFiles = Blueprint.prototype.files;
66

7+
function validateName(name) {
8+
if (name.indexOf('-') >= 0) {
9+
return true;
10+
} else if (name === name.toUpperCase()) {
11+
return false;
12+
} else if (name === name.toLowerCase()) {
13+
return false;
14+
}
15+
return true;
16+
}
17+
718
module.exports = {
819
description: '',
920

@@ -16,6 +27,11 @@ module.exports = {
1627
var parsedPath = dynamicPathParser(this.project, entityName);
1728

1829
this.dynamicPath = parsedPath;
30+
31+
if (!validateName(parsedPath.name)) {
32+
throw 'Invalid name. Names must be camelCase or kabob-case';
33+
}
34+
1935
return parsedPath.name;
2036
},
2137

tests/acceptance/generate-component.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,26 @@ describe('Acceptance: ng generate component', function () {
137137
expect(existsSync(testPath)).to.equal(false);
138138
});
139139
});
140+
141+
it('ng generate component mycomp will fail: no dashes in name', () => {
142+
return ng(['generate', 'component', 'mycomp'])
143+
.then((exitCode) => {
144+
expect(exitCode).to.equal(1);
145+
});
146+
});
147+
148+
it('ng generate component MYCOMP will fail: no dashes in name', () => {
149+
return ng(['generate', 'component', 'MYCOMP'])
150+
.then((exitCode) => {
151+
expect(exitCode).to.equal(1);
152+
});
153+
});
154+
155+
it('ng generate component myComp will succeed', () => {
156+
return ng(['generate', 'component', 'myComp'])
157+
.then(() => {
158+
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', 'my-comp', 'my-comp.component.ts');
159+
expect(existsSync(testPath)).to.equal(true);
160+
});
161+
});
140162
});

0 commit comments

Comments
 (0)