I have two monolithic ap…

2 minute read

I have two monolithic apps(angular and nestjs). I want to migrate to nx, what is the best way to do it and keep the commit history for both front-end and back-end?

Responses:

The support channel is a better place for questions :) But I have done this before and you have a few options. Easiest way is to scrap one of your repos history and use nx’s to migrate the frontend or backend. The other way is to use sub modules and a new repo to merge it all together (more complicated and time consuming)

Another option would be convert both of your repos separately into nx mono repos then checkout both converted repos into a new repos using git remotes into different folders app1/ app2/ then move everything into root of new repo. I hope this makes sense lol

I think the last option makes more sense to me. Could you explain a little bit more? I understood I could move both repos to nx independently. Do i need to create a new repo and then move both repos into my new repo (app1 and app2)?

I have a pretty decent process that needs some vetting I can get it this weekend some time.

Let us know. Thank you.

I ended up heading out of town, maybe tonight. process is similar to mine although there are a couple tools to help with the process.

would love to know what tools you used! Keep us posted. you will create a new repo and need to add the old repos as remotes ‘git remote -v’ will show you current remotes. Then set-url I believe is what you want. Add both app1 and 2 as remotes pointing to your locally copies. Then checkout each remote into a folder in your new repo and then start to merge the code today. At this point it all manual merging of code. Hope that helps

It’s git remote add <remotename> /local/file/path/to/repo

thanks, I should of wrote that after my morning coffee

This is a good article, it doesn’t specifically talk about the tool above but if you take the process and use the tool it is pretty helpful https://ondrejsevcik.com/merge-git-repos/

I reread my document I created and it needs to be updated a bit. The one step I add into the process mentioned by Alex and in the article, is to create the new application or library in the monorepo before starting the migration from the source.

So basically if you were migrating an angular app (and you cant migrate in the source repo beforehand) you would run the command to create the app

  1. In the monorepo create an empty project of the type you are migrating. In this scenario we will be migrating the member-admin-webui project and all examples will use that as the source repo.

    ng generate @nrwl/angular:application --name=member-admin-webui --style=scss --no-interactive
    

    This will create the folder structure and update the nx.json, angular.json, package.json, tslint.json for the new project.

  2. Now stash all the apps/member-admin-webui files we will use these later to make sure we get all the proper configuration.

    git add app/member-admin-webui
    git stash
    

Then you use the filter-repo tool to migrate from the source, then unstash your changes from the steps above and resolve conflicts. This helps you make sure your repo is structured correctly.

Updated: