-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-build.js
More file actions
executable file
·110 lines (97 loc) · 3.41 KB
/
check-build.js
File metadata and controls
executable file
·110 lines (97 loc) · 3.41 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
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env node
/**
* Build validation script - checks for common issues
*/
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const distDir = path.join(__dirname, 'dist');
const errors = [];
const warnings = [];
console.log('🔍 Checking build...\n');
// Check if dist directory exists
if (!fs.existsSync(distDir)) {
errors.push('❌ dist/ directory does not exist. Run: npm run build');
console.error(errors[0]);
process.exit(1);
}
// Check content.js
const contentJs = path.join(distDir, 'content.js');
if (!fs.existsSync(contentJs)) {
errors.push('❌ dist/content.js is missing. Run: npm run build');
} else {
const content = fs.readFileSync(contentJs, 'utf8');
// Check format
if (content.trim().startsWith('var ') || content.trim().startsWith('(function')) {
console.log('✅ content.js is in IIFE format');
} else if (content.includes('const _vite_mapDeps') || content.includes('import ') || content.includes('export ')) {
errors.push('❌ content.js contains ES module syntax (import/export). Should be IIFE format.');
} else {
warnings.push('⚠️ content.js format unclear - may need manual inspection');
}
// Check size
const size = fs.statSync(contentJs).size;
if (size < 10000) {
warnings.push(`⚠️ content.js is very small (${size} bytes) - may be incomplete`);
} else {
console.log(`✅ content.js size: ${(size / 1024).toFixed(1)} KB`);
}
}
// Check manifest.json
const manifestJson = path.join(distDir, 'manifest.json');
if (!fs.existsSync(manifestJson)) {
errors.push('❌ dist/manifest.json is missing');
} else {
const manifest = JSON.parse(fs.readFileSync(manifestJson, 'utf8'));
// Check content script config
if (manifest.content_scripts && manifest.content_scripts[0]) {
const cs = manifest.content_scripts[0];
if (cs.js && cs.js.includes('content.js')) {
console.log('✅ manifest.json correctly references content.js');
} else {
errors.push('❌ manifest.json content_scripts does not reference content.js');
}
} else {
errors.push('❌ manifest.json missing content_scripts configuration');
}
}
// Check background.js
const backgroundJs = path.join(distDir, 'background.js');
if (!fs.existsSync(backgroundJs)) {
errors.push('❌ dist/background.js is missing');
} else {
console.log('✅ background.js exists');
}
// Check icons
const iconsDir = path.join(distDir, 'icons');
if (!fs.existsSync(iconsDir)) {
warnings.push('⚠️ dist/icons/ directory missing');
} else {
const requiredIcons = ['icon16.png', 'icon48.png', 'icon128.png'];
const missingIcons = requiredIcons.filter(icon =>
!fs.existsSync(path.join(iconsDir, icon))
);
if (missingIcons.length > 0) {
warnings.push(`⚠️ Missing icons: ${missingIcons.join(', ')}`);
} else {
console.log('✅ All required icons present');
}
}
// Summary
console.log('\n' + '='.repeat(50));
if (errors.length > 0) {
console.error('\n❌ ERRORS FOUND:');
errors.forEach(e => console.error(' ' + e));
process.exit(1);
} else {
console.log('\n✅ Build validation passed!');
if (warnings.length > 0) {
console.log('\n⚠️ WARNINGS:');
warnings.forEach(w => console.warn(' ' + w));
}
console.log('\n📦 Extension is ready to load in Chrome');
console.log(' Location: ' + distDir);
process.exit(0);
}