hale-commenting-system 2.2.5 → 2.2.8

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/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "hale-commenting-system",
3
- "version": "2.2.5",
4
- "description": "An open source build scaffolding utility for web apps.",
3
+ "version": "2.2.8",
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
  "repository": "https://github.com/patternfly/patternfly-react-seed.git",
6
- "homepage": "https://patternfly-react-seed.surge.sh",
6
+ "homepage": "https://www.npmjs.com/package/hale-commenting-system",
7
7
  "license": "MIT",
8
8
  "main": "src/app/commenting-system/index.ts",
9
9
  "types": "src/app/commenting-system/index.ts",
@@ -141,6 +141,15 @@ async function prompt(questions) {
141
141
  }
142
142
 
143
143
  function findFile(filename, startDir = process.cwd()) {
144
+ // For index.tsx, prioritize src/app/index.tsx over src/index.tsx
145
+ // because src/app/index.tsx contains the App component with Router
146
+ if (filename === 'index.tsx') {
147
+ const appIndexPath = path.join(startDir, 'src', 'app', filename);
148
+ if (fs.existsSync(appIndexPath)) {
149
+ return appIndexPath;
150
+ }
151
+ }
152
+
144
153
  const possiblePaths = [
145
154
  path.join(startDir, filename),
146
155
  path.join(startDir, 'src', filename),
@@ -503,6 +512,41 @@ JIRA_API_TOKEN=
503
512
  }
504
513
  }
505
514
 
