mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Remember the chosen project template
This commit is contained in:
6 files changed
+121
-20
No files matched your search
@@ -312,4 +312,50 @@ export class DotAI {
|
||||
console.warn(`Failed to write .git/shakespeare/COST file: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read template metadata from .git/shakespeare/template.json file
|
||||
* @returns Template metadata object or null if not found or invalid
|
||||
*/
|
||||
async readTemplate(): Promise<{ name: string; description: string; url: string } | null> {
|
||||
try {
|
||||
const templatePath = join(this.workingDir, ".git", "shakespeare", "template.json");
|
||||
const content = await this.fs.readFile(templatePath, "utf8");
|
||||
const template = JSON.parse(content);
|
||||
|
||||
// Validate that required fields exist
|
||||
if (template && typeof template.name === 'string' &&
|
||||
typeof template.description === 'string' &&
|
||||
typeof template.url === 'string') {
|
||||
return {
|
||||
name: template.name,
|
||||
description: template.description,
|
||||
url: template.url,
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write template metadata to .git/shakespeare/template.json file
|
||||
* @param template Template metadata with name, description, and url
|
||||
*/
|
||||
async writeTemplate(template: { name: string; description: string; url: string }): Promise<void> {
|
||||
const shakespeareDir = join(this.workingDir, ".git", "shakespeare");
|
||||
const templatePath = join(shakespeareDir, "template.json");
|
||||
|
||||
try {
|
||||
// Ensure .git/shakespeare directory exists
|
||||
await this.fs.mkdir(shakespeareDir, { recursive: true });
|
||||
|
||||
// Write the template metadata as formatted JSON
|
||||
await this.fs.writeFile(templatePath, JSON.stringify(template, null, 2) + "\n");
|
||||
} catch (error) {
|
||||
console.warn(`Failed to write .git/shakespeare/template.json file: ${error}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import JSZip from 'jszip';
|
||||
import { Git } from '@/lib/git';
|
||||
import type { JSRuntimeFS } from '@/lib/JSRuntime';
|
||||
import { ensurePersistentStorage } from '@/lib/persistentStorage';
|
||||
import { DotAI } from '@/lib/DotAI';
|
||||
|
||||
// Polyfill Buffer for browser
|
||||
if (typeof window !== 'undefined') {
|
||||
@@ -197,7 +198,7 @@ export class ProjectsManager {
|
||||
}
|
||||
}
|
||||
|
||||
async createProject(name: string, templateUrl: string, customId?: string, onTemplateUpdateError?: (error: Error) => void): Promise<Project> {
|
||||
async createProject(name: string, templateUrl: string, customId?: string, onTemplateUpdateError?: (error: Error) => void, templateMetadata?: { name: string; description: string }): Promise<Project> {
|
||||
const id = customId || await this.generateUniqueProjectId(name);
|
||||
|
||||
// Check if project with this ID already exists when using custom ID
|
||||
@@ -230,6 +231,21 @@ export class ProjectsManager {
|
||||
defaultBranch: 'main',
|
||||
});
|
||||
|
||||
// Save template metadata to .git/shakespeare/template.json if provided
|
||||
if (templateMetadata) {
|
||||
try {
|
||||
const dotAI = new DotAI(this.fs, projectPath);
|
||||
await dotAI.writeTemplate({
|
||||
name: templateMetadata.name,
|
||||
description: templateMetadata.description,
|
||||
url: templateUrl,
|
||||
});
|
||||
} catch (error) {
|
||||
// Don't fail project creation if template metadata save fails
|
||||
console.warn('Failed to save template metadata:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Add all files to git
|
||||
const files = await this.getAllFiles(projectPath);
|
||||
for (const file of files) {
|
||||
|
||||
Reference in new issue
Block a user