From 630538037a79f3bd1b6dc5a6701d17887bb89449 Mon Sep 17 00:00:00 2001 From: Aleix Soler Date: Thu, 19 Mar 2026 11:52:27 +0100 Subject: [PATCH] refactor(templates): separate predefined templates into subdirectory and update build script --- constants/predefinedTemplates.ts | 394 +++++++++--------- esbuild.config.mjs | 37 +- templates/{ => predefined}/academic.json | 0 templates/{ => predefined}/colorful.json | 0 .../{ => predefined}/creative-writing.json | 0 .../{ => predefined}/default-starter.json | 0 templates/{ => predefined}/minimal.json | 0 templates/{ => predefined}/project.json | 0 types/pluginSettings.ts | 1 + 9 files changed, 232 insertions(+), 200 deletions(-) rename templates/{ => predefined}/academic.json (100%) rename templates/{ => predefined}/colorful.json (100%) rename templates/{ => predefined}/creative-writing.json (100%) rename templates/{ => predefined}/default-starter.json (100%) rename templates/{ => predefined}/minimal.json (100%) rename templates/{ => predefined}/project.json (100%) diff --git a/constants/predefinedTemplates.ts b/constants/predefinedTemplates.ts index e6a914e..c036254 100644 --- a/constants/predefinedTemplates.ts +++ b/constants/predefinedTemplates.ts @@ -1,278 +1,288 @@ /** * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT MANUALLY. - * To add a new template, create a JSON file in the /templates directory. + * To add a new predefined template, create a JSON file in the /templates/predefined directory. + * To add a community template, create a JSON file in the /templates directory. */ import { StatusTemplate } from "types/pluginSettings"; export const PREDEFINED_TEMPLATES: StatusTemplate[] = [ { - "id": "academic", - "name": "Academic research", - "description": "Status workflow for academic research and writing", - "authorGithub": "soler1212", - "statuses": [ + id: "academic", + name: "Academic research", + description: "Status workflow for academic research and writing", + authorGithub: "soler1212", + statuses: [ { - "name": "research", - "icon": "πŸ”", - "color": "#2196F3", - "templateId": "academic" + name: "research", + icon: "πŸ”", + color: "#2196F3", + templateId: "academic", }, { - "name": "outline", - "icon": "πŸ“‘", - "color": "#9E9E9E", - "templateId": "academic" + name: "outline", + icon: "πŸ“‘", + color: "#9E9E9E", + templateId: "academic", }, { - "name": "draft", - "icon": "✏️", - "color": "#FFC107", - "templateId": "academic" + name: "draft", + icon: "✏️", + color: "#FFC107", + templateId: "academic", }, { - "name": "review", - "icon": "πŸ”¬", - "color": "#9C27B0", - "templateId": "academic" + name: "review", + icon: "πŸ”¬", + color: "#9C27B0", + templateId: "academic", }, { - "name": "revision", - "icon": "πŸ“", - "color": "#FF5722", - "templateId": "academic" + name: "revision", + icon: "πŸ“", + color: "#FF5722", + templateId: "academic", }, { - "name": "final", - "icon": "πŸ“š", - "color": "#4CAF50", - "templateId": "academic" + name: "final", + icon: "πŸ“š", + color: "#4CAF50", + templateId: "academic", }, { - "name": "published", - "icon": "πŸŽ“", - "color": "#795548", - "templateId": "academic" - } - ] + name: "published", + icon: "πŸŽ“", + color: "#795548", + templateId: "academic", + }, + ], + isPredefined: true, }, { - "id": "colorful", - "name": "Colorful workflow", - "description": "A colorful set of workflow statuses with descriptive icons", - "authorGithub": "soler1212", - "statuses": [ + id: "colorful", + name: "Colorful workflow", + description: + "A colorful set of workflow statuses with descriptive icons", + authorGithub: "soler1212", + statuses: [ { - "name": "idea", - "icon": "πŸ’‘", - "color": "#FFEB3B", - "templateId": "colorful" + name: "idea", + icon: "πŸ’‘", + color: "#FFEB3B", + templateId: "colorful", }, { - "name": "draft", - "icon": "πŸ“", - "color": "#E0E0E0", - "templateId": "colorful" + name: "draft", + icon: "πŸ“", + color: "#E0E0E0", + templateId: "colorful", }, { - "name": "inProgress", - "icon": "πŸ”§", - "color": "#FFC107", - "templateId": "colorful" + name: "inProgress", + icon: "πŸ”§", + color: "#FFC107", + templateId: "colorful", }, { - "name": "editing", - "icon": "πŸ–ŠοΈ", - "color": "#2196F3", - "templateId": "colorful" + name: "editing", + icon: "πŸ–ŠοΈ", + color: "#2196F3", + templateId: "colorful", }, { - "name": "pending", - "icon": "⏳", - "color": "#9C27B0", - "templateId": "colorful" + name: "pending", + icon: "⏳", + color: "#9C27B0", + templateId: "colorful", }, { - "name": "onHold", - "icon": "⏸", - "color": "#9E9E9E", - "templateId": "colorful" + name: "onHold", + icon: "⏸", + color: "#9E9E9E", + templateId: "colorful", }, { - "name": "needsUpdate", - "icon": "πŸ”„", - "color": "#FF5722", - "templateId": "colorful" + name: "needsUpdate", + icon: "πŸ”„", + color: "#FF5722", + templateId: "colorful", }, { - "name": "completed", - "icon": "βœ…", - "color": "#4CAF50", - "templateId": "colorful" + name: "completed", + icon: "βœ…", + color: "#4CAF50", + templateId: "colorful", }, { - "name": "archived", - "icon": "πŸ“¦", - "color": "#795548", - "templateId": "colorful" - } - ] + name: "archived", + icon: "πŸ“¦", + color: "#795548", + templateId: "colorful", + }, + ], + isPredefined: true, }, { - "id": "creative-writing", - "name": "Creative Writing", - "description": "Workflow for novelists and creative writers", - "authorGithub": "soler1212", - "statuses": [ + id: "creative-writing", + name: "Creative Writing", + description: "Workflow for novelists and creative writers", + authorGithub: "soler1212", + statuses: [ { - "name": "idea", - "icon": "🧠", - "color": "#FFD700", - "templateId": "creative-writing" + name: "idea", + icon: "🧠", + color: "#FFD700", + templateId: "creative-writing", }, { - "name": "outline", - "icon": "πŸ—ΊοΈ", - "color": "#87CEEB", - "templateId": "creative-writing" + name: "outline", + icon: "πŸ—ΊοΈ", + color: "#87CEEB", + templateId: "creative-writing", }, { - "name": "first-draft", - "icon": "✍️", - "color": "#FFA07A", - "templateId": "creative-writing" + name: "first-draft", + icon: "✍️", + color: "#FFA07A", + templateId: "creative-writing", }, { - "name": "revision", - "icon": "πŸ”", - "color": "#DA70D6", - "templateId": "creative-writing" + name: "revision", + icon: "πŸ”", + color: "#DA70D6", + templateId: "creative-writing", }, { - "name": "final-polish", - "icon": "✨", - "color": "#32CD32", - "templateId": "creative-writing" - } - ] + name: "final-polish", + icon: "✨", + color: "#32CD32", + templateId: "creative-writing", + }, + ], + isPredefined: true, }, { - "id": "default-starter", - "name": "Starter Template", - "description": "A simplified set of essential workflow statuses to get you started.", - "authorGithub": "soler1212", - "statuses": [ + id: "default-starter", + name: "Starter Template", + description: + "A simplified set of essential workflow statuses to get you started.", + authorGithub: "soler1212", + statuses: [ { - "name": "todo", - "icon": "πŸ“Œ", - "color": "#F44336", - "templateId": "default-starter" + name: "todo", + icon: "πŸ“Œ", + color: "#F44336", + templateId: "default-starter", }, { - "name": "inProgress", - "icon": "βš™οΈ", - "color": "#2196F3", - "templateId": "default-starter" + name: "inProgress", + icon: "βš™οΈ", + color: "#2196F3", + templateId: "default-starter", }, { - "name": "review", - "icon": "πŸ‘€", - "color": "#9C27B0", - "templateId": "default-starter" + name: "review", + icon: "πŸ‘€", + color: "#9C27B0", + templateId: "default-starter", }, { - "name": "done", - "icon": "βœ“", - "color": "#4CAF50", - "templateId": "default-starter" - } - ] + name: "done", + icon: "βœ“", + color: "#4CAF50", + templateId: "default-starter", + }, + ], + isPredefined: true, }, { - "id": "minimal", - "name": "Minimal workflow", - "description": "A simplified set of essential workflow statuses", - "authorGithub": "soler1212", - "statuses": [ + id: "minimal", + name: "Minimal workflow", + description: "A simplified set of essential workflow statuses", + authorGithub: "soler1212", + statuses: [ { - "name": "todo", - "icon": "πŸ“Œ", - "color": "#F44336", - "templateId": "minimal" + name: "todo", + icon: "πŸ“Œ", + color: "#F44336", + templateId: "minimal", }, { - "name": "inProgress", - "icon": "βš™οΈ", - "color": "#2196F3", - "templateId": "minimal" + name: "inProgress", + icon: "βš™οΈ", + color: "#2196F3", + templateId: "minimal", }, { - "name": "review", - "icon": "πŸ‘€", - "color": "#9C27B0", - "templateId": "minimal" + name: "review", + icon: "πŸ‘€", + color: "#9C27B0", + templateId: "minimal", }, { - "name": "done", - "icon": "βœ“", - "color": "#4CAF50", - "templateId": "minimal" - } - ] + name: "done", + icon: "βœ“", + color: "#4CAF50", + templateId: "minimal", + }, + ], + isPredefined: true, }, { - "id": "project", - "name": "Project management", - "description": "Status workflow for project management and tracking", - "authorGithub": "soler1212", - "statuses": [ + id: "project", + name: "Project management", + description: "Status workflow for project management and tracking", + authorGithub: "soler1212", + statuses: [ { - "name": "planning", - "icon": "πŸ—“οΈ", - "color": "#9E9E9E", - "templateId": "project" + name: "planning", + icon: "πŸ—“οΈ", + color: "#9E9E9E", + templateId: "project", }, { - "name": "backlog", - "icon": "πŸ“‹", - "color": "#E0E0E0", - "templateId": "project" + name: "backlog", + icon: "πŸ“‹", + color: "#E0E0E0", + templateId: "project", }, { - "name": "ready", - "icon": "🚦", - "color": "#8BC34A", - "templateId": "project" + name: "ready", + icon: "🚦", + color: "#8BC34A", + templateId: "project", }, { - "name": "inDevelopment", - "icon": "πŸ‘¨β€πŸ’»", - "color": "#2196F3", - "templateId": "project" + name: "inDevelopment", + icon: "πŸ‘¨β€πŸ’»", + color: "#2196F3", + templateId: "project", }, { - "name": "testing", - "icon": "πŸ§ͺ", - "color": "#9C27B0", - "templateId": "project" + name: "testing", + icon: "πŸ§ͺ", + color: "#9C27B0", + templateId: "project", }, { - "name": "review", - "icon": "πŸ‘οΈ", - "color": "#FFC107", - "templateId": "project" + name: "review", + icon: "πŸ‘οΈ", + color: "#FFC107", + templateId: "project", }, { - "name": "approved", - "icon": "πŸ‘", - "color": "#4CAF50", - "templateId": "project" + name: "approved", + icon: "πŸ‘", + color: "#4CAF50", + templateId: "project", }, { - "name": "live", - "icon": "πŸš€", - "color": "#3F51B5", - "templateId": "project" - } - ] - } + name: "live", + icon: "πŸš€", + color: "#3F51B5", + templateId: "project", + }, + ], + isPredefined: true, + }, ]; +export const COMMUNITY_TEMPLATES: StatusTemplate[] = []; diff --git a/esbuild.config.mjs b/esbuild.config.mjs index 6b64ec6..e2ab7de 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -5,7 +5,7 @@ import fs from "fs"; import path from "path"; const banner = -`/* + `/* THIS IS A GENERATED/BUNDLED FILE BY ESBUILD if you want to view the source, please visit the github repository of this plugin */ @@ -18,31 +18,52 @@ const generateTemplatesIndex = () => { const templatesDir = "./templates"; const outputFile = "./constants/predefinedTemplates.ts"; + const predefinedDir = path.join(templatesDir, "predefined"); + if (!fs.existsSync(templatesDir)) return; + if (!fs.existsSync(predefinedDir)) { + fs.mkdirSync(predefinedDir, { recursive: true }); + } - const files = fs.readdirSync(templatesDir); - const templates = []; + const predefinedTemplates = []; + const communityTemplates = []; - files.forEach((file) => { + // Read predefined templates + const predefinedFiles = fs.readdirSync(predefinedDir); + predefinedFiles.forEach((file) => { + if (file.endsWith(".json")) { + const filePath = path.join(predefinedDir, file); + const content = JSON.parse(fs.readFileSync(filePath, "utf8")); + content.isPredefined = true; + predefinedTemplates.push(content); + } + }); + + // Read community templates + const rootFiles = fs.readdirSync(templatesDir); + rootFiles.forEach((file) => { if (file.endsWith(".json")) { const filePath = path.join(templatesDir, file); const content = JSON.parse(fs.readFileSync(filePath, "utf8")); - templates.push(content); + content.isPredefined = false; + communityTemplates.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. + * To add a new predefined template, create a JSON file in the /templates/predefined directory. + * To add a community template, create a JSON file in the /templates directory. */ import { StatusTemplate } from "types/pluginSettings"; -export const PREDEFINED_TEMPLATES: StatusTemplate[] = ${JSON.stringify(templates, null, "\t")}; +export const PREDEFINED_TEMPLATES: StatusTemplate[] = ${JSON.stringify(predefinedTemplates, null, "\t")}; +export const COMMUNITY_TEMPLATES: StatusTemplate[] = ${JSON.stringify(communityTemplates, null, "\t")}; `; fs.writeFileSync(outputFile, content); console.log( - `\x1b[36m[Templates]\x1b[0m Automatically registered ${templates.length} templates.`, + `\x1b[36m[Templates]\x1b[0m Automatically registered ${predefinedTemplates.length} predefined and ${communityTemplates.length} community templates.`, ); }; diff --git a/templates/academic.json b/templates/predefined/academic.json similarity index 100% rename from templates/academic.json rename to templates/predefined/academic.json diff --git a/templates/colorful.json b/templates/predefined/colorful.json similarity index 100% rename from templates/colorful.json rename to templates/predefined/colorful.json diff --git a/templates/creative-writing.json b/templates/predefined/creative-writing.json similarity index 100% rename from templates/creative-writing.json rename to templates/predefined/creative-writing.json diff --git a/templates/default-starter.json b/templates/predefined/default-starter.json similarity index 100% rename from templates/default-starter.json rename to templates/predefined/default-starter.json diff --git a/templates/minimal.json b/templates/predefined/minimal.json similarity index 100% rename from templates/minimal.json rename to templates/predefined/minimal.json diff --git a/templates/project.json b/templates/predefined/project.json similarity index 100% rename from templates/project.json rename to templates/predefined/project.json diff --git a/types/pluginSettings.ts b/types/pluginSettings.ts index 03a738f..b63b4a1 100644 --- a/types/pluginSettings.ts +++ b/types/pluginSettings.ts @@ -20,6 +20,7 @@ export interface StatusTemplate { name: string; description: string; authorGithub?: string; + isPredefined?: boolean; statuses: NoteStatus[]; }