515
+ function createCommentsComponent() {
516
+ const cwd = process.cwd();
517
+ const commentsDir = path.join(cwd, 'src', 'app', 'Comments');
518
+ const commentsFile = path.join(commentsDir, 'Comments.tsx');
519
+
520
+ // Check if already exists
521
+ if (fs.existsSync(commentsFile)) {
522
+ return; // Already exists, skip
523
+ }
524
+
525
+ // Create directory if it doesn't exist
526
+ if (!fs.existsSync(commentsDir)) {
527
+ fs.mkdirSync(commentsDir, { recursive: true });
528
+ }
529
+
530
+ // Read the Comments component from the package and modify the import
531
+ // The file is in the package at src/app/Comments/Comments.tsx
532
+ const scriptDir = __dirname || path.dirname(require.resolve('./integrate.js'));
533
+ const packageCommentsFile = path.join(scriptDir, '..', 'src', 'app', 'Comments', 'Comments.tsx');
534
+
535
+ let commentsComponentContent;
536
+ if (fs.existsSync(packageCommentsFile)) {
537
+ // Read from package and replace import path
538
+ commentsComponentContent = fs.readFileSync(packageCommentsFile, 'utf8')
539
+ .replace(/from ['"]@app\/commenting-system['"]/g, "from 'hale-commenting-system'");
540
+ } else {
541
+ // Fallback: create a minimal version (shouldn't happen if package is properly built)
542
+ console.log(' ⚠️ Comments component not found in package, skipping creation');
543
+ return;
544
+ }
545
+
546
+ fs.writeFileSync(commentsFile, commentsComponentContent);
547
+ console.log(' ✅ Created Comments component');
548
+ }
549
+
506
550
  function integrateWebpackMiddleware() {
507
551
  const cwd = process.cwd();
508
552
  const webpackDevPath = path.join(cwd, 'webpack.dev.js');
@@ -750,13 +794,47 @@ function integrateWebpackMiddleware() {
750
794
  `;
751
795
 
752
796
  // Find the setupMiddlewares function and inject our code
753
- const setupMiddlewaresRegex = /(setupMiddlewares\s*:\s*\([^)]+\)\s*=>\s*\{)/;
754
- const match = webpackContent.match(setupMiddlewaresRegex);
797
+ // Try multiple patterns to match different webpack.dev.js structures
798
+ const setupMiddlewaresPatterns = [
799
+ /(setupMiddlewares\s*:\s*\([^)]+\)\s*=>\s*\{)/, // Arrow function
800
+ /(setupMiddlewares\s*:\s*function\s*\([^)]+\)\s*\{)/, // Function declaration
801
+ /(setupMiddlewares\s*:\s*\([^)]+\)\s*\{)/, // Shorthand method
802
+ ];
803
+
804
+ let match = null;
805
+ for (const pattern of setupMiddlewaresPatterns) {
806
+ match = webpackContent.match(pattern);
807
+ if (match) break;
808
+ }
755
809
 
756
810
  if (!match) {
757
- console.log(' ⚠️ Could not find setupMiddlewares in webpack.dev.js');
758
- console.log(' 📋 Manual integration required. See webpack middleware documentation\n');
759
- return;
811
+ // If setupMiddlewares doesn't exist, we need to add it to devServer config
812
+ // Check if devServer config exists
813
+ const devServerMatch = webpackContent.match(/(devServer\s*:\s*\{)/);
814
+ if (devServerMatch) {
815
+ // Add setupMiddlewares to devServer config
816
+ const insertIndex = devServerMatch.index + devServerMatch[0].length;
817
+ const before = webpackContent.substring(0, insertIndex);
818
+ const after = webpackContent.substring(insertIndex);
819
+
820
+ const setupMiddlewaresCode = `
821
+ setupMiddlewares: (middlewares, devServer) => {
822
+ if (!devServer || !devServer.app) {
823
+ return middlewares;
824
+ }
825
+ ${middlewareCode}
826
+ return middlewares;
827
+ },`;
828
+
829
+ webpackContent = before + setupMiddlewaresCode + '\n' + after;
830
+ fs.writeFileSync(webpackDevPath, webpackContent);
831
+ console.log(' ✅ Added setupMiddlewares to webpack.dev.js');
832
+ return;
833
+ } else {
834
+ console.log(' ⚠️ Could not find setupMiddlewares or devServer config in webpack.dev.js');
835
+ console.log(' 📋 Manual integration required. See webpack middleware documentation\n');
836
+ return;
837
+ }
760
838
  }
761
839
 
762
840
  // Find where to inject (after express.json() setup, before return middlewares)
@@ -983,10 +1061,62 @@ function modifyRoutesTsx(filePath) {
983
1061
  });
984
1062
 
985
1063
  if (routesArray) {
986
- // Add Comments route group
1064
+ // Check if Comments component is imported
1065
+ let hasCommentsImport = false;
1066
+ let commentsImportName = 'Comments';
1067
+
1068
+ traverse(ast, {
1069
+ ImportDeclaration(path) {
1070
+ const source = path.node.source.value;
1071
+ if (source.includes('Comments') || source.includes('@app/Comments')) {
1072
+ hasCommentsImport = true;
1073
+ // Get the imported name
1074
+ path.node.specifiers.forEach(spec => {
1075
+ if (spec.type === 'ImportSpecifier' && spec.imported.name === 'Comments') {
1076
+ commentsImportName = spec.local.name;
1077
+ }
1078
+ });
1079
+ }
1080
+ }
1081
+ });
1082
+
1083
+ // Add Comments import if missing
1084
+ if (!hasCommentsImport) {
1085
+ let lastImportIndex = -1;
1086
+ for (let i = ast.program.body.length - 1; i >= 0; i--) {
1087
+ if (ast.program.body[i].type === 'ImportDeclaration') {
1088
+ lastImportIndex = i;
1089
+ break;
1090
+ }
1091
+ }
1092
+ const importIndex = lastImportIndex >= 0 ? lastImportIndex + 1 : 0;
1093
+
1094
+ const commentsImport = types.importDeclaration(
1095
+ [types.importSpecifier(types.identifier('Comments'), types.identifier('Comments'))],
1096
+ types.stringLiteral('@app/Comments/Comments')
1097
+ );
1098
+
1099
+ ast.program.body.splice(importIndex, 0, commentsImport);
1100
+ }
1101
+
1102
+ // Add Comments route group with a route to the Comments component
1103
+ const commentsRouteElement = types.jsxElement(
1104
+ types.jsxOpeningElement(types.jsxIdentifier(commentsImportName), [], true),
1105
+ null,
1106
+ []
1107
+ );
1108
+
1109
+ const commentsRouteItem = types.objectExpression([
1110
+ types.objectProperty(types.identifier('element'), commentsRouteElement),
1111
+ types.objectProperty(types.identifier('exact'), types.booleanLiteral(true)),
1112
+ types.objectProperty(types.identifier('label'), types.stringLiteral('View all')),
1113
+ types.objectProperty(types.identifier('path'), types.stringLiteral('/comments')),
1114
+ types.objectProperty(types.identifier('title'), types.stringLiteral('Hale Commenting System | Comments'))
1115
+ ]);
1116
+
987
1117
  const commentsRoute = types.objectExpression([
988
1118
  types.objectProperty(types.identifier('label'), types.stringLiteral('Comments')),
989
- types.objectProperty(types.identifier('routes'), types.arrayExpression([]))
1119
+ types.objectProperty(types.identifier('routes'), types.arrayExpression([commentsRouteItem]))
990
1120
  ]);
991
1121
 
992
1122
  routesArray.elements.push(commentsRoute);
@@ -1531,6 +1661,10 @@ async function main() {
1531
1661
  skippedCount++;
1532
1662
  }
1533
1663
 
1664
+ // Create Comments component first (needed for routes)
1665
+ console.log('\n📝 Creating Comments component...');
1666
+ createCommentsComponent();
1667
+
1534
1668
  // Modify routes.tsx
1535
1669
  console.log(`\n📝 ${routesPath}`);
1536
1670
  if (modifyRoutesTsx(routesPath)) {