hale-commenting-system 3.8.5 → 3.8.7

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/package.json +1 -1
  2. package/scripts/integrate.js +121 -28
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hale-commenting-system",
3
- "version": "3.8.5",
3
+ "version": "3.8.7",
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
  "repository": {
@@ -473,10 +473,10 @@ VITE_JIRA_BASE_URL=
473
473
  existing.includes('VITE_PROVIDER_TYPE');
474
474
 
475
475
  if (hasCommentingSystemConfig) {
476
- // Remove old commenting system section and replace with new one
476
+ // Remove ALL commenting system related lines and replace with new config
477
477
  const lines = existing.split('\n');
478
478
  let newLines = [];
479
- let inCommentingSection = false;
479
+ let skipUntilEmptyLine = false;
480
480
  let foundSection = false;
481
481
 
482
482
  for (let i = 0; i < lines.length; i++) {
@@ -484,7 +484,7 @@ VITE_JIRA_BASE_URL=
484
484
 
485
485
  // Detect start of commenting system section
486
486
  if (line.includes('Hale Commenting System')) {
487
- inCommentingSection = true;
487
+ skipUntilEmptyLine = true;
488
488
  foundSection = true;
489
489
  // Add the new content at this position
490
490
  newLines.push(...envContent.split('\n'));
@@ -492,42 +492,74 @@ VITE_JIRA_BASE_URL=
492
492
  }
493
493
 
494
494
  // Skip lines that are part of the commenting system config
495
- if (inCommentingSection) {
495
+ if (skipUntilEmptyLine) {
496
496
  // Check if this is still part of the commenting system section
497
497
  if (line.startsWith('VITE_GITHUB_') ||
498
498
  line.startsWith('VITE_GITLAB_') ||
499
499
  line.startsWith('VITE_PROVIDER_TYPE') ||
500
500
  line.startsWith('VITE_JIRA_BASE_URL') ||
501
- (line.startsWith('#') && (line.includes('GitHub') || line.includes('GitLab') || line.includes('Jira') || line.includes('Provider')))) {
501
+ (line.startsWith('#') && (line.includes('GitHub') || line.includes('GitLab') || line.includes('Jira') || line.includes('Provider') || line.includes('OAuth') || line.includes('Target')))) {
502
502
  // Still in commenting section, skip this line
503
503
  continue;
504
504
  }
505
505
 
506
506
  // Empty line after commenting section - skip it and exit section
507
507
  if (line.trim() === '') {
508
- inCommentingSection = false;
508
+ skipUntilEmptyLine = false;
509
+ // Don't add this empty line, we'll add one after our new content
509
510
  continue;
510
511
  }
511
512
 
512
513
  // Non-empty, non-commenting line - exit section and keep the line
513
- inCommentingSection = false;
514
+ skipUntilEmptyLine = false;
515
+ } else {
516
+ // Also check for standalone commenting system variables (in case header is missing)
517
+ // ALWAYS skip these, regardless of whether header exists
518
+ if (line.startsWith('VITE_GITHUB_') ||
519
+ line.startsWith('VITE_GITLAB_') ||
520
+ line.startsWith('VITE_PROVIDER_TYPE') ||
521
+ line.startsWith('VITE_JIRA_BASE_URL')) {
522
+ // Skip standalone commenting system variables
523
+ continue;
524
+ }
514
525
  }
515
526
 
516
527
  // Keep lines that are not part of commenting system section
517
528
  newLines.push(line);
518
529
  }
519
530
 
520
- // If we didn't find the section marker, append to end
531
+ // If we didn't find the section marker but detected config, append to end
521
532
  if (!foundSection) {
522
- newLines.push('');
533
+ // Remove any trailing empty lines
534
+ while (newLines.length > 0 && newLines[newLines.length - 1].trim() === '') {
535
+ newLines.pop();
536
+ }
537
+ // Only add separator if there's existing content
538
+ if (newLines.length > 0) {
539
+ newLines.push('');
540
+ }
523
541
  newLines.push(...envContent.split('\n'));
524
542
  }
525
543
 
526
- fs.writeFileSync(envPath, newLines.join('\n'));
527
- console.log(' ✅ Updated .env file');
544
+ // Ensure we have content to write
545
+ const finalContent = newLines.join('\n');
546
+ if (finalContent.trim().length > 0) {
547
+ fs.writeFileSync(envPath, finalContent);
548
+ console.log(' ✅ Updated .env file');
549
+ } else {
550
+ // Fallback: if somehow we ended up with empty content, just write the new content
551
+ fs.writeFileSync(envPath, envContent);
552
+ console.log(' ✅ Updated .env file');
553
+ }
528
554
  } else {
529
555
  // Append if commenting system config not present
530
- fs.appendFileSync(envPath, '\n' + envContent);
556
+ const trimmedExisting = existing.trim();
557
+ if (trimmedExisting.length > 0) {
558
+ fs.appendFileSync(envPath, '\n' + envContent);
559
+ } else {
560
+ // File is empty, just write the new content
561
+ fs.writeFileSync(envPath, envContent);
562
+ }
531
563
  console.log(' ✅ Updated .env file');
532
564
  }
533
565
  } else {
@@ -608,29 +640,90 @@ JIRA_API_TOKEN=
608
640
  if (fs.existsSync(envServerPath)) {
609
641
  let existing = fs.readFileSync(envServerPath, 'utf-8');
610
642
 
611
- if (existing.includes('GITHUB_CLIENT_SECRET')) {
612
- // Update existing values
643
+ // Check if commenting system config exists (check for header or any secret)
644
+ const hasCommentingSystemConfig = existing.includes('Hale Commenting System - Server Secrets') ||
645
+ existing.includes('GITHUB_CLIENT_SECRET') ||
646
+ existing.includes('GITLAB_CLIENT_SECRET') ||
647
+ existing.includes('JIRA_API_TOKEN');
648
+
649
+ if (hasCommentingSystemConfig) {
650
+ // Remove ALL commenting system related lines and replace with new config
613
651
  const lines = existing.split('\n');
614
- const updatedLines = lines.map(line => {
615
- if (line.startsWith('GITHUB_CLIENT_SECRET=')) {
616
- const trimmed = String(config.github?.clientSecret || '').trim();
617
- return `GITHUB_CLIENT_SECRET=${trimmed}`;
652
+ let newLines = [];
653
+ let skipUntilEmptyLine = false;
654
+ let foundSection = false;
655
+
656
+ for (let i = 0; i < lines.length; i++) {
657
+ const line = lines[i];
658
+
659
+ // Detect start of commenting system section
660
+ if (line.includes('Hale Commenting System - Server Secrets')) {
661
+ skipUntilEmptyLine = true;
662
+ foundSection = true;
663
+ // Add the new content at this position
664
+ newLines.push(...envServerContent.split('\n'));
665
+ continue;
618
666
  }
619
- if (line.startsWith('JIRA_API_TOKEN=')) {
620
- const trimmed = String(config.jira?.apiToken || '').trim();
621
- return `JIRA_API_TOKEN=${trimmed}`;
667
+
668
+ // Skip lines that are part of the commenting system config
669
+ if (skipUntilEmptyLine) {
670
+ // Check if this is still part of the commenting system section
671
+ if (line.startsWith('GITHUB_CLIENT_SECRET=') ||
672
+ line.startsWith('GITLAB_CLIENT_SECRET=') ||
673
+ line.startsWith('JIRA_API_TOKEN=') ||
674
+ line.startsWith('JIRA_EMAIL=') ||
675
+ (line.startsWith('#') && (line.includes('GitHub') || line.includes('GitLab') || line.includes('Jira') || line.includes('OAuth') || line.includes('Server Secrets')))) {
676
+ // Still in commenting section, skip this line
677
+ continue;
678
+ }
679
+
680
+ // Empty line after commenting section - skip it and exit section
681
+ if (line.trim() === '') {
682
+ skipUntilEmptyLine = false;
683
+ continue;
684
+ }
685
+
686
+ // Non-empty, non-commenting line - exit section and keep the line
687
+ skipUntilEmptyLine = false;
688
+ } else {
689
+ // Also check for standalone commenting system variables (in case header is missing)
690
+ if (line.startsWith('GITHUB_CLIENT_SECRET=') ||
691
+ line.startsWith('GITLAB_CLIENT_SECRET=') ||
692
+ line.startsWith('JIRA_API_TOKEN=') ||
693
+ line.startsWith('JIRA_EMAIL=')) {
694
+ // Skip standalone commenting system variables
695
+ continue;
696
+ }
622
697
  }
623
- if (line.startsWith('JIRA_EMAIL=')) {
624
- const trimmed = String(config.jira?.email || '').trim();
625
- return `JIRA_EMAIL=${trimmed}`;
698
+
699
+ // Keep lines that are not part of commenting system section
700
+ newLines.push(line);
701
+ }
702
+
703
+ // If we didn't find the section marker but detected config, append to end
704
+ if (!foundSection) {
705
+ // Remove any trailing empty lines
706
+ while (newLines.length > 0 && newLines[newLines.length - 1].trim() === '') {
707
+ newLines.pop();
626
708
  }
627
- return line;
628
- });
629
- fs.writeFileSync(envServerPath, updatedLines.join('\n'));
709
+ // Only add separator if there's existing content
710
+ if (newLines.length > 0) {
711
+ newLines.push('');
712
+ }
713
+ newLines.push(...envServerContent.split('\n'));
714
+ }
715
+
716
+ fs.writeFileSync(envServerPath, newLines.join('\n'));
630
717
  console.log(' ✅ Updated .env.server file');
631
718
  } else {
632
719
  // Append if commenting system config not present
633
- fs.appendFileSync(envServerPath, '\n' + envServerContent);
720
+ const trimmedExisting = existing.trim();
721
+ if (trimmedExisting.length > 0) {
722
+ fs.appendFileSync(envServerPath, '\n' + envServerContent);
723
+ } else {
724
+ // File is empty, just write the new content
725
+ fs.writeFileSync(envServerPath, envServerContent);
726
+ }
634
727
  console.log(' ✅ Updated .env.server file');
635
728
  }
636
729
  } else {