[ui] DaySentence: Her folded petal, the words and their source; the library bundled after validation
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import { svelte } from '@sveltejs/vite-plugin-svelte';
|
||||
import { readdirSync, readFileSync } from 'node:fs';
|
||||
import { join, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { defineConfig, type Plugin } from 'vite';
|
||||
import { VitePWA } from 'vite-plugin-pwa';
|
||||
// A relative path, not '@rosea/schema', on purpose. Vite bundles a config's
|
||||
@@ -55,12 +58,43 @@ function contentSecurityPolicy(): Plugin {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The hope library, bundled at build time as `virtual:rosea-library`
|
||||
* (day-sentence.md P5). The build script runs `validate:library` first and stops if
|
||||
* it fails, so the app holds exactly what passed and never validates in the browser
|
||||
* (GAP_ANALYSIS G0.12: Ajv needs `new Function`, which the CSP forbids).
|
||||
* `ROSEA_LIBRARY_DIR` swaps the folder, for the e2e build only.
|
||||
*/
|
||||
const LIBRARY_DIR = resolve(fileURLToPath(new URL('../..', import.meta.url)), process.env['ROSEA_LIBRARY_DIR'] ?? 'content/library');
|
||||
|
||||
function hopeLibrary(): Plugin {
|
||||
const id = 'virtual:rosea-library';
|
||||
const resolved = `\0${id}`;
|
||||
return {
|
||||
name: 'rosea-library',
|
||||
resolveId: (source) => (source === id ? resolved : undefined),
|
||||
load(source) {
|
||||
if (source !== resolved) return undefined;
|
||||
const entries: unknown[] = [];
|
||||
for (const file of readdirSync(LIBRARY_DIR).filter((f) => f.endsWith('.json')).sort()) {
|
||||
const path = join(LIBRARY_DIR, file);
|
||||
this.addWatchFile(path);
|
||||
const data: unknown = JSON.parse(readFileSync(path, 'utf8'));
|
||||
if (!Array.isArray(data)) throw new Error(`${path}: must be an array of entries`);
|
||||
entries.push(...data);
|
||||
}
|
||||
return `export default ${JSON.stringify(entries)};`;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Nothing binds to anything but 127.0.0.1 (CLAUDE.md §5.7).
|
||||
export default defineConfig({
|
||||
base: BASE,
|
||||
plugins: [
|
||||
svelte(),
|
||||
contentSecurityPolicy(),
|
||||
hopeLibrary(),
|
||||
VitePWA({
|
||||
strategies: 'generateSW',
|
||||
// Never swap a running app silently. A new worker waits until the player
|
||||
|
||||
Reference in New Issue
Block a user