11import { normalizeStories } from '@storybook/core-common' ;
2- import type { CoreConfig , Options } from '@storybook/types' ;
2+ import type { DocsOptions , Options , TagsOptions } from '@storybook/types' ;
33import { readFile } from 'fs-extra' ;
44import { virtualAppFilename } from './virtual-file-names.js' ;
55
@@ -10,35 +10,44 @@ export async function generateIframeHtml(options: Options): Promise<string> {
1010 require . resolve ( '../static/iframe-template.html' ) ,
1111 'utf-8' ,
1212 ) ;
13- const { configType, features, presets, serverChannelUrl } = options ;
13+ const { configType, features, presets } = options ;
14+ const build = await presets . apply ( 'build' ) ;
1415 const frameworkOptions = await presets . apply < Record < string , any > | null > ( 'frameworkOptions' ) ;
1516 const headHtmlSnippet = await presets . apply < PreviewHtml > ( 'previewHead' ) ;
1617 const bodyHtmlSnippet = await presets . apply < PreviewHtml > ( 'previewBody' ) ;
1718 const logLevel = await presets . apply ( 'logLevel' , undefined ) ;
18- // const docsOptions = await presets.apply<DocsOptions>('docs');
19- const coreOptions = await presets . apply < CoreConfig > ( 'core' ) ;
19+ const docsOptions = await presets . apply < DocsOptions > ( 'docs' ) ;
20+ const tagsOptions = await presets . apply < TagsOptions > ( 'tags' ) ;
21+ const coreOptions = await presets . apply ( 'core' ) ;
2022 const stories = normalizeStories ( await options . presets . apply ( 'stories' , [ ] , options ) , {
2123 configDir : options . configDir ,
2224 workingDir : process . cwd ( ) ,
2325 } ) . map ( specifier => ( {
2426 ...specifier ,
2527 importPathMatcher : specifier . importPathMatcher . source ,
2628 } ) ) ;
27- return (
28- iframeHtmlTemplate
29- . replace ( '[CONFIG_TYPE HERE]' , configType || '' )
30- . replace ( '[LOGLEVEL HERE]' , logLevel || '' )
31- . replace ( `'[FRAMEWORK_OPTIONS HERE]'` , JSON . stringify ( frameworkOptions ) )
32- . replace (
33- `'[CHANNEL_OPTIONS HERE]'` ,
34- JSON . stringify ( coreOptions && coreOptions . channelOptions ? coreOptions . channelOptions : { } ) ,
35- )
36- . replace ( `'[FEATURES HERE]'` , JSON . stringify ( features || { } ) )
37- . replace ( `'[STORIES HERE]'` , JSON . stringify ( stories || { } ) )
38- // .replace(`'[DOCS_OPTIONS HERE]'`, JSON.stringify(docsOptions || {}))
39- . replace ( `'[SERVER_CHANNEL_URL HERE]'` , JSON . stringify ( serverChannelUrl ) )
40- . replace ( '<!-- [HEAD HTML SNIPPET HERE] -->' , headHtmlSnippet || '' )
41- . replace ( '<!-- [BODY HTML SNIPPET HERE] -->' , bodyHtmlSnippet || '' )
42- . replace ( `[APP MODULE SRC HERE]` , virtualAppFilename )
43- ) ;
29+ const otherGlobals = {
30+ ...( build ?. test ?. disableBlocks ? { __STORYBOOK_BLOCKS_EMPTY_MODULE__ : { } } : { } ) ,
31+ } ;
32+ return iframeHtmlTemplate
33+ . replace ( '[CONFIG_TYPE HERE]' , configType || '' )
34+ . replace ( '[LOGLEVEL HERE]' , logLevel || '' )
35+ . replace ( `'[FRAMEWORK_OPTIONS HERE]'` , JSON . stringify ( frameworkOptions ) )
36+ . replace (
37+ `('OTHER_GLOBLALS HERE');` ,
38+ Object . entries ( otherGlobals )
39+ . map ( ( [ k , v ] ) => `window["${ k } "] = ${ JSON . stringify ( v ) } ;` )
40+ . join ( '' ) ,
41+ )
42+ . replace (
43+ `'[CHANNEL_OPTIONS HERE]'` ,
44+ JSON . stringify ( coreOptions && coreOptions . channelOptions ? coreOptions . channelOptions : { } ) ,
45+ )
46+ . replace ( `'[FEATURES HERE]'` , JSON . stringify ( features || { } ) )
47+ . replace ( `'[STORIES HERE]'` , JSON . stringify ( stories || { } ) )
48+ . replace ( `'[DOCS_OPTIONS HERE]'` , JSON . stringify ( docsOptions || { } ) )
49+ . replace ( `'[TAGS_OPTIONS HERE]'` , JSON . stringify ( tagsOptions || { } ) )
50+ . replace ( '<!-- [HEAD HTML SNIPPET HERE] -->' , headHtmlSnippet || '' )
51+ . replace ( '<!-- [BODY HTML SNIPPET HERE] -->' , bodyHtmlSnippet || '' )
52+ . replace ( `[APP MODULE SRC HERE]` , virtualAppFilename ) ;
4453}
0 commit comments