6bc5d128d2
Notify users when HTML publish guards reject stub pages instead of silently failing, send real page links when non-stub files exist, and split wechat-mp into wechat-mp.bundle.mjs for fast production updates without full portal rebuilds. Co-authored-by: Cursor <cursoragent@cursor.com>
29 lines
882 B
JavaScript
29 lines
882 B
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { pathToFileURL } from 'node:url';
|
|
import { loadWechatMpConfig } from './wechat-mp-config.mjs';
|
|
|
|
export { loadWechatMpConfig };
|
|
|
|
let cachedModule = null;
|
|
let cachedTarget = '';
|
|
let cachedMtime = 0;
|
|
|
|
function resolveWechatMpEntry(root = process.cwd()) {
|
|
const bundlePath = path.join(root, 'wechat-mp.bundle.mjs');
|
|
if (fs.existsSync(bundlePath)) return bundlePath;
|
|
return path.join(root, 'wechat-mp.mjs');
|
|
}
|
|
|
|
export async function loadWechatMpModule(root = process.cwd()) {
|
|
const target = resolveWechatMpEntry(root);
|
|
const mtime = fs.statSync(target).mtimeMs;
|
|
if (cachedModule && cachedTarget === target && cachedMtime === mtime) {
|
|
return cachedModule;
|
|
}
|
|
cachedModule = await import(`${pathToFileURL(target).href}?v=${mtime}`);
|
|
cachedTarget = target;
|
|
cachedMtime = mtime;
|
|
return cachedModule;
|
|
}
|