evm-compat-check is a utility tool designed to help developers ensure their smart contracts and related files are compatible with the Ethereum Virtual Machine (EVM). By providing robust file handling and validation features, this tool simplifies the process of verifying file integrity, structure, and compatibility, making it easier to develop reliable and secure Ethereum-based applications.
- File Loading: Asynchronously load file contents.
- File Existence Check: Verify if a file exists at a specified path.
- File Extension Validation: Ensure files have allowed extensions.
- File Size Retrieval: Get the size of a file in bytes.
- Modification Time Retrieval: Fetch the last modification time of a file.
- Backup Creation: Create timestamped backups of files.
- Path Utilities: Extract directory paths and filenames.
- EVM Compatibility Checks: Validate smart contract compatibility with EVM (to be implemented).
-
Clone the Repository
git clone https://github.com/yourusername/evm-compat-check.git cd evm-compat-check -
Install Dependencies
Ensure you have Node.js installed. Then, install the necessary packages:
npm install
-
Install TypeScript and Node.js Types
npm install --save-dev typescript @types/node
-
Build the Project
npx tsc
-
Import the Loader Class
import { Loader } from "./src/loader";
-
Create an Instance of Loader
const loader = new Loader("path/to/your/file.sol");
-
Utilize Loader Methods
async function processFile() { if (await loader.fileExists()) { if (loader.validateFileExtension(["sol"])) { const content = await loader.loadFile(); console.log("File Content:", content); const size = await loader.getFileSize(); console.log("File Size:", size, "bytes"); const lastModified = await loader.getLastModified(); console.log("Last Modified:", lastModified); const backupPath = await loader.createBackup(); console.log("Backup Created At:", backupPath); const directory = loader.getDirectory(); console.log("Directory:", directory); const fileName = loader.getFileName(); console.log("Filename:", fileName); } else { console.log("Invalid file extension."); } } else { console.log("File does not exist."); } } processFile().catch(console.error);
The Loader class provides methods for handling file operations essential for verifying EVM compatibility.
constructor(filePath: string)- Parameters
filePath: The path to the file to be managed.
-
loadFile
async loadFile(): Promise<string>
Asynchronously loads and returns the content of the specified file.
-
fileExists
async fileExists(): Promise<boolean>
Checks if the specified file exists.
-
validateFileExtension
validateFileExtension(allowedExtensions: string[]): boolean
Validates whether the file has one of the allowed extensions.
-
getFileSize
async getFileSize(): Promise<number>
Retrieves the size of the file in bytes.
-
getLastModified
async getLastModified(): Promise<Date>
Gets the last modification time of the file.
-
createBackup
async createBackup(): Promise<string>
Creates a timestamped backup of the file and returns the backup file path.
-
getDirectory
getDirectory(): string
Retrieves the directory path of the file.
-
getFileName
getFileName(): string
Retrieves the filename without the path.
Ensure your tsconfig.json is properly configured to include Node.js types and resolve modules correctly.
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"types": ["node"],
"moduleResolution": "node",
"outDir": "./dist",
"strict": true,
"esModuleInterop": true
},
"include": ["src/**/*"]
}Contributions are welcome! Please follow these steps:
-
Fork the Repository
-
Create a New Branch
git checkout -b feature/your-feature-name
-
Commit Your Changes
git commit -m "feat: add your feature" -
Push to the Branch
git push origin feature/your-feature-name
-
Open a Pull Request
Explain the changes and the reasons behind them.
This project is licensed under the MIT License.