diff --git a/README.md b/README.md index 21d9cee..ac8e12c 100644 --- a/README.md +++ b/README.md @@ -60,3 +60,11 @@ Mock contracts are used to improve the testing of smart contracts. As they are o ```bash truffle run contract-size --ignoreMocks ``` + +### Show total size + +You can show the total size of all the contracts specified by running + +```bash +truffle run contract-size --showTotal +``` \ No newline at end of file diff --git a/package.json b/package.json index f28c367..b96b568 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "truffle-contract-size", - "version": "2.0.1", + "version": "2.0.2", "description": "Displays the size of a truffle contracts in kilobytes", "main": "src/index.js", "scripts": { diff --git a/src/index.js b/src/index.js index 7bdb4f9..e087377 100644 --- a/src/index.js +++ b/src/index.js @@ -21,7 +21,7 @@ module.exports = async (config, done) => { yargs.parse(process.argv.slice(3)) const contractNames = yargs.argv.contracts - const { checkMaxSize, ignoreMocks } = yargs.argv + const { checkMaxSize, ignoreMocks, showTotal } = yargs.argv if (!isValidCheckMaxSize(checkMaxSize)) { done(`--checkMaxSize: invalid value ${checkMaxSize}`) @@ -35,6 +35,8 @@ module.exports = async (config, done) => { // array of objects of {file: path to file, name: name of the contract} const contracts = await getContracts(config, contractNames, ignoreMocks, done) + let total = 0 + const contractPromises = contracts.map(async (contract) => { await checkFile(contract.file, done) @@ -43,6 +45,7 @@ module.exports = async (config, done) => { if (!('deployedBytecode' in contractFile)) { done(`Error: deployedBytecode not found in ${contract.file} (it is not a contract json file)`) } + total += computeByteCodeSizeInKiB(contractFile.deployedBytecode) const byteCodeSize = computeByteCodeSizeInKiB(contractFile.deployedBytecode) @@ -54,6 +57,18 @@ module.exports = async (config, done) => { await Promise.all(contractPromises) + if (showTotal) { + table.push([ + '-', + '-' + ]) + + table.push([ + 'Total', + formatByteCodeSize(total) + ]) + } + console.log(table.toString()) if (checkMaxSize) {