mdinterface 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/start.sh ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env bash
2
+ # mdinterface launcher — stop any running instance, start fresh in the background, print the URL.
3
+ # Usage: ./start.sh [path/to/doc.md] (defaults to this repo's README.md)
4
+ # MDINTERFACE_PORT=8000 ./start.sh ~/notes/draft.md
5
+ DIR="$(cd "$(dirname "$0")" && pwd)"
6
+ DOC="${1:-$DIR/README.md}"
7
+ PORT="${MDINTERFACE_PORT:-7777}"
8
+ LOG="${TMPDIR:-/tmp}/mdinterface.log"
9
+
10
+ # Stop only OUR server on this port — match the server.js command rather than killing
11
+ # whatever happens to be listening — then wait for the port to free (avoids EADDRINUSE).
12
+ for pid in $(lsof -ti :"$PORT" 2>/dev/null || true); do
13
+ if ps -p "$pid" -o command= 2>/dev/null | grep -q "server.js"; then kill "$pid" 2>/dev/null || true; fi
14
+ done
15
+ for _ in $(seq 1 20); do lsof -ti :"$PORT" >/dev/null 2>&1 || break; sleep 0.1; done
16
+
17
+ # Launch detached so it keeps running after this script (and your shell) returns.
18
+ nohup node "$DIR/server.js" "$DOC" --port "$PORT" > "$LOG" 2>&1 &
19
+
20
+ # Wait for the startup line, then surface the tokenized URL.
21
+ for _ in $(seq 1 50); do grep -q "http://localhost" "$LOG" 2>/dev/null && break; sleep 0.2; done
22
+ URL="$(grep -o 'http://localhost[^ ]*' "$LOG" | tail -1)"
23
+ echo
24
+ if [ -n "$URL" ]; then
25
+ echo " mdinterface ▸ running ▸ $URL"
26
+ echo " logs: $LOG · stop: lsof -ti :$PORT | xargs kill"
27
+ else
28
+ echo " mdinterface did not start cleanly — last lines of $LOG:"
29
+ tail -5 "$LOG" 2>/dev/null
30
+ fi
31
+ echo