Skip to content

Commit

Permalink
fix: enhancers to work for a list
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyhw committed Oct 26, 2024
1 parent 4333d26 commit 0d9dbca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
1 change: 0 additions & 1 deletion examples/expo-example/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import { View, Appearance } from 'react-native';
import { withBackgrounds } from '@storybook/addon-ondevice-backgrounds';
import type { Preview } from '@storybook/react';
Expand Down
19 changes: 13 additions & 6 deletions packages/react-native/scripts/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,26 @@ function generate({ configPath, absolute = false, useJs = false }) {

const registerAddons = main.addons?.map((addon) => `import "${addon}/register";`).join('\n');

const doctools = 'require("@storybook/react-native/dist/preview")';
const docTools = 'require("@storybook/react-native/dist/preview")';

const enhancer = [];
const enhancers = [docTools];

main.addons?.forEach((addon) => {
for (const addon of main.addons) {
let addonPath;
try {
addonPath = path.dirname(require.resolve(addon));
} catch (error) {
console.error(`Failed to resolve addon: ${addon}`, error);

return null; // Skip this addon if it cannot be resolved
}

const isPreviewFileExists = getPreviewExists({ configPath: addonPath });

if (isPreviewFileExists) {
enhancer.push(`require('${addon}/preview')`);
enhancers.push(`require('${addon}/preview')`);
}
});
}

let options = '';
let optionsVar = '';
Expand All @@ -77,7 +80,11 @@ function generate({ configPath, absolute = false, useJs = false }) {

const previewExists = getPreviewExists({ configPath });

const annotations = `[${previewExists ? "require('./preview')," : ''}${doctools}, ${enhancer}]`;
if (previewExists) {
enhancers.unshift("require('./preview')");
}

const annotations = `[${enhancers.join(', ')}]`;

const globalTypes = `
declare global {
Expand Down

0 comments on commit 0d9dbca

Please sign in to comment.