Jur van den Berg cb8400eea3
Some checks reported errors
continuous-integration/drone/push Build was killed
Cleanup frontend
2022-04-19 22:07:43 +02:00
2022-04-19 22:07:43 +02:00
2022-04-19 22:07:43 +02:00
2022-04-19 21:22:59 +02:00
2022-04-19 22:07:43 +02:00
2022-01-22 19:48:47 +01:00
2021-12-17 21:21:58 +01:00
2021-12-17 21:21:58 +01:00
2022-04-19 22:07:43 +02:00
2022-04-19 21:22:59 +02:00

Covergen

Just generates some magic PDF invoice covers using straight up dark magic.

Building it

# Builds the CLI
make build

# Builds the WASM blob
make wasm

Custom font notes

The PDF uses the font Mark, which isn't a commonly available font. For this reason they have been vendored into the repository in pkg/covergen/fonts together with the cp1252 character map (used in most PDFs because UTF-8 hasn't been invented yet in the PDF world). For usage in fpdf they need to be encoded, which is done throught he makefont tool provided by fpdf, see https://github.com/go-pdf/fpdf#nonstandard-fonts. The section linked will also provide instructions on how to use it, but for this specific repo, the call to regenerate or add more fonts is:

makefont --embed --enc=pkg/covergen/fonts/cp1252.map --dst=pkg/covergen/font_embed pkg/covergen/fonts/*.ttf

To get the makefont binary, clone the go-fpdf/fpdf repo and run go build in the makefont directory.

A note on WASM

An interesting architectural note about how WASM binaries are run in browsers is that you should not see it as a shell command 'exec'-ing out into a new binary, but rather as two processes living side by side. The calling a method exposed by WASM behaves more like doing IPC between the two processes. You can sort of see this happening in cmd/wasm/main.go where the main function is actually used. It registers the two exposed commands to the global scope (in browsers: window) before just deadlocking by waiting on an anonymous channel.

The most important note you should take from that is that the WASM binary can crash. If it crashes, it doesn't just 'boot itself' again. And the JS -> WASM boundary is very, very unsafe. Like 'do the smallest thing wrong and the program crashes' level of unsafe. No, type safety won't help you, you're literally playing with the equivalent of void pointers. Even panic recovery (present in the two exposed methods) doesn't protect against all of it.

I think where I'm going is just a strong warning to be very careful at that boundary. Don't trust any js.Value. Parse it thoroughly and quickly into golang-specified types.

Languages
JavaScript 34.6%
Go 34.4%
Vue 21.2%
TypeScript 6.3%
Makefile 2.2%
Other 1.3%