feat(cli): add bin wrapper

This commit is contained in:
rcmerci
2026-01-22 21:09:44 +08:00
parent 2580cd27ce
commit ee5bfaccc3
9 changed files with 26 additions and 17 deletions

2
.gitignore vendored
View File

@@ -77,3 +77,5 @@ clj-e2e/e2e-dump
.dir-locals.el
.projectile
*.map
/dist/db-worker-node.js
/dist/logseq-cli.js

View File

@@ -23,7 +23,7 @@
## db-worker-node
- Build: `clojure -M:cljs compile db-worker-node`
- Run: `node ./static/db-worker-node.js` (default port 9101)
- Run: `node ./dist/db-worker-node.js` (default port 9101)
## Common used cljs keywords
- All commonly used ClojureScript keywords are defined using `logseq.common.defkeywords/defkeyword`.

2
bb.edn
View File

@@ -180,7 +180,7 @@
{:doc "Compile and start db-worker-node (pass-through args forwarded to node)"
:task (do
(shell "clojure" "-M:cljs" "compile" "db-worker-node")
(apply shell "node" "./static/db-worker-node.js" *command-line-args*))}
(apply shell "node" "./dist/db-worker-node.js" *command-line-args*))}
lint:dev
logseq.tasks.dev.lint/dev

6
dist/logseq.js vendored Executable file
View File

@@ -0,0 +1,6 @@
#!/usr/bin/env node
"use strict";
const path = require("path");
require(path.resolve(__dirname, "./logseq-cli.js"));

View File

@@ -12,7 +12,7 @@ Related: Relates to docs/agent-guide/task--basic-logseq-cli.md and docs/agent-gu
## Problem statement
We need a new Logseq CLI that is independent of any existing CLI code in the repo.
The CLI must run in Node.js, be written in ClojureScript, and connect to the db-worker-node server started from static/db-worker-node.js.
The CLI must run in Node.js, be written in ClojureScript, and connect to the db-worker-node server started from dist/db-worker-node.js.
The CLI should provide a stable interface for scripting and troubleshooting, and it should be easy to extend with new commands.
## Testing Plan

View File

@@ -65,7 +65,7 @@ Key changes:
2. If lock file exists, read port/pid; probe `/healthz` + `/readyz`.
3. If healthy, reuse existing server; build the connection URL from localhost and the lock file port.
4. If unhealthy or stale, attempt to spawn a new server; if db-worker-node cannot handle the lock situation, CLI repairs the lock then retries.
5. Spawn via `child_process.spawn`: `node ./static/db-worker-node.js --repo <repo> --data-dir <...>`.
5. Spawn via `child_process.spawn`: `node ./dist/db-worker-node.js --repo <repo> --data-dir <...>`.
6. Resolve actual port from the lock file written by db-worker-node.
- **Connection URL**: derived from the repo lock file; host is always localhost and the port is always discovered from the lock file.

View File

@@ -15,7 +15,7 @@ clojure -M:cljs compile logseq-cli
## Run the CLI
```bash
node ./static/logseq-cli.js graph list
node ./dist/logseq.js graph list
If installed globally, run:
@@ -115,12 +115,12 @@ id8 └── b8
Examples:
```bash
node ./static/logseq-cli.js graph create --repo demo
node ./static/logseq-cli.js graph export --type edn --output /tmp/demo.edn --repo demo
node ./static/logseq-cli.js graph import --type edn --input /tmp/demo.edn --repo demo-import
node ./static/logseq-cli.js add block --target-page-name TestPage --content "hello world"
node ./static/logseq-cli.js move --uuid <uuid> --target-page-name TargetPage
node ./static/logseq-cli.js search "hello"
node ./static/logseq-cli.js show --page-name TestPage --format json --output json
node ./static/logseq-cli.js server list
node ./dist/logseq.js graph create --repo demo
node ./dist/logseq.js graph export --type edn --output /tmp/demo.edn --repo demo
node ./dist/logseq.js graph import --type edn --input /tmp/demo.edn --repo demo-import
node ./dist/logseq.js add block --target-page-name TestPage --content "hello world"
node ./dist/logseq.js move --uuid <uuid> --target-page-name TargetPage
node ./dist/logseq.js search "hello"
node ./dist/logseq.js show --page-name TestPage --format json --output json
node ./dist/logseq.js server list
```

View File

@@ -4,10 +4,11 @@
"private": true,
"main": "static/electron.js",
"bin": {
"logseq": "static/logseq-cli.js"
"logseq": "dist/logseq.js"
},
"files": [
"static/db-worker-node.js"
"dist/db-worker-node.js",
"dist/logseq-cli.js"
],
"engines": {
"node": ">=22.20.0"

View File

@@ -86,7 +86,7 @@
:loader-mode :eval}}
:db-worker-node {:target :node-script
:output-to "static/db-worker-node.js"
:output-to "dist/db-worker-node.js"
:main frontend.worker.db-worker-node/main
:compiler-options {:infer-externs :auto
:source-map true
@@ -96,7 +96,7 @@
:redef false}}}
:logseq-cli {:target :node-script
:output-to "static/logseq-cli.js"
:output-to "dist/logseq-cli.js"
:main logseq.cli.main/main
:compiler-options {:infer-externs :auto
:source-map true