ember-codemod-pod-to-octane
ember-codemod-pod-to-octane copied to clipboard
Move template.hbs alongside route.js or component.js
Ember's component blueprint will nest components under the app/components/ directory. However it's also valid Ember to place components directly in a pod folder under the app/ root.
Both of these are valid components
app/
components/
my-pod-b/
component.js
template.hbs
my-pod-a/
component.js
template.hbs
Problem is route templates pod similarly to my-pod-a, and if all you're looking at is template.hbs you have no way to know if it's a route or a component template. You need the broader context of there being a route.js or component.js present.
If you have components stored like my-pod-a and run this codemod, the map-route-template will move the component's template.hbs into the app/templates/ folder, and map-component-classes will never move the component.js. This breaks the component.
I don't see a way to fix this with the current architecture. I think there needs to be a more broad map-route and map-component concept which, upon spotting a route.js or component.js, also look for the sibling template.hbs and move it appropriately.
One more complication is that a lone template.hbs as in
app/
my-pod-c/
template.hbs
is a route template, but the absence of sibling component.js is the only way to know that.
Maybe that speaks to another architectural approach where there's a generic map-template replacing map-component-template and map-route-template, and only that mapper peeks at siblings to figure out what kind of template it is
I didn't know that a component class could live outside the components folder, and appreciate your documenting an edge case (maybe it's an unintended bug in ember-cli or ember-source?).
In general, the codemods that I write target the 80% case, and I leave it up to end-developers to handle the other 20% (e.g. things specific to their project). Since the command ember g component creates component classes in components for podded projects and Ember CLI documents so in cli.emberjs.com, I think it's okay for the codemod to not handle this edge case.
# Copied from cli.emberjs.com
app
├── components
| └── tags
| ├── component.js
| └── template.hbs
├── post
| ├── controller.js
| ├── model.js
| ├── route.js
| └── template.hbs
├── app.js
├── index.html
├── resolver.js
└── router.js
I'll close the issue, as I think the described case is an edge case and don't currently have time to look into possible solutions. (Will reopen it later if needed.)