💾 Archived View for d.moonfire.us › blog › 2021 › 12 › 19 › yeoman-generators captured on 2022-04-29 at 11:21:48. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2022-04-28)
-=-=-=-=-=-=-
I create a lot of projects. I think between Github and Gitlab, I have a few hundred now. Much if it is because I started pushing toward strictly being one story per repository (OSPR). This means I have a lot of common patterns that not only do I have to set up but also maintain as my skills and knowledge evolve. The problem comes when I figure out a new pattern, I have to update a couple hundred repositories if I want to keep them consistent. Needless to say, this is one drawback of a monorepo but there are a lot of advantages of OSPR.
A lot of my inspiration comes from Larry Wall's Three Virtues of a Great Programmer:
This means, instead of manually doing it, I want to find a nice automated way (virtue one) that I can script and have it run across everything at once (virtue two).
Previously, I had used Yeoman[1] but I was wondering if I needed to break out of that to work on a “me-specific” CLI tool. That line of thought came down because so many of the tools I'm using all package their own custom CLIs. While I do enjoy writing a good CLI, I don't want to write one if I can't.
In the process of finding an alternative, I finally understood how to compose Yeoman generators together. That means I could create a generic project generator and then layer the writing[2] one on top of it.
At the same time, I could migrate away from asdf[3] and onto my preferred infrastructure du jour, Nix[4].
Side Note: Let me be honest, I'm constantly evolving my structures and they change as I learn new tools and my processes change with me. I won't be on Nix forever, but right now, Nix works out very nicely for what I want it to do.
This weekend I pulled something together and actually got a working version by tonight. This involves three projects:
5: https://gitlab.com/mfgames-writing/mfgames-writing-js/
6: https://gitlab.com/mfgames-js/generator-mfgames-nix-project
7: https://gitlab.com/mfgames-writing/generator-mfgames-writing-js
I pulled out the basic project stuff from `generator-mfgames-writing` and made it a dedicated generator while improving it. It still asks a bunch of questions, but mainly it does the following:
9: /tags/conventional-commits/
That's a lot of work and it was getting tedious as I migrated/created new projects over the last month or so as I figured out the pattern. I like it, though it is opinionated. Previously, I hated that word, but this is honestly how I work and I think it's a reasonable pattern for any writing or coding project.
Running it is pretty simple:
$ npm install -g generator-mfgames-nix-project yo $ mkdir name-of-project $ cd name-of-project $ yo mfgames-nix-project ... lots of prompting
Overall, I like the resulting project and I'm going to be testing it fairly heavily in the new few weeks.
Most of the intial work for `generator-mfgames-nix-project` came from `generator-mfgames-writing`, but I ended up also expanding that over the weekend to ask better questions about theme, author information, and the release process. It works the same as the project generator.
$ npm install -g generator-mfgames-writing yo $ mkdir name-of-project $ cd name-of-project $ yo mfgames-writing ... a different set of questions $ npm run build ... lots of noise $ ls *.epub *.pdf name-of-project-0.0.1.epub name-of-project-0.0.1.pdf
This one bypasses some questions that the project one does (build, test, and release questions) and adds some other ones (theme, configuration file format, title of the work), but otherwise works the same as the other. The end result is something you should be able to build and get the output immediately.
I honestly think that is really cool.
There were a bunch of versions with this, but I needed to tweak some processes because I found some bugs in these tools while writing the generators. Sadly, a “simple” fix of moving `rimraf` from a developer dependency to a normal dependency required me to upgrade TypeScript[17] to the last version and accept a wall of warnings because some of the linting tools don't like the latest version.
Categories:
Tags:
Below are various useful links within this site and to related sites (not all have been converted over to Gemini).