How to Automate Documentation with DocShip

Step 1: Install DocShip#

  1. Open your terminal.

  2. Navigate to your GitHub project directory.

  3. Run the following command to install DocShip:

    npm install -g docship

Step 2: Initialize DocShip#

  1. In your project directory, execute:

    docship init
  2. This command creates a docship.config.js file in your project root. Open this file to configure your documentation settings.

Step 3: Configure Your Documentation Settings#

  1. In docship.config.js, set the source and output paths. For example:

    module.exports = {
      source: './src/docs',
      output: './docs',
    };
  2. Specify the format of your documentation. Choose between Markdown or HTML by adding:

    format: 'markdown',
  3. Save your changes to the configuration file.

Step 4: Add Documentation Comments in Your Code#

  1. Go through your codebase and add documentation comments using JSDoc format. For example:

    /**
     * Adds two numbers together.
     * @param {number} a - The first number.
     * @param {number} b - The second number.
     * @returns {number} The sum of a and b.
     */
    function add(a, b) {
      return a + b;
    }
  2. Ensure you document all public functions and classes to generate comprehensive documentation.

Step 5: Generate Your Documentation#

  1. In your terminal, run the following command to generate your documentation:

    docship generate
  2. Check the ./docs directory for the generated documentation files.

Step 6: Review and Publish Your Documentation#

  1. Open the generated documentation files in your browser to review them.
  2. Make any necessary adjustments in your code comments or configuration.
  3. Once satisfied, commit your changes and push them to your GitHub repository.

Conclusion#

You have successfully automated your documentation process using DocShip. Now, you can focus on coding while DocShip handles the documentation generation.