-2

I am developing an Angular 4 (Angular CLI) project. My main app uses one git repository (http://..../main.git). I have 2 subprojects that will contain Angular 4 components (http://..../subproject1.git and http://..../subproject2.git).

This is the structure for main app

main-app

|----e2e

|----node_modules

|----src

-----|----app

----------|----components

----------|----submodules

-----|----assets

This is the structure for both subproject1 and subproject2 app

subproject1

|----JavaCode

-----|----...

|----AngularCode

-----|----components

----------|----component1

----------|----component2

subproject2

|----JavaCode

-----|----...

|----AngularCode

-----|----components

----------|----component3

----------|----component4

Is there any way I can "copy at build time" or make a symlink for the subprojects to reside under the folder

main-app

|----...

|----src

-----|----app

----------|----...

----------|----submodules

------------------|----subproject1 //AngularCode folder

------------------|----subproject2 //AngularCode folder

before the ng build phase runs, so Angular CLI could recognize my two submodules?

Alfredo A.
  • 1,697
  • 3
  • 30
  • 43

2 Answers2

0

You could actually make use of gut submodules: https://git-scm.com/book/en/v2/Git-Tools-Submodules

Basically you can use those to register a git repo as a submodule of another git repo. In your main repo git then always tracks one specific commit as the reference to your submodule. If you make changes to your submodules, you can then simply update to the latest commit by using git submodule update - - remote.

You can also just work on the submodule inside of your main project, then check in your changes in the submodule and afterwards update the reference in your main repo!

Might be useful to read through the documentation, but I'd say this is exactly what you want!

OClyde
  • 1,036
  • 6
  • 11
  • Not exactly. My git submodules contain other information and files (mainly, java code). Basically, my git submodule has one subfolder for the java code (Spring java backend code), and one for the Angular 5 code. I need to copy/move only the Angular part into my angular main-app. I updated my question to reflect that. – Alfredo A. Mar 20 '18 at 18:38
  • In this case I'd suggest you look at this question: https://stackoverflow.com/questions/5303496/how-to-change-a-git-submodule-to-point-to-a-subfolder Generally submodules do not allow you to do this, such a scenario can only be achieved using some kind of workaround as e.g. mentioned in the linked question! – OClyde Mar 20 '18 at 22:18
  • The question is not so much about git submodules as it is about building tools and angular cli. What I need is some sort of mechanism that handles the building process, that is able to copy the angular submodules (not git submodules) that are located in a path that is external to the main app folder. The mechanism should be able to copy those submodules to the app build path before the building process start. I had an AngularJS project (not Angular) that worked using this principle and used Grunt as the building tool, I need to know what is the tool I need to achieve this with Angular 4+ – Alfredo A. Mar 21 '18 at 00:22
  • Out of the box you won't find a utility doing this in the Angular CLI itself. As you said you could simply use grunt or gulp, setup the copy logic and then execute the build command automatically after the copy has finished. Even easier would be a bash script which would be more suitable for the copy task, then you simply create a "copy-build" script in your package.json which is executing "copy.sh && ng build", so that you can simply run "npm run copy-build", without even utilizing an extra tool. – OClyde Mar 21 '18 at 10:11
0

Ok, so I think I figure it out. I need to define my git submodules as Angular modules, and package them by using the ng-packagr tool. After that, I need to install them in my main project as a regular Angular module dependency.

For more references, you can check the project official url

Alfredo A.
  • 1,697
  • 3
  • 30
  • 43