32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
const dirPath = './src/app/restaurant-types';
|
|
|
|
function walkDir(dir, callback) {
|
|
fs.readdirSync(dir).forEach(f => {
|
|
let p = path.join(dir, f);
|
|
let isDirectory = fs.statSync(p).isDirectory();
|
|
isDirectory ? walkDir(p, callback) : callback(p);
|
|
});
|
|
}
|
|
|
|
walkDir(dirPath, function(filePath) {
|
|
if (filePath.endsWith('.tsx')) {
|
|
let content = fs.readFileSync(filePath, 'utf8');
|
|
let original = content;
|
|
|
|
if (content.includes('[User1, User2, User3]') && !content.includes('User1 from')) {
|
|
const importStatement = `\nimport User1 from '@/assets/restaurant/Join 2,460+ Restaurants/1.jpg';\nimport User2 from '@/assets/restaurant/Join 2,460+ Restaurants/2.jpg';\nimport User3 from '@/assets/restaurant/Join 2,460+ Restaurants/3.jpg';\n`;
|
|
|
|
// Find the first import and inject after it
|
|
content = content.replace(/(import [^\n]+\n)/, `$1${importStatement}`);
|
|
|
|
if (content !== original) {
|
|
fs.writeFileSync(filePath, content);
|
|
console.log(`Fixed imports in ${filePath}`);
|
|
}
|
|
}
|
|
}
|
|
});
|