Files
memind/scripts/patch-portal-learn-assistant-103.mjs
T
john 348e192800 feat(learn): add family learning assistant API routes and public pages
Wire /learn static delivery, parent/child portal routes, and Tang page build scripts for 103 deploy.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-11 17:09:52 +08:00

40 lines
1.6 KiB
JavaScript

#!/usr/bin/env node
/**
* 在 103 已打包的 server.mjs 中热插入 learn-assistant 路由
*/
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
const serverPath = path.join(root, 'server.mjs');
let src = fs.readFileSync(serverPath, 'utf8');
if (src.includes('attachLearnAssistantPublicRoutes(api')) {
console.log(JSON.stringify({ ok: true, patched: false, reason: 'already_patched' }));
process.exit(0);
}
const publicNeedle = 'attachShenmeiOpinionFormRoutes(api, { rootDir: __dirname6 });';
const publicInsert = `${publicNeedle}
attachLearnAssistantPublicRoutes(api, { rootDir: __dirname6 });`;
const parentNeedle = '}));\n\nattachPortalImageMakeRuntimeConfigRoute(api, {';
const parentInsert = `}));\n\nattachLearnAssistantParentRoutes(api, { rootDir: __dirname6 });\n\nattachPortalImageMakeRuntimeConfigRoute(api, {`;
if (!src.includes(publicNeedle) || !src.includes(parentNeedle)) {
console.error('patch needles not found in bundled server.mjs');
process.exit(1);
}
const topImport = "import { attachLearnAssistantPublicRoutes, attachLearnAssistantParentRoutes } from './learn-assistant-routes.mjs';\n";
if (!src.includes("from './learn-assistant-routes.mjs'")) {
const firstImportEnd = src.indexOf(';\n') + 2;
src = `${src.slice(0, firstImportEnd)}${topImport}${src.slice(firstImportEnd)}`;
}
src = src.replace(publicNeedle, publicInsert);
src = src.replace(parentNeedle, parentInsert);
fs.writeFileSync(serverPath, src);
console.log(JSON.stringify({ ok: true, patched: true, serverPath }));