UNPKG

@web/storybook-builder

Version:
44 lines 2.82 kB
"use strict"; // based on https://github.com/storybookjs/storybook/blob/v8.5.0/code/builders/builder-vite/src/transform-iframe-html.ts Object.defineProperty(exports, "__esModule", { value: true }); exports.generateIframeHtml = void 0; const core_common_1 = require("@storybook/core-common"); const promises_1 = require("node:fs/promises"); const virtual_file_names_js_1 = require("./virtual-file-names.js"); async function generateIframeHtml(options) { var _a; const iframeHtmlTemplate = await (0, promises_1.readFile)(require.resolve('../static/iframe-template.html'), { encoding: 'utf-8', }); const { configType, features, presets } = options; const build = await presets.apply('build'); const frameworkOptions = await presets.apply('frameworkOptions'); const headHtmlSnippet = await presets.apply('previewHead'); const bodyHtmlSnippet = await presets.apply('previewBody'); const logLevel = await presets.apply('logLevel', undefined); const docsOptions = await presets.apply('docs'); const tagsOptions = await presets.apply('tags'); const coreOptions = await presets.apply('core'); const stories = (0, core_common_1.normalizeStories)(await options.presets.apply('stories', [], options), { configDir: options.configDir, workingDir: process.cwd(), }).map(specifier => (Object.assign(Object.assign({}, specifier), { importPathMatcher: specifier.importPathMatcher.source }))); const otherGlobals = Object.assign({}, (((_a = build === null || build === void 0 ? void 0 : build.test) === null || _a === void 0 ? void 0 : _a.disableBlocks) ? { __STORYBOOK_BLOCKS_EMPTY_MODULE__: {} } : {})); return iframeHtmlTemplate .replace('[CONFIG_TYPE HERE]', configType || '') .replace('[LOGLEVEL HERE]', logLevel || '') .replace(`'[FRAMEWORK_OPTIONS HERE]'`, JSON.stringify(frameworkOptions)) .replace(`('OTHER_GLOBLALS HERE');`, Object.entries(otherGlobals) .map(([k, v]) => `window["${k}"] = ${JSON.stringify(v)};`) .join('')) .replace(`'[CHANNEL_OPTIONS HERE]'`, JSON.stringify(coreOptions && coreOptions.channelOptions ? coreOptions.channelOptions : {})) .replace(`'[FEATURES HERE]'`, JSON.stringify(features || {})) .replace(`'[STORIES HERE]'`, JSON.stringify(stories || {})) .replace(`'[DOCS_OPTIONS HERE]'`, JSON.stringify(docsOptions || {})) .replace(`'[TAGS_OPTIONS HERE]'`, JSON.stringify(tagsOptions || {})) .replace('<!-- [HEAD HTML SNIPPET HERE] -->', headHtmlSnippet || '') .replace('<!-- [BODY HTML SNIPPET HERE] -->', bodyHtmlSnippet || '') .replace(`[APP MODULE SRC HERE]`, virtual_file_names_js_1.virtualAppFilename); } exports.generateIframeHtml = generateIframeHtml; //# sourceMappingURL=generate-iframe-html.js.map