From 16e255fd5719b8ed4f6c95488b05a4bce5bbd8fe Mon Sep 17 00:00:00 2001 From: Cole Lawrence Date: Fri, 17 Jun 2022 15:23:35 -0400 Subject: [PATCH] dev: Initial playground re-design (#218) Improve the landing page for playground items. --- REMOVEME.md | 1 + packages/playground/devEnv/Home.tsx | 29 ---- packages/playground/devEnv/build.ts | 54 ++++++-- .../devEnv/home/ItemSectionWithPreviews.tsx | 130 ++++++++++++++++++ .../devEnv/home/PlaygroundHeader.tsx | 124 +++++++++++++++++ .../playground/devEnv/home/PlaygroundPage.tsx | 67 +++++++++ packages/playground/devEnv/index.html | 3 - 7 files changed, 365 insertions(+), 43 deletions(-) create mode 100644 REMOVEME.md delete mode 100644 packages/playground/devEnv/Home.tsx create mode 100644 packages/playground/devEnv/home/ItemSectionWithPreviews.tsx create mode 100644 packages/playground/devEnv/home/PlaygroundHeader.tsx create mode 100644 packages/playground/devEnv/home/PlaygroundPage.tsx diff --git a/REMOVEME.md b/REMOVEME.md new file mode 100644 index 0000000..f620022 --- /dev/null +++ b/REMOVEME.md @@ -0,0 +1 @@ +file for testing commit diff --git a/packages/playground/devEnv/Home.tsx b/packages/playground/devEnv/Home.tsx deleted file mode 100644 index e7b7c49..0000000 --- a/packages/playground/devEnv/Home.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import React from 'react' - -export const Home = ({groups}: {groups: {[groupName: string]: string[]}}) => ( - -) - -const Group = (props: {groupName: string; modules: string[]}) => { - const {groupName, modules} = props - return ( - - ) -} diff --git a/packages/playground/devEnv/build.ts b/packages/playground/devEnv/build.ts index 153d7b1..da2a9c3 100644 --- a/packages/playground/devEnv/build.ts +++ b/packages/playground/devEnv/build.ts @@ -7,7 +7,8 @@ import {definedGlobals} from '../../../theatre/devEnv/definedGlobals' import {mapValues} from 'lodash-es' import React from 'react' import {renderToStaticMarkup} from 'react-dom/server' -import {Home} from './Home' +import {ServerStyleSheet} from 'styled-components' +import {PlaygroundPage} from './home/PlaygroundPage' import {timer} from './timer' import {openForOS} from './openForOS' import {tryMultiplePorts} from './tryMultiplePorts' @@ -83,11 +84,31 @@ export async function start(options: { ) // Render home page contents - const homeHtml = renderToStaticMarkup( - React.createElement(Home, { - groups: mapValues(groups, (group) => Object.keys(group)), - }), - ) + + // Render home page contents + const homeHtml = (() => { + const sheet = new ServerStyleSheet() + try { + const html = renderToStaticMarkup( + sheet.collectStyles( + React.createElement(PlaygroundPage, { + groups: mapValues(groups, (group) => Object.keys(group)), + }), + ), + ) + const styleTags = sheet.getStyleTags() // or sheet.getStyleElement(); + sheet.seal() + return { + head: styleTags, + html, + } + } catch (error) { + // handle error + console.error(error) + sheet.seal() + process.exit(1) + } + })() const _initialBuild = timer('esbuild initial playground entry point builds') @@ -108,7 +129,12 @@ export async function start(options: { 'window.__IS_VISUAL_REGRESSION_TESTING': 'true', }, banner: liveReload?.esbuildBanner, - watch: liveReload?.esbuildWatch, + watch: liveReload?.esbuildWatch && { + onRebuild(error, result) { + esbuildWatchStop = result?.stop ?? esbuildWatchStop + liveReload?.esbuildWatch.onRebuild?.(error, result) + }, + }, } let esbuildWatchStop: undefined | (() => void) @@ -128,17 +154,23 @@ export async function start(options: { // Write home page writeFile( path.join(buildDir, 'index.html'), - index.replace(/[\s\S]*<\/body>/, `${homeHtml}`), + index + .replace(/<\/head>/, `${homeHtml.head}<\/head>`) + .replace(//, `${homeHtml.html}`), 'utf-8', ), // Write module pages ...outDirs.map((outDir) => writeFile( path.join(outDir, 'index.html'), - // Substitute %ENTRYPOINT% placeholder with the output file path + // Insert the script index.replace( - '%ENTRYPOINT%', - path.join('/', path.relative(buildDir, outDir), 'index.js'), + /<\/body>/, + ``, ), 'utf-8', ), diff --git a/packages/playground/devEnv/home/ItemSectionWithPreviews.tsx b/packages/playground/devEnv/home/ItemSectionWithPreviews.tsx new file mode 100644 index 0000000..8460828 --- /dev/null +++ b/packages/playground/devEnv/home/ItemSectionWithPreviews.tsx @@ -0,0 +1,130 @@ +import React from 'react' +import styled from 'styled-components' + +export const ItemSectionWithPreviews = (props: { + groupName: string + modules: string[] +}) => { + let {groupName, modules} = props + return ( +
+ {groupName} + + {modules.map((moduleName) => { + const href = `/${groupName}/${moduleName}` + return ( + + + +