import fs from "node:fs/promises"; import path from "node:path"; import { PROJECTS_ROOT } from "./config.js"; const SEED_PROJECT = "hello"; const SEED_FILE = "main.typ"; const SEED_CONTENT = `= Hello, typst-leaf! Welcome to your first project. Edit this file on the left; the preview on the right updates as you type. == Features - Instant preview powered by *tinymist* - Live diagnostics and autocomplete - A real editor in your browser == Math The quadratic formula: $ x = (-b +- sqrt(b^2 - 4 a c)) / (2 a) $ == Code listing \`\`\`typ #let greet(name) = [Hello, *#name*!] #greet("world") \`\`\` `; export async function seedIfMissing(): Promise { await fs.mkdir(PROJECTS_ROOT, { recursive: true }); const projectDir = path.join(PROJECTS_ROOT, SEED_PROJECT); const file = path.join(projectDir, SEED_FILE); try { await fs.access(file); } catch { await fs.mkdir(projectDir, { recursive: true }); await fs.writeFile(file, SEED_CONTENT, "utf8"); console.log(`[seed] created ${SEED_PROJECT}/${SEED_FILE}`); } }