lightman-agent 1.0.20 → 1.0.21

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
@@ -8,27 +8,30 @@ 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
22
-
23
- Options:
24
- --slug <value> Device slug (example: C-AV01)
25
- --server <url> Server URL or IP (example: 192.168.10.100 or http://192.168.10.100:3401)
26
- --timezone <tz> Timezone override (default: Asia/Kolkata)
27
- --pair-timeout <s> Wait time for pairing in seconds (default: 900, 0 = no timeout)
28
- --no-restart Skip reboot after successful install/update
29
- -h, --help Show help
30
- `);
31
- }
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 INSTALL_PACKAGE_PATH = 'C:\\Program Files\\Lightman\\Agent\\package.json';
14
+
15
+ function printUsage() {
16
+ console.log(`
17
+ cms-agent <command> [options]
18
+
19
+ Commands:
20
+ install Prompt slug and server IP, install agent with ShellReplace, reboot
21
+ setup Alias of install
22
+ update Reinstall/update using installed config, reboot
23
+ version Show CLI package version and installed agent version
24
+
25
+ Options:
26
+ --slug <value> Device slug (example: C-AV01)
27
+ --server <url> Server URL or IP (example: 192.168.10.100 or http://192.168.10.100:3401)
28
+ --timezone <tz> Timezone override (default: Asia/Kolkata)
29
+ --pair-timeout <s> Wait time for pairing in seconds (default: 900, 0 = no timeout)
30
+ --no-restart Skip reboot after successful install/update
31
+ -v, --version Show version
32
+ -h, --help Show help
33
+ `);
34
+ }
32
35
 
33
36
  function parseArgs(argv) {
34
37
  const args = {};
@@ -177,14 +180,27 @@ async function promptServer(defaultServer) {
177
180
  }
178
181
  }
179
182
 
180
- function resolveInstallScript() {
181
- const here = dirname(fileURLToPath(import.meta.url));
182
- const packaged = resolve(here, '../scripts/install-windows.ps1');
183
+ function resolveInstallScript() {
184
+ const here = dirname(fileURLToPath(import.meta.url));
185
+ const packaged = resolve(here, '../scripts/install-windows.ps1');
183
186
  const localRepo = resolve(cwd(), 'scripts/install-windows.ps1');
184
187
  if (existsSync(packaged)) return packaged;
185
188
  if (existsSync(localRepo)) return localRepo;
186
- throw new Error('install-windows.ps1 not found. Expected in package scripts/ or current folder scripts/.');
187
- }
189
+ throw new Error('install-windows.ps1 not found. Expected in package scripts/ or current folder scripts/.');
190
+ }
191
+
192
+ function runVersion() {
193
+ const here = dirname(fileURLToPath(import.meta.url));
194
+ const bundledPkg = safeReadJson(resolve(here, '../package.json')) || {};
195
+ const installedPkg = safeReadJson(INSTALL_PACKAGE_PATH) || {};
196
+
197
+ const cliVersion = typeof bundledPkg.version === 'string' ? bundledPkg.version : 'unknown';
198
+ const installedVersion = typeof installedPkg.version === 'string' ? installedPkg.version : 'not-installed';
199
+
200
+ console.log(`lightman-agent cli: ${cliVersion}`);
201
+ console.log(`lightman-agent installed: ${installedVersion}`);
202
+ console.log(`node: ${process.version}`);
203
+ }
188
204
 
189
205
  function installUsingPowerShell({ scriptPath, slug, server, timezone, pairingTimeoutSeconds, noRestart }) {
190
206
  console.log(`powershell -ExecutionPolicy Bypass -File scripts\\install-windows.ps1 -Slug "${slug}" -Server "${server}" -ShellReplace`);
@@ -262,19 +278,24 @@ async function runUpdate(opts) {
262
278
  installUsingPowerShell({ scriptPath, slug, server, timezone, pairingTimeoutSeconds, noRestart });
263
279
  }
264
280
 
265
- async function main() {
266
- const [, , commandRaw, ...rest] = process.argv;
267
- const command = commandRaw || '';
268
- const opts = parseArgs(rest);
269
-
270
- if (!command || opts.help || command === 'help' || command === '--help' || command === '-h') {
271
- printUsage();
272
- return;
273
- }
274
-
275
- if (command === 'install' || command === 'setup') {
276
- await runInstall(opts);
277
- return;
281
+ async function main() {
282
+ const [, , commandRaw, ...rest] = process.argv;
283
+ const command = commandRaw || '';
284
+ const opts = parseArgs(rest);
285
+
286
+ if (!command || opts.help || command === 'help' || command === '--help' || command === '-h') {
287
+ printUsage();
288
+ return;
289
+ }
290
+
291
+ if (command === 'version' || command === '--version' || command === '-v') {
292
+ runVersion();
293
+ return;
294
+ }
295
+
296
+ if (command === 'install' || command === 'setup') {
297
+ await runInstall(opts);
298
+ return;
278
299
  }
279
300
  if (command === 'update') {
280
301
  await runUpdate(opts);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lightman-agent",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "description": "LIGHTMAN Agent - System-level daemon for museum display machines",
5
5
  "private": false,
6
6
  "type": "module",
@@ -25,11 +25,35 @@ $ChromeData = "C:\ProgramData\Lightman\chrome-kiosk"
25
25
  $NssmDir = "C:\ProgramData\Lightman\nssm"
26
26
  $NssmExe = "$NssmDir\nssm.exe"
27
27
  $ServiceName = "LightmanAgent"
28
- $GuardianTask = "LIGHTMAN Guardian"
29
- $KioskTask = "LIGHTMAN Kiosk Browser"
30
- $AgentTask = "LIGHTMAN Agent"
31
- $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
32
- $AgentDir = Split-Path -Parent $ScriptDir
28
+ $GuardianTask = "LIGHTMAN Guardian"
29
+ $KioskTask = "LIGHTMAN Kiosk Browser"
30
+ $AgentTask = "LIGHTMAN Agent"
31
+ $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
32
+ $AgentDir = Split-Path -Parent $ScriptDir
33
+
34
+ function Ensure-PathContains {
35
+ param(
36
+ [Parameter(Mandatory=$true)][ValidateSet('Machine','User')] [string]$Scope,
37
+ [Parameter(Mandatory=$true)] [string]$Entry
38
+ )
39
+ $current = [System.Environment]::GetEnvironmentVariable("Path", $Scope)
40
+ if (-not $current) { $current = "" }
41
+ $parts = $current -split ';' | Where-Object { $_ -and $_.Trim() -ne "" }
42
+ $normalizedEntry = $Entry.TrimEnd('\')
43
+ $exists = $false
44
+ foreach ($p in $parts) {
45
+ if ($p.TrimEnd('\') -ieq $normalizedEntry) {
46
+ $exists = $true
47
+ break
48
+ }
49
+ }
50
+ if (-not $exists) {
51
+ $newPath = if ($current -and $current.Trim() -ne "") { "$current;$Entry" } else { $Entry }
52
+ [System.Environment]::SetEnvironmentVariable("Path", $newPath, $Scope)
53
+ return $true
54
+ }
55
+ return $false
56
+ }
33
57
 
34
58
  if (-not $Username) { $Username = $env:USERNAME }
35
59
 
@@ -91,9 +115,9 @@ Write-Host ""
91
115
  # PART 1: BUILD & INSTALL
92
116
  # ============================================================
93
117
 
94
- # --- 1. Node.js ---
95
- Write-Host "[1/19] Checking Node.js..." -ForegroundColor Yellow
96
- try {
118
+ # --- 1. Node.js ---
119
+ Write-Host "[1/19] Checking Node.js..." -ForegroundColor Yellow
120
+ try {
97
121
  $nodeVersion = (node -v) -replace 'v', ''
98
122
  if ([int]($nodeVersion.Split('.')[0]) -lt 20) { throw "old" }
99
123
  Write-Host " Found Node.js v$nodeVersion"
@@ -106,7 +130,19 @@ try {
106
130
  $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
107
131
  if (-not (Get-Command node -ErrorAction SilentlyContinue)) { Write-Host " FATAL: Node.js install failed!" -ForegroundColor Red; exit 1 }
108
132
  Write-Host " Node.js installed" -ForegroundColor Green
109
- }
133
+ }
134
+
135
+ # Always ensure Node path remains available after kiosk conversion
136
+ $nodePath = (Get-Command node).Source
137
+ $nodeDir = Split-Path -Parent $nodePath
138
+ $addedMachine = Ensure-PathContains -Scope "Machine" -Entry $nodeDir
139
+ $addedUser = Ensure-PathContains -Scope "User" -Entry $nodeDir
140
+ $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
141
+ if ($addedMachine -or $addedUser) {
142
+ Write-Host " Ensured Node.js path in PATH: $nodeDir" -ForegroundColor Green
143
+ } else {
144
+ Write-Host " Node.js path already present in PATH"
145
+ }
110
146
 
111
147
  # --- 2. Build ---
112
148
  Write-Host "[2/19] Building agent..." -ForegroundColor Yellow