shared-things-server 1.0.4 → 1.0.5

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.
Files changed (2) hide show
  1. package/dist/cli.js +48 -6
  2. package/package.json +3 -2
package/dist/cli.js CHANGED
@@ -4,6 +4,7 @@
4
4
  import { Command } from "commander";
5
5
  import { input, confirm } from "@inquirer/prompts";
6
6
  import chalk from "chalk";
7
+ import updateNotifier from "update-notifier";
7
8
 
8
9
  // src/db.ts
9
10
  import Database from "better-sqlite3";
@@ -409,6 +410,42 @@ function registerRoutes(app, db) {
409
410
 
410
411
  // src/cli.ts
411
412
  var pkg = JSON.parse(fs2.readFileSync(new URL("../package.json", import.meta.url), "utf-8"));
413
+ var updateCheckInterval = 1e3 * 60 * 60;
414
+ var notifier = updateNotifier({ pkg, updateCheckInterval });
415
+ if (notifier.update) {
416
+ notifier.update.current = pkg.version;
417
+ if (notifier.update.current === notifier.update.latest) {
418
+ notifier.update = void 0;
419
+ }
420
+ }
421
+ var lastCheck = notifier.config?.get("lastUpdateCheck") ?? 0;
422
+ var isFirstRun = Date.now() - lastCheck < 1e3;
423
+ var intervalPassed = Date.now() - lastCheck >= updateCheckInterval;
424
+ if (!notifier.update && (isFirstRun || intervalPassed)) {
425
+ try {
426
+ const update = await notifier.fetchInfo();
427
+ notifier.config?.set("lastUpdateCheck", Date.now());
428
+ if (update && update.type !== "latest") {
429
+ notifier.update = update;
430
+ }
431
+ } catch {
432
+ }
433
+ }
434
+ if (notifier.update && notifier.update.current !== notifier.update.latest) {
435
+ notifier.config?.set("update", notifier.update);
436
+ } else {
437
+ notifier.config?.delete("update");
438
+ }
439
+ process.on("exit", () => {
440
+ if (notifier.update && notifier.update.current !== notifier.update.latest) {
441
+ console.error(
442
+ chalk.yellow(`
443
+ Update available: ${notifier.update.current} \u2192 ${notifier.update.latest}`) + chalk.dim(`
444
+ Run: npm i -g ${pkg.name}
445
+ `)
446
+ );
447
+ }
448
+ });
412
449
  var DATA_DIR2 = process.env.DATA_DIR || path2.join(os2.homedir(), ".shared-things-server");
413
450
  var PID_FILE = path2.join(DATA_DIR2, "server.pid");
414
451
  var LOG_FILE = path2.join(DATA_DIR2, "server.log");
@@ -522,24 +559,29 @@ program.command("stop").description("Stop the background server").action(() => {
522
559
  program.command("status").description("Show server status").action(() => {
523
560
  const status = isServerRunning();
524
561
  console.log(chalk.bold("\n\u{1F4CA} Server Status\n"));
562
+ let versionLine = ` ${chalk.dim("Version:")} ${pkg.version}`;
563
+ if (notifier.update && notifier.update.current !== notifier.update.latest) {
564
+ versionLine += chalk.yellow(` \u2192 ${notifier.update.latest} available`);
565
+ }
566
+ console.log(versionLine);
525
567
  if (status.running) {
526
- console.log(` ${chalk.dim("Status:")} ${chalk.green("\u25CF running")}`);
527
- console.log(` ${chalk.dim("PID:")} ${status.pid}`);
568
+ console.log(` ${chalk.dim("Status:")} ${chalk.green("\u25CF running")}`);
569
+ console.log(` ${chalk.dim("PID:")} ${status.pid}`);
528
570
  } else {
529
- console.log(` ${chalk.dim("Status:")} ${chalk.red("\u25CB stopped")}`);
571
+ console.log(` ${chalk.dim("Status:")} ${chalk.red("\u25CB stopped")}`);
530
572
  }
531
573
  if (fs2.existsSync(LOG_FILE)) {
532
574
  const stats = fs2.statSync(LOG_FILE);
533
575
  const sizeKB = Math.round(stats.size / 1024);
534
- console.log(` ${chalk.dim("Logs:")} ${LOG_FILE} (${sizeKB}KB)`);
576
+ console.log(` ${chalk.dim("Logs:")} ${LOG_FILE} (${sizeKB}KB)`);
535
577
  }
536
578
  const dbPath = path2.join(DATA_DIR2, "data.db");
537
579
  if (fs2.existsSync(dbPath)) {
538
580
  const db = initDatabase();
539
581
  const users = listUsers(db);
540
582
  const todos = getAllTodos(db);
541
- console.log(` ${chalk.dim("Users:")} ${users.length}`);
542
- console.log(` ${chalk.dim("Todos:")} ${todos.length}`);
583
+ console.log(` ${chalk.dim("Users:")} ${users.length}`);
584
+ console.log(` ${chalk.dim("Todos:")} ${todos.length}`);
543
585
  }
544
586
  console.log();
545
587
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shared-things-server",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Sync server for Things 3 projects",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -42,7 +42,8 @@
42
42
  "better-sqlite3": "^11.0.0",
43
43
  "chalk": "^5.6.2",
44
44
  "commander": "^12.0.0",
45
- "fastify": "^4.26.0"
45
+ "fastify": "^4.26.0",
46
+ "update-notifier": "^7.0.0"
46
47
  },
47
48
  "devDependencies": {
48
49
  "@types/better-sqlite3": "^7.6.8",