Introduction
As we know, it's a laborious thing to generate the codebase from zero to one. There are so many things we need to do, such as lint configuration, DevOps and Pipeline configuration, auto-upgrade dependencies, GitHub issue templates etc. So that is why we need generators to reduce our workloads. In this post, I will make a comparison between Yeoman and Plop. They are all popular generator tools.
Comparison
In this section, I will make a comparison between Yeoman and Plop with the following items:
Ecosystem
Complete documentation
Create the testable generator
Ecosystem
The ecosystem is the most important when we make a comparison. Yeoman has provided the Generators repository. Your Yeoman generator will show in the list if your generator has been published to npmjs.org, The name should be generator-your-unique-name
, yeoman-generator
in the keyword property.
For Plop, it didn't provide the repository that we can search the generator from it.
Complete documentation
Yeoman and Plop both provide complete documentation. But the documentation of Yeoman will tell you how to make unit testing. It makes with JavaScript but can help me to make it with TypeScript.
Create the testable generator
Yeoman provides the following test tools to help us to create the testable generator.
Here is an example:
const runResult = await helpers
.create(path.join(__dirname, "../../generators/app"))
.withOptions({
isTesting: true,
} as GeneratorOptions)
.withAnswers({
name: name,
} as IAnswers)
test("Expect package.json is created", () => {
assert.file("package.json")
})
test("Expect package.json have correct name", () => {
assert.fileContent("package.json", `"name": "${name}"`)
})
You can see the complete example in this repository: https://github.com/helbing/generator-example.
Otherwise, Plop doesn't provide test tools to help us to create the testable generator. But I thought you can learn to write unit tests via the test cases in its repository.
How to create Yeoman Generator
Conclusion
I have to say this is a subjective comparison. The comparison items: ecosystem, complete documentation and writing testable code, are my concern. If they are both your concern, I highly recommend you use Yeoman.