chiubaka / generator-chiubaka-typescript-package

Yeoman generator for standard Chiubaka Technologies TypeScript packages for libraries and other such things.
1 stars 0 forks source link

Move README shield generation for respective services to their own generators #79

Open chiubaka opened 2 years ago

chiubaka commented 2 years ago

For example, the NodeModuleGenerator should be responsible for the NPM shield and the CircleCiGenerator should be responsible for the CircleCI shield.

This would be nice because it means that subgenerators are, themselves, completely self-contained. If I don't run the CircleCiGenerator, no other generator is going to see anything at all related to CircleCI. There are a few exceptions since we globally expect there to be both a README and a .gitignore file, but for the most part this model makes sense to me.

I encountered some difficulty getting this to work properly. Specifically, I was finding that the NodeModuleGenerator would constantly fail to find the README.md file that should have been created already by the ReadmeGenerator that it was composed with.

Some logging did reveal that the ReadmeGenerator#writing method was being called before my attempts to write to README.md (note, though, that by default NodeModuleGenerator#writing appears to happen before its composed sub-generators, so I placed my write attempt in conflicts or install).

I kept getting that README.md does not exist. Weirdly, doing this.fs.exists("README.md") would return true, but this.fs.read("README.md") would throw the error.

I did some searching around in the Yeoman docs and in the underlying mem-fs-editor docs and found that this functionality should be working because mem-fs-editor seems like it should be checking its in-memory files before going to disc and because Yeoman claims to be sharing the mem-fs-editor instance across all subgenerators.

Ultimately, I gave up on getting this to work and decided to move the shield generation into ReadmeGenerator, which I don't love.

chiubaka commented 2 years ago

Just did a very, very quick test and am thinking this may actually still be achievable.

I had an inkling that the way I was passing options down to sub generators might be squashing some internals in a bad way. I've since changed this to only pass the answers down instead of the full options object.

A very quick test suggests to me that I can now read the README.md file in NodeModuleGenerator#install normally.