This commit is contained in:
NotII
2025-04-07 19:25:24 +01:00
parent 7f7dd78818
commit 2f48ee38c2
102 changed files with 1825 additions and 761 deletions

View File

@@ -0,0 +1,89 @@
/**
* Script to find deprecated imports in the codebase
* Run with: node scripts/find-deprecated-imports.js
*/
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
// Deprecated patterns to search for
const DEPRECATED_PATTERNS = [
"from '@/lib/client-utils'",
"from '@/lib/client-service'",
"from '@/lib/data-service'",
"from '@/lib/server-service'",
"from '@/lib/productData'",
"from '@/lib/shippingHelper'",
"from '@/lib/storeHelper'",
"from '@/lib/stats-service'",
// Add other deprecated import patterns here
];
// Run grep to find deprecated imports
function findDeprecatedImports() {
console.log('Searching for deprecated imports...\n');
DEPRECATED_PATTERNS.forEach(pattern => {
try {
// Using grep to find the pattern in all TypeScript/JavaScript files
const result = execSync(`grep -r "${pattern}" --include="*.ts" --include="*.tsx" --include="*.js" --include="*.jsx" .`, { encoding: 'utf8' });
if (result) {
console.log(`\n== Found deprecated imports: ${pattern} ==`);
console.log(result);
console.log(`\n== Suggested replacement: ==`);
suggestReplacement(pattern);
}
} catch (error) {
// grep returns non-zero exit code if no matches found
if (error.status !== 1) {
console.error(`Error searching for ${pattern}:`, error.message);
}
}
});
}
function suggestReplacement(pattern) {
// Extract the import path
const match = pattern.match(/from '([^']+)'/);
if (!match) return;
const oldPath = match[1];
let replacement = '';
// Generate replacement suggestions based on deprecated path
switch (oldPath) {
case '@/lib/client-utils':
case '@/lib/client-service':
case '@/lib/data-service':
replacement = "import { clientFetch, fetchClient } from '@/lib/api';";
break;
case '@/lib/server-service':
replacement = "import { fetchServer } from '@/lib/api'; // Only use in Server Components";
break;
case '@/lib/productData':
replacement = "import { getProducts, createProduct, updateProduct, deleteProduct } from '@/lib/api';";
break;
case '@/lib/shippingHelper':
replacement = "import { getShippingOptions, createShippingOption, updateShippingOption, deleteShippingOption } from '@/lib/api';";
break;
case '@/lib/storeHelper':
replacement = "import { clientFetch } from '@/lib/api';";
break;
case '@/lib/stats-service':
replacement = "import { getPlatformStats } from '@/lib/api';";
break;
default:
replacement = "import from '@/lib/api';";
}
console.log(replacement);
console.log("\nReplace the specific imports with the corresponding ones from @/lib/api");
}
// Run the search
findDeprecatedImports();
// Uncomment the following line to run the remove-old-files.js script
// node scripts/remove-old-files.js