navskit
Version:
Deploy TypeScript logic on Ethereum. Includes core library, CLI tools, and utilities.
68 lines (52 loc) • 2.4 kB
JavaScript
const fs = require('fs');
const path = require('path');
// Paths (adjusted for unified package structure)
const CONTRACTS_L2_DIR = path.join(__dirname, '../../contracts-l2');
const FOUNDRY_OUTPUT = path.join(CONTRACTS_L2_DIR, 'out/ITaskDispatch.sol/ITaskDispatch.json');
const TARGET_FILE = path.join(__dirname, '../src/deploy/abi/TaskDispatch.ts');
console.log('🚀 Updating TaskDispatch ABI from interface...');
// Check if Foundry output exists
if (!fs.existsSync(FOUNDRY_OUTPUT)) {
console.error(`❌ Error: Foundry output not found at ${FOUNDRY_OUTPUT}`);
console.error('Please run "forge build" in the contracts-l2 directory first.');
process.exit(1);
}
try {
// Read and parse the Foundry output
console.log('📖 Reading Foundry output...');
const foundryOutput = JSON.parse(fs.readFileSync(FOUNDRY_OUTPUT, 'utf8'));
if (!foundryOutput.abi) {
throw new Error('No ABI found in Foundry output');
}
// Create backup
if (fs.existsSync(TARGET_FILE)) {
fs.copyFileSync(TARGET_FILE, `${TARGET_FILE}.backup`);
console.log('💾 Created backup');
}
// Generate TypeScript content
const abiJson = JSON.stringify(foundryOutput.abi, null, 2);
const tsContent = `export const abi = ${abiJson} as const;\n`;
// Write to file
fs.writeFileSync(TARGET_FILE, tsContent, 'utf8');
// Validate
const functions = foundryOutput.abi.filter(item => item.type === 'function').length;
const events = foundryOutput.abi.filter(item => item.type === 'event').length;
console.log('✅ Successfully updated TaskDispatch.ts from ITaskDispatch interface');
console.log(` 📊 ABI contains: ${functions} functions, ${events} events`);
console.log(` 📁 File size: ${fs.statSync(TARGET_FILE).size} bytes`);
// Clean up backup
if (fs.existsSync(`${TARGET_FILE}.backup`)) {
fs.unlinkSync(`${TARGET_FILE}.backup`);
}
console.log('🎉 ABI update completed successfully!');
} catch (error) {
console.error('❌ Error updating ABI:', error.message);
// Restore backup if it exists
if (fs.existsSync(`${TARGET_FILE}.backup`)) {
fs.copyFileSync(`${TARGET_FILE}.backup`, TARGET_FILE);
fs.unlinkSync(`${TARGET_FILE}.backup`);
console.log('🔄 Restored backup file');
}
process.exit(1);
}