From e85ecd2bcf0296b223b38ab91cf3b8341dbacb24 Mon Sep 17 00:00:00 2001 From: Pabloader Date: Fri, 10 Apr 2026 13:48:40 +0000 Subject: [PATCH] Add styles based on app flag --- build/assets/app.css | 7 ++++ {src/common => build}/assets/global.css | 9 ----- build/html.ts | 53 +++++++++++++++---------- src/common/assets/modal.module.css | 2 - src/common/assets/ui.module.css | 2 - src/games/storywriter/assets/style.css | 2 - 6 files changed, 39 insertions(+), 36 deletions(-) create mode 100644 build/assets/app.css rename {src/common => build}/assets/global.css (79%) diff --git a/build/assets/app.css b/build/assets/app.css new file mode 100644 index 0000000..5bcfb42 --- /dev/null +++ b/build/assets/app.css @@ -0,0 +1,7 @@ +body { + background: var(--bg); + color: var(--text); + font-family: 'Georgia', serif; + font-size: 14px; + line-height: 1.5; +} \ No newline at end of file diff --git a/src/common/assets/global.css b/build/assets/global.css similarity index 79% rename from src/common/assets/global.css rename to build/assets/global.css index 7c9f93b..e7894cd 100644 --- a/src/common/assets/global.css +++ b/build/assets/global.css @@ -34,13 +34,4 @@ body { margin: 0; padding: 0; overflow: hidden; - font-family: sans-serif; -} - -body { - background: var(--bg); - color: var(--text); - font-family: 'Georgia', serif; - font-size: 14px; - line-height: 1.5; } \ No newline at end of file diff --git a/build/html.ts b/build/html.ts index f9f7194..5a112ab 100644 --- a/build/html.ts +++ b/build/html.ts @@ -73,13 +73,31 @@ connect(); `; async function buildBundle(game: string, production: boolean) { + const assetsDir = path.resolve(import.meta.dir, 'assets'); const srcDir = path.resolve(import.meta.dir, '..', 'src'); - return Bun.build({ + const gameDir = path.resolve(srcDir, 'games', game); + const gameAssetsDir = path.resolve(gameDir, 'assets'); + + let appConfig = Bun.file(path.resolve(gameAssetsDir, 'config.yml')); + let config = DEFAULT_CONFIG; + if (await appConfig.exists()) { + try { + const maybeConfig = Bun.YAML.parse(await appConfig.text()); + if (Type.Is(AppConfigScheme, maybeConfig)) { + config = maybeConfig; + } + } catch { } + } + const entrypoints = [ + path.resolve(assetsDir, 'global.css'), + ]; + if (config.isApp) { + entrypoints.push(path.resolve(assetsDir, 'app.css')); + } + entrypoints.push(path.resolve(srcDir, 'index.ts')); + const bundle = await Bun.build({ outdir: '/tmp', - entrypoints: [ - path.resolve(srcDir, 'index.ts'), - path.resolve(srcDir, 'common', 'assets', 'global.css'), - ], + entrypoints, sourcemap: production ? 'none' : 'inline', define: { global: 'window', @@ -94,6 +112,8 @@ async function buildBundle(game: string, production: boolean) { filePlugin, ] }); + + return { bundle, config, gameDir, gameAssetsDir, srcDir, assetsDir }; } export async function buildHTML(game: string, { @@ -101,13 +121,14 @@ export async function buildHTML(game: string, { mobile = false, local = false, }: Args = {}) { - const assetsDir = path.resolve(import.meta.dir, 'assets'); - const srcDir = path.resolve(import.meta.dir, '..', 'src'); - const gameDir = path.resolve(srcDir, 'games', game); - const gameAssetsDir = path.resolve(gameDir, 'assets'); + const { + bundle, + config, + gameAssetsDir, + assetsDir, + } = await buildBundle(game, production); const html = await Bun.file(path.resolve(assetsDir, 'index.html')).text(); - const bundle = await buildBundle(game, production); if (bundle.success) { const scriptFile = bundle.outputs.find(a => a.kind === 'entry-point' && a.path.endsWith('.js')); @@ -137,16 +158,6 @@ export async function buildHTML(game: string, { } const pwaIconData = await pwaIcon.getBase64("image/png"); - let appConfig = Bun.file(path.resolve(gameAssetsDir, 'config.yml')); - let config = DEFAULT_CONFIG; - if (await appConfig.exists()) { - try { - const maybeConfig = Bun.YAML.parse(await appConfig.text()); - if (Type.Is(AppConfigScheme, maybeConfig)) { - config = maybeConfig; - } - } catch { } - } let manifest = ''; if (production && !local) { const publishURL = process.env.PUBLISH_URL ? `${process.env.PUBLISH_URL}${game}` : '.'; @@ -226,7 +237,7 @@ export async function buildHTML(game: string, { * Used by the dev server for CSS hot reload. */ export async function buildCSS(game: string): Promise { - const bundle = await buildBundle(game, false); + const { bundle } = await buildBundle(game, false); if (bundle.success) { let style = ''; for (const file of bundle.outputs.filter(a => a.kind === 'asset' && a.path.endsWith('.css'))) { diff --git a/src/common/assets/modal.module.css b/src/common/assets/modal.module.css index f36a4fc..c517509 100644 --- a/src/common/assets/modal.module.css +++ b/src/common/assets/modal.module.css @@ -1,5 +1,3 @@ -@import './global.css'; - .dialog { position: fixed; inset: 0; diff --git a/src/common/assets/ui.module.css b/src/common/assets/ui.module.css index 81a33c9..61dd6d2 100644 --- a/src/common/assets/ui.module.css +++ b/src/common/assets/ui.module.css @@ -1,5 +1,3 @@ -@import "./global.css"; - /* ─── Form Fields ─────────────────────────────────────────── */ .input, input, textarea { diff --git a/src/games/storywriter/assets/style.css b/src/games/storywriter/assets/style.css index f863dc0..1d8c745 100644 --- a/src/games/storywriter/assets/style.css +++ b/src/games/storywriter/assets/style.css @@ -1,5 +1,3 @@ -@import "@common/assets/global.css"; - :root { --textColor: #DCDCD2; --italicColor: #AFAFAF;