From 0f810a79e10c8793937cd2884195edd1863134f0 Mon Sep 17 00:00:00 2001 From: Aleix Soler Date: Wed, 18 Mar 2026 17:53:23 +0100 Subject: [PATCH] feat: automate marketplace template registration during build process --- README.md | 5 +- constants/predefinedTemplates.ts | 294 +++++++++++++++++++++++++++++-- esbuild.config.mjs | 42 ++++- 3 files changed, 323 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index b5dcbe1..b965631 100644 --- a/README.md +++ b/README.md @@ -113,10 +113,9 @@ You can contribute your own status templates to the plugin! ] } ``` -4. Register your template in `constants/predefinedTemplates.ts` by adding an import and adding it to the `PREDEFINED_TEMPLATES` array. -5. Submit a Pull Request! +4. Submit a Pull Request with your JSON file! -Once accepted, your template will be available in the marketplace for all users. +Once accepted and merged, your template will be automatically included in the next build and available in the marketplace for all users. ## Installation diff --git a/constants/predefinedTemplates.ts b/constants/predefinedTemplates.ts index eb27071..1fb8ca5 100644 --- a/constants/predefinedTemplates.ts +++ b/constants/predefinedTemplates.ts @@ -1,18 +1,284 @@ -import { StatusTemplate } from "types/pluginSettings"; -import academic from "../templates/academic.json"; -import colorful from "../templates/colorful.json"; -import creativeWriting from "../templates/creative-writing.json"; -import minimal from "../templates/minimal.json"; -import project from "../templates/project.json"; - /** - * Predefined status templates imported directly from the templates directory. - * This file serves as an index for the marketplace. + * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT MANUALLY. + * To add a new template, create a JSON file in the /templates directory. */ +import { StatusTemplate } from "types/pluginSettings"; + export const PREDEFINED_TEMPLATES: StatusTemplate[] = [ - academic as StatusTemplate, - colorful as StatusTemplate, - creativeWriting as StatusTemplate, - minimal as StatusTemplate, - project as StatusTemplate, + { + "id": "academic", + "name": "Academic research", + "description": "Status workflow for academic research and writing", + "author": "Obsidian Note Status", + "github": "https://github.com/devonthesofa/obsidian-note-status", + "statuses": [ + { + "name": "research", + "icon": "πŸ”", + "color": "#2196F3", + "templateId": "academic" + }, + { + "name": "outline", + "icon": "πŸ“‘", + "color": "#9E9E9E", + "templateId": "academic" + }, + { + "name": "draft", + "icon": "✏️", + "color": "#FFC107", + "templateId": "academic" + }, + { + "name": "review", + "icon": "πŸ”¬", + "color": "#9C27B0", + "templateId": "academic" + }, + { + "name": "revision", + "icon": "πŸ“", + "color": "#FF5722", + "templateId": "academic" + }, + { + "name": "final", + "icon": "πŸ“š", + "color": "#4CAF50", + "templateId": "academic" + }, + { + "name": "published", + "icon": "πŸŽ“", + "color": "#795548", + "templateId": "academic" + } + ] + }, + { + "id": "colorful", + "name": "Colorful workflow", + "description": "A colorful set of workflow statuses with descriptive icons", + "author": "Obsidian Note Status", + "github": "https://github.com/devonthesofa/obsidian-note-status", + "statuses": [ + { + "name": "idea", + "icon": "πŸ’‘", + "color": "#FFEB3B", + "templateId": "colorful" + }, + { + "name": "draft", + "icon": "πŸ“", + "color": "#E0E0E0", + "templateId": "colorful" + }, + { + "name": "inProgress", + "icon": "πŸ”§", + "color": "#FFC107", + "templateId": "colorful" + }, + { + "name": "editing", + "icon": "πŸ–ŠοΈ", + "color": "#2196F3", + "templateId": "colorful" + }, + { + "name": "pending", + "icon": "⏳", + "color": "#9C27B0", + "templateId": "colorful" + }, + { + "name": "onHold", + "icon": "⏸", + "color": "#9E9E9E", + "templateId": "colorful" + }, + { + "name": "needsUpdate", + "icon": "πŸ”„", + "color": "#FF5722", + "templateId": "colorful" + }, + { + "name": "completed", + "icon": "βœ…", + "color": "#4CAF50", + "templateId": "colorful" + }, + { + "name": "archived", + "icon": "πŸ“¦", + "color": "#795548", + "templateId": "colorful" + } + ] + }, + { + "id": "creative-writing", + "name": "Creative Writing", + "description": "Workflow for novelists and creative writers", + "author": "Obsidian Community", + "github": "https://github.com/obsidian-community", + "statuses": [ + { + "name": "idea", + "icon": "🧠", + "color": "#FFD700", + "templateId": "creative-writing" + }, + { + "name": "outline", + "icon": "πŸ—ΊοΈ", + "color": "#87CEEB", + "templateId": "creative-writing" + }, + { + "name": "first-draft", + "icon": "✍️", + "color": "#FFA07A", + "templateId": "creative-writing" + }, + { + "name": "revision", + "icon": "πŸ”", + "color": "#DA70D6", + "templateId": "creative-writing" + }, + { + "name": "final-polish", + "icon": "✨", + "color": "#32CD32", + "templateId": "creative-writing" + } + ] + }, + { + "id": "removeme", + "name": "I am a test", + "description": "asdfasdf", + "author": "asfdlei", + "github": "https://github.com/devonthesofa/obsidian-note-status", + "statuses": [ + { + "name": "hello", + "icon": "πŸ“Œ", + "color": "#F44336", + "templateId": "minimal" + }, + { + "name": "inProgress", + "icon": "βš™οΈ", + "color": "#2196F3", + "templateId": "minimal" + }, + { + "name": "review", + "icon": "πŸ‘€", + "color": "#9C27B0", + "templateId": "minimal" + }, + { + "name": "done", + "icon": "βœ“", + "color": "#4CAF50", + "templateId": "minimal" + } + ] + }, + { + "id": "minimal", + "name": "Minimal workflow", + "description": "A simplified set of essential workflow statuses", + "author": "Obsidian Note Status", + "github": "https://github.com/devonthesofa/obsidian-note-status", + "statuses": [ + { + "name": "todo", + "icon": "πŸ“Œ", + "color": "#F44336", + "templateId": "minimal" + }, + { + "name": "inProgress", + "icon": "βš™οΈ", + "color": "#2196F3", + "templateId": "minimal" + }, + { + "name": "review", + "icon": "πŸ‘€", + "color": "#9C27B0", + "templateId": "minimal" + }, + { + "name": "done", + "icon": "βœ“", + "color": "#4CAF50", + "templateId": "minimal" + } + ] + }, + { + "id": "project", + "name": "Project management", + "description": "Status workflow for project management and tracking", + "author": "Obsidian Note Status", + "github": "https://github.com/devonthesofa/obsidian-note-status", + "statuses": [ + { + "name": "planning", + "icon": "πŸ—“οΈ", + "color": "#9E9E9E", + "templateId": "project" + }, + { + "name": "backlog", + "icon": "πŸ“‹", + "color": "#E0E0E0", + "templateId": "project" + }, + { + "name": "ready", + "icon": "🚦", + "color": "#8BC34A", + "templateId": "project" + }, + { + "name": "inDevelopment", + "icon": "πŸ‘¨β€πŸ’»", + "color": "#2196F3", + "templateId": "project" + }, + { + "name": "testing", + "icon": "πŸ§ͺ", + "color": "#9C27B0", + "templateId": "project" + }, + { + "name": "review", + "icon": "πŸ‘οΈ", + "color": "#FFC107", + "templateId": "project" + }, + { + "name": "approved", + "icon": "πŸ‘", + "color": "#4CAF50", + "templateId": "project" + }, + { + "name": "live", + "icon": "πŸš€", + "color": "#3F51B5", + "templateId": "project" + } + ] + } ]; diff --git a/esbuild.config.mjs b/esbuild.config.mjs index f6dca29..6b64ec6 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -1,6 +1,8 @@ import esbuild from "esbuild"; import process from "process"; import builtins from "builtin-modules"; +import fs from "fs"; +import path from "path"; const banner = `/* @@ -9,7 +11,45 @@ if you want to view the source, please visit the github repository of this plugi */ `; -const prod = (process.argv[2] === "production"); +/** + * Automatically generates the predefinedTemplates.ts file by scanning the templates directory. + */ +const generateTemplatesIndex = () => { + const templatesDir = "./templates"; + const outputFile = "./constants/predefinedTemplates.ts"; + + if (!fs.existsSync(templatesDir)) return; + + const files = fs.readdirSync(templatesDir); + const templates = []; + + files.forEach((file) => { + if (file.endsWith(".json")) { + const filePath = path.join(templatesDir, file); + const content = JSON.parse(fs.readFileSync(filePath, "utf8")); + templates.push(content); + } + }); + + const content = `/** + * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT MANUALLY. + * To add a new template, create a JSON file in the /templates directory. + */ +import { StatusTemplate } from "types/pluginSettings"; + +export const PREDEFINED_TEMPLATES: StatusTemplate[] = ${JSON.stringify(templates, null, "\t")}; +`; + + fs.writeFileSync(outputFile, content); + console.log( + `\x1b[36m[Templates]\x1b[0m Automatically registered ${templates.length} templates.`, + ); +}; + +// Generate templates index before build +generateTemplatesIndex(); + +const prod = process.argv[2] === "production"; // CSS bundling function const buildStyles = async () => {