mirror of
https://github.com/lossless-group/perplexed-plugin.git
synced 2026-07-22 17:00:32 +00:00
A freshly-installed perplexed has no templates folder, so the directory-template commands have nothing to match. Users had to copy templates from the plugin source by hand. Now the four shipped templates (concept-, vocabulary-, source-, toolkit-profile) plus a README are inlined into main.js via esbuild's text loader for .md files, and a seeder writes them into the configured templates root on plugin load — but only if the folder is missing or contains no markdown, so existing customizations are never touched. A new "Re-seed templates" button in the Directory templates settings section fills in any shipped file whose filename doesn't already exist (for pulling in new templates after a plugin update). Pieces: - esbuild.config.mjs: register `.md` text loader so markdown imports work - src/types/markdown.d.ts: TS shim for `*.md` imports - src/services/templateSeederService.ts: seedTemplatesIfMissing + reSeedMissingFiles (idempotent, never overwrites) - src/docs/templates/README.md: end-user docs for the template system (zone anatomy, interpolation tokens, commands, image markers, citation behavior, frontmatter stamps, writing a custom template) - main.ts: seeder fires after settings load; settings tab gains a Re-seed button Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
68 lines
1.6 KiB
JavaScript
68 lines
1.6 KiB
JavaScript
import esbuild from 'esbuild';
|
|
import process from 'node:process';
|
|
import { builtinModules as builtins } from 'node:module';
|
|
|
|
const banner = `/*
|
|
* Content Farm Plugin for Obsidian
|
|
* Generated: ${new Date().toISOString()}
|
|
* Build: ${process.env.NODE_ENV || 'development'}
|
|
*/`;
|
|
|
|
const isProduction = process.argv[2] === 'production' || process.env.NODE_ENV === 'production';
|
|
|
|
const external = [
|
|
'obsidian',
|
|
'electron',
|
|
'@codemirror/autocomplete',
|
|
'@codemirror/collab',
|
|
'@codemirror/commands',
|
|
'@codemirror/language',
|
|
'@codemirror/lint',
|
|
'@codemirror/search',
|
|
'@codemirror/state',
|
|
'@codemirror/view',
|
|
'@lezer/common',
|
|
'@lezer/highlight',
|
|
'@lezer/lr',
|
|
...builtins
|
|
];
|
|
|
|
// First, build the CSS file
|
|
await esbuild.build({
|
|
entryPoints: ['src/styles/main.css'],
|
|
bundle: true,
|
|
minify: isProduction,
|
|
outfile: 'styles.css',
|
|
loader: { '.css': 'css' },
|
|
});
|
|
|
|
const context = await esbuild.context({
|
|
banner: {
|
|
js: banner,
|
|
},
|
|
entryPoints: ['main.ts'],
|
|
bundle: true,
|
|
external: [...external, './styles.css'],
|
|
format: 'cjs',
|
|
platform: 'node',
|
|
target: 'es2022',
|
|
treeShaking: true,
|
|
sourcemap: !isProduction ? 'inline' : false,
|
|
minify: isProduction,
|
|
define: {
|
|
'process.env.NODE_ENV': `"${isProduction ? 'production' : 'development'}"`,
|
|
},
|
|
logLevel: 'info',
|
|
outfile: 'main.js',
|
|
loader: { '.css': 'text', '.md': 'text' },
|
|
});
|
|
|
|
if (isProduction) {
|
|
// Build only for production
|
|
await context.rebuild();
|
|
process.exit(0);
|
|
} else {
|
|
// Enable watch mode for development
|
|
await context.watch();
|
|
console.log('Watching for changes...');
|
|
}
|