feat: automate marketplace template registration during build process

This commit is contained in:
Aleix Soler 2026-03-18 17:53:23 +01:00
parent bd0469f7c7
commit 0f810a79e1
3 changed files with 323 additions and 18 deletions

View file

@ -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

View file

@ -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"
}
]
}
];

View file

@ -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 () => {