Packages for LaTeX2e often are maintained using the dtx format.
.dtx-files are text files with the file name extension .dtx that contain both the package documentation and the user manual and the code of the .sty-files etc and the commenting on that code.
When you write a .dtx file, usually the documentation-part is written using the doc package.
Usually you get a pdf file containing documentation, manual and probably commented sources by compiling that .dtx file with a (pdf)LaTeX-compiler.
For extracting/generating the .sty-files etc from a .dtx file, usually the docstrip package is used.
Often people write text files with file name extension .ins .
These .ins-files contain directives for extracting/generating .sty-files and the like from .dtx-files.
When compiling an .ins-file with (La)TeX, that .ins-file will load the docstrip package and by means of that package the directives for extracting/generating .sty-files and the like from .dtx-files will be carried out.
But you can also have a section within the .dtx-file itself which causes loading docstrip and extracting/generating .sty-files and the like before further processing the .dtx-file for creating the .pdf-file containing package documentation, user manual and commented sources and the like.
Here are a few links to CTAN in case you are interested in the dtx format and in the packages doc and docstrip:
docstrip — Remove comments from file: https://www.ctan.org/pkg/docstrip
doc — Format LaTeX documentation: https://www.ctan.org/pkg/doc
dtxtut — Tutorial on writing .dtx and .ins files: https://www.ctan.org/pkg/dtxtut