How I built an open source CLI tool in less than 24 hours

The last weekend I built an open source CLI tool in less than 24 hours, for the first time and this how I did it meanwhile I tweeted

✨ How I started

I noticed in my Ghost blog that when I upload any image, the blog creates another one optimized. But when you remove this image from the post or just delete the entire post, the images kept in the server.

So I just started to research what could I do


πŸ‘¨β€πŸ’» Coding to figure it out

I started to create a dirty script to validate if it would be possible

On one hand I fetched all posts & pages of the blog and on the other hand, get the list of all the uploaded images.

Then it matches if any uploaded image is being used on the post, page or metadata (twitter card, facebook card or post image)


πŸ”₯ Improving it

I got it running with success but needed some extra time to improve the code, turn into a CLI tool and test it.

So I ordered pizza and I kept working


I created a list action to just print the files list


Then I created the delete action


At this point I created the repository at Github


🧐 Learning on the fly

And started to turn it into a Command Line Interface (CLI). As I had no idea how to do it because I never did it before, I found some issues


Some time later I went to bed


And about 9h later I continued. Remember I have 2 kids and wife πŸ˜…


πŸ’Ž Testing

I fixed the previous issues but when testing in a real blog server I noticed I should update the script to don't remove the publication logo, cover and icon.


Some time later was done for publication logo and cover


About the publication icon (the blog favicon) was not a problem because Ghost creates the file favicon.ico from the uploaded image and does not use it anywhere later


I tested it in this blog and also in the Ghostboard blog


With success! πŸŽ‰


πŸ’… Final touches

Then I improved the README at the repo and added some screenshots


And that's all!


🌎 Resources

You can find:

Feel free to leave a comment with your feedback or any question πŸ™‚
πŸ‘‹ Thanks for reading!