Improve code formatting and readability in build verification script

This commit is contained in:
2026-01-29 13:50:37 +00:00
parent d2e03b1d62
commit 098c9e30fd

View File

@@ -1,6 +1,6 @@
/** /**
* Build Verification Script * Build Verification Script
* *
* Verifies that the production build was successful and contains * Verifies that the production build was successful and contains
* all necessary files for deployment. * all necessary files for deployment.
*/ */
@@ -37,11 +37,13 @@ console.log('\n📋 Checking required files:');
for (const file of REQUIRED_FILES) { for (const file of REQUIRED_FILES) {
const filePath = path.join(DIST_DIR, file); const filePath = path.join(DIST_DIR, file);
const exists = fs.existsSync(filePath); const exists = fs.existsSync(filePath);
if (exists) { if (exists) {
const stats = fs.statSync(filePath); const stats = fs.statSync(filePath);
const isDir = stats.isDirectory(); const isDir = stats.isDirectory();
console.log(`${file} ${isDir ? '(directory)' : `(${(stats.size / 1024).toFixed(2)} KB)`}`); console.log(
`${file} ${isDir ? '(directory)' : `(${(stats.size / 1024).toFixed(2)} KB)`}`
);
} else { } else {
errors.push(`Required file missing: ${file}`); errors.push(`Required file missing: ${file}`);
console.log(`${file} - MISSING`); console.log(`${file} - MISSING`);
@@ -55,30 +57,34 @@ if (fs.existsSync(assetsDir)) {
const files = fs.readdirSync(assetsDir); const files = fs.readdirSync(assetsDir);
const jsFiles = files.filter(f => f.endsWith('.js')); const jsFiles = files.filter(f => f.endsWith('.js'));
const cssFiles = files.filter(f => f.endsWith('.css')); const cssFiles = files.filter(f => f.endsWith('.css'));
if (jsFiles.length === 0) { if (jsFiles.length === 0) {
errors.push('No JavaScript bundles found in assets/'); errors.push('No JavaScript bundles found in assets/');
console.log(' ❌ No JavaScript bundles found'); console.log(' ❌ No JavaScript bundles found');
} else { } else {
console.log(` ✅ Found ${jsFiles.length} JavaScript bundles`); console.log(` ✅ Found ${jsFiles.length} JavaScript bundles`);
// Show bundle sizes // Show bundle sizes
const totalJsSize = jsFiles.reduce((total, file) => { const totalJsSize = jsFiles.reduce((total, file) => {
const stats = fs.statSync(path.join(assetsDir, file)); const stats = fs.statSync(path.join(assetsDir, file));
return total + stats.size; return total + stats.size;
}, 0); }, 0);
console.log(` Total JS size: ${(totalJsSize / 1024 / 1024).toFixed(2)} MB`); console.log(
` Total JS size: ${(totalJsSize / 1024 / 1024).toFixed(2)} MB`
);
// Warn if bundles are too large // Warn if bundles are too large
jsFiles.forEach(file => { jsFiles.forEach(file => {
const stats = fs.statSync(path.join(assetsDir, file)); const stats = fs.statSync(path.join(assetsDir, file));
const sizeMB = stats.size / 1024 / 1024; const sizeMB = stats.size / 1024 / 1024;
if (sizeMB > 1) { if (sizeMB > 1) {
warnings.push(`Large bundle detected: ${file} (${sizeMB.toFixed(2)} MB)`); warnings.push(
`Large bundle detected: ${file} (${sizeMB.toFixed(2)} MB)`
);
} }
}); });
} }
if (cssFiles.length === 0) { if (cssFiles.length === 0) {
warnings.push('No CSS files found in assets/'); warnings.push('No CSS files found in assets/');
console.log(' ⚠️ No CSS files found'); console.log(' ⚠️ No CSS files found');
@@ -95,7 +101,7 @@ console.log('\n📄 Checking index.html:');
const indexPath = path.join(DIST_DIR, 'index.html'); const indexPath = path.join(DIST_DIR, 'index.html');
if (fs.existsSync(indexPath)) { if (fs.existsSync(indexPath)) {
const content = fs.readFileSync(indexPath, 'utf8'); const content = fs.readFileSync(indexPath, 'utf8');
// Check for script tags // Check for script tags
const scriptTags = content.match(/<script[^>]*src="[^"]*"[^>]*>/g); const scriptTags = content.match(/<script[^>]*src="[^"]*"[^>]*>/g);
if (scriptTags && scriptTags.length > 0) { if (scriptTags && scriptTags.length > 0) {
@@ -104,7 +110,7 @@ if (fs.existsSync(indexPath)) {
errors.push('No script tags found in index.html'); errors.push('No script tags found in index.html');
console.log(' ❌ No script tags found'); console.log(' ❌ No script tags found');
} }
// Check for stylesheet links // Check for stylesheet links
const linkTags = content.match(/<link[^>]*rel="stylesheet"[^>]*>/g); const linkTags = content.match(/<link[^>]*rel="stylesheet"[^>]*>/g);
if (linkTags && linkTags.length > 0) { if (linkTags && linkTags.length > 0) {
@@ -123,18 +129,18 @@ console.log('\n📊 Build Statistics:');
function getDirSize(dirPath) { function getDirSize(dirPath) {
let size = 0; let size = 0;
const files = fs.readdirSync(dirPath); const files = fs.readdirSync(dirPath);
for (const file of files) { for (const file of files) {
const filePath = path.join(dirPath, file); const filePath = path.join(dirPath, file);
const stats = fs.statSync(filePath); const stats = fs.statSync(filePath);
if (stats.isDirectory()) { if (stats.isDirectory()) {
size += getDirSize(filePath); size += getDirSize(filePath);
} else { } else {
size += stats.size; size += stats.size;
} }
} }
return size; return size;
} }