@pure-ds/storybook 0.3.8 → 0.3.9
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/bin/index.js +23 -5
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -51,11 +51,29 @@ if (process.cwd() !== packageRoot) {
|
|
|
51
51
|
} else if (entry.isFile()) {
|
|
52
52
|
if (entry.name.endsWith('.stories.js') || entry.name.endsWith('.stories.ts') || entry.name.endsWith('.stories.mjs')) {
|
|
53
53
|
let content = fs.readFileSync(srcPath, 'utf-8');
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
|
|
55
|
+
// Find export default to locate the main title and avoid matching other 'title' properties defined before it
|
|
56
|
+
const exportDefaultIndex = content.indexOf('export default');
|
|
57
|
+
|
|
58
|
+
if (exportDefaultIndex !== -1) {
|
|
59
|
+
const before = content.substring(0, exportDefaultIndex);
|
|
60
|
+
const after = content.substring(exportDefaultIndex);
|
|
61
|
+
|
|
62
|
+
// Replace the first title property found in the export default block
|
|
63
|
+
const newAfter = after.replace(/(title:\s*['"])(.+?)(['"])/, (match, prefix, title, suffix) => {
|
|
64
|
+
if (title.startsWith('PDS/')) return match;
|
|
65
|
+
return `${prefix}PDS/${title}${suffix}`;
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
content = before + newAfter;
|
|
69
|
+
} else {
|
|
70
|
+
// Fallback if no export default found (unlikely for valid stories)
|
|
71
|
+
content = content.replace(/(title:\s*['"])(.+?)(['"])/, (match, prefix, title, suffix) => {
|
|
72
|
+
if (title.startsWith('PDS/')) return match;
|
|
73
|
+
return `${prefix}PDS/${title}${suffix}`;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
59
77
|
fs.writeFileSync(destPath, content);
|
|
60
78
|
} else {
|
|
61
79
|
fs.copyFileSync(srcPath, destPath);
|