Skip to content

Commit

Permalink
change mechanism for detecting addon docs being active
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelangen committed Oct 31, 2023
1 parent 5aaf56e commit 02f9b36
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 126 deletions.
17 changes: 3 additions & 14 deletions code/renderers/html/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import type { LoadedPreset, StorybookConfig } from '@storybook/types';
import type { StorybookConfig } from '@storybook/types';
import { join } from 'path';

const hasDocs = (presetsList: LoadedPreset[]) => {
return presetsList.some((preset: string | { name: string }) => {
const presetName = typeof preset === 'string' ? preset : preset.name;
return presetName.includes('@storybook/addon-docs');
});
};

export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => {
const { presetsList } = options;
if (!presetsList) {
return input;
}
const docsInList = hasDocs(presetsList);
const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0;
const result: string[] = [];

return result
.concat(input)
.concat([join(__dirname, 'preview.mjs')])
.concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []);
.concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []);
};
17 changes: 3 additions & 14 deletions code/renderers/preact/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import type { LoadedPreset, StorybookConfig } from '@storybook/types';
import type { StorybookConfig } from '@storybook/types';
import { join } from 'path';

const hasDocs = (presetsList: LoadedPreset[]) => {
return presetsList.some((preset: string | { name: string }) => {
const presetName = typeof preset === 'string' ? preset : preset.name;
return presetName.includes('@storybook/addon-docs');
});
};

export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => {
const { presetsList } = options;
if (!presetsList) {
return input;
}
const docsInList = hasDocs(presetsList);
const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0;
const result: string[] = [];

return result
.concat(input)
.concat([join(__dirname, 'preview.mjs')])
.concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []);
.concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []);
};
17 changes: 3 additions & 14 deletions code/renderers/react/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
import type { StorybookConfig, LoadedPreset } from '@storybook/types';
import type { StorybookConfig } from '@storybook/types';

import { join } from 'path';

export const addons: StorybookConfig['addons'] = [
require.resolve('@storybook/react-dom-shim/dist/preset'),
];

const hasDocs = (presetsList: LoadedPreset[]) => {
return presetsList.some((preset: string | { name: string }) => {
const presetName = typeof preset === 'string' ? preset : preset.name;
return presetName.includes('@storybook/addon-docs');
});
};

export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => {
const { presetsList } = options;
if (!presetsList) {
return input;
}
const docsInList = hasDocs(presetsList);
const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0;
const result: string[] = [];

return result
.concat(input)
.concat([join(__dirname, 'preview.mjs')])
.concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []);
.concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []);
};
17 changes: 3 additions & 14 deletions code/renderers/svelte/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import type { LoadedPreset, StorybookConfig } from '@storybook/types';
import type { StorybookConfig } from '@storybook/types';
import { join } from 'path';

const hasDocs = (presetsList: LoadedPreset[]) => {
return presetsList.some((preset: string | { name: string }) => {
const presetName = typeof preset === 'string' ? preset : preset.name;
return presetName.includes('@storybook/addon-docs');
});
};

export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => {
const { presetsList } = options;
if (!presetsList) {
return input;
}
const docsInList = hasDocs(presetsList);
const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0;
const result: string[] = [];

return result
.concat(input)
.concat([join(__dirname, 'preview.mjs')])
.concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []);
.concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []);
};
17 changes: 3 additions & 14 deletions code/renderers/vue/preset.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import type { LoadedPreset, StorybookConfig } from '@storybook/types';
import type { StorybookConfig } from '@storybook/types';
import { join } from 'path';

const hasDocs = (presetsList: LoadedPreset[]) => {
return presetsList.some((preset: string | { name: string }) => {
const presetName = typeof preset === 'string' ? preset : preset.name;
return presetName.includes('@storybook/addon-docs');
});
};

export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => {
const { presetsList } = options;
if (!presetsList) {
return input;
}
const docsInList = hasDocs(presetsList);
const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0;
const result: string[] = [];

return result
.concat(input)
.concat([join(__dirname, 'preview.mjs')])
.concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []);
.concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []);
};
17 changes: 3 additions & 14 deletions code/renderers/vue/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import type { LoadedPreset, StorybookConfig } from '@storybook/types';
import type { StorybookConfig } from '@storybook/types';
import { join } from 'path';

const hasDocs = (presetsList: LoadedPreset[]) => {
return presetsList.some((preset: string | { name: string }) => {
const presetName = typeof preset === 'string' ? preset : preset.name;
return presetName.includes('@storybook/addon-docs');
});
};

export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => {
const { presetsList } = options;
if (!presetsList) {
return input;
}
const docsInList = hasDocs(presetsList);
const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0;
const result: string[] = [];

return result
.concat(input)
.concat([join(__dirname, 'preview.mjs')])
.concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []);
.concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []);
};
17 changes: 3 additions & 14 deletions code/renderers/vue3/preset.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import type { LoadedPreset, StorybookConfig } from '@storybook/types';
import type { StorybookConfig } from '@storybook/types';
import { join } from 'path';

const hasDocs = (presetsList: LoadedPreset[]) => {
return presetsList.some((preset: string | { name: string }) => {
const presetName = typeof preset === 'string' ? preset : preset.name;
return presetName.includes('@storybook/addon-docs');
});
};

export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => {
const { presetsList } = options;
if (!presetsList) {
return input;
}
const docsInList = hasDocs(presetsList);
const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0;
const result: string[] = [];

return result
.concat(input)
.concat([join(__dirname, 'preview.mjs')])
.concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []);
.concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []);
};
17 changes: 3 additions & 14 deletions code/renderers/vue3/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import type { LoadedPreset, StorybookConfig } from '@storybook/types';
import type { StorybookConfig } from '@storybook/types';
import { join } from 'path';

const hasDocs = (presetsList: LoadedPreset[]) => {
return presetsList.some((preset: string | { name: string }) => {
const presetName = typeof preset === 'string' ? preset : preset.name;
return presetName.includes('@storybook/addon-docs');
});
};

export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => {
const { presetsList } = options;
if (!presetsList) {
return input;
}
const docsInList = hasDocs(presetsList);
const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0;
const result: string[] = [];

return result
.concat(input)
.concat([join(__dirname, 'preview.mjs')])
.concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []);
.concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []);
};
17 changes: 3 additions & 14 deletions code/renderers/web-components/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import type { LoadedPreset, StorybookConfig } from '@storybook/types';
import type { StorybookConfig } from '@storybook/types';
import { join } from 'path';

const hasDocs = (presetsList: LoadedPreset[]) => {
return presetsList.some((preset: string | { name: string }) => {
const presetName = typeof preset === 'string' ? preset : preset.name;
return presetName.includes('@storybook/addon-docs');
});
};

export const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input, options) => {
const { presetsList } = options;
if (!presetsList) {
return input;
}
const docsInList = hasDocs(presetsList);
const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0;
const result: string[] = [];

return result
.concat(input)
.concat([join(__dirname, 'preview.mjs')])
.concat(docsInList ? [join(__dirname, 'preview-docs.mjs')] : []);
.concat(docsEnabled ? [join(__dirname, 'preview-docs.mjs')] : []);
};

0 comments on commit 02f9b36

Please sign in to comment.