feat(waas): add catch-all route, page manager and draft-publish pipeline
This commit is contained in:
@@ -210,12 +210,20 @@ function readJsonFile<T>(filePath: string, fallback: T): T {
|
||||
}
|
||||
}
|
||||
|
||||
export function loadWaasConfigs(userAgent: string = '') {
|
||||
export function loadWaasConfigs(userAgent: string = '', isDraft: boolean = false) {
|
||||
const dataDir = process.env.DATA_DIR || path.join(process.cwd(), 'app', 'data');
|
||||
const device = detectDeviceType(userAgent);
|
||||
|
||||
const draftSitePath = path.join(dataDir, 'site.config.draft.json');
|
||||
const deviceSitePath = path.join(dataDir, `site.${device}.config.json`);
|
||||
const genericSitePath = path.join(dataDir, 'site.config.json');
|
||||
const sitePath = fs.existsSync(deviceSitePath) ? deviceSitePath : genericSitePath;
|
||||
|
||||
let sitePath = genericSitePath;
|
||||
if (isDraft && fs.existsSync(draftSitePath)) {
|
||||
sitePath = draftSitePath;
|
||||
} else if (fs.existsSync(deviceSitePath)) {
|
||||
sitePath = deviceSitePath;
|
||||
}
|
||||
|
||||
const deviceThemePath = path.join(dataDir, `theme.${device}.config.json`);
|
||||
const genericThemePath = path.join(dataDir, 'theme.config.json');
|
||||
@@ -239,3 +247,8 @@ export function loadWaasConfigs(userAgent: string = '') {
|
||||
|
||||
return { siteConfig, themeConfig, smtpConfig };
|
||||
}
|
||||
|
||||
export function getSiteConfig(isDraft: boolean = false) {
|
||||
return loadWaasConfigs('', isDraft).siteConfig;
|
||||
}
|
||||
|
||||
|
||||
48
src/utils/editorController.ts
Normal file
48
src/utils/editorController.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
// Editor controller for drag‑and‑drop synchronization
|
||||
// Provides functions to load, save and publish draft config JSON
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
const draftPath = path.resolve(process.cwd(), 'app', 'data', 'site.config.draft.json');
|
||||
const livePath = path.resolve(process.cwd(), 'app', 'data', 'site.config.json');
|
||||
|
||||
/** Load current draft config (or empty object) */
|
||||
export function loadDraft(): Record<string, any> {
|
||||
if (fs.existsSync(draftPath)) {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(draftPath, 'utf8'));
|
||||
} catch (e) {
|
||||
console.error('Failed to parse draft JSON', e);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
/** Save draft config */
|
||||
export function saveDraft(data: Record<string, any>): void {
|
||||
fs.mkdirSync(path.dirname(draftPath), { recursive: true });
|
||||
fs.writeFileSync(draftPath, JSON.stringify(data, null, 2), 'utf8');
|
||||
}
|
||||
|
||||
/** Publish draft to live config atomically */
|
||||
export function publishDraft(): void {
|
||||
if (!fs.existsSync(draftPath)) return;
|
||||
const content = fs.readFileSync(draftPath, 'utf8');
|
||||
fs.mkdirSync(path.dirname(livePath), { recursive: true });
|
||||
fs.writeFileSync(livePath, content, 'utf8');
|
||||
}
|
||||
|
||||
/** Helper to get both draft and live (for debugging) */
|
||||
export function getLiveConfig(): Record<string, any> {
|
||||
if (fs.existsSync(livePath)) {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(livePath, 'utf8'));
|
||||
} catch (e) {
|
||||
console.error('Failed to parse live JSON', e);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
Reference in New Issue
Block a user