@gricha/perry 0.1.4 → 0.1.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.
package/dist/index.js CHANGED
@@ -12,6 +12,7 @@ import { startDockerProxy, parsePortForward as parseDockerPortForward, formatPor
12
12
  import { loadAgentConfig, getConfigDir, ensureConfigDir } from './config/loader';
13
13
  import { buildImage } from './docker';
14
14
  import { DEFAULT_AGENT_PORT, WORKSPACE_IMAGE_LOCAL } from './shared/constants';
15
+ import { checkForUpdates } from './update-checker';
15
16
  const program = new Command();
16
17
  program
17
18
  .name('perry')
@@ -477,4 +478,5 @@ function formatUptime(seconds) {
477
478
  parts.push(`${seconds}s`);
478
479
  return parts.join(' ');
479
480
  }
481
+ checkForUpdates(pkg.version);
480
482
  program.parse();
@@ -0,0 +1,81 @@
1
+ import { homedir } from 'os';
2
+ import { join } from 'path';
3
+ import { mkdir, readFile, writeFile } from 'fs/promises';
4
+ const PACKAGE_NAME = '@gricha/perry';
5
+ const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000; // 24 hours
6
+ async function getCacheDir() {
7
+ const dir = join(homedir(), '.config', 'perry');
8
+ await mkdir(dir, { recursive: true });
9
+ return dir;
10
+ }
11
+ async function readCache() {
12
+ try {
13
+ const cacheFile = join(await getCacheDir(), 'update-cache.json');
14
+ const content = await readFile(cacheFile, 'utf-8');
15
+ return JSON.parse(content);
16
+ }
17
+ catch {
18
+ return null;
19
+ }
20
+ }
21
+ async function writeCache(cache) {
22
+ try {
23
+ const cacheFile = join(await getCacheDir(), 'update-cache.json');
24
+ await writeFile(cacheFile, JSON.stringify(cache));
25
+ }
26
+ catch {
27
+ // Ignore cache write errors
28
+ }
29
+ }
30
+ async function fetchLatestVersion() {
31
+ try {
32
+ const response = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`, {
33
+ signal: AbortSignal.timeout(3000),
34
+ });
35
+ if (!response.ok)
36
+ return null;
37
+ const data = (await response.json());
38
+ return data.version || null;
39
+ }
40
+ catch {
41
+ return null;
42
+ }
43
+ }
44
+ function compareVersions(current, latest) {
45
+ const currentParts = current.split('.').map(Number);
46
+ const latestParts = latest.split('.').map(Number);
47
+ for (let i = 0; i < Math.max(currentParts.length, latestParts.length); i++) {
48
+ const c = currentParts[i] || 0;
49
+ const l = latestParts[i] || 0;
50
+ if (l > c)
51
+ return 1;
52
+ if (l < c)
53
+ return -1;
54
+ }
55
+ return 0;
56
+ }
57
+ export async function checkForUpdates(currentVersion) {
58
+ try {
59
+ const cache = await readCache();
60
+ const now = Date.now();
61
+ let latestVersion = null;
62
+ if (cache && now - cache.lastCheck < CHECK_INTERVAL_MS) {
63
+ latestVersion = cache.latestVersion;
64
+ }
65
+ else {
66
+ latestVersion = await fetchLatestVersion();
67
+ await writeCache({ lastCheck: now, latestVersion });
68
+ }
69
+ if (latestVersion && compareVersions(currentVersion, latestVersion) > 0) {
70
+ console.log('');
71
+ console.log(`\x1b[33m╭─────────────────────────────────────────────────────────╮\x1b[0m`);
72
+ console.log(`\x1b[33m│\x1b[0m Update available: \x1b[90m${currentVersion}\x1b[0m → \x1b[32m${latestVersion}\x1b[0m \x1b[33m│\x1b[0m`);
73
+ console.log(`\x1b[33m│\x1b[0m Run \x1b[36mnpm install -g ${PACKAGE_NAME}\x1b[0m to update \x1b[33m│\x1b[0m`);
74
+ console.log(`\x1b[33m╰─────────────────────────────────────────────────────────╯\x1b[0m`);
75
+ console.log('');
76
+ }
77
+ }
78
+ catch {
79
+ // Silently ignore update check errors
80
+ }
81
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gricha/perry",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Self-contained CLI for spinning up Docker-in-Docker development environments with SSH and proxy helpers.",
5
5
  "type": "module",
6
6
  "bin": {