How to share code and scripts?

I have code which I use accross multiple my Elixir projects. I have it locally. This includes bash, javascript scripts as well as Elixir code.

What’s the best way to edit it in one place and use the most recent version of it in all the projects? I don’t want to keep doing copy-paste to each project each time I update it.

Should I create a separate project “shared_code” and a special bash script which will copy and overwrite the latest version to each real project?

Or is there a smarter way to refer to it from each project? “ln -s” won’t work, will it?

Create a package and depend on it. Thats the way to go for elixir dependencies.

Bash scripts should be installed globally and made available to contributors in a separate repository.

If though you require them to be available, copy them to the repository in that version that you know to work.

1 Like

You could store these scripts in a separate git repository (if you are using a git repository) and add this repository to your projects as a git submodule (https://git-scm.com/book/en/v2/Git-Tools-Submodules). This allows you to track things when they change and pull the latest code without having to do things manually.

2 Likes

I’m the only owner, I don’t want a) any contributors and b) make the code public.

Always treat your code as if you would. That will help you much to understand it next week :wink:

And even for private stuff, I try to strictly separate between tools and sources. Especially as most of my tools have sources in their own repository.

I have about everything in a (private) repository on git{hub,lab} or bitbucket. Makes it easier to switch computers.

1 Like

What are you saying?

Basically, that all I said before remains valid, even if you do not want to publish at all.

1 Like

To each repo of each of my apps where I want to use my shared code? Any disadvantages to this?

I don’t use npm or bunch. How to install them?

How are npm and brunch related to your programs if you do not use npm or brunch?

How to install bash scripts globally?

Make them executable and drop them in your PATH.

2 Likes