Wails - You don't need CLIs anymore
Power of native desktop app with pleasant UI instead of a CLI tool.
I am a big fan of productivity tools and automating stuff.
A company where I work started the migration process from Zendesk Help Center (it's where all our documentation is hosted) to React based Docusaurus.
Big challenge that they faced is to migrate all of HTML-based articles to Markdown. In addition to that - each Markdown file has to be of .mdx
file format (which would allow. them to import assets, components and all that kind of good stuff that you usually use nowadays).
Sounds like a good place for a CLI tool, right? - that's what I thought.
Preparation
There is not much to it really, so I will be quick.
- Get all the data needed somewhere - which is in my case, a list of all articles that our documentation team wanted to migrate.
For that, I decided to export all the articles data from Zendesk Help Center into Google Spreadsheet. If you ever find yourself in the same position - use Awesome Table Connector addon, it's a seriously helpful tool.
- Decide on which programming language to choose from. There are only 2 languages in my belt (for now) I can choose from - JS or Go. But, I do prefer Go, so the choice here was obvious. And, as I soon will find out this was the right choice.
CLI Tool
Now that I have my data and chose the language, my CLI tool was fairly simple:
- With help of Google Service accounts, fetch list of HTML bodies from prepared Google Spreadsheet
- Transform each HTML body into a Markdown file, where the html-to-markdown package does all the heavy lifting.
- In the process of transforming, collect all the images and their URLs from
<img src=".." />
tags and download them. Had to be extra careful here though, as I am big fan of Go and its goroutines feature, making a big amount of network requests to download them (1200 image URLs) would lead to some troubles such as timeouts etc, thus it had to be batched. - Add imports of those images to each transformed
.mdx
file.
First version result
Because the tool is not for me personally, but for other teams, and the migration is an ongoing process for them, the tool cannot have hard coded values in it (such as Spreadsheet ID, for example) in order to not lose flexibility and be useful in the long run.
This resulted in a small handy CLI tool that did the job, that requested you to provide a Spreadsheet ID, Range where to look for and making sure you added the service account to the file's sharing list.
Replace CLI with Wails
Now, that's all nice and cool, but I remembered, absolutely randomly, that I stumbled upon a Go library called Wails.
This tool is designed to give Go developers means to build native desktop apps with front-end technologies, using HTML / CSS / JS. It's aiming to be an alternative to Electron (uses NodeJS as its backend) and another famous alternative out there - Tauri (which uses Rust as its backend). I am a web developer, so this sounds like an easy way to create a great UI.
It is truly amazing what the team behind Wails put together - intuitive API, lightweight build output (15 Mb for an application that used React + Tailwind + bundled all together to be native application). One big difference between Electron and Wails - they don't ship "browser" inside the bundle to the end-user. Another awesome thing, that I personally love - is binding generation between your Go codebase and JS. I love type safety, and this allows me to go fast and safe, making correct calls from front-end calls to Go and having a TypeScript compiler telling me what arguments are expected and will be returned.
So, in order to transform my CLI into a desktop app, I went for React + Tailwind + Vite. It took me half of the day in order to move the logic from CLI to the newly desktop app powered by Wails. And this is the result!
I think that's a pretty decent looking desktop application, compared to a boring CLI.
If you are interested - I'd be happy to write down the actual implementation guide in Wails, showing how you can achieve the same. Let me know :)