Re-generated `ElectronClient/app/lib/models/Setting.js` on build

While fiddling with adding to the desktop Preferences panel for this PR, I got quite confused by the fact that my code I was adding in ElectronClient/app/lib/models/Setting.js seemed to get deleted every time I rebuilt the desktop app.

Then I realized that it must be auto-generated on build or something, and that I should actually be editing ReactNativeClient/lib/models/Setting.js to get the effect I wanted. Once I did that, the code was then copied correctly into the corresponding ElectronClient/ file I’d previously been trying to edit directly, and the Preference pane successfully updated.

This was pretty confusing, and I imagine it’ll confuse other devs in the future too. Would it make sense to add a message something like this to the top of the ReactNativeClient/ file (and thus the generated ElectronClient/ file too)?


/***********************************************************************
 ***********************************************************************
 ****                                                               ****
 ****  Each build regenerates                                       ****
 ****  ElectronClient/app/lib/models/Setting.js from                ****
 ****  ReactNativeClient/lib/models/Setting.js, so only edit the    ****
 ****  latter and not the former, otherwise you'll be confused      ****
 ****  about why your code keeps disappearing.                      ****
 ****                                                               ****
 ***********************************************************************
 ***********************************************************************/

This isn’t exactly an elegant solution, so I’d love other better ideas too!

Or maybe we can add it to the BUILD.md file. But whatever makes the process more clear is fine with me, but it’s not my decision.

In fact the entire lib directory is taken from ReactNativeClient. The run script calls build, which in turn rsyncs the lib dir before starting the build.

It used to be that you had to set up the rsync manually so during build setup there was at least some mention.

How about if there was a diff performed at the start of run.sh that checks if the electron client version has been edited, we could probably use git to achieve that. This would mean the warning doesn’t have to be duplicated on all files and can appear for only those that make the mistake.

1 Like

Not a bad idea, but lib is in gitignore. And something like git ls-files -mo gives too much output, even if you grep app/lib/.

As @tessus, it’s the whole lib folder that gets copied on each build, but just Setting.js so the comment would not be enough.

I can’t think of any good simple solution to this actually:

I guess we could have a script that adds the header to all the files that have been copied. But the problem is that it’s slow, and it means stacktraces won’t show the right line anymore. We could solve this with source maps, but that’s not so simple and needs to work on all 3 apps.

Another way maybe would be to make the copied lib read-only? That won’t give any info, but at least it’s a hint that something is wrong if you try to edit one of these files?