feat: add comprehensive template embedding and release automation

Implements dual-strategy template distribution for reliable plugin deployment:

Template Embedding System:
- Add esbuild plugin to embed .typ templates as base64 strings in main.js
- Create EmbeddedTemplateManager for automatic template extraction
- Add TypeScript declarations for virtual template-embed module
- Templates auto-extract on plugin load if missing from disk

Release Automation:
- Add GitHub Actions workflow for automated ZIP releases
- Create package-plugin.js script for complete distribution packages
- Update version-bump.mjs for Obsidian-compliant tags (no 'v' prefix)
- Ensure releases include templates/ directory for manual installations

Documentation Updates:
- Comprehensive installation instructions with troubleshooting
- Clear warnings about requiring complete ZIP packages
- Multiple installation methods including manual and automated

This ensures the plugin works regardless of installation method:
- ZIP releases provide templates/ directory (primary method)
- Embedded templates auto-extract as fallback (secondary method)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Jarvis committed 2025-09-05 15:34:00 +02:00
1 parent d40253e6c4
commit 8557720f43
10 files changed
+1619 -21

No files matched your search

+143
View File
@@ -0,0 +1,143 @@
import { extractTemplate, getAllTemplateNames } from 'template-embed:templates';
import * as fs from 'fs';
import * as path from 'path';
export interface TemplateInfo {
name: string;
exists: boolean;
needsExtraction: boolean;
}
/**
* Template manager that handles embedded templates and extraction
*/
export class EmbeddedTemplateManager {
private pluginDir: string;
private templatesDir: string;
constructor(pluginDir: string) {
this.pluginDir = pluginDir;
this.templatesDir = path.join(pluginDir, 'templates');
}
/**
* Get information about all templates
*/
getTemplateInfo(): TemplateInfo[] {
const embeddedNames = getAllTemplateNames();
const templateInfo: TemplateInfo[] = [];
for (const name of embeddedNames) {
const filePath = path.join(this.templatesDir, name);
const exists = fs.existsSync(filePath);
templateInfo.push({
name,
exists,
needsExtraction: !exists
});
}
return templateInfo;
}
/**
* Extract a single template if it doesn't exist
*/
extractTemplateIfNeeded(templateName: string): boolean {
const filePath = path.join(this.templatesDir, templateName);
// Check if template already exists
if (fs.existsSync(filePath)) {
return false; // No extraction needed
}
try {
// Ensure templates directory exists
if (!fs.existsSync(this.templatesDir)) {
fs.mkdirSync(this.templatesDir, { recursive: true });
}
// Extract template content
const content = extractTemplate(templateName, filePath);
// Write template to disk
fs.writeFileSync(filePath, content, 'utf8');
console.log(`Extracted embedded template: ${templateName}`);
return true; // Extraction successful
} catch (error) {
console.error(`Failed to extract template ${templateName}:`, error);
return false;
}
}
/**
* Extract all missing templates
*/
extractAllMissingTemplates(): { extracted: string[], failed: string[] } {
const extracted: string[] = [];
const failed: string[] = [];
const templateInfo = this.getTemplateInfo();
for (const info of templateInfo) {
if (info.needsExtraction) {
const success = this.extractTemplateIfNeeded(info.name);
if (success) {
extracted.push(info.name);
} else {
failed.push(info.name);
}
}
}
return { extracted, failed };
}
/**
* Force extract all templates (overwrites existing ones)
*/
forceExtractAllTemplates(): { extracted: string[], failed: string[] } {
const extracted: string[] = [];
const failed: string[] = [];
const embeddedNames = getAllTemplateNames();
// Ensure templates directory exists
if (!fs.existsSync(this.templatesDir)) {
fs.mkdirSync(this.templatesDir, { recursive: true });
}
for (const templateName of embeddedNames) {
try {
const filePath = path.join(this.templatesDir, templateName);
const content = extractTemplate(templateName, filePath);
fs.writeFileSync(filePath, content, 'utf8');
extracted.push(templateName);
console.log(`Force extracted template: ${templateName}`);
} catch (error) {
console.error(`Failed to force extract template ${templateName}:`, error);
failed.push(templateName);
}
}
return { extracted, failed };
}
/**
* Check if all templates are available (either on disk or embedded)
*/
areAllTemplatesAvailable(): boolean {
const embeddedNames = getAllTemplateNames();
return embeddedNames.length > 0;
}
/**
* Get the list of all available template names
*/
getAvailableTemplateNames(): string[] {
return getAllTemplateNames();
}
}
+5
View File
@@ -0,0 +1,5 @@
declare module 'template-embed:templates' {
export const embeddedTemplates: Record<string, string>;
export function extractTemplate(templateName: string, targetPath?: string): string;
export function getAllTemplateNames(): string[];
}