fix: copy templates to the distribution

This commit is contained in:
2026-02-22 19:30:40 +01:00
parent a1c6930355
commit 9cd16885d4
3 changed files with 41 additions and 5 deletions

View File

@@ -131,6 +131,10 @@
{ {
"from": "drizzle", "from": "drizzle",
"to": "drizzle" "to": "drizzle"
},
{
"from": "src/main/engine/templates",
"to": "templates"
} }
], ],
"protocols": [ "protocols": [

View File

@@ -815,6 +815,28 @@ export function recordToMap(record: unknown): Map<string, string> {
); );
} }
export function resolvePageRendererTemplateRoots(options?: {
moduleDir?: string;
cwd?: string;
resourcesPath?: string;
}): string[] {
const moduleDir = options?.moduleDir ?? __dirname;
const cwd = options?.cwd ?? process.cwd();
const resourcesPath = options?.resourcesPath ?? process.resourcesPath;
const roots = [
path.resolve(moduleDir, 'templates'),
path.resolve(cwd, 'dist', 'main', 'engine', 'templates'),
path.resolve(cwd, 'src', 'main', 'engine', 'templates'),
];
if (typeof resourcesPath === 'string' && resourcesPath.length > 0) {
roots.unshift(path.resolve(resourcesPath, 'templates'));
}
return Array.from(new Set(roots));
}
export class PageRenderer { export class PageRenderer {
private readonly mediaEngine: MediaEngineContract; private readonly mediaEngine: MediaEngineContract;
private readonly postMediaEngine: PostMediaEngineContract; private readonly postMediaEngine: PostMediaEngineContract;
@@ -826,11 +848,7 @@ export class PageRenderer {
this.postMediaEngine = postMediaEngine; this.postMediaEngine = postMediaEngine;
this.postEngineForMacros = postEngineForMacros; this.postEngineForMacros = postEngineForMacros;
const templateRoots = [ const templateRoots = resolvePageRendererTemplateRoots();
path.resolve(__dirname, 'templates'),
path.resolve(process.cwd(), 'dist', 'main', 'engine', 'templates'),
path.resolve(process.cwd(), 'src', 'main', 'engine', 'templates'),
];
this.liquid = new Liquid({ this.liquid = new Liquid({
root: templateRoots, root: templateRoots,

View File

@@ -0,0 +1,14 @@
import { describe, expect, it } from 'vitest';
import { resolvePageRendererTemplateRoots } from '../../src/main/engine/PageRenderer';
describe('resolvePageRendererTemplateRoots', () => {
it('includes templates under process resources path for packaged app builds', () => {
const roots = resolvePageRendererTemplateRoots({
moduleDir: '/Applications/Blogging Desktop Server.app/Contents/Resources/app.asar/dist/main/engine',
cwd: '/tmp/runtime-cwd',
resourcesPath: '/Applications/Blogging Desktop Server.app/Contents/Resources',
});
expect(roots).toContain('/Applications/Blogging Desktop Server.app/Contents/Resources/templates');
});
});