pureinit: a tool for cleaning `zig init` templates
Hi everyone, I really like Zig language. A tool was recently developed.
- Repo link: https://github.com/Hentioe/pureinit
- Readme:
pureinit
A tool for cleaning redundant code from templates, currently used to clean Zig project templates generated by zig init.
Introduction
This tool extracts cleanup information from patches generated by git-diff. It does not scan for code targets or comments. Therefore, it is effectively generic and can perform cleanup from external patches. The built-in patches are actually located in the src/diff_patchs source directory.
Usage
For the zig init template in Zig 0.17.1, it has:
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Zig 4 29 115 101
-------------------------------------------------------------------------------
SUM: 4 29 115 101
-------------------------------------------------------------------------------
It is filled with a large number of comments (115 lines) and example code (more than half). This may help beginners, but it is meaningless for experienced users. In my view, this is all "noise."
Use pureinit to clean it (it detects the version in build.zig.zon and uses the corresponding patch):
| | | | |
+=======================+==========+=====+========+
| | | | |
Afterward:
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Zig 4 9 2 43
-------------------------------------------------------------------------------
SUM: 4 9 2 43
-------------------------------------------------------------------------------
The project template is now very clean! You can view these cleaned templates in the templates directory.
Building
This is a pure Zig project, so:
Install it to the system (the user bin directory):
For Other Projects
Because it is generic by design, you can create your own patches and use pureinit to clean them. First (assuming your framework is called foo):
- Commit the original template code to Git, then perform the manual cleanup.
- When finished, add the modifications to the staging area.
Now you can generate a patch:
|
Use pureinit to apply your custom patch:
Note: pureinit does not delete files, because cleaning zig init does not currently require this.
I know zig init has --minimal parameter, but this tool still makes sense I think.
- First of all it is universal. This phenomenon also exists for other tools/frameworks. The templates they generate are too "bloated".
- Actually I don't like the
zig init --minimaltemplate either. It's too "concise" for either a program or a library.