Share code between KM App and KM Server
Some of our code is common between both server and app.
We could factor some of that code into either NPM modules, GIT tags or GIT submodules.
There are many ways to do this, and none are perfect :
NPM Modules
We rely on NPM's registry already, so that's not a real issue. We can create private NPM modules (like, for example @karaokemugen/tags to have a common authorized tag list)
Publishing new versions to NPM could be done with a CI/CD pipeline.
One disadvantage is that if you have to modify some code in one of the modules, you'll need to :
- Clone the module repo
- Make changes
- Git commit and push
- Wait for the package to be published on NPM
- On the main project, change package.json's dependencies to pull the new version
It's cleaner, but not particularly coveninent
GIT tags
Same as above except we don't use NPM and instead rely on git tags to know which version to pull in package.json.
Disadvantage is that it relies on Gitlab instead of NPM. If Shelter is down, no one can npm install our app.
GIT submodules
One advantage is that you can edit modules from inside the main project but it can become quite confusing and relies on some user configuration for normal git users (submodules aren't pulled by default, for example)
I insist on the confusing side of this. It has advantages but could bite us later when we least expect it. No git submodule tutorial is clear about anything.
So now, what to do...
list of stuff to modularize
List of things we can take outside of the KM main app :
-
Preview generation (on KM Server it's 3 pictures, on KM App it's a small video. A flag could enable either but the code is practically the same) -
Validators -
Object Helpers -
File helpers -
ffmpeg calls (same code on KMServer/KMApp, making this a prime candidate) -
Date helpers -
Types (once we switch KM Server to typescript, see karaokemugen/karaokemugen-server#26 ) -
Kara creation -
Database generation -
Kara and serie file management (DAO) Kara and serie database objects would be trickier since our schemas aren't the same at all.-
Database management (We use the same tools, so...) -
Tags and type lists