plc-checkweigher 1.13.0 → 1.14.0

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 (2) hide show
  1. package/bin/cli.js +39 -24
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -47,10 +47,9 @@ function dotRows(word) {
47
47
  }
48
48
 
49
49
  // ── TØVEX-SYSTEMS access banner ───────────────────────────────────────────────
50
- function showAccessDenied() {
51
- const INNER = 52; // characters between the ║ borders
50
+ function buildBanner() {
51
+ const INNER = 52;
52
52
 
53
- // Center a plain-text string inside INNER
54
53
  function cen(str) {
55
54
  const len = str.length;
56
55
  const lpad = Math.floor((INNER - len) / 2);
@@ -67,29 +66,45 @@ function showAccessDenied() {
67
66
 
68
67
  const tRow = dotRows('TØVEX');
69
68
  const sRow = dotRows('SYSTEMS');
69
+ const sep = Array.from({ length: sRow[0].length }, (_, i) => i % 2 ? ' ' : '·').join('');
70
+
71
+ const lines = [
72
+ '',
73
+ `${B}╔${bar}╗${NC}`,
74
+ blank,
75
+ ...tRow.map(r => boxRow(r, B)),
76
+ blank,
77
+ boxRow(sep, D),
78
+ blank,
79
+ ...sRow.map(r => boxRow(r, B)),
80
+ blank,
81
+ `${B}╚${bar}╝${NC}`,
82
+ '',
83
+ ` ${R}⚠ Please contact administrator for access${NC}`,
84
+ '',
85
+ ];
86
+ return lines.join('\n');
87
+ }
70
88
 
71
- // Dot-separator exactly as wide as SYSTEMS
72
- const sep = Array.from({ length: sRow[0].length }, (_, i) => i % 2 ? ' ' : '·').join('');
73
-
74
- // ── Print box ─────────────────────────────────────────────────────────────
75
- console.log('');
76
- console.log(`${B}╔${bar}╗${NC}`);
77
- console.log(blank);
78
- for (const r of tRow) console.log(boxRow(r, B));
79
- console.log(blank);
80
- console.log(boxRow(sep, D));
81
- console.log(blank);
82
- for (const r of sRow) console.log(boxRow(r, B));
83
- console.log(blank);
84
- console.log(`${B}╚${bar}╝${NC}`);
85
-
86
- // ── Access-denied message ─────────────────────────────────────────────────
87
- console.log('');
88
- console.log(` ${R}⚠ Please contact administrator for access${NC}`);
89
- console.log('');
89
+ function showAccessDenied() {
90
+ const banner = buildBanner();
91
+ const isPostinstall = process.env.npm_lifecycle_event === 'postinstall';
92
+
93
+ if (isPostinstall) {
94
+ // npm 7+ pipes away stdout/stderr of dependency lifecycle scripts.
95
+ // Write directly to /dev/tty so it reaches the terminal regardless.
96
+ try {
97
+ const fd = fs.openSync('/dev/tty', 'w');
98
+ fs.writeSync(fd, banner + '\n');
99
+ fs.closeSync(fd);
100
+ } catch (_) {
101
+ // No real terminal attached (CI, pipe) — silently skip.
102
+ }
103
+ process.exit(0);
104
+ }
90
105
 
91
- // Exit 0 when invoked by npm postinstall so the install is not marked failed
92
- process.exit(process.env.npm_lifecycle_event === 'postinstall' ? 0 : 1);
106
+ console.log(banner);
107
+ process.exit(1);
93
108
  }
94
109
 
95
110
  // ── Argument parsing ──────────────────────────────────────────────────────────
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plc-checkweigher",
3
- "version": "1.13.0",
3
+ "version": "1.14.0",
4
4
  "description": "One-command installer for the PLC Check-Weigher system on Raspberry Pi (PREEMPT_RT kernel, Python stack, WiFi, SMB, systemd RT services)",
5
5
  "scripts": {
6
6
  "postinstall": "node bin/cli.js"