-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.js
More file actions
executable file
·100 lines (88 loc) · 2.44 KB
/
validate.js
File metadata and controls
executable file
·100 lines (88 loc) · 2.44 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
#!/usr/bin/env node
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
console.log('🔍 SnapCode Validation Report\n');
// Check if index.html exists
const indexPath = path.join(__dirname, 'index.html');
if (!fs.existsSync(indexPath)) {
console.error('❌ index.html not found');
process.exit(1);
}
// Read and analyze HTML file
const html = fs.readFileSync(indexPath, 'utf8');
// Basic HTML structure checks
const checks = [
{
name: 'DOCTYPE declaration',
test: () => html.includes('<!DOCTYPE html>'),
fix: 'Add <!DOCTYPE html> at the beginning'
},
{
name: 'HTML lang attribute',
test: () => html.includes('<html lang='),
fix: 'Add lang attribute to <html> tag'
},
{
name: 'Meta charset',
test: () => html.includes('<meta charset='),
fix: 'Add <meta charset="UTF-8"> in <head>'
},
{
name: 'Meta viewport',
test: () => html.includes('name="viewport"'),
fix: 'Add viewport meta tag for responsive design'
},
{
name: 'Title tag',
test: () => html.includes('<title>') && html.includes('</title>'),
fix: 'Add <title> tag in <head>'
},
{
name: 'Alpine.js x-data',
test: () => html.includes('x-data='),
fix: 'Ensure Alpine.js is properly initialized'
},
{
name: 'No x-if templates (should use x-show)',
test: () => !html.includes('x-if='),
fix: 'Replace x-if with x-show to avoid cloneNode errors'
},
{
name: 'Service Worker registration',
test: () => html.includes('serviceWorker.register'),
fix: 'Add service worker registration for PWA'
}
];
let passed = 0;
let failed = 0;
checks.forEach(check => {
if (check.test()) {
console.log(`✅ ${check.name}`);
passed++;
} else {
console.log(`❌ ${check.name}`);
console.log(` 💡 ${check.fix}\n`);
failed++;
}
});
// File size check
const stats = fs.statSync(indexPath);
const fileSizeKB = Math.round(stats.size / 1024);
console.log(`\n📊 File size: ${fileSizeKB}KB`);
if (fileSizeKB > 100) {
console.log('⚠️ File is getting large, consider optimization');
} else {
console.log('✅ File size is optimal');
}
// Summary
console.log(`\n📋 Summary: ${passed} passed, ${failed} failed`);
if (failed === 0) {
console.log('🎉 All checks passed!');
process.exit(0);
} else {
console.log('🔧 Please fix the issues above');
process.exit(1);
}