-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplace_dashboard_logo.js
More file actions
122 lines (109 loc) · 5.28 KB
/
Copy pathreplace_dashboard_logo.js
File metadata and controls
122 lines (109 loc) · 5.28 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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;
// Pattern for the old zap logo block in headers
const logoBlockPattern = /<div className="flex items-center gap-2">\s*<div\s*className={cn\(\s*"relative flex items-center justify-center h-10 w-10"\s*\)}\s*>\s*<div\s*className={cn\(\s*"relative flex items-center justify-center bg-white\/10 backdrop-blur-md border border-white\/20 shadow-lg transition-all duration-1000 ease-in-out rounded-lg",\s*"h-10 w-10 p-2"\s*\)}\s*>\s*<div className="flex items-center justify-center w-full h-full">\s*<Zap[^>]*>\s*<\/Zap>|<Zap[^>]*\/>\s*(<Zap[^>]*>\s*<\/Zap>|<Zap[^>]*\/>)\s*<\/div>\s*<\/div>\s*<\/div>\s*<\/div>/g;
// Actually, a simpler regex is just matching <div className="flex items-center gap-2"> down to the first four closing divs that contain two <Zap /> elements
// Let's use a simpler pattern based on the exact string
const searchStr = `<div className="flex items-center gap-2">
<div
className={cn(
"relative flex items-center justify-center h-10 w-10"
)}
>
<div
className={cn(
"relative flex items-center justify-center bg-white/10 backdrop-blur-md border border-white/20 shadow-lg transition-all duration-1000 ease-in-out rounded-lg",
"h-10 w-10 p-2"
)}
>
<div className="flex items-center justify-center w-full h-full">
<Zap
className={cn(
"text-white transition-all duration-1000 ease-in-out absolute",
"h-5 w-5 -translate-x-1"
)}
/>
<Zap
className={cn(
"text-white transition-all duration-1000 ease-in-out absolute",
"h-5 w-5 translate-x-1"
)}
/>
</div>
</div>
</div>
</div>`;
// Standardize spaces to allow matching
const standardize = (s) => s.replace(/\s+/g, ' ');
if (standardize(content).includes(standardize(searchStr))) {
// We'll just replace it using regex on standardized string is risky.
// Let's use a generic regex for this specific block:
const regex = /<div className="flex items-center gap-2">[\s\S]*?h-5 w-5 translate-x-1[\s\S]*?<\/div>\s*<\/div>\s*<\/div>\s*<\/div>/;
content = content.replace(regex, '<AppHeaderBrand href="/" />');
changed = true;
if (!content.includes('import { AppHeaderBrand }')) {
// add import at top
content = content.replace('import ', 'import { AppHeaderBrand } from "@/components/brand/AppHeaderBrand";\nimport ');
}
}
// Handle other variations if any
const searchStr2 = `<div className="flex items-center gap-2">
<div
className={cn(
"relative flex items-center justify-center h-10 w-10"
)}
>
<div
className={cn(
"relative flex items-center justify-center bg-white/10 backdrop-blur-md border border-white/20 shadow-lg transition-all duration-1000 ease-in-out rounded-lg",
"h-10 w-10 p-2"
)}
>
<div className="flex items-center justify-center w-full h-full">
<Zap
className={cn(
"text-white transition-all duration-1000 ease-in-out absolute",
"h-5 w-5 -translate-x-1"
)}
/>
<Zap
className={cn(
"text-white transition-all duration-1000 ease-in-out absolute",
"h-5 w-5 translate-x-1"
)}
/>
</div>
</div>
</div>
</div>`;
if (standardize(content).includes(standardize(searchStr2)) && !changed) {
const regex = /<div className="flex items-center gap-2">[\s\S]*?h-5 w-5 translate-x-1[\s\S]*?<\/div>\s*<\/div>\s*<\/div>\s*<\/div>/;
content = content.replace(regex, '<AppHeaderBrand href="/" />');
changed = true;
if (!content.includes('import { AppHeaderBrand }')) {
content = content.replace('import ', 'import { AppHeaderBrand } from "@/components/brand/AppHeaderBrand";\nimport ');
}
}
if (changed) {
fs.writeFileSync(file, content);
console.log('Replaced logo in ' + file);
}
});