Repository navigation
Expand file tree
/
Copy pathfix_missing_fragment_starts.js
More file actions
71 lines (55 loc) · 2.46 KB
/
Copy pathfix_missing_fragment_starts.js
File metadata and controls
71 lines (55 loc) · 2.46 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
const fs = require('fs');
const path = require('path');
const files = [
'src/pages/Favorites.tsx',
'src/pages/ResetPassword.tsx',
'src/pages/VerifyEmail.tsx',
'src/pages/ArtistDashboard.tsx',
'src/pages/Messages.tsx',
'src/pages/Notifications.tsx',
'src/pages/PlaylistDetail.tsx',
'src/pages/RecentlyPlayed.tsx',
'src/pages/Search.tsx',
'src/features/upload/pages/MusicUpload.tsx'
];
const projectRoot = path.resolve('d:/m-zik-platform-main');
files.forEach(relativePath => {
const fullPath = path.join(projectRoot, relativePath);
if (!fs.existsSync(fullPath)) {
console.log(`Skipping ${relativePath} (not found)`);
return;
}
let content = fs.readFileSync(fullPath, 'utf8');
let originalContent = content;
// We only want to apply this if we see a stray `</>` that likely corresponds to these patterns.
// But counting properly is hard.
// Heuristic: If we replace `(<Tag` with `(<> <Tag`, valid code like `return (<div...</div>)` becomes `return (<> <div...</div>)`.
// This is problematic if there is no `</>`.
// So we ONLY proceed if we detect `</>` in the file.
// And to be safer, we can try to only target blocks that look suspicious.
// Pattern 1: `) : (<Tag`
// Pattern 2: `? (<Tag`
// Pattern 3: `&& (<Tag`
// We will do a global check.
// If the file contains `</>`, we act.
const hasClosingFragment = content.includes('</>');
if (hasClosingFragment) {
// Regex to match `) : (<TagName` NOT starting with `<>`
// We use negative lookahead for `<>` ? No, just match `<[a-zA-Z]`
// Match `) : (<` followed by a letter.
content = content.replace(/\) : \(<([a-zA-Z])/g, ') : (<> <$1');
// Match `? (<` followed by a letter.
content = content.replace(/\? \(<([a-zA-Z])/g, '? (<> <$1');
// Match `&& (<` followed by a letter.
content = content.replace(/&& \(<([a-zA-Z])/g, '&& (<> <$1');
// Special case for VerifyEmail/ResetPassword where it starts with `return (` or inside `map`?
// No, in VerifyEmail it was `&& (<div` (Pattern 3).
// In Favorites it was `) : (<span` (Pattern 1).
if (content !== originalContent) {
console.log(`Fixed missing fragments in ${relativePath}`);
fs.writeFileSync(fullPath, content, 'utf8');
} else {
console.log(`No matching patterns found in ${relativePath} despite having </>.`);
}
}
});