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
+34 -10
View File
@@ -336,21 +336,45 @@ function renameNode(node, subName, isClash = true) {
} }
function detectTemplates() { 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(yamlTpl)) {
const yamls = fs.readdirSync('.').filter(f => f.endsWith('.yaml') || f.endsWith('.yml')); if (fs.existsSync(tplDir)) {
const matched = yamls.find(f => f.includes('CatMata')); const yamls = fs.readdirSync(tplDir).filter(f => f.endsWith('.yaml') || f.endsWith('.yml'));
if (matched) yamlTpl = matched; 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(jsonTpl)) {
if (fs.existsSync('CatMata-tun.json')) { if (fs.existsSync(tplDir)) {
jsonTpl = 'CatMata-tun.json'; 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 { } else {
const jsons = fs.readdirSync('.').filter(f => f.endsWith('.json') && f !== 'subs.json'); jsonTpl = 'CatMata.json';
const matched = jsons.find(f => f.includes('CatMata')); if (!fs.existsSync(jsonTpl)) {
if (matched) jsonTpl = matched; if (fs.existsSync('CatMata-tun.json')) {
jsonTpl = 'CatMata-tun.json';
} else {
const jsons = fs.readdirSync('.').filter(f => f.endsWith('.json') && f !== 'subs.json');
const matched = jsons.find(f => f.includes('CatMata'));
if (matched) jsonTpl = matched;
}
}
} }
} }
return { yamlTpl, jsonTpl }; return { yamlTpl, jsonTpl };