Skip to content
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

[BUGFIX beta] Blueprints can generate components with a single word name #17153

Merged
merged 1 commit into from
Oct 29, 2018
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
7 changes: 2 additions & 5 deletions blueprints/component-addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

const path = require('path');
const stringUtil = require('ember-cli-string-utils');
const validComponentName = require('ember-cli-valid-component-name');
const getPathOption = require('ember-cli-get-component-path-option');
const normalizeEntityName = require('ember-cli-normalize-entity-name');

module.exports = {
description: 'Generates a component. Name must contain a hyphen.',
description: 'Generates a component.',

fileMapTokens: function() {
return {
Expand All @@ -33,9 +32,7 @@ module.exports = {
},

normalizeEntityName: function(entityName) {
entityName = normalizeEntityName(entityName);

return validComponentName(entityName);
return normalizeEntityName(entityName);
},

locals: function(options) {
Expand Down
7 changes: 2 additions & 5 deletions blueprints/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
const path = require('path');
const stringUtil = require('ember-cli-string-utils');
const pathUtil = require('ember-cli-path-utils');
const validComponentName = require('ember-cli-valid-component-name');
const getPathOption = require('ember-cli-get-component-path-option');
const normalizeEntityName = require('ember-cli-normalize-entity-name');
const isModuleUnificationProject = require('../module-unification').isModuleUnificationProject;

module.exports = {
description: 'Generates a component. Name must contain a hyphen.',
description: 'Generates a component.',

availableOptions: [
{
Expand Down Expand Up @@ -72,9 +71,7 @@ module.exports = {
},

normalizeEntityName: function(entityName) {
entityName = normalizeEntityName(entityName);

return validComponentName(entityName);
return normalizeEntityName(entityName);
},

locals: function(options) {
Expand Down
7 changes: 7 additions & 0 deletions node-tests/blueprints/component-addon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ describe('Blueprint: component-addon', function() {
return emberNew({ target: 'addon' });
});

it('component-addon foo', function() {
return emberGenerateDestroy(['component-addon', 'foo'], _file => {
expect(_file('app/components/foo.js')).to.contain(
"export { default } from 'my-addon/components/foo';"
);
});
});
it('component-addon foo-bar', function() {
return emberGenerateDestroy(['component-addon', 'foo-bar'], _file => {
expect(_file('app/components/foo-bar.js')).to.contain(
Expand Down
145 changes: 145 additions & 0 deletions node-tests/blueprints/component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ describe('Blueprint: component', function() {
return emberNew();
});

it('component foo', function() {
return emberGenerateDestroy(['component', 'foo'], _file => {
expect(_file('app/components/foo.js'))
.to.contain("import Component from '@ember/component';")
.to.contain('export default Component.extend({')
.to.contain('});');

expect(_file('app/templates/components/foo.hbs')).to.equal('{{yield}}');

expect(_file('tests/integration/components/foo-test.js'))
.to.contain("import { moduleForComponent, test } from 'ember-qunit';")
.to.contain("import hbs from 'htmlbars-inline-precompile';")
.to.contain("moduleForComponent('foo'")
.to.contain('integration: true')
.to.contain('{{foo}}')
.to.contain('{{#foo}}');
});
});

it('component x-foo', function() {
return emberGenerateDestroy(['component', 'x-foo'], _file => {
expect(_file('app/components/x-foo.js'))
Expand Down Expand Up @@ -233,6 +252,25 @@ describe('Blueprint: component', function() {
setupPodConfig({ podModulePrefix: true });
});

it('component foo --pod', function() {
return emberGenerateDestroy(['component', 'foo', '--pod'], _file => {
expect(_file('app/pods/components/foo/component.js'))
.to.contain("import Component from '@ember/component';")
.to.contain('export default Component.extend({')
.to.contain('});');

expect(_file('app/pods/components/foo/template.hbs')).to.equal('{{yield}}');

expect(_file('tests/integration/pods/components/foo/component-test.js'))
.to.contain("import { moduleForComponent, test } from 'ember-qunit';")
.to.contain("import hbs from 'htmlbars-inline-precompile';")
.to.contain("moduleForComponent('foo'")
.to.contain('integration: true')
.to.contain('{{foo}}')
.to.contain('{{#foo}}');
});
});

it('component x-foo --pod', function() {
return emberGenerateDestroy(['component', 'x-foo', '--pod'], _file => {
expect(_file('app/pods/components/x-foo/component.js'))
Expand Down Expand Up @@ -394,6 +432,25 @@ describe('Blueprint: component', function() {
return emberNew().then(() => fs.ensureDirSync('src'));
});

it('component foo', function() {
return emberGenerateDestroy(['component', 'foo'], _file => {
expect(_file('src/ui/components/foo/component.js'))
.to.contain("import Component from '@ember/component';")
.to.contain('export default Component.extend({')
.to.contain('});');

expect(_file('src/ui/components/foo/template.hbs')).to.equal('{{yield}}');

expect(_file('src/ui/components/foo/component-test.js'))
.to.contain("import { moduleForComponent, test } from 'ember-qunit';")
.to.contain("import hbs from 'htmlbars-inline-precompile';")
.to.contain("moduleForComponent('foo'")
.to.contain('integration: true')
.to.contain('{{foo}}')
.to.contain('{{#foo}}');
});
});

it('component x-foo', function() {
return emberGenerateDestroy(['component', 'x-foo'], _file => {
expect(_file('src/ui/components/x-foo/component.js'))
Expand Down Expand Up @@ -438,6 +495,31 @@ describe('Blueprint: component', function() {
return emberNew({ target: 'addon' });
});

it('component foo', function() {
return emberGenerateDestroy(['component', 'foo'], _file => {
expect(_file('addon/components/foo.js'))
.to.contain("import Component from '@ember/component';")
.to.contain("import layout from '../templates/components/foo';")
.to.contain('export default Component.extend({')
.to.contain('layout')
.to.contain('});');

expect(_file('addon/templates/components/foo.hbs')).to.equal('{{yield}}');

expect(_file('app/components/foo.js')).to.contain(
"export { default } from 'my-addon/components/foo';"
);

expect(_file('tests/integration/components/foo-test.js'))
.to.contain("import { moduleForComponent, test } from 'ember-qunit';")
.to.contain("import hbs from 'htmlbars-inline-precompile';")
.to.contain("moduleForComponent('foo'")
.to.contain('integration: true')
.to.contain('{{foo}}')
.to.contain('{{#foo}}');
});
});

it('component x-foo', function() {
return emberGenerateDestroy(['component', 'x-foo'], _file => {
expect(_file('addon/components/x-foo.js'))
Expand Down Expand Up @@ -548,6 +630,26 @@ describe('Blueprint: component', function() {
return emberNew({ target: 'addon' }).then(() => fs.ensureDirSync('src'));
});

it('component foo', function() {
return emberGenerateDestroy(['component', 'foo'], _file => {
expect(_file('src/ui/components/foo/component.js'))
.to.contain("import Component from '@ember/component';")
.to.contain('export default Component.extend({')
.to.contain('});');

expect(_file('src/ui/components/foo/template.hbs')).to.equal('{{yield}}');

expect(_file('src/ui/components/foo/component-test.js'))
.to.contain("import { moduleForComponent, test } from 'ember-qunit';")
.to.contain("import hbs from 'htmlbars-inline-precompile';")
.to.contain("moduleForComponent('my-addon::foo'")
.to.contain('integration: true')
.to.contain('{{my-addon::foo}}')
.to.contain('{{#my-addon::foo}}')
.to.contain('{{/my-addon::foo}}');
});
});

it('component x-foo', function() {
return emberGenerateDestroy(['component', 'x-foo'], _file => {
expect(_file('src/ui/components/x-foo/component.js'))
Expand Down Expand Up @@ -626,6 +728,31 @@ describe('Blueprint: component', function() {
return emberNew({ target: 'in-repo-addon' });
});

it('component foo --in-repo-addon=my-addon', function() {
return emberGenerateDestroy(['component', 'foo', '--in-repo-addon=my-addon'], _file => {
expect(_file('lib/my-addon/addon/components/foo.js'))
.to.contain("import Component from '@ember/component';")
.to.contain("import layout from '../templates/components/foo';")
.to.contain('export default Component.extend({')
.to.contain('layout')
.to.contain('});');

expect(_file('lib/my-addon/addon/templates/components/foo.hbs')).to.equal('{{yield}}');

expect(_file('lib/my-addon/app/components/foo.js')).to.contain(
"export { default } from 'my-addon/components/foo';"
);

expect(_file('tests/integration/components/foo-test.js'))
.to.contain("import { moduleForComponent, test } from 'ember-qunit';")
.to.contain("import hbs from 'htmlbars-inline-precompile';")
.to.contain("moduleForComponent('foo'")
.to.contain('integration: true')
.to.contain('{{foo}}')
.to.contain('{{#foo}}');
});
});

it('component x-foo --in-repo-addon=my-addon', function() {
return emberGenerateDestroy(['component', 'x-foo', '--in-repo-addon=my-addon'], _file => {
expect(_file('lib/my-addon/addon/components/x-foo.js'))
Expand Down Expand Up @@ -737,6 +864,24 @@ describe('Blueprint: component', function() {
return emberNew({ target: 'in-repo-addon' }).then(() => fs.ensureDirSync('src'));
});

it('component foo --in-repo-addon=my-addon', function() {
return emberGenerateDestroy(['component', 'foo', '--in-repo-addon=my-addon'], _file => {
expect(_file('packages/my-addon/src/ui/components/foo/component.js'))
.to.contain('export default Component.extend({')
.to.contain('});');

expect(_file('packages/my-addon/src/ui/components/foo/template.hbs')).to.equal('{{yield}}');

expect(_file('packages/my-addon/src/ui/components/foo/component-test.js'))
.to.contain("import { moduleForComponent, test } from 'ember-qunit';")
.to.contain("import hbs from 'htmlbars-inline-precompile';")
.to.contain("moduleForComponent('my-addon::foo'")
.to.contain('integration: true')
.to.contain('{{#my-addon::foo}}')
.to.contain('{{my-addon::foo}}');
});
});

it('component x-foo --in-repo-addon=my-addon', function() {
return emberGenerateDestroy(['component', 'x-foo', '--in-repo-addon=my-addon'], _file => {
expect(_file('packages/my-addon/src/ui/components/x-foo/component.js'))
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"ember-cli-normalize-entity-name": "^1.0.0",
"ember-cli-path-utils": "^1.0.0",
"ember-cli-string-utils": "^1.1.0",
"ember-cli-valid-component-name": "^1.0.0",
"ember-cli-version-checker": "^2.1.0",
"ember-router-generator": "^1.2.3",
"inflection": "^1.12.0",
Expand Down