-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_imports.js
More file actions
35 lines (30 loc) · 1.01 KB
/
Copy pathfix_imports.js
File metadata and controls
35 lines (30 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const fs = require('fs');
const path = require('path');
function getAllFiles(dirPath, arrayOfFiles) {
const files = fs.readdirSync(dirPath);
arrayOfFiles = arrayOfFiles || [];
files.forEach(function(file) {
if (fs.statSync(dirPath + '/' + file).isDirectory()) {
arrayOfFiles = getAllFiles(dirPath + '/' + file, arrayOfFiles);
} else {
if(file.endsWith('.tsx')) {
arrayOfFiles.push(path.join(dirPath, '/', file));
}
}
});
return arrayOfFiles;
}
const files = getAllFiles('src/app');
files.forEach(file => {
let content = fs.readFileSync(file, 'utf8');
let changed = false;
if (content.includes('<AppHeaderBrand') && !content.includes('import { AppHeaderBrand }')) {
// Find the first import statement and put it before that
content = content.replace('import ', 'import { AppHeaderBrand } from "@/components/brand/AppHeaderBrand";\nimport ');
changed = true;
}
if (changed) {
fs.writeFileSync(file, content);
console.log('Fixed imports in ' + file);
}
});