josephburnett / jd

JSON diff and patch
MIT License
826 stars 38 forks source link

Should web/serve/files.go be version controled? #31

Closed tad-lispy closed 3 years ago

tad-lispy commented 3 years ago

Hello! Thank you for developing this useful tool.

I'm not a go developer so please excuse my ignorance. I am trying to package your program using Nix Flakes with hope of contributing the flake.nix file to your repository. Truth be told I'm also learning Nix, so bear with me :grin:

I got some progress and was about to commit, but then I've noticed that when building or running tests web/serve/files.go got modified. Now I'm not sure if I should stage it or not. Looks like the file is generated:

https://github.com/josephburnett/jd/blob/19e9fd8433ac29b88fcb6d594d70590b5d667ead/web/pack/main.go#L28

So should it be committed to git? Or maybe it should be removed and ignored?

josephburnett commented 3 years ago

Currently files.go is generated and source controlled, so you should stage it. This isn't ideal but it's a temporary work around for users who get jd via go get github.com/josephburnett/jd. See https://github.com/josephburnett/jd/issues/28

I wanted to include the web UI with the commandline tool because it's a nice alternative way to play with diffs. And it's live, so you can see the diff be produced as you type. The UI uses jd as a library, so it's the same golang code compiled to web assembly. Just a different main that runs in a browser. All the data stays in the browser too; it doesn't make any service calls.

The web UI is just three files (also hosted from a GCS bucket at http://play.jd-tool.io/). In order to include them in the jd commandline binary, I base64 encode those three files into a golang source file (similar to go-bindata) and include them. So when the library changes, the two binaries need to be changed: 1) the native golang main and 2) the web assembly main.

I would prefer the web assembly be generated on demand, which happens with make release. But it doesn't work with go get. I think there's a way to have go get run commands when getting files via special comments. That would let me remove files.go from source control. But for now, that's the work around.

josephburnett commented 3 years ago

I figured out how to remove this file from version control without breaking go get using a build directive. https://github.com/josephburnett/jd/commit/05af9a9f74d509338136eacdf0c05bb9e7373397