@onlook/storybook-plugin 0.4.0-beta.3 → 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.
Files changed (2) hide show
  1. package/dist/index.js +58 -34
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -542,43 +542,67 @@ 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;
546
+ console.log("[ASG] Plugin created", {
547
+ preset: options.preset,
548
+ imports: options.imports,
549
+ isGenerateStoriesFileAtBuild: options.isGenerateStoriesFileAtBuild,
550
+ storiesFolder: options.storiesFolder,
551
+ projectRoot: projectRootDir,
552
+ cwd: process.cwd()
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
+ }
545
595
  return {
546
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)
547
603
  async buildStart() {
548
- if (!options.isGenerateStoriesFileAtBuild) return;
549
- const patterns = options.imports ?? ["src/**/*.tsx"];
550
- const ignorePatterns = options.ignores ?? [];
551
- console.log(`[ASG] Scanning for components: ${patterns.join(", ")}`);
552
- const allFiles = await getAllFilePaths({
553
- patterns,
554
- ignorePatterns,
555
- projectRootDir
556
- });
557
- const filesToProcess = allFiles.filter((filePath) => {
558
- if (filePath.includes(".stories")) return false;
559
- if (options.cacheEnabled !== false) {
560
- const storyPath = getStoryFilePath(filePath, options.storiesFolder);
561
- const storyExists = fs.existsSync(storyPath);
562
- if (!hasFileChanged(filePath) && storyExists) return false;
563
- }
564
- return true;
565
- });
566
- console.log(
567
- `[ASG] Found ${allFiles.length} files, ${filesToProcess.length} need processing`
568
- );
569
- let totalProcessed = 0;
570
- for (let i = 0; i < filesToProcess.length; i += batchSize) {
571
- const batch = filesToProcess.slice(i, i + batchSize);
572
- const count = await processBatch(batch, options, projectRootDir, concurrency);
573
- totalProcessed += count;
574
- if (options.onProgress) {
575
- options.onProgress(totalProcessed, filesToProcess.length);
576
- }
577
- if (i + batchSize < filesToProcess.length) {
578
- await new Promise((r) => setTimeout(r, 0));
579
- }
580
- }
581
- console.log(`[ASG] Generated stories for ${totalProcessed} components`);
604
+ console.log("[ASG] buildStart hook fired");
605
+ await generateAllStories();
582
606
  },
583
607
  async watchChange(id, change) {
584
608
  if (change.event === "delete") return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onlook/storybook-plugin",
3
- "version": "0.4.0-beta.3",
3
+ "version": "0.4.0-beta.5",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "onlook-storybook": "./dist/cli/index.js"