Skip to content

Commit 70bed06

Browse files
committed
amend test env output
1 parent 701290d commit 70bed06

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

scripts/create-testenv.mjs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mkdir, readdir, rm, writeFile } from 'node:fs/promises';
1+
import { mkdir, readdir, readFile, rm, writeFile } from 'node:fs/promises';
22
import path from 'node:path';
33
import { fileURLToPath } from 'node:url';
44
import { spawnSync } from 'node:child_process';
@@ -254,6 +254,23 @@ function renderIndexPage({ branchName, commitSha, buildTimestamp }) {
254254
`;
255255
}
256256

257+
const TESTENV_HIDE_HEADER_STYLE = `
258+
<style data-testenv-hide-header>
259+
.header {
260+
display: none !important;
261+
}
262+
</style>`;
263+
264+
async function hideTopHeaderInBuiltPage(pagePath) {
265+
const html = await readFile(pagePath, 'utf8');
266+
if (html.includes('data-testenv-hide-header')) {
267+
return;
268+
}
269+
270+
const nextHtml = html.replace('</head>', `${TESTENV_HIDE_HEADER_STYLE}\n </head>`);
271+
await writeFile(pagePath, nextHtml, 'utf8');
272+
}
273+
257274
await clearDirectoryContents(outputDir);
258275

259276
const buildMetadata = resolveBuildMetadata();
@@ -272,6 +289,9 @@ runCommand('pnpm', [
272289

273290
runCommand('pnpm', ['exec', 'storybook', 'build', '--output-dir', storybookDir]);
274291

292+
await hideTopHeaderInBuiltPage(path.join(outputDir, 'app.html'));
293+
await hideTopHeaderInBuiltPage(path.join(outputDir, 'generator.html'));
294+
275295
await writeFile(path.join(outputDir, 'index.html'), renderIndexPage(buildMetadata), 'utf8');
276296

277297
console.log(`Created test environment in ${outputDir}`);

0 commit comments

Comments
 (0)