Skip to content

chore: force component and route names to have dashes #467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions addon/ng2/blueprints/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ var dynamicPathParser = require('../../utilities/dynamic-path-parser');
var addBarrelRegistration = require('../../utilities/barrel-management');
var getFiles = Blueprint.prototype.files;

function validateName(name) {
if (name.indexOf('-') >= 0) {
return true;
} else if (name === name.toUpperCase()) {
return false;
} else if (name === name.toLowerCase()) {
return false;
}
return true;
}

module.exports = {
description: '',

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

this.dynamicPath = parsedPath;

if (!validateName(parsedPath.name)) {
throw 'Names must contain a dash either include a dash or multiCase name. (i.e. multiCase -> multi-case)';
}

return parsedPath.name;
},

Expand Down
22 changes: 22 additions & 0 deletions tests/acceptance/generate-component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,26 @@ describe('Acceptance: ng generate component', function () {
expect(existsSync(testPath)).to.equal(false);
});
});

it('ng generate component mycomp will fail: no dashes in name', () => {
return ng(['generate', 'component', 'mycomp'])
.then((exitCode) => {
expect(exitCode).to.equal(1);
});
});

it('ng generate component MYCOMP will fail: no dashes in name', () => {
return ng(['generate', 'component', 'MYCOMP'])
.then((exitCode) => {
expect(exitCode).to.equal(1);
});
});

it('ng generate component myComp will succeed', () => {
return ng(['generate', 'component', 'myComp'])
.then(() => {
var testPath = path.join(root, 'tmp', 'foo', 'src', 'client', 'app', 'my-comp', 'my-comp.component.ts');
expect(existsSync(testPath)).to.equal(true);
});
});
});