- Add test-build.js script to verify standalone build locally - Add pre-commit hook with security, build, and test checks - Copy required-server-files.json to root of standalone for Amplify - Add husky for automatic pre-commit validation This ensures we test builds locally before pushing
69 lines
1.8 KiB
JavaScript
Executable File
69 lines
1.8 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
const { execSync } = require('child_process');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
console.log('🧪 Testing build locally...\n');
|
|
|
|
// Clean previous build
|
|
console.log('🧹 Cleaning previous build...');
|
|
try {
|
|
execSync('rm -rf .next', { stdio: 'inherit' });
|
|
} catch (e) {
|
|
// Ignore if doesn't exist
|
|
}
|
|
|
|
// Run build
|
|
console.log('\n🔨 Running build...');
|
|
try {
|
|
execSync('npm run build', { stdio: 'inherit' });
|
|
} catch (e) {
|
|
console.error('❌ Build failed!');
|
|
process.exit(1);
|
|
}
|
|
|
|
// Check for required files
|
|
console.log('\n🔍 Checking build output...');
|
|
const checks = [
|
|
{ path: '.next/standalone/server.js', name: 'Standalone server' },
|
|
{ path: '.next/standalone/.next/required-server-files.json', name: 'Required server files' },
|
|
{ path: '.next/static', name: 'Static directory' },
|
|
];
|
|
|
|
let allPassed = true;
|
|
for (const check of checks) {
|
|
if (fs.existsSync(check.path)) {
|
|
console.log(`✅ ${check.name}: Found`);
|
|
} else {
|
|
console.error(`❌ ${check.name}: Missing at ${check.path}`);
|
|
allPassed = false;
|
|
}
|
|
}
|
|
|
|
// Test the copy command
|
|
console.log('\n📋 Testing copy command...');
|
|
try {
|
|
execSync('cp -r .next/static .next/standalone/.next/', { stdio: 'inherit' });
|
|
console.log('✅ Copy command successful');
|
|
} catch (e) {
|
|
console.error('❌ Copy command failed');
|
|
allPassed = false;
|
|
}
|
|
|
|
// Check final structure
|
|
console.log('\n📁 Final structure check...');
|
|
const finalPath = '.next/standalone/.next/static';
|
|
if (fs.existsSync(finalPath)) {
|
|
console.log('✅ Static files copied successfully');
|
|
} else {
|
|
console.error('❌ Static files not in final location');
|
|
allPassed = false;
|
|
}
|
|
|
|
if (!allPassed) {
|
|
console.error('\n❌ Build test failed! Do not push.');
|
|
process.exit(1);
|
|
} else {
|
|
console.log('\n✅ All build tests passed!');
|
|
} |