hale-commenting-system 2.2.6 → 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 +3 -3
- package/scripts/integrate.js +132 -7
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hale-commenting-system",
|
|
3
|
-
"version": "2.2.
|
|
4
|
-
"description": "
|
|
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://
|
|
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",
|
package/scripts/integrate.js
CHANGED
|
@@ -512,6 +512,41 @@ JIRA_API_TOKEN=
|
|
|
512
512
|
}
|
|
513
513
|
}
|
|
514
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
|
+
|
|
515
550
|
function integrateWebpackMiddleware() {
|
|
516
551
|
const cwd = process.cwd();
|
|
517
552
|
const webpackDevPath = path.join(cwd, 'webpack.dev.js');
|
|
@@ -759,13 +794,47 @@ function integrateWebpackMiddleware() {
|
|
|
759
794
|
`;
|
|
760
795
|
|
|
761
796
|
// Find the setupMiddlewares function and inject our code
|
|
762
|
-
|
|
763
|
-
const
|
|
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
|
+
}
|
|
764
809
|
|
|
765
810
|
if (!match) {
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
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
|
+
}
|
|
769
838
|
}
|
|
770
839
|
|
|
771
840
|
// Find where to inject (after express.json() setup, before return middlewares)
|
|
@@ -992,10 +1061,62 @@ function modifyRoutesTsx(filePath) {
|
|
|
992
1061
|
});
|
|
993
1062
|
|
|
994
1063
|
if (routesArray) {
|
|
995
|
-
//
|
|
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
|
+
|
|
996
1117
|
const commentsRoute = types.objectExpression([
|
|
997
1118
|
types.objectProperty(types.identifier('label'), types.stringLiteral('Comments')),
|
|
998
|
-
types.objectProperty(types.identifier('routes'), types.arrayExpression([]))
|
|
1119
|
+
types.objectProperty(types.identifier('routes'), types.arrayExpression([commentsRouteItem]))
|
|
999
1120
|
]);
|
|
1000
1121
|
|
|
1001
1122
|
routesArray.elements.push(commentsRoute);
|
|
@@ -1540,6 +1661,10 @@ async function main() {
|
|
|
1540
1661
|
skippedCount++;
|
|
1541
1662
|
}
|
|
1542
1663
|
|
|
1664
|
+
// Create Comments component first (needed for routes)
|
|
1665
|
+
console.log('\n📝 Creating Comments component...');
|
|
1666
|
+
createCommentsComponent();
|
|
1667
|
+
|
|
1543
1668
|
// Modify routes.tsx
|
|
1544
1669
|
console.log(`\n📝 ${routesPath}`);
|
|
1545
1670
|
if (modifyRoutesTsx(routesPath)) {
|