@pure-ds/storybook 0.3.8 → 0.3.10

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/bin/index.js +51 -5
  2. 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
- // Prepend PDS/ to title
55
- content = content.replace(/(title:\s*['"])(.+?)(['"])/, (match, prefix, title, suffix) => {
56
- if (title.startsWith('PDS/')) return match;
57
- return `${prefix}PDS/${title}${suffix}`;
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);
@@ -65,6 +83,34 @@ if (process.cwd() !== packageRoot) {
65
83
  };
66
84
 
67
85
  copyAndTransform(srcStoriesDir, cacheDir);
86
+
87
+ // Also copy dist folder to cache so relative imports work
88
+ const cacheDistDir = join(process.cwd(), 'node_modules', '.cache', 'pds-storybook', 'dist');
89
+ const srcDistDir = join(packageRoot, 'dist');
90
+
91
+ if (fs.existsSync(srcDistDir)) {
92
+ if (fs.existsSync(cacheDistDir)) {
93
+ fs.rmSync(cacheDistDir, { recursive: true, force: true });
94
+ }
95
+ fs.mkdirSync(cacheDistDir, { recursive: true });
96
+
97
+ // Simple recursive copy for dist
98
+ const copyDir = (src, dest) => {
99
+ const entries = fs.readdirSync(src, { withFileTypes: true });
100
+ for (const entry of entries) {
101
+ const srcPath = join(src, entry.name);
102
+ const destPath = join(dest, entry.name);
103
+ if (entry.isDirectory()) {
104
+ fs.mkdirSync(destPath, { recursive: true });
105
+ copyDir(srcPath, destPath);
106
+ } else {
107
+ fs.copyFileSync(srcPath, destPath);
108
+ }
109
+ }
110
+ };
111
+ copyDir(srcDistDir, cacheDistDir);
112
+ }
113
+
68
114
  process.env.PDS_STORIES_PATH = cacheDir.replace(/\\/g, '/');
69
115
 
70
116
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pure-ds/storybook",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "description": "Storybook showcase for Pure Design System with live configuration",
5
5
  "type": "module",
6
6
  "private": false,