shared-things-server 1.0.3 → 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 (3) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cli.js +48 -6
  3. package/package.json +9 -9
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 yungweng
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
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.3",
3
+ "version": "1.0.5",
4
4
  "description": "Sync server for Things 3 projects",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -11,11 +11,6 @@
11
11
  "dist",
12
12
  "README.md"
13
13
  ],
14
- "scripts": {
15
- "build": "tsup",
16
- "dev": "tsx watch src/cli.ts start",
17
- "prepublishOnly": "pnpm build"
18
- },
19
14
  "keywords": [
20
15
  "things",
21
16
  "things3",
@@ -47,14 +42,19 @@
47
42
  "better-sqlite3": "^11.0.0",
48
43
  "chalk": "^5.6.2",
49
44
  "commander": "^12.0.0",
50
- "fastify": "^4.26.0"
45
+ "fastify": "^4.26.0",
46
+ "update-notifier": "^7.0.0"
51
47
  },
52
48
  "devDependencies": {
53
- "@shared-things/common": "workspace:*",
54
49
  "@types/better-sqlite3": "^7.6.8",
55
50
  "@types/node": "^20.0.0",
56
51
  "tsup": "^8.5.1",
57
52
  "tsx": "^4.7.0",
58
- "typescript": "^5.3.0"
53
+ "typescript": "^5.3.0",
54
+ "@shared-things/common": "0.1.0"
55
+ },
56
+ "scripts": {
57
+ "build": "tsup",
58
+ "dev": "tsx watch src/cli.ts start"
59
59
  }
60
60
  }