Has anyone created a codemod for ember-bootstrap or at least one that works on template files?


#1

We’re converting a large app from using the bootstrap jQuery plugins to use ember-bootstrap instead. There are hundreds of tooltips and other bootstrap components littered throughout the code base, so we wanted to try using a codemod to automate converting the files if possible.

I’ve seen lots of examples of how to us jscodeshift to modify the .js files in an ember app, but haven’t found any examples of codemods that work on .hbs templates. I was able to use w/ ASTExplorer to parse .hbs content and remove things like data-toggle="tooltip":

https://astexplorer.net/#/gist/cf1131f07ee65caf39816bee92fa2150/4cca9fdd090dd4186ce83a24252429dd33d5c2d8

However, I’m not sure how to add new handlebars nodes like {{#bs-tooltip}}.

Any pointers in the right direction would be greatly appreciated.


#2

Last I knew, there’s not a handlebars AST printer that does a good job of preserving formatting. That is the main blocker to writing HBS code mods.

(People modify handlebars AST often, but it’s usually as a transform that runs at build time, so that the code it emits goes straight into the template compiler, not back out into your repo.)


Angle bracket invocation codemod