We’re at the tail-end of one conversion and the start of another. There is a good amount of stuff to do, however, we completed the conversion in a week.
We broke it into 4 basic phases
- Restructuring the rails project to match the structure of an ember-cli project
- Creating the basic ember project with all the dependencies that we need
- Moving all front-end code over to the ember project
- Removing all front-end code from the rails project
Interestingly enough I believe the second is probably the biggest because it requires that we make sure all our libraries, and addons (that includes custom addons that we’ll need to create) are in the project.
Restructuring the rails project to match the structure of an ember-cli project
This is all about matching the file names and folder structure. For example some of our files had both the route and controller in the same file. This will need to be separated. It will also need to be renamed to match the right conventions for the resolver. Especially because we aren’t naming the object inside the file anymore (when it’s in ember-cli) but instead it’s based on the name.
We’ve opted for the pod structure from the beginning and so we continued using that. However we ended up making a couple of minor changes to the folder structure that I may put together in more detail at some point.
Creating the basic ember project with all the dependencies that we need
Here is where we create a brand new ember project and pull in any dependency that we need. For us that means
- ember-validations
- semantic-ui-ember
- ember-json-api
- ember-document-title
- ember-simple-auth
- …
But it also means our own extensions that we need to create custom addons for including
- ajax
- current-user
- errors
- generators
- schema
- …
You should have the basic working pieces of an app here with some testing routes before you start pulling application code over. Making sure you can call the api, validate things, titles get mapped, etc. It’s easier to test the basic working parts in this phase than we you have half of your application code ported over.
Moving all front-end code over to the ember project
Since we already renamed the files in the first step this phase is pretty mechanical and we use generators to build the structure with a simple copy. Goes like this
ember g route user/login
Open pods/user/login/route.coffee and take everything to the right of the object name
App.UserRoute = Ember.Route.extend(App.SomeMixin, {
// user code
})
and put it into our newly generated route
import Ember from 'ember'
UserRoute = Ember.Route.extend(App.SomeMixin, {
// user code
})
export default UserRoute
At this stage any objects you’re referencing such as “App.SomeMixin” will need to be pulled over and referenced properly as an ES6 module. We follow the tree, generate the mixin, copy the code and then reference it properly within the file.
Removing all front-end code from the rails project
This one is pretty easy. Drop all the existing code from the rails project, make sure all the API bits are intact. Call it good.