Skip to content

[FEATURE] Add a --route-authoring-format option to the route generator #20835

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% if (addTitle) {%>import { pageTitle } from 'ember-page-title';

<%}%><template>
<% if (addTitle) {%>{{pageTitle "<%= routeName %>"}}
<%}%>{{outlet}}
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { TOC } from '@ember/component/template-only';
<% if (addTitle) {%>import { pageTitle } from 'ember-page-title';<%}%>

interface <%= routeName %>Signature {
Args: {
model: unknown;
controller: unknown;
};
}

<template>
<% if (addTitle) {%>{{pageTitle "<%= routeName %>"}}
<%}%>{{outlet}}
</template> satisfies TOC<<%= routeName %>Signature>;
23 changes: 23 additions & 0 deletions blueprints/route/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ module.exports = {
name: 'reset-namespace',
type: Boolean,
},
{
name: 'route-authoring-format',
type: ['loose', 'strict'],
default: 'loose',
aliases: [{ loose: 'loose' }, { strict: 'strict' }],
},
],

init() {
Expand Down Expand Up @@ -80,6 +86,23 @@ module.exports = {
};
},

files() {
let files = this._super.files.apply(this, arguments);

if (this.options.routeAuthoringFormat === 'strict') {
const strictFilesToRemove =
this.options.isTypeScriptProject || this.options.typescript ? '.gjs' : '.gts';
files = files.filter(
(file) =>
!(file.endsWith('.js') || file.endsWith('.hbs') || file.endsWith(strictFilesToRemove))
);
} else {
files = files.filter((file) => !(file.endsWith('.gjs') || file.endsWith('.gts')));
}

return files;
},

locals: function (options) {
let moduleName = options.entity.name;
let rawRouteName = moduleName.split('/').pop();
Expand Down
71 changes: 71 additions & 0 deletions node-tests/blueprints/route-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,77 @@ describe('Blueprint: route', function () {
});
});

it('route foo --route-authoring-format strict', function () {
return emberGenerateDestroy(
['route', 'foo', '--route-authoring-format', 'strict'],
(_file) => {
expect(_file('app/routes/foo.js')).to.equal(fixture('route/route.js'));

expect(_file('app/templates/foo.gjs')).to.equal(
fixture('route/strict-route-template.gjs')
);
expect(_file('app/templates/foo.hbs')).to.not.exist;

expect(_file('tests/unit/routes/foo-test.js')).to.equal(fixture('route-test/app.js'));

expect(file('app/router.js')).to.contain("this.route('foo')");
}
);
});

it('route foo --strict', function () {
return emberGenerateDestroy(['route', 'foo', '--strict'], (_file) => {
expect(_file('app/routes/foo.js')).to.equal(fixture('route/route.js'));

expect(_file('app/templates/foo.gjs')).to.equal(fixture('route/strict-route-template.gjs'));
expect(_file('app/templates/foo.hbs')).to.not.exist;

expect(_file('tests/unit/routes/foo-test.js')).to.equal(fixture('route-test/app.js'));

expect(file('app/router.js')).to.contain("this.route('foo')");
});
});

it('route foo --strict --typescript', function () {
return emberGenerateDestroy(['route', 'foo', '--strict', '--typescript'], (_file) => {
expect(_file('app/routes/foo.ts')).to.equal(fixture('route/route.js'));

expect(_file('app/templates/foo.gts')).to.equal(fixture('route/strict-route-template.gts'));
expect(_file('app/templates/foo.hbs')).to.not.exist;

expect(_file('tests/unit/routes/foo-test.ts')).to.equal(fixture('route-test/app.js'));

expect(file('app/router.js')).to.contain("this.route('foo')");
});
});

it('route foo --route-authoring-format loose', function () {
return emberGenerateDestroy(
['route', 'foo', '--route-authoring-format', 'loose'],
(_file) => {
expect(_file('app/routes/foo.js')).to.equal(fixture('route/route.js'));

expect(_file('app/templates/foo.hbs')).to.equal('{{page-title "Foo"}}\n{{outlet}}');

expect(_file('tests/unit/routes/foo-test.js')).to.equal(fixture('route-test/app.js'));

expect(file('app/router.js')).to.contain("this.route('foo')");
}
);
});

it('route foo --loose', function () {
return emberGenerateDestroy(['route', 'foo', '--loose'], (_file) => {
expect(_file('app/routes/foo.js')).to.equal(fixture('route/route.js'));

expect(_file('app/templates/foo.hbs')).to.equal('{{page-title "Foo"}}\n{{outlet}}');

expect(_file('tests/unit/routes/foo-test.js')).to.equal(fixture('route-test/app.js'));

expect(file('app/router.js')).to.contain("this.route('foo')");
});
});

it('route foo --pod', function () {
return emberGenerateDestroy(['route', 'foo', '--pod'], (_file) => {
expect(_file('app/foo.js/route.js')).to.not.exist;
Expand Down
6 changes: 6 additions & 0 deletions node-tests/fixtures/route/strict-route-template.gjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { pageTitle } from 'ember-page-title';

<template>
{{pageTitle "Foo"}}
{{outlet}}
</template>
14 changes: 14 additions & 0 deletions node-tests/fixtures/route/strict-route-template.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { TOC } from '@ember/component/template-only';
import { pageTitle } from 'ember-page-title';

interface FooSignature {
Args: {
model: unknown;
controller: unknown;
Comment on lines +6 to +7
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I matched what the template-tag codemod outputs.

};
}

<template>
{{pageTitle "Foo"}}
{{outlet}}
</template> satisfies TOC<FooSignature>;