community templates (#691)

This commit is contained in:
Will Chen
2025-07-23 10:11:16 -07:00
committed by GitHub
parent 9edd0fa80f
commit e947eede7a
37 changed files with 544 additions and 135 deletions

View File

@@ -5,7 +5,7 @@ import http from "isomorphic-git/http/node";
import { app } from "electron";
import { copyDirectoryRecursive } from "../utils/file_utils";
import { readSettings } from "@/main/settings";
import { DEFAULT_TEMPLATE_ID, getTemplateOrThrow } from "@/shared/templates";
import { getTemplateOrThrow } from "../utils/template_utils";
import log from "electron-log";
const logger = log.scope("createFromTemplate");
@@ -16,7 +16,7 @@ export async function createFromTemplate({
fullAppPath: string;
}) {
const settings = readSettings();
const templateId = settings.selectedTemplateId ?? DEFAULT_TEMPLATE_ID;
const templateId = settings.selectedTemplateId;
if (templateId === "react") {
await copyDirectoryRecursive(
@@ -26,7 +26,7 @@ export async function createFromTemplate({
return;
}
const template = getTemplateOrThrow(templateId);
const template = await getTemplateOrThrow(templateId);
if (!template.githubUrl) {
throw new Error(`Template ${templateId} has no GitHub URL`);
}

View File

@@ -0,0 +1,19 @@
import { createLoggedHandler } from "./safe_handle";
import log from "electron-log";
import { getAllTemplates } from "../utils/template_utils";
import { localTemplatesData, type Template } from "../../shared/templates";
const logger = log.scope("template_handlers");
const handle = createLoggedHandler(logger);
export function registerTemplateHandlers() {
handle("get-templates", async (): Promise<Template[]> => {
try {
const templates = await getAllTemplates();
return templates;
} catch (error) {
logger.error("Error fetching templates:", error);
return localTemplatesData;
}
});
}