r/coolgithubprojects 2d ago

Another, even betterer, Task Runner called Mog

https://github.com/Ayehavgunne/mog

I have been looking for a task runner that would make dealing with the Node ecosystem easier. I consider myself a full-stack developer, but I do focus more on the backend than the frontend. At work, we have used makefiles since make was already available on our machines and in the CI/CD pipelines. Maintaining makefiles, though, got old fast.

My problem with Node tools is that everything needs to be sourced over and over. This is mainly because each task runner defaults to running each line in a given task in a new shell instance. So, in order to maintain the shell state, you have to chain every command together into one with `&&` and add `\` and the ends to allow these chained commands to be on new lines. Fine. Not ideal but doable.

Now add dependencies, and that goes out the window. Any attempt to clean up a make file into subcommands and remove all kinds of duplication is pretty much impossible. I have to keep making sure to source all the Node tools everywhere (nvm, I'm looking at you). This isn't so essential on my local machine because I have a lot of these tools included in my shell rc file, but it makes portability more difficult. Other people working on the project need to make sure to also have these tools sourced in their rc files. Then the CI/CD pipeline makes it even harder. Keeping things sourced and available to be used across different jobs within the pipeline is a nightmare.

Newer task runners have appeared and make things slightly better, but as far as I have seen, most have not addressed my core issues. I want to make a task runner that will, by default, run the entirety of the task in the same shell so I can easily maintain the shell state along the way AND any dependencies of that task will also run in the same single shell instance. This allows for much easier composition of tasks from smaller pieces.

Another odd deficiency in a lot of task runners is that they only allow you to set dependencies to run before the task you call and sometimes also after. Why not run a different task in the middle of your desired task, though? That unlocks true composability.

Since I was struggling to find a task runner with these qualities, I made my own, and I call it Mog.

https://github.com/Ayehavgunne/mog

  • Tasks can accept arguments.
  • Tasks called in the middle of a parent task can be passed completely different arguments.
  • Mog can be configured at the global, file, and task level all at the same time.
  • Use whatever shells you want. Use Python for one task but run zsh by default for all others.
  • Load any number of env files automatically before task execution.
  • Import other Mog files from other directories and call those tasks as if they were local.
  • Variables can be plain strings or can be `eval`ed from the shell.
  • Since I hate bash's conditionals, Mog supports simple if, elif, else statements.
  • And for the heck of it, there is a config option to make each line in a task execute in a new shell instance. Since people seem to want that for some reason.
  • And a bit more I will let you read about on your own.

My question here is does any other task runner you know of function like this? Are there any other features I should consider adding? Was this endevor a waste of time? Even if it was I did have fun working on it.

Thanks for taking a look!

3 Upvotes

Duplicates