hardhat-abi-exporter
Advanced tools
Comparing version 2.6.1 to 2.7.0
@@ -11,2 +11,3 @@ module.exports = { | ||
'task': 'readonly', | ||
'subtask': 'readonly', | ||
}, | ||
@@ -13,0 +14,0 @@ 'parserOptions': { |
import 'hardhat/types/config'; | ||
interface AbiExporterUserConfig { | ||
path?: string, | ||
runOnCompile?: boolean, | ||
clear?: boolean, | ||
flat?: boolean, | ||
only?: string[], | ||
except?: string[], | ||
spacing?: number, | ||
pretty?: boolean, | ||
filter?: (abiElement: any, index: number, abi: any, fullyQualifiedName: string) => boolean, | ||
} | ||
declare module 'hardhat/types/config' { | ||
interface HardhatUserConfig { | ||
abiExporter?: { | ||
path?: string, | ||
runOnCompile?: boolean, | ||
clear?: boolean, | ||
flat?: boolean, | ||
only?: string[], | ||
except?: string[], | ||
spacing?: number, | ||
pretty?: boolean, | ||
filter?: (abiElement: any, index: number, abi: any, fullyQualifiedName: string) => boolean, | ||
} | ||
abiExporter?: AbiExporterUserConfig | AbiExporterUserConfig[] | ||
} | ||
@@ -29,4 +31,4 @@ | ||
filter: (abiElement: any, index: number, abi: any, fullyQualifiedName: string) => boolean, | ||
} | ||
}[] | ||
} | ||
} |
29
index.js
@@ -7,17 +7,18 @@ const { extendConfig } = require('hardhat/config'); | ||
const DEFAULT_CONFIG = { | ||
path: './abi', | ||
runOnCompile: false, | ||
clear: false, | ||
flat: false, | ||
only: [], | ||
except: [], | ||
spacing: 2, | ||
pretty: false, | ||
filter: () => true, | ||
}; | ||
extendConfig(function (config, userConfig) { | ||
config.abiExporter = Object.assign( | ||
{ | ||
path: './abi', | ||
runOnCompile: false, | ||
clear: false, | ||
flat: false, | ||
only: [], | ||
except: [], | ||
spacing: 2, | ||
pretty: false, | ||
filter: () => true, | ||
}, | ||
userConfig.abiExporter | ||
); | ||
config.abiExporter = [userConfig.abiExporter].flatten().map(function (el) { | ||
return Object.assign(DEFAULT_CONFIG, el); | ||
}); | ||
}); |
{ | ||
"name": "hardhat-abi-exporter", | ||
"version": "2.6.1", | ||
"version": "2.7.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Export Ethereum smart contract ABIs on compilation", |
@@ -35,2 +35,4 @@ # Hardhat ABI Exporter | ||
Note that the configuration formatted as either a single `Object`, or an `Array` of objects. An `Array` may be used to specify multiple outputs. | ||
```javascript | ||
@@ -46,2 +48,15 @@ abiExporter: { | ||
} | ||
// or | ||
abiExporter: [ | ||
{ | ||
path: './abi/pretty', | ||
pretty: true, | ||
}, | ||
{ | ||
path: './abi/ugly', | ||
pretty: false, | ||
}, | ||
] | ||
``` | ||
@@ -48,0 +63,0 @@ |
const fs = require('fs'); | ||
const path = require('path'); | ||
const deleteEmpty = require('delete-empty'); | ||
const { types } = require('hardhat/config'); | ||
const { Interface } = require('@ethersproject/abi'); | ||
@@ -23,6 +24,16 @@ | ||
task('clear-abi', async function (args, hre) { | ||
const config = hre.config.abiExporter; | ||
const configs = hre.config.abiExporter; | ||
const outputDirectory = path.resolve(hre.config.paths.root, config.path); | ||
await Promise.all(configs.map((abiExporterConfig) => { | ||
return hre.run('clear-abi-group', { path: abiExporterConfig.path }); | ||
})); | ||
}); | ||
subtask( | ||
'clear-abi-group' | ||
).addParam( | ||
'path', 'path to look for ABIs', undefined, types.string | ||
).setAction(async function (args, hre) { | ||
const outputDirectory = path.resolve(hre.config.paths.root, args.path); | ||
if (!fs.existsSync(outputDirectory)) { | ||
@@ -29,0 +40,0 @@ return; |
@@ -10,6 +10,11 @@ const { | ||
if (hre.config.abiExporter.runOnCompile && !args.noExportAbi) { | ||
// Disable compile to avoid an infinite loop | ||
await hre.run('export-abi', { noCompile: true }); | ||
if (!args.noExportAbi) { | ||
const configs = hre.config.abiExporter; | ||
await Promise.all(configs.map(abiGroupConfig => { | ||
if (abiGroupConfig.runOnCompile) { | ||
return hre.run('export-abi-group', { abiGroupConfig }); | ||
} | ||
})); | ||
} | ||
}); |
@@ -5,2 +5,3 @@ const fs = require('fs'); | ||
const { Interface, FormatTypes } = require('@ethersproject/abi'); | ||
const { types } = require('hardhat/config'); | ||
const { | ||
@@ -19,4 +20,16 @@ TASK_COMPILE, | ||
const config = hre.config.abiExporter; | ||
const configs = hre.config.abiExporter; | ||
await Promise.all(configs.map(abiGroupConfig => { | ||
return hre.run('export-abi-group', { abiGroupConfig }) | ||
})); | ||
}); | ||
subtask( | ||
'export-abi-group' | ||
).addParam( | ||
'abiGroupConfig', 'a single abi-exporter config object', undefined, types.any | ||
).setAction(async function (args, hre) { | ||
const { abiGroupConfig: config } = args; | ||
const outputDirectory = path.resolve(hre.config.paths.root, config.path); | ||
@@ -65,3 +78,3 @@ | ||
if (config.clear) { | ||
await hre.run('clear-abi'); | ||
await hre.run('clear-abi-group', { path: config.path }); | ||
} | ||
@@ -68,0 +81,0 @@ |
11021
242
81