0

I have an Angular library that i use in another project. I build my library with the following command:

ng build

Which creates a dist/my-library directory at the library root. I want to publish the dist content on a separate git repository so that it can be consumed directly by other projects.

I have created a git submodule but when i do a build and enter the dist directory, git doesn't see any changes. If i do:

git submodule update

it will detect changes but it will be detached from head, so i can't publish changes on the master branch.

The weird thing is that i managed to get it to work a few times by pure luck, so it must be a viable solution.

How can i get git to publish the content of the dist folder on the dedicated repository?

phd
  • 82,685
  • 13
  • 120
  • 165
Magnesium
  • 597
  • 6
  • 22
  • The better option would be to publish a private npm package for this library and install it directly in other projects. Did you consider that? – Lukasz Gawrys Aug 20 '21 at 12:07
  • I am thinking about it but i have to think first about what it implies for my company's policy. If i can get it to work, it might be several weeks before i get a server. – Magnesium Aug 20 '21 at 12:08
  • https://stackoverflow.com/a/36375256/7976758 Found in https://stackoverflow.com/search?q=%5Bgit-submodules%5D+detached+head – phd Aug 20 '21 at 13:51
  • Another option is to use [git-subtree](https://github.com/git/git/blob/master/contrib/subtree/git-subtree.txt). Something like `git subtree push -P dist dist-repo-URL` – phd Aug 20 '21 at 13:53
  • Thanks, i'll try it when i get back to work on Monday. – Magnesium Aug 20 '21 at 15:52

1 Answers1

0

I found this which works:

ng build
echo "gitdir: ../../.git/modules/dist/ngx-mylib" > dist/ngx-mylib/.git

Now when i go in my dist folder i can do a git add, commit and push. But i don't know what it does exactly so feel free to elaborate.

Magnesium
  • 597
  • 6
  • 22