Organize templates into templates/ folder and update detectTemplates logic

This commit is contained in:
jocayn
2026-06-13 15:47:57 +08:00
parent 0411f4672a
commit 2c0773f4f7
9 changed files with 34 additions and 10 deletions
+26 -2
View File
@@ -336,14 +336,36 @@ function renameNode(node, subName, isClash = true) {
}
function detectTemplates() {
let yamlTpl = 'CatMata.optimized.yaml';
const tplDir = 'templates';
let yamlTpl = path.join(tplDir, 'CatMata.optimized.yaml');
let jsonTpl = path.join(tplDir, 'CatMata.json');
if (!fs.existsSync(yamlTpl)) {
if (fs.existsSync(tplDir)) {
const yamls = fs.readdirSync(tplDir).filter(f => f.endsWith('.yaml') || f.endsWith('.yml'));
const matched = yamls.find(f => f.includes('CatMata'));
if (matched) yamlTpl = path.join(tplDir, matched);
} else {
yamlTpl = 'CatMata.optimized.yaml';
if (!fs.existsSync(yamlTpl)) {
const yamls = fs.readdirSync('.').filter(f => f.endsWith('.yaml') || f.endsWith('.yml'));
const matched = yamls.find(f => f.includes('CatMata'));
if (matched) yamlTpl = matched;
}
}
}
let jsonTpl = 'CatMata.json';
if (!fs.existsSync(jsonTpl)) {
if (fs.existsSync(tplDir)) {
if (fs.existsSync(path.join(tplDir, 'CatMata-tun.json'))) {
jsonTpl = path.join(tplDir, 'CatMata-tun.json');
} else {
const jsons = fs.readdirSync(tplDir).filter(f => f.endsWith('.json'));
const matched = jsons.find(f => f.includes('CatMata'));
if (matched) jsonTpl = path.join(tplDir, matched);
}
} else {
jsonTpl = 'CatMata.json';
if (!fs.existsSync(jsonTpl)) {
if (fs.existsSync('CatMata-tun.json')) {
jsonTpl = 'CatMata-tun.json';
@@ -353,6 +375,8 @@ function detectTemplates() {
if (matched) jsonTpl = matched;
}
}
}
}
return { yamlTpl, jsonTpl };
}