UNPKG

creevey

Version:

Cross-browser screenshot testing tool for Storybook with fancy UI Runner

38 lines 1.94 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.shouldEnsureClientStaticsForCommand = exports.isLocalSourceCheckout = void 0; exports.ensureClientStaticsForLocalDev = ensureClientStaticsForLocalDev; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const utils_js_1 = require("../server/utils.js"); const getClientIndexHtml = () => path_1.default.join((0, utils_js_1.getClientDir)(), 'index.html'); const getViteConfigPath = () => path_1.default.resolve((0, utils_js_1.getClientDir)(), '../../../vite.config.mts'); const getRepoViteConfigPath = (runtimeDir) => path_1.default.join(runtimeDir, '../vite.config.mts'); const getErrorMessage = (error) => (error instanceof Error ? error.message : String(error)); const isLocalSourceCheckout = (runtimeDir) => fs_1.default.existsSync(getRepoViteConfigPath(runtimeDir)); exports.isLocalSourceCheckout = isLocalSourceCheckout; const shouldEnsureClientStaticsForCommand = (command) => command === 'report' || command === 'test'; exports.shouldEnsureClientStaticsForCommand = shouldEnsureClientStaticsForCommand; async function ensureClientStaticsForLocalDev() { const indexHtml = getClientIndexHtml(); if (fs_1.default.existsSync(indexHtml)) return; console.log('Building Creevey web UI...'); try { const { build } = await import('vite'); await build({ configFile: getViteConfigPath(), logLevel: 'error', }); if (!fs_1.default.existsSync(indexHtml)) { throw new Error('index.html was not generated.'); } } catch (error) { throw new Error(`Failed to build Creevey web UI: ${getErrorMessage(error)}`); } } //# sourceMappingURL=ensure-client-statics.js.map