tr200 2.0.2 → 2.0.3

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/tr200.js +88 -26
  2. package/package.json +1 -1
package/bin/tr200.js CHANGED
@@ -35,6 +35,63 @@ if (Get-Command tr200 -ErrorAction SilentlyContinue) {
35
35
  }
36
36
  `;
37
37
 
38
+ // All patterns to detect (TR-100 and TR-200 variants)
39
+ const ALL_MARKERS = [
40
+ 'TR-200 Machine Report (npm)', // npm-installed
41
+ 'TR-200 Machine Report configuration', // install.sh installed
42
+ 'TR-200 Machine Report - run on login', // .profile/.zprofile
43
+ 'TR-200 Machine Report - run on bash login', // .bash_profile
44
+ 'Run Machine Report only when in interactive mode', // TR-100 (original upstream)
45
+ 'TR-100 Machine Report', // TR-100 header
46
+ '# Machine Report alias', // TR-100 alias marker
47
+ ];
48
+
49
+ // Clean a profile file of ALL TR-100/TR-200 entries
50
+ function cleanProfileFile(filePath) {
51
+ if (!fs.existsSync(filePath)) return false;
52
+
53
+ let content = fs.readFileSync(filePath, 'utf8');
54
+ const originalContent = content;
55
+
56
+ // Check if any markers exist
57
+ const hasMarkers = ALL_MARKERS.some(marker => content.includes(marker));
58
+ if (!hasMarkers && !content.includes('machine_report')) {
59
+ return false;
60
+ }
61
+
62
+ // Remove npm-style TR-200 blocks (Unix)
63
+ content = content.replace(/\n?# TR-200 Machine Report \(npm\) - auto-run\nif command -v tr200 &> \/dev\/null; then\n tr200\nfi\n?/g, '');
64
+
65
+ // Remove npm-style TR-200 blocks (PowerShell)
66
+ content = content.replace(/\n?# TR-200 Machine Report \(npm\) - auto-run\nif \(Get-Command tr200 -ErrorAction SilentlyContinue\) \{\n tr200\n\}\n?/g, '');
67
+
68
+ // Remove install.sh TR-200 blocks (matches the full block including aliases)
69
+ content = content.replace(/\n?# TR-200 Machine Report configuration\nalias report=.*\nalias uninstall=.*\n\n?# Auto-run on interactive (?:bash|zsh) shell.*\nif \[\[.*\]\]; then\n clear\n ~\/.machine_report\.sh\nfi\n?/g, '');
70
+
71
+ // Remove TR-200 login blocks (.profile/.zprofile/.bash_profile)
72
+ content = content.replace(/\n?# TR-200 Machine Report - run on (?:login|bash login).*\nif \[ -x "\$HOME\/.machine_report\.sh" \]; then\n clear\n "\$HOME\/.machine_report\.sh"\nfi\n?/g, '');
73
+
74
+ // Remove TR-100 blocks (original upstream pattern)
75
+ content = content.replace(/\n?# Run Machine Report only when in interactive mode\nif \[\[ \$- == \*i\* \]\]; then\n ~\/.machine_report\.sh\nfi\n?/g, '');
76
+
77
+ // Remove any stray alias lines
78
+ content = content.replace(/\n?alias report=.*machine_report.*\n?/g, '\n');
79
+ content = content.replace(/\n?alias uninstall=.*machine_report.*\n?/g, '\n');
80
+
81
+ // Remove TR-100 alias marker
82
+ content = content.replace(/\n?# Machine Report alias\n?/g, '\n');
83
+
84
+ // Clean up excessive blank lines (more than 2 consecutive)
85
+ content = content.replace(/\n{3,}/g, '\n\n');
86
+ content = content.trim();
87
+
88
+ if (content !== originalContent.trim()) {
89
+ fs.writeFileSync(filePath, content + '\n', 'utf8');
90
+ return true;
91
+ }
92
+ return false;
93
+ }
94
+
38
95
  // Shell profile paths
39
96
  function getProfilePaths() {
40
97
  if (isWindows) {
@@ -70,13 +127,21 @@ function askConfirmation(question) {
70
127
  });
71
128
  }
72
129
 
73
- // Check if config already exists in file
130
+ // Check if npm config already exists in file
74
131
  function hasConfig(filePath) {
75
132
  if (!fs.existsSync(filePath)) return false;
76
133
  const content = fs.readFileSync(filePath, 'utf8');
77
134
  return content.includes(CONFIG_MARKER);
78
135
  }
79
136
 
137
+ // Check if ANY TR-100/TR-200 config exists (for cleanup detection)
138
+ function hasAnyConfig(filePath) {
139
+ if (!fs.existsSync(filePath)) return false;
140
+ const content = fs.readFileSync(filePath, 'utf8');
141
+ return ALL_MARKERS.some(marker => content.includes(marker)) ||
142
+ content.includes('machine_report');
143
+ }
144
+
80
145
  // Install auto-run to shell profiles
81
146
  async function installAutoRun() {
82
147
  const profiles = getProfilePaths();
@@ -94,11 +159,25 @@ async function installAutoRun() {
94
159
  process.exit(0);
95
160
  }
96
161
 
162
+ // First, clean up any existing TR-100/TR-200 configurations
163
+ console.log('Cleaning previous installations...');
164
+ let cleaned = 0;
165
+ for (const profilePath of profiles) {
166
+ if (cleanProfileFile(profilePath)) {
167
+ console.log(` [cleaned] ${profilePath}`);
168
+ cleaned++;
169
+ }
170
+ }
171
+ if (cleaned > 0) {
172
+ console.log(` Cleaned ${cleaned} profile(s)`);
173
+ }
174
+ console.log('');
175
+
97
176
  let installed = 0;
98
177
  let skipped = 0;
99
178
 
100
179
  for (const profilePath of profiles) {
101
- // Check if already configured
180
+ // Check if already configured (with npm marker specifically)
102
181
  if (hasConfig(profilePath)) {
103
182
  console.log(` [skip] ${profilePath} - already configured`);
104
183
  skipped++;
@@ -136,7 +215,7 @@ async function uninstallAutoRun() {
136
215
  const profiles = getProfilePaths();
137
216
 
138
217
  console.log('\nTR-200 Machine Report - Remove Auto-Run\n');
139
- console.log('This will remove the auto-run configuration from your shell profile(s).');
218
+ console.log('This will remove ALL TR-100/TR-200 configurations from your shell profile(s).');
140
219
  console.log('Profile(s) to check:');
141
220
  profiles.forEach(p => console.log(` - ${p}`));
142
221
  console.log('');
@@ -154,27 +233,10 @@ async function uninstallAutoRun() {
154
233
  continue;
155
234
  }
156
235
 
157
- const content = fs.readFileSync(profilePath, 'utf8');
158
- if (!content.includes(CONFIG_MARKER)) {
159
- continue;
160
- }
161
-
162
- // Remove the config block (handles both Unix and PowerShell formats)
163
- // Match from the comment line through the closing fi/}
164
- const unixPattern = /\n?# TR-200 Machine Report \(npm\) - auto-run\nif command -v tr200 &> \/dev\/null; then\n tr200\nfi\n?/g;
165
- const psPattern = /\n?# TR-200 Machine Report \(npm\) - auto-run\nif \(Get-Command tr200 -ErrorAction SilentlyContinue\) \{\n tr200\n\}\n?/g;
166
-
167
- let newContent = content.replace(unixPattern, '');
168
- newContent = newContent.replace(psPattern, '');
169
-
170
- if (newContent !== content) {
171
- try {
172
- fs.writeFileSync(profilePath, newContent, 'utf8');
173
- console.log(` [done] ${profilePath}`);
174
- removed++;
175
- } catch (err) {
176
- console.error(` [error] ${profilePath}: ${err.message}`);
177
- }
236
+ // Use the comprehensive cleanup function
237
+ if (cleanProfileFile(profilePath)) {
238
+ console.log(` [done] ${profilePath}`);
239
+ removed++;
178
240
  }
179
241
  }
180
242
 
@@ -280,7 +342,7 @@ function runReport() {
280
342
  // Handle help flag
281
343
  if (process.argv.includes('--help') || process.argv.includes('-h')) {
282
344
  console.log(`
283
- TR-200 Machine Report v2.0.1
345
+ TR-200 Machine Report v2.0.3
284
346
 
285
347
  Usage: tr200 [options]
286
348
  report [options]
@@ -300,7 +362,7 @@ More info: https://github.com/RealEmmettS/usgc-machine-report
300
362
 
301
363
  // Handle version flag
302
364
  if (process.argv.includes('--version') || process.argv.includes('-v')) {
303
- console.log('2.0.2');
365
+ console.log('2.0.3');
304
366
  process.exit(0);
305
367
  }
306
368
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tr200",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "Cross-platform system information report with Unicode box-drawing display",
5
5
  "author": "shaughv",
6
6
  "license": "BSD-3-Clause",