npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

code-to-docx

v1.2.8

Published

Extract code to generate a docx file

Downloads

671

Readme

Code to docx

Description

code-to-docx is a command-line tool that allows you to scan a specified directory for source code files and generate a .docx document containing the extracted code. It is particularly useful for generating documentation for projects, including code samples from the entire content of the project.

Features

  • Scan a specified directory and extract code from specific file types (e.g., .vue, .js, .ts).
  • Generate a .docx document containing all the source code from the specified directory.

Installation

First, you can install the tool globally using npm:

# Install globally from npm
npm install -g code-to-docx

After 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 install

Run 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>

Parameters

| 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 .docx files must be writable by the user running the script.
  • The -t parameter allows multiple file extensions to be specified as a comma-separated list.

Example

code-to-docx -s /path/to/vue-project/src -t .vue,.js -o output.docx

or using the alias:

c2d -s /path/to/vue-project/src -t .vue,.js -o output.docx

This command will:

  • Scan the /path/to/vue-project/src directory for .vue and .js files.
  • Generate output.docx containing all lines of code from the specified files.

Testing

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 test

This command will execute all test cases and provide output about the success or failure of each.

Dependencies

  • docx (third-party npm package): For creating .docx documents. Note that docx is not a Node.js native library, but an external package that needs to be installed separately.
  • commander (npm package): For handling command-line arguments.

License

This project is licensed under the MIT License.