5.0.0 • Published 1 month ago

storycrawler v5.0.0

Weekly downloads
19,065
License
MIT
Repository
github
Last release
1 month ago

Storycrawler

Utilities to build Storybook crawling tools with Puppeteer.

Install

$ npm i storycrawler

Usage

import {
  StorybookConnection,
  StoriesBrowser,
  StoryPreviewBrowser,
  MetricsWatcher,
  createExecutionService,
} from 'storycrawler';

(async function () {
  // Connect to the target Storybook server.
  const storybookUrl = 'https://storybookjs.netlify.app/vue-kitchen-sink';
  const connection = await new StorybookConnection({ storybookUrl }).connect();

  // Launch Puppeteer process to fetch stories info.
  const storiesBrowser = await new StoriesBrowser(connection).boot();
  // Item in stories has name, kind and id of the corresponding story
  const stories = await storiesBrowser.getStories();

  // Launce Puppeteer browsers to visit each story's preview window(iframe.html)
  const workers = await Promise.all([0, 1, 2, 3].map(i => new StoryPreviewBrowser(connection, i).boot()));

  try {
    // `createExecutionService` creates a queue of the tasks for each story.
    const service = createExecutionService(workers, stories, story => async worker => {
      // Display story in the worker's preview window
      await worker.setCurrentStory(story);

      // Wait for UI framework updating DOM
      await new MetricsWatcher(worker.page).waitForStable();

      // Extract information from the preview window.
      // You can access Puppeteer's page instance via `worker.page`.
      const m = await worker.page.metrics();
      return { story, nodesCount: m.Nodes };
    });

    // `createExecutionService` register tasks but does not kick them.
    // Tasks in queue start via calling `.execute()`.
    const results = await service.execute();

    results.forEach(({ story, nodesCount }) => console.log(`${story.id}: ${nodesCount}`));
  } finally {
    await storiesBrowser.close();
    await Promise.all(workers.map(worker => worker.close()));
    await connection.disconnect();
  }
})();

API

See here.

LICENSE

MIT

5.0.0

1 month ago

5.0.0-alpha.0

1 month ago

4.3.1

1 month ago

4.3.0

2 months ago

4.1.2

11 months ago

4.2.0

10 months ago

4.1.0

1 year ago

4.0.0

1 year ago

4.1.1

1 year ago

4.0.0-alpha.2

2 years ago

3.1.8

2 years ago

4.0.0-alpha.1

2 years ago

4.0.0-alpha.0

2 years ago

3.1.7

2 years ago

3.1.6

2 years ago

3.1.2

2 years ago

3.1.1

2 years ago

3.1.5

2 years ago

3.1.4

2 years ago

3.1.5-alpha.0

2 years ago

3.1.0

3 years ago

3.0.4

3 years ago

3.0.3

3 years ago

3.0.2

3 years ago

3.0.1

4 years ago

3.0.0

4 years ago

3.0.0-alpha.1

4 years ago

3.0.0-alpha.0

4 years ago

2.3.7

4 years ago

2.3.6

4 years ago

2.3.5

4 years ago

2.3.1

4 years ago

2.3.0

4 years ago

2.0.0

5 years ago

2.0.0-alpha.6

5 years ago

2.0.0-alpha.5

5 years ago

2.0.0-alpha.4

5 years ago