Automates decaffeination and applies basic codemods to emulate an ember 2.x state Ember app in flux - in preparation for further upgrades.
Some of the https://github.com/linearza/ember-v2-codemods mods were inspired by:
The main differences are around how imports are handled, and slight improvements like the lack of user prompt inputs, in order to automate the process in this toolkit.
npm install ember2-coffeescript-conversion-toolkit -g
e2cct [command]
Commands:
e2cct convert [file] [optional: --nolint, --clean] Decaffeinate, codemod and lint a file
e2cct lint [file] Lint and fix possible issues
e2cct update Update e2cct to the latest version
e2cct reset Caution: Reverts unstaged changes and
decaffeinate commits.
e2cct clean Remove the .original.coffee artifact
files
Options:
--help Show help [boolean]
-v, --version Show version number [boolean]
- decaffeinate: Decaffeinating the file...
- legacy-computed-codemod: Converting .property() to computed()...
- legacy-observer-codemod: Converting .observes() to observer()...
- legacy-get-codemod: Converting this.get to get(this...
- legacy-set-codemod: Converting this.set to set(this...
- legacy-setProperties-codemod: Converting this.setProperties to setProperties(this...
- legacy-getProperties-codemod: Converting this.getProperties to getProperties(this...
- ember-modules-codemod: Converting Ember.Component.extend({ to Component.extend({...
- ember-computed-getter-codemod: Converting computed(function() to computed({get()...
- eslint: Fixing possible issues... Pass 1
- eslint: Fixing possible issues... Pass 2
Linting is done by default as part of the conversion process, if you would like to not lint you can pass in the optional --nolint
flag, eg e2cct path/to/file.coffee --nolint
.
Rules are inherited from the project.
NOTE: With bigger files you might have to run the linting more than once, we automatically do 2 passes for convenience. In case you still see the message indicating potentially fixable issues with the '--fix' option after the conversion, you can manually run linting again using e2cct lint
This toolkit makes the assumption that your project already aligns the prettier and eslint rules. If not, the automated fixing might result in a half-baked solution which potentially does not match your existing linting checks.
Worth noting is that bulk-decaffeinate
specifically aims to retain git history on files converted through it, nevertheless, if you squash the commits upon merging, instead of creating a merge commit you will lose some ability to navigate the history as per normal on providers like Github. That being said, the history is always traceable via the original commit which references the old .coffee
file. Additionally you can use the following command to log the full file history:
git log --oneline --follow --all -- path/to/my/converted/file.js
Once you have run the automated conversion, there are some manual steps required:
- Merge any imports depending on the same declarations if required
- Check if any Prettify rules are not yet applied, and amend.
- Add order category comments, eg:
// Services
- Do logic sanity check - feel free to open an issue here if you spot something
- Finally, delete the old .coffee file
- Unused imports
- Delete coffee file
- Update mod lifecycle hooks like: .on('willDestroyElement')