-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_back_button.js
More file actions
59 lines (48 loc) · 2.18 KB
/
Copy pathadd_back_button.js
File metadata and controls
59 lines (48 loc) · 2.18 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
const fs = require('fs');
const path = require('path');
const targetFiles = [
'src/app/signup/page.tsx',
'src/app/signup/details/page.tsx',
'src/app/forgot-password/page.tsx',
'src/app/recover-account/page.tsx',
'src/app/reset-password/page.tsx',
'src/app/security-phrase/page.tsx',
'src/app/verify-phrase/page.tsx',
'src/app/verify-recovery-otp/page.tsx'
];
targetFiles.forEach(file => {
if (!fs.existsSync(file)) return;
let content = fs.readFileSync(file, 'utf8');
let changed = false;
const headerPattern = /<div className="absolute left-10 top-10 z-20 flex flex-row items-center gap-3">\s*<AppHeaderBrand href="\/" \/>\s*<\/div>/g;
if (headerPattern.test(content) && !content.includes('absolute right-10 top-10')) {
const backBtnMarkup = `\n <div className="absolute right-10 top-10 z-20">\n <Button asChild variant="ghost" size="icon" className="text-white hover:bg-white/10 hover:text-white">\n <Link href="/">\n <ArrowLeft className="h-6 w-6" />\n </Link>\n </Button>\n </div>`;
content = content.replace(headerPattern, (match) => {
return match + backBtnMarkup;
});
// Add imports if missing
if (!content.includes('import { ArrowLeft')) {
if (content.includes('lucide-react')) {
content = content.replace(/import\s+{([^}]*)}\s+from\s+['"]lucide-react['"]/, (match, p1) => {
if (!p1.includes('ArrowLeft')) {
return `import { ${p1.trim()}, ArrowLeft } from "lucide-react"`;
}
return match;
});
} else {
content = content.replace('import ', 'import { ArrowLeft } from "lucide-react";\nimport ');
}
}
if (!content.includes('import { Button }')) {
content = content.replace('import ', 'import { Button } from "@/components/ui/button";\nimport ');
}
if (!content.includes('import Link from "next/link"')) {
content = content.replace('import ', 'import Link from "next/link";\nimport ');
}
changed = true;
}
if (changed) {
fs.writeFileSync(file, content);
console.log('Added back button to ' + file);
}
});