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

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":


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

Any pointers in the right direction would be greatly appreciated.

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.)

1 Like

I know this thread is far too old, but I stumbled upon this by coincidence, so for the record in case someone reads this again:

  • I have a PR to support template transforms in codemod-cli , using ember-template-recast that AFAICT does a decent job at preserving formatting, however when creating new AST nodes the formatting is usually not so perfect (i.e. violates ember-template-lint rules). The PR: https://github.com/rwjblue/codemod-cli/pull/81
  • Here is a codemod for templates and ember-bootstrap based on that that I recently worked on: https://github.com/kaliber5/ember-bootstrap-codemods. So it’s possible (now), but certainly way too late for the OP, sorry! :wink:
1 Like