hale-commenting-system 3.4.5 → 3.5.1

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/README.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  A commenting system for PatternFly React applications that allows designers and developers to add comments directly on design pages, sync with GitHub Issues, and link Jira tickets.
4
4
 
5
+ ## 🚨 **CRITICAL: Read Before Uninstalling**
6
+
7
+ **This package modifies your project files during setup.**
8
+
9
+ **BEFORE uninstalling, you MUST run:**
10
+ ```bash
11
+ npx hale-commenting-system remove
12
+ npm uninstall hale-commenting-system
13
+ ```
14
+
15
+ **Failure to run `remove` first will break your app!** See the [Uninstalling](#uninstalling) section below.
16
+
5
17
  ## Features
6
18
 
7
19
  - **Pin-based commenting** - Click anywhere on a page to add a comment pin
@@ -21,15 +33,9 @@ This package was developed for **PatternFly React Seed** projects, but can be us
21
33
 
22
34
  The automated integration script (`npx hale-commenting-system init`) works best with PatternFly React Seed or projects with a similar structure.
23
35
 
24
- ## Installation
36
+ ## Installation and Setup
25
37
 
26
- ```bash
27
- npm install hale-commenting-system
28
- ```
29
-
30
- > **āš ļø Important:** This package modifies your project files during installation. Before uninstalling, always run `npx hale-commenting-system remove` to cleanly remove the integration and avoid breaking your application.
31
-
32
- ## Quick Start
38
+ > **āš ļø Note:** This package modifies your project files during setup. See the [Uninstalling](#uninstalling) section for proper removal instructions.
33
39
 
34
40
  1. **Install the package:**
35
41
  ```bash
@@ -54,21 +60,50 @@ npm install hale-commenting-system
54
60
 
55
61
  ## Uninstalling
56
62
 
57
- **IMPORTANT:** Before uninstalling the package, you must first remove the integration to avoid breaking your application.
63
+ **āš ļø IMPORTANT: Two-Step Process Required**
64
+
65
+ You **MUST** run the removal script before uninstalling to avoid breaking your app:
66
+
67
+ ### Step 1: Remove Integration
68
+
69
+ ```bash
70
+ npx hale-commenting-system remove
71
+ ```
72
+
73
+ This removes all integration code from your project files.
74
+
75
+ ### Step 2: Uninstall Package
76
+
77
+ ```bash
78
+ npm uninstall hale-commenting-system
79
+ ```
80
+
81
+ ### Step 3: Restart Dev Server
58
82
 
59
- ### Clean Uninstall Process
83
+ ```bash
84
+ npm run start:dev
85
+ ```
86
+
87
+ ### What If I Forgot and Already Uninstalled?
88
+
89
+ If you uninstalled without running `remove` first and your app is now broken:
90
+
91
+ 1. **Reinstall the package:**
92
+ ```bash
93
+ npm install hale-commenting-system
94
+ ```
60
95
 
61
- 1. **Run the removal script:**
96
+ 2. **Run the removal script:**
62
97
  ```bash
63
98
  npx hale-commenting-system remove
64
99
  ```
65
100
 
66
- 2. **Uninstall the package:**
101
+ 3. **Uninstall again:**
67
102
  ```bash
68
103
  npm uninstall hale-commenting-system
69
104
  ```
70
105
 
71
- 3. **Restart your dev server:**
106
+ 4. **Restart your dev server:**
72
107
  ```bash
73
108
  npm run start:dev
74
109
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hale-commenting-system",
3
- "version": "3.4.5",
3
+ "version": "3.5.1",
4
4
  "description": "A commenting system for PatternFly React applications that allows designers and developers to add comments directly on design pages, sync with GitHub Issues, and link Jira tickets.",
5
5
  "homepage": "https://www.npmjs.com/package/hale-commenting-system",
6
6
  "license": "MIT",
@@ -17,6 +17,8 @@
17
17
  "GITHUB_OAUTH_ENV_TEMPLATE.md"
18
18
  ],
19
19
  "scripts": {
20
+ "postinstall": "node scripts/postinstall.js || true",
21
+ "preuninstall": "node scripts/auto-remove.js || true",
20
22
  "prebuild": "npm run type-check && npm run clean",
21
23
  "build": "webpack --config webpack.prod.js",
22
24
  "start": "sirv dist --cors --single --host --port 8080",
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Automatic cleanup script that runs before npm uninstall
5
+ * This ensures the user's app doesn't break when they uninstall the package
6
+ */
7
+
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+
11
+ // Determine project root based on where this script is running
12
+ // During preuninstall, CWD could be either:
13
+ // 1. The package directory: /path/to/project/node_modules/hale-commenting-system
14
+ // 2. The project directory: /path/to/project
15
+ let projectRoot;
16
+
17
+ if (process.cwd().includes('node_modules')) {
18
+ // Running from inside node_modules/hale-commenting-system
19
+ projectRoot = path.resolve(process.cwd(), '../..');
20
+ } else {
21
+ // Running from project root
22
+ projectRoot = process.cwd();
23
+ }
24
+
25
+ console.log('\n╔════════════════════════════════════════════════════╗');
26
+ console.log('ā•‘ Hale Commenting System - Auto Cleanup ā•‘');
27
+ console.log('ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•\n');
28
+ console.log('🧹 Removing integration before uninstall...\n');
29
+
30
+ let filesModified = 0;
31
+
32
+ try {
33
+ // 1. Remove from src/app/index.tsx
34
+ const indexPath = path.join(projectRoot, 'src/app/index.tsx');
35
+ if (fs.existsSync(indexPath)) {
36
+ let content = fs.readFileSync(indexPath, 'utf8');
37
+ const originalContent = content;
38
+
39
+ // Remove the import
40
+ content = content.replace(/import\s*{\s*CommentProvider\s*,\s*GitHubAuthProvider\s*}\s*from\s*["']hale-commenting-system["'];?\s*\n?/g, '');
41
+
42
+ // Remove the providers from JSX - be more aggressive with whitespace handling
43
+ content = content.replace(/<GitHubAuthProvider>\s*/g, '');
44
+ content = content.replace(/\s*<\/GitHubAuthProvider>/g, '');
45
+ content = content.replace(/<CommentProvider>\s*/g, '');
46
+ content = content.replace(/\s*<\/CommentProvider>/g, '');
47
+
48
+ if (content !== originalContent) {
49
+ fs.writeFileSync(indexPath, content, 'utf8');
50
+ console.log('āœ… Cleaned up src/app/index.tsx');
51
+ filesModified++;
52
+ }
53
+ }
54
+
55
+ // 2. Remove from src/app/AppLayout/AppLayout.tsx
56
+ const appLayoutPath = path.join(projectRoot, 'src/app/AppLayout/AppLayout.tsx');
57
+ if (fs.existsSync(appLayoutPath)) {
58
+ let content = fs.readFileSync(appLayoutPath, 'utf8');
59
+ const originalContent = content;
60
+
61
+ // Remove the import
62
+ content = content.replace(/import\s*{\s*CommentPanel\s*,\s*CommentOverlay\s*}\s*from\s*["']hale-commenting-system["'];?\s*\n?/g, '');
63
+
64
+ // Remove the components from JSX
65
+ content = content.replace(/<CommentPanel>\s*/g, '');
66
+ content = content.replace(/\s*<\/CommentPanel>/g, '');
67
+ content = content.replace(/<CommentOverlay\s*\/>\s*/g, '');
68
+
69
+ if (content !== originalContent) {
70
+ fs.writeFileSync(appLayoutPath, content, 'utf8');
71
+ console.log('āœ… Cleaned up src/app/AppLayout/AppLayout.tsx');
72
+ filesModified++;
73
+ }
74
+ }
75
+
76
+ if (filesModified > 0) {
77
+ console.log(`\nāœ… Successfully cleaned up ${filesModified} file(s)`);
78
+ console.log(' Your app will continue to work after uninstall.\n');
79
+ } else {
80
+ console.log('ā„¹ļø No integration found to clean up.\n');
81
+ }
82
+ } catch (error) {
83
+ // Don't block uninstall, but show the error
84
+ console.error('āš ļø Error during automatic cleanup:');
85
+ console.error(' ', error.message);
86
+ console.error('\n You may need to manually remove imports from your files.');
87
+ console.error(' See: https://www.npmjs.com/package/hale-commenting-system#manual-uninstall\n');
88
+ }
89
+
90
+ // Always exit successfully so uninstall can proceed
91
+ process.exit(0);
@@ -474,6 +474,7 @@ GITHUB_CLIENT_SECRET=
474
474
  }
475
475
 
476
476
  if (config.jira && config.jira.apiToken) {
477
+ const trimmedToken = String(config.jira.apiToken || '').trim();
477
478
  envServerContent += `# Jira API Token (server-only)
478
479
  # For Red Hat Jira, generate a Personal Access Token:
479
480
  # 1. Visit: https://issues.redhat.com/secure/ViewProfile.jspa
@@ -481,7 +482,7 @@ GITHUB_CLIENT_SECRET=
481
482
  # 3. Click "Create token"
482
483
  # 4. Give it a name and remove expiration
483
484
  # 5. Copy the token
484
- JIRA_API_TOKEN=${config.jira.apiToken}
485
+ JIRA_API_TOKEN=${trimmedToken}
485
486
  `;
486
487
  } else {
487
488
  envServerContent += `# Jira API Token (server-only)
@@ -496,7 +497,8 @@ JIRA_API_TOKEN=
496
497
  }
497
498
 
498
499
  if (config.jira && config.jira.email) {
499
- envServerContent += `JIRA_EMAIL=${config.jira.email}\n`;
500
+ const trimmedEmail = String(config.jira.email || '').trim();
501
+ envServerContent += `JIRA_EMAIL=${trimmedEmail}\n`;
500
502
  }
501
503
 
502
504
  if (fs.existsSync(envServerPath)) {
@@ -507,13 +509,16 @@ JIRA_API_TOKEN=
507
509
  const lines = existing.split('\n');
508
510
  const updatedLines = lines.map(line => {
509
511
  if (line.startsWith('GITHUB_CLIENT_SECRET=')) {
510
- return `GITHUB_CLIENT_SECRET=${config.github?.clientSecret || ''}`;
512
+ const trimmed = String(config.github?.clientSecret || '').trim();
513
+ return `GITHUB_CLIENT_SECRET=${trimmed}`;
511
514
  }
512
515
  if (line.startsWith('JIRA_API_TOKEN=')) {
513
- return `JIRA_API_TOKEN=${config.jira?.apiToken || ''}`;
516
+ const trimmed = String(config.jira?.apiToken || '').trim();
517
+ return `JIRA_API_TOKEN=${trimmed}`;
514
518
  }
515
519
  if (line.startsWith('JIRA_EMAIL=')) {
516
- return `JIRA_EMAIL=${config.jira?.email || ''}`;
520
+ const trimmed = String(config.jira?.email || '').trim();
521
+ return `JIRA_EMAIL=${trimmed}`;
517
522
  }
518
523
  return line;
519
524
  });
@@ -573,10 +578,13 @@ function integrateWebpackMiddleware() {
573
578
  // Note: Requires Node.js 18+ for native fetch() support
574
579
  try {
575
580
  const dotenv = require('dotenv');
576
- dotenv.config({ path: path.resolve(__dirname, '.env') });
577
- dotenv.config({ path: path.resolve(__dirname, '.env.server'), override: true });
581
+ const envResult = dotenv.config({ path: path.resolve(__dirname, '.env') });
582
+ const envServerResult = dotenv.config({ path: path.resolve(__dirname, '.env.server'), override: true });
583
+ if (envServerResult.error && envServerResult.error.code !== 'ENOENT') {
584
+ console.warn('[Commenting System] Warning loading .env.server:', envServerResult.error.message);
585
+ }
578
586
  } catch (e) {
579
- // no-op
587
+ console.warn('[Commenting System] Warning loading environment files:', e.message);
580
588
  }
581
589
 
582
590
  const express = require('express');
@@ -685,12 +693,13 @@ function integrateWebpackMiddleware() {
685
693
  if (!key) return res.status(400).json({ message: 'Missing ?key (e.g. ABC-123)' });
686
694
 
687
695
  const baseUrl = (process.env.VITE_JIRA_BASE_URL || 'https://issues.redhat.com').replace(/\\/+$/, '');
688
- const email = process.env.JIRA_EMAIL;
689
- const token = process.env.JIRA_API_TOKEN;
696
+ const email = (process.env.JIRA_EMAIL || '').trim();
697
+ const token = (process.env.JIRA_API_TOKEN || '').trim();
690
698
 
691
699
  if (!token) {
700
+ console.error('[Commenting System] JIRA_API_TOKEN is missing or empty. Check .env.server file.');
692
701
  return res.status(500).json({
693
- message: 'Missing JIRA_API_TOKEN. For local dev, put it in .env.server (gitignored).',
702
+ message: 'Missing JIRA_API_TOKEN. For local dev, put it in .env.server (gitignored). Make sure the dev server was restarted after creating/updating .env.server.',
694
703
  });
695
704
  }
696
705
 
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+
3
+ console.log('\n╔══════════════════════════════════════════════════════════╗');
4
+ console.log('ā•‘ ā•‘');
5
+ console.log('ā•‘ šŸ“¦ Hale Commenting System installed successfully! ā•‘');
6
+ console.log('ā•‘ ā•‘');
7
+ console.log('ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•\n');
8
+
9
+ console.log('šŸ“ Next steps:');
10
+ console.log(' 1. Run: npx hale-commenting-system init');
11
+ console.log(' 2. Start your dev server\n');
12
+
13
+ console.log('🚨 CRITICAL - BEFORE UNINSTALLING:');
14
+ console.log(' ══════════════════════════════════════════════════════');
15
+ console.log(' This package modifies your project files during setup.');
16
+ console.log(' ');
17
+ console.log(' BEFORE running "npm uninstall hale-commenting-system",');
18
+ console.log(' you MUST run:');
19
+ console.log(' ');
20
+ console.log(' ā–¶ npx hale-commenting-system remove');
21
+ console.log(' ');
22
+ console.log(' Otherwise your app will break with import errors!');
23
+ console.log(' ══════════════════════════════════════════════════════\n');
24
+
25
+ console.log('šŸ“š Documentation: https://www.npmjs.com/package/hale-commenting-system\n');