Skip to content

Implement CLI JSON-RPC wrapper for docxgo and Node.js integration #19

@mmonterroca

Description

@mmonterroca

Context

We need a robust command-line interface (CLI) for docxgo that enables seamless invocation from Node.js, supporting integration across AWS Lambda, local servers, and any platform (Linux, Windows, macOS, arm64/x64).

PR Scope

  • Create cmd/docxgo/main.go implementing:
    • Mode 1: One-shot execution (docxgo exec --request 'JSON')—for simple calls via child_process.
    • Mode 2: Persistent JSON-RPC session (docxgo rpc)—for high-frequency batch/Lambda usage; runs as a process, receives JSON requests over stdin, writes JSON responses to stdout.
    • Protocol: simple JSON-RPC, supporting all relevant docxgo operations: create document, open, modify, save, validate, inspect, etc.
  • Accept input/output as file path or as Base64/buffer via JSON, to maximize compatibility with Node and Lambda.

Implementation Plan

1. CLI Design

  • Design the protocol: JSON-RPC with mapped methods (document.create, document.open, ...)
  • Support file input/output and buffer modes.

2. CLI Implementation

  • Create cmd/docxgo package.
  • Implement mode selector (exec/rpc).
  • Wire up domain API to JSON-RPC handlers.

3. Test Cases

  • Unit tests for CLI interface and JSON mapping.
  • E2E test: Create, modify, save a document via CLI.

4. Documentation

  • Usage examples: both from shell and from Node.js (child_process.spawn)
  • Reference protocol (JSON formats, error responses)

5. Future Work

  • NPM wrapper: multi-platform binary download + JS/TS client (builder/fluent API)
  • AWS Lambda optimization: packaged binary, direct buffer send

Reference


This PR implements the CLI (step 1), with full plan below to guide subsequent npm package and integration work.


Full Implementation Plan (for Node integration)

A. CLI/JSON-RPC Layer (Go)

  • Implement cmd/docxgo/main.go with one-shot and rpc modes.
  • Define JSON-RPC schema, methods for document, paragraph, table, image, fields, metadata, etc.
  • Support platform detection and output to stdout/file/base64.

B. Node.js Wrapper (future, after CLI)

  • Create npm package @mmonterroca/docxgo.
  • Implement JS/TS client for RPC protocol.
  • Platform binary distribution (optionalDependencies).
  • Fluent builder API mirroring Go API.
  • Buffer/file input/output.
  • AWS Lambda testing and optimization.
  • Examples and docs.

C. CI/CD

  • Build and release multi-platform Go binaries.
  • Automate GH Releases + npm publish.

D. Testing

  • CLI/unit/e2e tests in Go.
  • Integration tests Node → CLI → docx → validate output.

E. Docs

  • Protocol documentation, usage guide, integration guide.

Assign: @mmonterroca
Label: enhancement
Type: feature

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions