From f8723c87ff1d34020734f5339ecf963dbdd370f7 Mon Sep 17 00:00:00 2001 From: Rokojori Date: Sun, 12 Jul 2026 15:20:35 +0200 Subject: [PATCH] fix: copy CSS/SVG static assets in build step; fix mkdirSync to use recursive Co-Authored-By: Claude Sonnet 4.6 --- scripts/copy-pages.js | 39 ++++++++++++++++++++++++++++++++------- source/server/db.ts | 2 +- source/server/storage.ts | 2 +- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/scripts/copy-pages.js b/scripts/copy-pages.js index 0784303..8edee9e 100644 --- a/scripts/copy-pages.js +++ b/scripts/copy-pages.js @@ -1,13 +1,38 @@ -const fs = require('fs'); +const fs = require('fs'); const path = require('path'); -const src = path.join(__dirname, '..', 'source', 'pages'); -const dest = path.join(__dirname, '..', 'build', 'app'); +const ROOT = path.join(__dirname, '..'); +const SRC = path.join(ROOT, 'source'); +const DEST = path.join(ROOT, 'build', 'app'); -fs.mkdirSync(dest, { recursive: true }); +// Server-side dirs or dirs with their own build step — skip +const SKIP = new Set(['server', 'locale-data', 'locales', 'library-ts', 'pages']); -for (const file of fs.readdirSync(src)) { - if (file.endsWith('.html')) { - fs.copyFileSync(path.join(src, file), path.join(dest, file)); +function copyStatic(src, dest) { + fs.mkdirSync(dest, { recursive: true }); + for (const entry of fs.readdirSync(src, { withFileTypes: true })) { + const srcPath = path.join(src, entry.name); + const destPath = path.join(dest, entry.name); + if (entry.isDirectory()) { + copyStatic(srcPath, destPath); + } else if (!entry.name.endsWith('.ts')) { + fs.copyFileSync(srcPath, destPath); + } + } +} + +// Copy HTML pages +const pagesDir = path.join(SRC, 'pages'); +fs.mkdirSync(DEST, { recursive: true }); +for (const file of fs.readdirSync(pagesDir)) { + if (file.endsWith('.html')) { + fs.copyFileSync(path.join(pagesDir, file), path.join(DEST, file)); + } +} + +// Copy all non-TS static assets (CSS, SVG, etc.) from frontend source dirs +for (const entry of fs.readdirSync(SRC, { withFileTypes: true })) { + if (entry.isDirectory() && !SKIP.has(entry.name)) { + copyStatic(path.join(SRC, entry.name), path.join(DEST, entry.name)); } } diff --git a/source/server/db.ts b/source/server/db.ts index 940d08b..b8e5e96 100644 --- a/source/server/db.ts +++ b/source/server/db.ts @@ -3,7 +3,7 @@ import path from 'path'; import { randomUUID } from 'crypto'; const DATA_DIR = path.join(__dirname, '..', '..', 'build', 'data', 'db'); -if (!fs.existsSync(DATA_DIR)) fs.mkdirSync(DATA_DIR); +if (!fs.existsSync(DATA_DIR)) fs.mkdirSync(DATA_DIR, { recursive: true }); export interface User { id: string; diff --git a/source/server/storage.ts b/source/server/storage.ts index 9fe91d3..308ac1b 100644 --- a/source/server/storage.ts +++ b/source/server/storage.ts @@ -2,7 +2,7 @@ import fs from 'fs'; import path from 'path'; const STORAGE_DIR = path.join(__dirname, '..', '..', 'build', 'data', 'storage'); -if (!fs.existsSync(STORAGE_DIR)) fs.mkdirSync(STORAGE_DIR); +if (!fs.existsSync(STORAGE_DIR)) fs.mkdirSync(STORAGE_DIR, { recursive: true }); const INITIAL_HTML = `