Cryogen using Deps and CLI

Bare Metal

I have always strived to know the lower-level tools. The tools that make you understand what is going on without inloving a lot of magic. Because when systems with magic break, it's really hard to figure out the spell that brought it together.

Leiningen is such a tool. Now I'll give credit where credit is due. There is nothing wrong with it and it solves a lot of problems for you. But when one wishes to do something small and simple, it often times feel like a bit of overload. It may be an indication of inexperience, I won't argue that. There is just so much to learn, and loads of magic.

I started exploring Clojure Deps and CLI after many recent artricles and posts jused it and I started to wonder why there is another Clojure tool. Isn't Boot and Leiningen enough?
So I went down the road of discovery and it was a bit frustrating at the time. But after a while I started seeing the benefit of it all. It's like getting to know your JDK tools really well, outside of an IDE! Now I would not say that I have mastered it by a long margin, but I'm getting there. Troubleshooting and figuring out what I can do is becoming easier, and the easier it gets, the more powerful it feels.

Cryogen

So when I first got started with Cryogen less than 24 hours ago, I saw that I needed to create the base application from a template using ~ $ lein new cryogen my-blog. I went with it, but wanted to see if I can get away with Deps + CLI.

After some back and forth I could figure out that there are a couple of basic things:

  • Generating the static content from the configuration and Markdown files
  • Watching the directories for changes
  • Serving the content.

So I started off with my minimal deps.edn file:

{:deps {}
 :paths []
 :aliases {}}

Because I've learned about how Deps look for sources and resources, I "got lucky" and knew that for :paths I had to include my src, content and themes directiories. The :deps I just copied from the project.clj file as is (updated for deps.edn) and added a :build and :serve alias to give me this:

{:deps
 {org.clojure/clojure {:mvn/version "1.10.0"}
  ring/ring-devel {:mvn/version "1.7.1"}
  compojure {:mvn/version "1.6.1"}
  ring-server {:mvn/version "0.5.0"}
  cryogen-flexmark {:mvn/version "0.1.2"}
  cryogen-core {:mvn/version "0.3.1"}}
 
 :paths
 ["src" "content" "themes"]
 
 :aliases
 {:build {:main-opts ["-m" "cryogen.core"]}
  :serve {:main-opts ["-m" "cryogen.server"]}}}

Now when I want to update the resources without serving using a local server, I do:

~ $ clj -A:build

And when I want to do development, I do:

~ $ clj -A:serve

The trick here is that I have figured out how to correctly translate lein run and its variations of commands to simpler clj -m <namespace> aliases in deps.cli.

The Cryogen project is kind enough to provide cryogen.core and cryogen.server namespaces which I could use as-is, and just add my own main function to launch the ring handler using ring-server:

(ns cryogen.server)
...
...
(defn -main [& args]
  (init)
  (ring-server/serve handler {:port 3000}))

If you have a repl handy, it's easy enough to use (init) only, as that does the watching on changes in files and rebuild when needed.

It feels a bit more snappy than having to wait for lein to finish doing its thing, and that generally makes me a happier person.

Right now I'm a fan of Cryogen as it is simple and straight forward. Customising the theme was like stealing candy from a baby hehe! I hope this can help someone out there, or even just myself, sometime in the future!

Happy coding!



Copyright © 2020 Johan Mynhardt
Powered by Cryogen
Theme by KingMob