-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_auth_to_pages.js
More file actions
48 lines (41 loc) · 1.76 KB
/
Copy pathadd_auth_to_pages.js
File metadata and controls
48 lines (41 loc) · 1.76 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
const fs = require('fs');
const path = require('path');
const pagesDir = path.join(__dirname, 'pages');
const authScript = ' <script src="../js/auth.js" type="module"></script>\n <script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>\n';
// Get all HTML files in the pages directory
fs.readdir(pagesDir, (err, files) => {
if (err) {
console.error('Error reading pages directory:', err);
return;
}
files.forEach(file => {
if (file.endsWith('.html') && file !== 'login.html' && file !== 'signup.html' &&
file !== 'forgot-password.html' && file !== 'reset-password.html') {
const filePath = path.join(pagesDir, file);
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error(`Error reading file ${file}:`, err);
return;
}
// Check if auth.js is already included
if (data.includes('auth.js')) {
console.log(`Skipping ${file} - auth.js already included`);
return;
}
// Find the closing head tag and insert our script before it
const updatedContent = data.replace(
/<\/head>/i,
` ${authScript}</head>`
);
// Write the updated content back to the file
fs.writeFile(filePath, updatedContent, 'utf8', err => {
if (err) {
console.error(`Error writing to ${file}:`, err);
return;
}
console.log(`Updated ${file} with auth script`);
});
});
}
});
});