print-lib
v1.0.3
Published
Print a GitHub repository's code as .docx or .pdf files
Downloads
7
Maintainers
Readme
print-lib
What it does
Print a GitHub repository's code as .docx or .pdf files.
Why?
When diving into a codebase, I like to have physical copies of the source code. It's easier on my eyes - especially after a long day of programming screen time.
Before, I'd manually copy and paste the content of a code file into MS Word, attach page numbers and a title (filename), and then convert it into pdf (using Word or online tools, etc.). Not much of an issue at all. Until the file count grew. Even repeating those steps for more than a few files felt ... hard-coded.
This is my attempt to automate the menial process. Of course, screen time is inevitable to a programmer (and non-coders alike). So, this solution may seem like a drop in the ocean, but hopefully more folks will come to appreciate physical source code study.
Installation
$ npm install print-lib
$ pip install -r node_modules/print-lib/requirements.txt
Requirements
python >= 3.8
Nodejs >= 14
- MS Word installed on local machine (needed for
.pdf
conversion)
Example
const { printLib } = require("print-lib");
(async () => {
const url = "https://github.com/Zen-cronic/scope-logger/tree/main/src";
await printLib({
link: url,
linkType: "recursive",
auth: process.env.API_ACCESS_TOKEN,
userAgent: "Zen-cronic",
convertTo: "pdf",
});
})();
Output:
Prints 3 directories in the root:
The code files in
code
The .docx files in
word
The .pdf files in
pdf
(This is optional; see theConfiguring Options
section )
Configuring options
All are required.
link <string>
: A valid github repository urllinkType <"file"|"dir"|"recursive">
: The type of the content represented by thelink
.A.
file
: A single source code file. For example, the link representsindex.js
only.B.
dir
: All the files in the given directory. Ignores files in sub-directories.C.
recursive
: Recursively traverse all files in a given directory, including sub-directories.
auth
: The GitHub API token needed to make the requests to fetch repository content. Without this, the rate limit is very low. Fine-grain access tokens are recommended. Check theResources
section for more information.userAgent
: Your GitHub username or the name of your GitHub App.convertTo <"word"|"pdf">
: The stage of the file conversions.A.
word
: Generate.docx
files from the files incode
directory. Works cross-platform.B.
pdf
: Generate.pdf
files from the files inword
directory. Only available on machines with MS Word installed. Therefore, it cannot be used on linux. If your local machine is not running on Windows or MacOS and this option is set, it fallbacks toword
.
Dependencies
- 0 javascript/nodejs dependency!
python-docx
for.docx
conversiondocx2pdf
for.pdf
conversion
Test
Uses dynamic imports in testing with jest. Therefore, the --experimental-vm-modules
flag must be set.
$ npm run test:dynamic