-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_imports.js
More file actions
34 lines (28 loc) · 1.11 KB
/
update_imports.js
File metadata and controls
34 lines (28 loc) · 1.11 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
import fs from 'fs';
import path from 'path';
function walk(dir, call) {
let files = fs.readdirSync(dir);
for (let file of files) {
let p = path.join(dir, file);
if (fs.statSync(p).isDirectory()) walk(p, call);
else if (p.endsWith('.ts') || p.endsWith('.tsx')) call(p);
}
}
walk('./src', p => {
// skip barrel files
if (p.replace(/\\/g, '/').endsWith('src/hooks/index.ts')) return;
if (p.replace(/\\/g, '/').endsWith('src/services/index.ts')) return;
let content = fs.readFileSync(p, 'utf8');
let original = content;
// Replace hook imports
content = content.replace(/from "(\.+\/)hooks\/useUser"/g, 'from "$1hooks"');
content = content.replace(/from "(\.+\/)hooks\/useNotification"/g, 'from "$1hooks"');
// Replace services imports
content = content.replace(/from "(\.+\/)services\/firebase"/g, 'from "$1services"');
content = content.replace(/from "(\.+\/)services\/permissions"/g, 'from "$1services"');
content = content.replace(/from "(\.+\/)services\/auth"/g, 'from "$1services"');
if (content !== original) {
fs.writeFileSync(p, content);
console.log(`Updated ${p}`);
}
});