lightman-agent 1.0.25 → 1.0.28

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/cms-agent.js CHANGED
@@ -1,24 +1,35 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { existsSync, readFileSync } from 'fs';
4
- import { networkInterfaces } from 'os';
5
- import { resolve, dirname } from 'path';
6
- import { fileURLToPath } from 'url';
3
+ import { existsSync, readFileSync } from 'fs';
4
+ import { networkInterfaces } from 'os';
5
+ import { resolve, dirname } from 'path';
6
+ import { fileURLToPath } from 'url';
7
7
  import { spawnSync } from 'child_process';
8
8
  import { createInterface } from 'readline/promises';
9
9
  import { stdin as input, stdout as output, cwd, platform, exit } from 'process';
10
10
 
11
- const DEFAULT_SERVER = 'http://192.168.10.100:3401';
12
- const INSTALL_CONFIG_PATH = 'C:\\Program Files\\Lightman\\Agent\\agent.config.json';
13
-
14
- function printUsage() {
15
- console.log(`
16
- cms-agent <command> [options]
17
-
18
- Commands:
19
- install Prompt slug and server IP, install agent with ShellReplace, reboot
20
- setup Alias of install
21
- update Reinstall/update using installed config, reboot
11
+ const DEFAULT_SERVER = 'http://192.168.10.100:3401';
12
+ const INSTALL_CONFIG_PATH = 'C:\\Program Files\\Lightman\\Agent\\agent.config.json';
13
+ const PACKAGE_JSON_PATH = resolve(dirname(fileURLToPath(import.meta.url)), '../package.json');
14
+
15
+ function getVersion() {
16
+ try {
17
+ const pkg = JSON.parse(readFileSync(PACKAGE_JSON_PATH, 'utf8'));
18
+ return String(pkg.version || '0.0.0');
19
+ } catch {
20
+ return '0.0.0';
21
+ }
22
+ }
23
+
24
+ function printUsage() {
25
+ console.log(`
26
+ cms-agent <command> [options]
27
+
28
+ Commands:
29
+ install Prompt slug and server IP, install agent with ShellReplace, reboot
30
+ setup Alias of install
31
+ update Reinstall/update using installed config, reboot
32
+ version Print package version
22
33
 
23
34
  Options:
24
35
  --slug <value> Device slug (example: C-AV01)
@@ -262,28 +273,32 @@ async function runUpdate(opts) {
262
273
  installUsingPowerShell({ scriptPath, slug, server, timezone, pairingTimeoutSeconds, noRestart });
263
274
  }
264
275
 
265
- async function main() {
266
- const [, , commandRaw, ...rest] = process.argv;
267
- const command = commandRaw || '';
268
- const opts = parseArgs(rest);
276
+ async function main() {
277
+ const [, , commandRaw, ...rest] = process.argv;
278
+ const command = commandRaw || '';
279
+ const opts = parseArgs(rest);
269
280
 
270
281
  if (!command || opts.help || command === 'help' || command === '--help' || command === '-h') {
271
282
  printUsage();
272
283
  return;
273
284
  }
274
285
 
275
- if (command === 'install' || command === 'setup') {
276
- await runInstall(opts);
277
- return;
278
- }
279
- if (command === 'update') {
280
- await runUpdate(opts);
281
- return;
282
- }
283
-
284
- printUsage();
285
- throw new Error(`Unknown command: ${command}`);
286
- }
286
+ if (command === 'install' || command === 'setup') {
287
+ await runInstall(opts);
288
+ return;
289
+ }
290
+ if (command === 'update') {
291
+ await runUpdate(opts);
292
+ return;
293
+ }
294
+ if (command === 'version' || command === '--version' || command === '-v') {
295
+ console.log(`lightman-agent v${getVersion()}`);
296
+ return;
297
+ }
298
+
299
+ printUsage();
300
+ throw new Error(`Unknown command: ${command}`);
301
+ }
287
302
 
288
303
  main().catch((err) => {
289
304
  console.error(err instanceof Error ? err.message : String(err));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lightman-agent",
3
- "version": "1.0.25",
3
+ "version": "1.0.28",
4
4
  "description": "LIGHTMAN Agent - System-level daemon for museum display machines",
5
5
  "private": false,
6
6
  "type": "module",
@@ -100,23 +100,20 @@ if "%BROWSER%"=="" (
100
100
  echo [%date% %time%] Browser: %BROWSER% >> "%LOG_FILE%"
101
101
  echo [%date% %time%] URL: %URL% >> "%LOG_FILE%"
102
102
 
103
- REM ----------------------------------------------------------------
104
- REM Wait for agent service (port 3403)
105
- REM ----------------------------------------------------------------
106
- echo [%date% %time%] Waiting for port 3403... >> "%LOG_FILE%"
107
- set WAIT_COUNT=0
108
- set MAX_WAIT=60
109
-
110
- :wait_for_agent
111
- netstat -an | findstr ":3403.*LISTENING" >nul 2>&1
112
- if %errorlevel%==0 goto agent_ready
113
- set /a WAIT_COUNT+=1
114
- if %WAIT_COUNT% geq %MAX_WAIT% (
115
- echo [%date% %time%] Port 3403 not ready after %MAX_WAIT%s, launching anyway >> "%LOG_FILE%"
116
- goto agent_ready
117
- )
118
- timeout /t 1 /nobreak >nul
119
- goto wait_for_agent
103
+ REM ----------------------------------------------------------------
104
+ REM Wait for agent service (port 3403)
105
+ REM ----------------------------------------------------------------
106
+ echo [%date% %time%] Waiting for port 3403... >> "%LOG_FILE%"
107
+ set WAIT_COUNT=0
108
+
109
+ :wait_for_agent
110
+ netstat -an | findstr ":3403.*LISTENING" >nul 2>&1
111
+ if %errorlevel%==0 goto agent_ready
112
+ set /a WAIT_COUNT+=1
113
+ set /a WAIT_MOD=WAIT_COUNT %% 30
114
+ if %WAIT_MOD%==0 echo [%date% %time%] Still waiting for port 3403... (%WAIT_COUNT%s) >> "%LOG_FILE%"
115
+ timeout /t 1 /nobreak >nul
116
+ goto wait_for_agent
120
117
 
121
118
  :agent_ready
122
119
  echo [%date% %time%] Agent ready >> "%LOG_FILE%"