Skip to content

Commit

Permalink
Merge pull request #17621 from ppcano/native-controller-blueprint
Browse files Browse the repository at this point in the history
Update controller blueprint to use native JS classes
  • Loading branch information
rwjblue committed Feb 15, 2019
2 parents fe93892 + 698e8b5 commit 98b3128
Show file tree
Hide file tree
Showing 26 changed files with 792 additions and 8 deletions.
5 changes: 3 additions & 2 deletions blueprints/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ const stringUtil = require('ember-cli-string-utils');
const pathUtil = require('ember-cli-path-utils');
const getPathOption = require('ember-cli-get-component-path-option');
const normalizeEntityName = require('ember-cli-normalize-entity-name');
const useEditionDetector = require('../edition-detector');
const isModuleUnificationProject = require('../module-unification').isModuleUnificationProject;
const EOL = require('os').EOL;

module.exports = {
module.exports = useEditionDetector({
description: 'Generates a component.',

availableOptions: [
Expand Down Expand Up @@ -101,4 +102,4 @@ module.exports = {
path: getPathOption(options),
};
},
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Component from '@ember/component';
<%= importTemplate %>
export default class <%= classifiedModuleName %>Component extends Component {<%= contents %>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{yield}}
5 changes: 3 additions & 2 deletions blueprints/controller/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';

const useEditionDetector = require('../edition-detector');
const isModuleUnificationProject = require('../module-unification').isModuleUnificationProject;
const path = require('path');

module.exports = {
module.exports = useEditionDetector({
description: 'Generates a controller.',
fileMapTokens() {
if (isModuleUnificationProject(this.project)) {
Expand All @@ -26,4 +27,4 @@ module.exports = {
};
}
},
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Controller from '@ember/controller';

export default class <%= classifiedModuleName %>Controller extends Controller {
};
12 changes: 12 additions & 0 deletions blueprints/edition-detector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

const path = require('path');

module.exports = function(blueprint) {
blueprint.filesPath = function() {
let rootPath = process.env.EMBER_VERSION === 'OCTANE' ? 'native-files' : 'files';
return path.join(this.path, rootPath);
};

return blueprint;
};
5 changes: 3 additions & 2 deletions blueprints/route/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ const path = require('path');
const chalk = require('chalk');
const stringUtil = require('ember-cli-string-utils');
const EmberRouterGenerator = require('ember-router-generator');
const useEditionDetector = require('../edition-detector');
const isModuleUnificationProject = require('../module-unification').isModuleUnificationProject;

module.exports = {
module.exports = useEditionDetector({
description: 'Generates a route and a template, and registers the route with the router.',

availableOptions: [
Expand Down Expand Up @@ -139,7 +140,7 @@ module.exports = {
afterUninstall: function(options) {
updateRouter.call(this, 'remove', options);
},
};
});

function updateRouter(action, options) {
let entity = options.entity;
Expand Down
4 changes: 4 additions & 0 deletions blueprints/route/native-files/__root__/__path__/__name__.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Route from '@ember/routing/route';

export default class <%= classifiedModuleName %>Route extends Route {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{outlet}}
5 changes: 3 additions & 2 deletions blueprints/service/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';

const useEditionDetector = require('../edition-detector');
const isModuleUnificationProject = require('../module-unification').isModuleUnificationProject;

module.exports = {
module.exports = useEditionDetector({
description: 'Generates a service.',

fileMapTokens() {
Expand All @@ -18,4 +19,4 @@ module.exports = {
};
}
},
};
});
4 changes: 4 additions & 0 deletions blueprints/service/native-files/__root__/__path__/__name__.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Service from '@ember/service';

export default class <%= classifiedModuleName %>Service extends Service {
}
225 changes: 225 additions & 0 deletions node-tests/blueprints/component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const expect = chai.expect;

const generateFakePackageManifest = require('../helpers/generate-fake-package-manifest');
const enableModuleUnification = require('../helpers/module-unification').enableModuleUnification;
const enableOctane = require('../helpers/setup-test-environment').enableOctane;
const fixture = require('../helpers/fixture');

describe('Blueprint: component', function() {
Expand Down Expand Up @@ -489,6 +490,75 @@ describe('Blueprint: component', function() {
});
});

describe('in app - octane', function() {
enableOctane();

beforeEach(function() {
return emberNew()
.then(() =>
modifyPackages([
{ name: 'ember-qunit', delete: true },
{ name: 'ember-cli-qunit', dev: true },
])
)
.then(() => generateFakePackageManifest('ember-cli-qunit', '4.1.0'));
});

it('component foo', function() {
return emberGenerateDestroy(['component', 'foo'], _file => {
expect(_file('src/ui/components/foo/component.js')).to.equal(
fixture('component/native-component.js')
);

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

expect(_file('src/ui/components/foo/component-test.js')).to.equal(
fixture('component-test/default-template.js', {
replace: {
component: 'foo',
},
})
);
});
});

it('component x-foo', function() {
return emberGenerateDestroy(['component', 'x-foo'], _file => {
expect(_file('src/ui/components/x-foo/component.js')).to.equal(
fixture('component/native-component-dash.js')
);

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

expect(_file('src/ui/components/x-foo/component-test.js')).to.equal(
fixture('component-test/default-template.js', {
replace: {
component: 'x-foo',
},
})
);
});
});

it('component foo/x-foo', function() {
return emberGenerateDestroy(['component', 'foo/x-foo'], _file => {
expect(_file('src/ui/components/foo/x-foo/component.js')).to.equal(
fixture('component/native-component-nested.js')
);

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

expect(_file('src/ui/components/foo/x-foo/component-test.js')).to.equal(
fixture('component-test/default-template.js', {
replace: {
component: 'foo/x-foo',
},
})
);
});
});
});

describe('in addon', function() {
beforeEach(function() {
return emberNew({ target: 'addon' })
Expand Down Expand Up @@ -716,6 +786,106 @@ describe('Blueprint: component', function() {
});
});

describe('in addon - octane', function() {
enableOctane();

beforeEach(function() {
return emberNew({ target: 'addon' })
.then(() =>
modifyPackages([
{ name: 'ember-qunit', delete: true },
{ name: 'ember-cli-qunit', dev: true },
])
)
.then(() => generateFakePackageManifest('ember-cli-qunit', '4.1.0'));
});

it('component foo', function() {
return emberGenerateDestroy(['component', 'foo'], _file => {
expect(_file('src/ui/components/foo/component.js')).to.equal(
fixture('component/native-component.js')
);

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

expect(_file('src/ui/components/foo/component-test.js')).to.equal(
fixture('component-test/default-template.js', {
replace: {
component: 'foo',
path: 'my-addon::',
},
})
);
});
});

it('component x-foo', function() {
return emberGenerateDestroy(['component', 'x-foo'], _file => {
expect(_file('src/ui/components/x-foo/component.js')).to.equal(
fixture('component/native-component-dash.js')
);

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

expect(_file('src/ui/components/x-foo/component-test.js')).to.equal(
fixture('component-test/default-template.js', {
replace: {
component: 'x-foo',
path: 'my-addon::',
},
})
);
});
});

it('component foo/x-foo', function() {
return emberGenerateDestroy(['component', 'foo/x-foo'], _file => {
expect(_file('src/ui/components/foo/x-foo/component.js')).to.equal(
fixture('component/native-component-nested.js')
);

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

expect(_file('src/ui/components/foo/x-foo/component-test.js')).to.equal(
fixture('component-test/default-template.js', {
replace: {
component: 'foo/x-foo',
path: 'my-addon::',
},
})
);
});
});

it('component x-foo --dummy', function() {
return emberGenerateDestroy(['component', 'x-foo', '--dummy'], _file => {
expect(_file('tests/dummy/src/ui/components/x-foo/component.js')).to.equal(
fixture('component/native-component-dash.js')
);

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

expect(_file('src/ui/components/x-foo/component.js')).to.not.exist;

expect(_file('src/ui/components/x-foo/component-test.js')).to.not.exist;
});
});

it('component foo/x-foo --dummy', function() {
return emberGenerateDestroy(['component', 'foo/x-foo', '--dummy'], _file => {
expect(_file('tests/dummy/src/ui/components/foo/x-foo/component.js')).to.equal(
fixture('component/native-component-nested.js')
);

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

expect(_file('src/ui/components/foo/x-foo/component.js')).to.not.exist;

expect(_file('src/ui/components/foo/x-foo/component-test.js')).to.not.exist;
});
});
});

describe('in in-repo-addon', function() {
beforeEach(function() {
return emberNew({ target: 'in-repo-addon' })
Expand Down Expand Up @@ -903,4 +1073,59 @@ describe('Blueprint: component', function() {
});
});
});

describe('in in-repo-addon - octane', function() {
enableOctane();

beforeEach(function() {
return emberNew({ target: 'in-repo-addon' })
.then(() =>
modifyPackages([
{ name: 'ember-qunit', delete: true },
{ name: 'ember-cli-qunit', dev: true },
])
)
.then(() => generateFakePackageManifest('ember-cli-qunit', '4.1.0'));
});

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.equal(
fixture('component/native-component.js')
);

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.equal(
fixture('component-test/default-template.js', {
replace: {
component: 'foo',
path: 'my-addon::',
},
})
);
});
});

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')).to.equal(
fixture('component/native-component-dash.js')
);

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

expect(_file('packages/my-addon/src/ui/components/x-foo/component-test.js')).to.equal(
fixture('component-test/default-template.js', {
replace: {
component: 'x-foo',
path: 'my-addon::',
},
})
);
});
});
});
});
Loading

0 comments on commit 98b3128

Please sign in to comment.