2.0.0 • Published 11 months ago

doclax v2.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
11 months ago

Doclax

Doclax is a command-line tool designed to generate different types of document formats (PDF, EPUB, MOBI) from HTML/Markdown input, with a live preview feature to see the output as you work. The tool is built with Node.js and uses several libraries like Puppeteer, epub-gen, and commander to handle various functionalities.

Features

  • Convert Markdown/MDX to PDF
  • Live preview server with auto-reload
  • Easy configuration and customization

Overall Functionalities

  1. PDF Generation: Convert HTML/Markdown into a PDF file using Puppeteer.
  2. EPUB Generation: Convert HTML/Markdown into an EPUB file using epub-gen.
  3. MOBI Generation: Convert HTML/Markdown into a MOBI file (for Kindle).
  4. Live Preview: Start a local server to preview your content in the browser while working.

Available Commands

  1. generate-pdf:

    • Description: Generates a PDF from the index.html file in the public folder.
    • Usage: npx doclax generate-pdf
    • Output: Saves the PDF in the output folder as output.pdf.
  2. generate-epub:

    • Description: Generates an EPUB from the index.html file in the public folder.
    • Usage: npx doclax generate-epub
    • Output: Saves the EPUB in the output folder as output.epub.
  3. generate-mobi:

    • Description: Generates a MOBI file from the index.html file in the public folder.
    • Usage: npx doclax generate-mobi
    • Output: Saves the MOBI file in the output folder as output.mobi.
  4. start-preview:

    • Description: Starts a live preview server to view the content of the index.html file in the public folder.
    • Usage: npx doclax start-preview
    • Output: Opens the preview in your default web browser at http://localhost:3000.

How the Tool Works

  1. Installation:

    • Clone the repository to your local machine.
    • Navigate to the directory and install the dependencies:
      git clone git@github.com:fasakinhenry/Doclax.git
      cd Doclax
      npm install
  2. Usage:

    • Run any of the available commands listed above using npx doclax <command>.
    • For example, to generate a PDF, you would run:
      npx doclax generate-pdf
    • This command uses the index.html file in the public folder, generates a PDF, and saves it in the output folder.
  3. Folder Structure:

    • The primary folders and files:
      • src/: Contains the main code for each functionality (e.g., pdf/generator.js, epub/generator.js, mobi/generator.js, etc.).
      • public/: Contains the index.html file used as the input for document generation.
      • output/: Created automatically to store the generated documents.
      • doclax.config.js: (Optional) Configuration file for customizing certain aspects of the tool.
  4. Configuration:

    • The tool is designed to work out of the box with minimal configuration. However, a configuration file (doclax.config.js) can be added in the config folder if customization is needed.

How to Publish the Tool

  1. Prepare for Publishing:

    • Ensure all dependencies are correctly listed in package.json.
    • Update the version number in package.json following semantic versioning.
    • Write a README.md file that describes how to install and use the tool.
  2. Login to npm:

    • If you don't already have an npm account, create one.
    • Log in to npm in your terminal:
      npm login
  3. Publish the Package:

    • Run the following command to publish the package to the npm registry:
      npm publish --access public
    • This will make Doclax available as an npm package that anyone can install and use globally.
  4. Global Installation:

    • Once published, users can install Doclax globally using:
      npm install -g doclax
  5. Usage After Installation:

    • After global installation, the tool can be used directly without npx:
      doclax generate-pdf
      doclax generate-epub
      doclax start-preview

Future Improvements

  • Customization: Allow users to customize the output formats (PDF, EPUB, MOBI) more granularly via a configuration file.
  • Template Support: Support for different templates for document generation.
  • Improved Error Handling: Enhance error messages and validation to guide users when issues arise.
  • Markdown Support: Integrate Markdown parsing directly to support Markdown files as input.

Packages used

Here’s what each package does:

  • commander: Helps create command-line interfaces.
  • puppeteer-core: Used for rendering HTML to PDF.
  • remark, unified, remark-parse, remark-rehype, rehype-stringify: Handle Markdown and MDX to HTML conversion.
  • figlet: Generates ASCII art from text.
  • chalk: Adds color to the terminal output.
  • cli-progress: Creates progress bars in the terminal.

Doclax Feature Checklist

  • PDF Generation

    • Generate PDF from compiled chapters.
    • Serve and preview PDF in the browser with live reload on changes.
  • HTML Preview

    • Convert chapters to an HTML template.
    • Serve and preview HTML in the browser with live reload on changes.
  • EPUB Generation

    • Generate EPUB format and serve it in the browser.
  • Terminal Interface Enhancements

    • Progress bar during file regeneration.
    • Figlet branding in the terminal.
    • Inquirer-based prompts for preview format selection.
  • File Watcher Integration

    • Automatically regenerate files and update previews using Chokidar.
  • Markdown and MDX Support

    • Parse and compile Markdown and MDX content into preview formats (HTML, PDF, EPUB).
  • Tailwind CSS Integration

    • Allow custom styling using Tailwind CSS in generated documents (HTML, PDF).
  • Multi-Format Output

    • Seamless generation of additional formats like MOBI.
  • Live Reload Enhancements

    • Improve the speed and efficiency of live reloading for large projects.
  • Theming and Customization

    • Support theming and customization of documents, including templates, fonts, colors, and layouts.
  • Collaboration and Versioning

    • Implement collaborative editing and version control features.
  • Improved User Interface for CLI

    • Further enhance the visual appeal and usability of the CLI interface.
  • Command-Line Tool Enhancements

    • Add additional commands or options to cater to a broader range of use cases.
  • Efficient Image Handling

    • Optimize image handling in documents to maintain quality while reducing file sizes.
  • PDF-specific Features

    • Explore additional PDF features like bookmarks, table of contents, and internal linking.