code-to-docx is a powerful command-line tool designed to scan a specified directory for source code files and generate a .docx document containing the extracted code. With options for customizable output, this tool is ideal for creating documentation that includes complete, formatted code samples. You can specify the number of lines per page in the generated document and easily exclude directories as needed, making it a flexible solution for project documentation.
- Directory Scanning: Automatically scans all files in a specified directory.
- Code Extraction: Extracts code from various file formats and languages.
- .docx Generation: Outputs code in a structured, styled Word document.
- Page Customization: Allows you to specify the number of lines per page in the generated document for better readability and control over document length.
- Directory Ignoring: Provides options to specify directories to ignore during scanning, giving you flexibility in excluding certain folders from the final output.
- Ideal for Documentation: Simplifies the process of generating reference materials.
code-to-docx is a powerful command-line tool designed to scan a specified directory for source code files and generate a .docx document containing the extracted code. With options for customizable output, this tool is ideal for creating documentation that includes complete, formatted code samples. You can specify the number of lines per page in the generated document and easily exclude files or directories as needed, making it a flexible solution for project documentation.
- Directory Scanning: Automatically scans all files in a specified directory.
- Code Extraction: Extracts code from various file formats and languages.
.docxGeneration: Outputs code in a structured, styled Word document.- Page Customization: Allows you to specify the number of lines per page in the generated document for better readability and control over document length.
- Directory Ignoring: : Provides options to specify directories to ignore during scanning, giving you flexibility in excluding certain folders from the final output.
- Ideal for Documentation: Simplifies the process of generating reference materials.
First, you can install the tool globally using npm:
# Install globally from npm
npm install -g code-to-docxAfter installing globally with npm, you can run the tool directly from the command line:
code-to-docx --source <source_directory> --type <file_types> --output <output_doc_path> --ignored-dirs <ignore_dirs> --lines-per-page <lines_per_page>You can also use the alias c2d for convenience:
c2d -s <source_directory> -t <file_types> -o <output_doc_path> -i <ignore_dirs> -l <lines_per_page>Alternatively, you can clone the repository and install the required dependencies:
# Clone the repository
git clone <repository-url>
# Install dependencies (install the `commander`, `docx`, ...)
yarn installRun the script using Yarn with the following command:
yarn start -s <source_directory> -t <file_types> -o <output_doc_path> -i <ignore_dirs> -l <lines_per_page>| Parameter | Description | Default |
|---|---|---|
-s, --source <path> |
(Required) Source directory to scan. This should be the directory containing your source code. It can be an absolute or relative path. | |
-t, --type <file_types> |
Comma-separated list of file types to scan, such as .vue,.js. |
.vue,.js,.jsx,.ts,.tsx |
-o, --output <path> |
Path to output the .docx file containing the extracted source code. This can be an absolute or relative path. |
output.docx |
-l, --lines-per-page <number> |
Number of lines per page in the output .docx file. |
50 |
-i, --ignored-dirs <directories> |
Comma-separated list of directory names to ignore during scanning. If you specify additional directories, they will be merged with the default list (duplicates will be removed). | "node_modules,dist,.git,target,bin,build,__pycache__,venv,out,pkg,cargo-cache,gems" |
Notes:
- Paths for
.docxfiles must be writable by the user running the script. - The
-tparameter allows multiple file extensions to be specified as a comma-separated list.
code-to-docx -s /path/to/vue-project/src -t .vue,.js -o output.docxor using the alias:
c2d -s /path/to/vue-project/src -t .vue,.js -o output.docxThis command will:
- Scan the
/path/to/vue-project/srcdirectory for.vueand.jsfiles. - Generate
output.docxcontaining all lines of code from the specified files.
We use Jest to test the functionality of the code extractor, including validation of the generated .docx file.
To run the tests, use the following command:
yarn testThis command will execute all test cases and provide output about the success or failure of each.
docx(third-party npm package): For creating.docxdocuments. Note thatdocxis not a Node.js native library, but an external package that needs to be installed separately.commander(npm package): For handling command-line arguments.
This project is licensed under the MIT License.