@onlook/storybook-plugin 0.4.0-beta.4 → 0.4.0-beta.5
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/dist/index.js +49 -37
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -542,6 +542,7 @@ function createAutoStoryPlugin(options) {
|
|
|
542
542
|
const projectRootDir = (options.projectRoot ?? process.cwd()).replace(/\\/g, "/");
|
|
543
543
|
const batchSize = options.batchSize ?? DEFAULT_BATCH_SIZE;
|
|
544
544
|
const concurrency = options.concurrency ?? DEFAULT_CONCURRENCY;
|
|
545
|
+
let hasRun = false;
|
|
545
546
|
console.log("[ASG] Plugin created", {
|
|
546
547
|
preset: options.preset,
|
|
547
548
|
imports: options.imports,
|
|
@@ -550,47 +551,58 @@ function createAutoStoryPlugin(options) {
|
|
|
550
551
|
projectRoot: projectRootDir,
|
|
551
552
|
cwd: process.cwd()
|
|
552
553
|
});
|
|
554
|
+
async function generateAllStories() {
|
|
555
|
+
if (hasRun) return;
|
|
556
|
+
hasRun = true;
|
|
557
|
+
if (!options.isGenerateStoriesFileAtBuild) {
|
|
558
|
+
console.log("[ASG] Skipping \u2014 isGenerateStoriesFileAtBuild is false");
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
const patterns = options.imports ?? ["src/**/*.tsx"];
|
|
562
|
+
const ignorePatterns = options.ignores ?? [];
|
|
563
|
+
console.log(`[ASG] Scanning for components: ${patterns.join(", ")}`);
|
|
564
|
+
const allFiles = await getAllFilePaths({
|
|
565
|
+
patterns,
|
|
566
|
+
ignorePatterns,
|
|
567
|
+
projectRootDir
|
|
568
|
+
});
|
|
569
|
+
const filesToProcess = allFiles.filter((filePath) => {
|
|
570
|
+
if (filePath.includes(".stories")) return false;
|
|
571
|
+
if (options.cacheEnabled !== false) {
|
|
572
|
+
const storyPath = getStoryFilePath(filePath, options.storiesFolder);
|
|
573
|
+
const storyExists = fs.existsSync(storyPath);
|
|
574
|
+
if (!hasFileChanged(filePath) && storyExists) return false;
|
|
575
|
+
}
|
|
576
|
+
return true;
|
|
577
|
+
});
|
|
578
|
+
console.log(
|
|
579
|
+
`[ASG] Found ${allFiles.length} files, ${filesToProcess.length} need processing`
|
|
580
|
+
);
|
|
581
|
+
let totalProcessed = 0;
|
|
582
|
+
for (let i = 0; i < filesToProcess.length; i += batchSize) {
|
|
583
|
+
const batch = filesToProcess.slice(i, i + batchSize);
|
|
584
|
+
const count = await processBatch(batch, options, projectRootDir, concurrency);
|
|
585
|
+
totalProcessed += count;
|
|
586
|
+
if (options.onProgress) {
|
|
587
|
+
options.onProgress(totalProcessed, filesToProcess.length);
|
|
588
|
+
}
|
|
589
|
+
if (i + batchSize < filesToProcess.length) {
|
|
590
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
console.log(`[ASG] Generated stories for ${totalProcessed} components`);
|
|
594
|
+
}
|
|
553
595
|
return {
|
|
554
596
|
name: PLUGIN_NAME,
|
|
597
|
+
// configureServer fires for Vite dev server (Storybook's use case)
|
|
598
|
+
async configureServer() {
|
|
599
|
+
console.log("[ASG] configureServer hook fired");
|
|
600
|
+
await generateAllStories();
|
|
601
|
+
},
|
|
602
|
+
// buildStart fires for builds (fallback)
|
|
555
603
|
async buildStart() {
|
|
556
604
|
console.log("[ASG] buildStart hook fired");
|
|
557
|
-
|
|
558
|
-
console.log("[ASG] Skipping \u2014 isGenerateStoriesFileAtBuild is false");
|
|
559
|
-
return;
|
|
560
|
-
}
|
|
561
|
-
const patterns = options.imports ?? ["src/**/*.tsx"];
|
|
562
|
-
const ignorePatterns = options.ignores ?? [];
|
|
563
|
-
console.log(`[ASG] Scanning for components: ${patterns.join(", ")}`);
|
|
564
|
-
const allFiles = await getAllFilePaths({
|
|
565
|
-
patterns,
|
|
566
|
-
ignorePatterns,
|
|
567
|
-
projectRootDir
|
|
568
|
-
});
|
|
569
|
-
const filesToProcess = allFiles.filter((filePath) => {
|
|
570
|
-
if (filePath.includes(".stories")) return false;
|
|
571
|
-
if (options.cacheEnabled !== false) {
|
|
572
|
-
const storyPath = getStoryFilePath(filePath, options.storiesFolder);
|
|
573
|
-
const storyExists = fs.existsSync(storyPath);
|
|
574
|
-
if (!hasFileChanged(filePath) && storyExists) return false;
|
|
575
|
-
}
|
|
576
|
-
return true;
|
|
577
|
-
});
|
|
578
|
-
console.log(
|
|
579
|
-
`[ASG] Found ${allFiles.length} files, ${filesToProcess.length} need processing`
|
|
580
|
-
);
|
|
581
|
-
let totalProcessed = 0;
|
|
582
|
-
for (let i = 0; i < filesToProcess.length; i += batchSize) {
|
|
583
|
-
const batch = filesToProcess.slice(i, i + batchSize);
|
|
584
|
-
const count = await processBatch(batch, options, projectRootDir, concurrency);
|
|
585
|
-
totalProcessed += count;
|
|
586
|
-
if (options.onProgress) {
|
|
587
|
-
options.onProgress(totalProcessed, filesToProcess.length);
|
|
588
|
-
}
|
|
589
|
-
if (i + batchSize < filesToProcess.length) {
|
|
590
|
-
await new Promise((r) => setTimeout(r, 0));
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
console.log(`[ASG] Generated stories for ${totalProcessed} components`);
|
|
605
|
+
await generateAllStories();
|
|
594
606
|
},
|
|
595
607
|
async watchChange(id, change) {
|
|
596
608
|
if (change.event === "delete") return;
|