Lines 16-56javascript
17// --- Self-update check (runs before server starts) ---
18const currentVersion = require('./package.json').version;
19const { execFile, execSync } = require('child_process');
20const shellOpt = process.platform === 'win32';
22function checkSelfUpdate() {
23 return new Promise(ok => {
24 // Skip in non-interactive or local dev contexts
25 if (!process.stdin.isTTY || !process.stdout.isTTY) return ok();
26 if (!__dirname.includes(join('node_modules', 'clideck'))) return ok();
27 execFile('npm', ['view', 'clideck', 'version'], { shell: shellOpt, timeout: 10000 }, (err, stdout) => {
29 const latest = stdout.trim();
30 if (!latest || latest === currentVersion) return ok();
31 const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
32 rl.question(`\n\x1b[38;5;105m Update available:\x1b[0m \x1b[38;5;245m${currentVersion}\x1b[0m → \x1b[38;5;44m${latest}\x1b[0m\n\n \x1b[38;5;252mUpdate now? [Y/n]\x1b[0m `, answer => {
34 if (answer.trim().toLowerCase() === 'n') return ok();
35 console.log('\n \x1b[38;5;245mUpdating...\x1b[0m\n');
37 execSync('npm install -g clideck', { stdio: 'inherit', shell: true });
38 console.log('\n \x1b[38;5;44mUpdated to v' + latest + '. Restarting...\x1b[0m\n');
HighRuntime Package Install
Package source invokes a package manager install command at runtime.
server.jsView on unpkg · L36 39 const { spawn } = require('child_process');
40 spawn(process.argv[0], process.argv.slice(1), { stdio: 'inherit', shell: shellOpt }).on('close', code => process.exit(code));
43 console.log('\n \x1b[38;5;196mUpdate failed.\x1b[0m Continuing with v' + currentVersion + '.\n');
51checkSelfUpdate().then(() => {
53const { acquireServerLock, removeLockIfOwned } = require('./single-instance');
54const serverLock = acquireServerLock();
56 const url = serverLock.lock?.url || `http://127.0.0.1:${serverLock.lock?.port || PORT}`;