How to Automate Documentation with DocShip
Step 1: Install DocShip#
-
Open your terminal.
-
Navigate to your GitHub project directory.
-
Run the following command to install DocShip:
npm install -g docship
Step 2: Initialize DocShip#
-
In your project directory, execute:
docship init -
This command creates a
docship.config.jsfile in your project root. Open this file to configure your documentation settings.
Step 3: Configure Your Documentation Settings#
-
In
docship.config.js, set thesourceandoutputpaths. For example:module.exports = { source: './src/docs', output: './docs', }; -
Specify the format of your documentation. Choose between Markdown or HTML by adding:
format: 'markdown', -
Save your changes to the configuration file.
Step 4: Add Documentation Comments in Your Code#
-
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; } -
Ensure you document all public functions and classes to generate comprehensive documentation.
Step 5: Generate Your Documentation#
-
In your terminal, run the following command to generate your documentation:
docship generate -
Check the
./docsdirectory for the generated documentation files.
Step 6: Review and Publish Your Documentation#
- Open the generated documentation files in your browser to review them.
- Make any necessary adjustments in your code comments or configuration.
- 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.