How nattie-nkosi/pdf-merger works
Main Components
• GUI Frontend (Electron Renderer Process):
• index.html, styles.css, renderer.js – these files support the interface.
• preload.js – serves as a secure bridge between the renderer and main process.
• Electron Main Process:
• main.js – initializes and manages the Electron application lifecycle.
• CLI Interface:
• cli.js – implements command-line functionality for automation.
• Core PDF Merging Library:
• index.js – potentially coordinates the PDF merge operations (and may act as a common entry point for both the GUI and CLI modes).
• Build/Configuration and Assets:
• package.json and package-lock.json – show dependencies, scripts, and configuration.
• check-files.js and dist/builder-effective-config.yaml – might be related to build checks or packaging steps.
• assets/screenshots – store UI-related assets for documentation or usage in the GUI.
Relationships and Interactions
• In GUI mode:
• The main process (main.js) launches the Electron window and loads index.html.
• The preload.js file securely exposes specific APIs to the renderer process (renderer.js) which manages the interactive UI.
• User interactions on the interface (via renderer.js) trigger PDF merge operations that might call shared functions in index.js or a dedicated merge module.
• In CLI mode:
• The cli.js file is the entry point when running in CLI-only mode. It parses command-line parameters (like input directory, output file, and merge options) and invokes the PDF merging functions.
• Both modes likely rely on a central PDF merge functionality (which may be imported from index.js or another module) that implements sorting, filtering (with regex patterns), and bookmarks addition.
Architectural Patterns and Design Principles
• Separation of Concerns: Distinct responsibilities between the GUI (Electron renderer process) and CLI modes, with shared logic for PDF merging.
• Modular Architecture: Independent modules for user interface, command-line logic, and core business logic (PDF merging).
• Dependency Injection/Callbacks: For instance, the programmatic usage example shows passing callbacks (like onProgress) to the merge function.
• Cross-Platform Design: The use of Electron ensures that the GUI works on Windows, macOS, and Linux, while the CLI remains lightweight.
Including Technologies and Frameworks
• Electron: Handles cross-platform GUI.
• Node.js: Underpins both CLI and Electron’s main process.
• NPM Packages: Used for merging PDFs and managing dependencies.
• Other tools like check-files.js hint at pre-check scripts or build processes, and dist/builder-effective-config.yaml suggests configuration for packaging or deployment.
Specific Elements
• Electron Main Process: Include main.js and link to preload.js.
• Electron Renderer Process: Include index.html, renderer.js, and styles.css.
• CLI Component: Show the cli.js file and note its alternative mode.
• How the Main Process invokes the Renderer via Electron.
• Communication between Renderer and Main processes through preload.js.
• CLI calls merging functions directly.