Organize templates into templates/ folder and update detectTemplates logic
This commit is contained in:
+34
-10
@@ -336,21 +336,45 @@ 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)) {
|
||||
const yamls = fs.readdirSync('.').filter(f => f.endsWith('.yaml') || f.endsWith('.yml'));
|
||||
const matched = yamls.find(f => f.includes('CatMata'));
|
||||
if (matched) yamlTpl = matched;
|
||||
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('CatMata-tun.json')) {
|
||||
jsonTpl = 'CatMata-tun.json';
|
||||
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 {
|
||||
const jsons = fs.readdirSync('.').filter(f => f.endsWith('.json') && f !== 'subs.json');
|
||||
const matched = jsons.find(f => f.includes('CatMata'));
|
||||
if (matched) jsonTpl = matched;
|
||||
jsonTpl = 'CatMata.json';
|
||||
if (!fs.existsSync(jsonTpl)) {
|
||||
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 };
|
||||
|
||||
Reference in New Issue
Block a user