CLI and scripting
Running tools and workflows headlessly with the eeshgarg command line, and how it differs from the browser APIs.
What the command is
Use it to run the site's tools on many files from a script. npm run eeshgarg is a command in the source repository. It runs the same site, in a headless Chromium on your machine, so canvas, workers, WebAssembly and ffmpeg behave as they do in a browser. It serves the built site on 127.0.0.1 with the site's own security headers, opens the page, gives your files to window.eeshgarg and writes the results to a folder. Every request that is not to 127.0.0.1 is blocked, and file contents are never printed. It needs Playwright and a built site (a build runs once if the output folder is missing).
Commands
npm run eeshgarg -- list [filter] [--json]
npm run eeshgarg -- describe <toolId> [--json]
npm run eeshgarg -- run <toolId> <files...> [--opt key=value ...] [--out dir] [--force] [--json]
npm run eeshgarg -- workflow <workflow.json> <files...> [--out dir] [--force] [--json]
npm run eeshgarg -- serve [--port n]| Flag | Meaning |
|---|---|
--out dir | Where results go. The default is ./eeshgarg-out. An existing file is not overwritten; the new one is numbered, unless you pass --force. |
--dist dir | A built site to serve. The default is ./dist. |
--port n | On serve only. The port for the local site (default 4321). |
--timeout s | How long to wait, in seconds. The default is 600. |
--opt key=value | On run only. Sets one tool option; repeat it for more. See Options and values below. |
--json | One JSON object on stdout and nothing else. |
--remember file.json | On run and workflow only. Saves the workflow and the paths of your input files (with size and modified time, never contents) to a local file. If that file already exists the command stops, unless you pass --force. |
--help | Help for the command, also per command. |
list and describe show what exists, run runs one tool, and workflow runs a saved workflow file. A folder among the files adds the files inside it. Input names must be unique. serve starts the local site and prints its address; with --json it prints { ok, url }.
Examples
$ npm run eeshgarg -- list feature:text
feature:text-transform Text transform [any] op="upper" find="" replace="" regex=false caseSensitive=true
feature:text-diff Text diff (unified patch) [any x2]
feature:text-merge Three-way text merge [any x3]
$ npm run eeshgarg -- run rotate scan.pdf --opt angle=90 --out out
Running rotate on 1 file...
Rotated 2 pages by 90°
out/scan-rotated.pdf (1002 bytes)
$ npm run eeshgarg -- run feature:redact-text notes.txt --out out
warning: notes.txt: 1 redaction. Patterns find likely identifiers; review the result.
out/notes-redacted.txt (34 bytes)A workflow file runs the same way. The example workflow in the repository rotates the PDFs in a folder, converts the images to WebP and zips both results. Files that match no input block are dropped:
$ npm run eeshgarg -- workflow docs/examples/pdfs-and-images.workflow.json scan.pdf photo.png notes.txt --out out
Running docs/examples/pdfs-and-images.workflow.json on 3 files...
Workflow done
out/archive.zip (929 bytes)archive.zip holds scan-rotated.pdf and photo.webp. The workflow itself is described in Workflow API.
Batch runs and multi-step pipelines
One run takes many files, and a folder among the arguments adds the files inside it. A command is one tool, so a pipeline is several commands in a row: the output folder of one is the input of the next. Each command starts the local site and a headless browser of its own.
# Merge two PDFs
npm run eeshgarg -- run merge a.pdf b.pdf --out out
# CSV to JSON, then zip the result. --json prints { ok, status, summary, warnings, files, nodes } for scripts.
npm run eeshgarg -- run feature:convert people.csv --opt to=json --out out --json
npm run eeshgarg -- run feature:zip-create out/people.json --out out
# Save a run as a workflow plus the paths of its inputs (never their contents)
npm run eeshgarg -- run rotate scan.pdf --opt angle=90 --remember rotate-scan.json --out out-h is a short form of --help. The headless command covers every operation the site has, including those that need a canvas, a worker or ffmpeg (OCR, image and media conversion), because it runs a real browser. Run commands from a source checkout; there is no installed eeshgarg program, and nothing is sent to a server.
Options and values
--opt values are typed from the tool's option list, which describe prints: numbers, true and false, and JSON for array or object options. An unknown option, a value of the wrong kind, or a value outside a tool's choices is a usage error (exit code 2). The option names and choices for every tool are in the catalog.
Exit codes and JSON output
| Code | Meaning |
|---|---|
| 0 | Success. |
| 1 | The tool or workflow failed, or a workflow node failed. |
| 2 | Bad usage: unknown command, tool or option, an unreadable file, or invalid workflow JSON. |
With --json, run and workflow print one object: { ok, status, summary, warnings, files: [{ name, path, bytes }], nodes }. File contents are never printed.
Command line, API, SDK or workflow runtime
| Way | What it is | Where it runs | Use it when |
|---|---|---|---|
| Command line | This command, which drives the site in a headless browser | Your machine, from a source checkout | You want scripted batch runs of the tools |
| Browser API | window.eeshgarg on the site, or the SDK from another page | The visitor's browser, on the visitor's device | You are building a page or a script in a browser |
| Workflow runtime | The engine that runs version 2 graphs and text pipelines | Wherever it is called: the Workflow board, the browser API, or the command | A fixed chain of steps with branches |
| Remote HTTP endpoint | Does not exist. This site has no processing API that accepts files over HTTP | Not applicable | Not applicable |
The last row is deliberate. Processing happens on the device that holds the file. A server that accepted files from other programs would have to receive them, which is what the site is built to avoid.