md-redline 0.1.3 → 0.1.4

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/bin/md-redline CHANGED
@@ -8,10 +8,14 @@ import { dirname, join, resolve } from 'path';
8
8
  import process from 'process';
9
9
  import { fileURLToPath } from 'url';
10
10
 
11
+ import { createRequire } from 'module';
12
+
11
13
  const __filename = fileURLToPath(import.meta.url);
12
14
  const __dirname = dirname(__filename);
13
15
 
14
16
  const APP_DIR = resolve(__dirname, '..');
17
+ const require = createRequire(import.meta.url);
18
+ const { version: CLI_VERSION } = require(join(APP_DIR, 'package.json'));
15
19
  const DIST_SERVER = join(APP_DIR, 'dist', 'server.js');
16
20
  const DEFAULT_SERVER_PORT = 3001;
17
21
  const DEFAULT_CLIENT_PORT = 5188;
@@ -29,8 +33,9 @@ function printHelp() {
29
33
  console.log('Supported platforms: macOS, Linux, and Windows.');
30
34
  console.log('');
31
35
  console.log('Options:');
32
- console.log(' --stop Stop the running mdr server');
33
- console.log(' -h, --help Show this help message');
36
+ console.log(' --stop Stop the running mdr server');
37
+ console.log(' -v, --version Show version number');
38
+ console.log(' -h, --help Show this help message');
34
39
  console.log('');
35
40
  console.log('Alias: md-redline');
36
41
  }
@@ -168,6 +173,19 @@ async function stopServer() {
168
173
  console.log('mdr stopped.');
169
174
  }
170
175
 
176
+ async function getServerVersion(port) {
177
+ try {
178
+ const response = await fetch(`http://localhost:${port}/api/version`, {
179
+ signal: AbortSignal.timeout(1_000),
180
+ });
181
+ if (response.ok) {
182
+ const data = await response.json();
183
+ return data.version ?? null;
184
+ }
185
+ } catch {}
186
+ return null;
187
+ }
188
+
171
189
  function isProductionMode() {
172
190
  try {
173
191
  statSync(DIST_SERVER);
@@ -179,7 +197,15 @@ function isProductionMode() {
179
197
 
180
198
  async function ensureServerRunning() {
181
199
  const existing = await findServerPort();
182
- if (existing) return;
200
+ if (existing) {
201
+ const serverVersion = await getServerVersion(existing);
202
+ if (serverVersion && serverVersion !== CLI_VERSION) {
203
+ console.log(`Updating mdr (${serverVersion} → ${CLI_VERSION})...`);
204
+ await stopServer();
205
+ } else {
206
+ return;
207
+ }
208
+ }
183
209
 
184
210
  console.log('Starting mdr...');
185
211
  let childExited = false;
@@ -260,6 +286,11 @@ async function main() {
260
286
  return;
261
287
  }
262
288
 
289
+ if (process.argv[2] === '-v' || process.argv[2] === '--version') {
290
+ console.log(CLI_VERSION);
291
+ return;
292
+ }
293
+
263
294
  if (process.argv[2] === '--stop') {
264
295
  await stopServer();
265
296
  return;
package/dist/server.js CHANGED
@@ -9,6 +9,7 @@ import { join as join2, extname, resolve, dirname } from "path";
9
9
  import { homedir, platform, tmpdir } from "os";
10
10
  import { execFile } from "child_process";
11
11
  import { fileURLToPath, pathToFileURL } from "url";
12
+ import { createRequire } from "module";
12
13
 
13
14
  // server/preferences.ts
14
15
  import { readFile, rename, open } from "fs/promises";
@@ -58,6 +59,8 @@ async function writePreferences(homeDir, patch) {
58
59
  }
59
60
 
60
61
  // server/index.ts
62
+ var require2 = createRequire(import.meta.url);
63
+ var { version: APP_VERSION } = require2("../package.json");
61
64
  var MIME_TYPES = {
62
65
  ".html": "text/html",
63
66
  ".js": "application/javascript",
@@ -199,6 +202,9 @@ function createApp(options = {}) {
199
202
  app2.get("/api/config", (c) => {
200
203
  return c.json({ initialFile, initialDir });
201
204
  });
205
+ app2.get("/api/version", (c) => {
206
+ return c.json({ version: APP_VERSION });
207
+ });
202
208
  app2.get("/api/preferences", async (c) => {
203
209
  return c.json(await readPreferences(homeDir));
204
210
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "md-redline",
3
3
  "description": "Local inline review for markdown files with agent-friendly comment markers.",
4
- "version": "0.1.3",
4
+ "version": "0.1.4",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "homepage": "https://github.com/dejuknow/md-redline",