0

My TypeScript project consists of two parts: a client and a server. Both should share code (like types, domain specific functions) and so I'd like to create a core package that can be consumed by them.

I found out that this is more complicated than one might think, especially when it comes to CI and stuff.

So the easiest solution I can think about would be a single folder that is synchronized between my projects: If I edit a file in one project, the changes will be reflected immediately in the other project (since they refer to the same file). And yes, when it comes to version control, both projects will contain their own copy.

Is this possible with JetBrains IntelliJ / WebStorm?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
K. D.
  • 4,041
  • 9
  • 48
  • 72
  • 2
    `Settings/Preferences | Directories --> Add Content Root` I guess... https://www.jetbrains.com/help/webstorm/configuring-project-structure.html#adding_content_root – LazyOne Nov 20 '19 at 10:52
  • Thank you, but then the folder doesn't exist within the single projects and so the code will be missing in Git/CI, right? – K. D. Nov 20 '19 at 11:00
  • 1
    I guess so. P.S. You can have multiple VCS roots: https://www.jetbrains.com/help/webstorm/enabling-version-control.html#associate_directory_with_VCS **P.P.S.** Symlinks anyone? – LazyOne Nov 20 '19 at 11:03

1 Answers1

1

I'm not sure why do you want a separate copy of the core package for each project when it comes to version control. That's not the way it should handle. I'll suggest a better way to do this.

You have to use a dependency manager like npm for your projects (most probably you may using it already). Create 3 separate modules(projects) called client, server and core. Then add package.json for each project. Then you can add core module as a dependency for server and client modules. Please refer this for adding local dependencies to package.json if you are not aware of it.

But if you really, really want to stick to your method (keep your files synchronized) you can do it by creating a deployment profile (Tools > Deployment > Configuration > Click on + > Local or mounted folder) on Intellij Idea / WebStrom and enable automatic deployment.

Chathura Buddhika
  • 2,067
  • 1
  • 21
  • 35
  • Thank you very much. In fact, I'd be very happy if there would be a better way. However, this "local package" approach fails when it comes to CI, for instance. How can I make my `core` package available there? How will the development / production workflow be then? – K. D. Nov 22 '19 at 08:18
  • 1
    Ideally there should be one project (one VCS root) with 3 modules (sub directories). So you can just add version control to project directory where there will be only one repository. When it comes to CI/CD you can define it with 3 steps to build each module. – Chathura Buddhika Nov 23 '19 at 09:52
  • 1
    If you are really uncomfortable with one-project-3-modules approach, you can host a private npm registry and configure CI/CD to publish `core` package to it. (https://stackoverflow.com/questions/7575627/can-you-host-a-private-repository-for-your-organization-to-use-with-npm). Then access core module from `client` and `server` module just like any other npm package. – Chathura Buddhika Nov 23 '19 at 09:58