mirror of
https://github.com/fireinrain/JHS-enhance.git
synced 2026-10-12 20:56:36 +08:00
重构拆分
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const allConstants = [
|
||||
'isJavBus', 'isJavDb', 'isSearchPage', 'currentHref',
|
||||
'Status_RUNNING', 'Status_SUCCESS', 'Status_FAIL', 'Status_LOADING',
|
||||
'Status_FILTER', 'Status_FAVORITE', 'Status_HAS_DOWN', 'Status_HAS_WATCH',
|
||||
'NO', 'YES'
|
||||
];
|
||||
|
||||
const pluginsDir = 'src/plugins';
|
||||
const files = fs.readdirSync(pluginsDir).filter(f => f.endsWith('.js'));
|
||||
|
||||
let fixed = 0;
|
||||
|
||||
for (const file of files) {
|
||||
const filePath = path.join(pluginsDir, file);
|
||||
let content = fs.readFileSync(filePath, 'utf8');
|
||||
|
||||
const needed = allConstants.filter(c => new RegExp('\\b' + c + '\\b').test(content));
|
||||
if (needed.length === 0) continue;
|
||||
|
||||
const importMatch = content.match(/import\s*\{([^}]+)\}\s*from\s*['"][^'"]*constants[^'"]*['"]/);
|
||||
|
||||
if (importMatch) {
|
||||
const existing = importMatch[1].split(',').map(s => s.trim()).filter(Boolean);
|
||||
const missing = needed.filter(c => !existing.includes(c));
|
||||
|
||||
if (missing.length > 0) {
|
||||
const newImports = [...existing, ...missing].join(', ');
|
||||
const newImportLine = `import { ${newImports} } from '../core/constants.js';`;
|
||||
content = content.replace(importMatch[0], newImportLine);
|
||||
fs.writeFileSync(filePath, content);
|
||||
console.log(`Fixed: ${file} +${missing.join(', ')}`);
|
||||
fixed++;
|
||||
}
|
||||
} else {
|
||||
const newImportLine = `import { ${needed.join(', ')} } from '../core/constants.js';`;
|
||||
const baseImportMatch = content.match(/import\s*\{[^}]*\}\s*from\s*['"][^'"]*base-plugin[^'"]*['"]/);
|
||||
if (baseImportMatch) {
|
||||
content = content.replace(baseImportMatch[0], baseImportMatch[0] + '\n' + newImportLine);
|
||||
fs.writeFileSync(filePath, content);
|
||||
console.log(`Fixed: ${file} +${needed.join(', ')} (new import)`);
|
||||
fixed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`\nTotal fixed: ${fixed} files`);
|
||||
Reference in New Issue
Block a user