Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add format parameter to hardhat-abi-exporter #42

Merged
merged 3 commits into from Jul 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions README.md
Expand Up @@ -29,7 +29,7 @@ Add configuration under the `abiExporter` key:
| `only` | `Array` of `String` matchers used to select included contracts, defaults to all contracts if `length` is 0 | `[]` |
| `except` | `Array` of `String` matchers used to exclude contracts | `[]` |
| `spacing` | number of spaces per indentation level of formatted output | `2` |
| `pretty` | whether to use interface-style formatting of output for better readability | `false` |
| `format` | format type ("json", "minimal", "humanReadable") | `json` |
thelostone-mc marked this conversation as resolved.
Show resolved Hide resolved
| `filter` | `Function` with signature `(abiElement: any, index: number, abi: any, fullyQualifiedName: string) => boolean` used to filter elements from each exported ABI | `() => true` |
| `rename` | `Function` with signature `(sourceName: string, contractName: string) => string` used to rename an exported ABI (incompatible with `flat` option) | `undefined` |

Expand All @@ -43,19 +43,23 @@ abiExporter: {
flat: true,
only: [':ERC20$'],
spacing: 2,
pretty: true,
format: "minimal",
}

// or

abiExporter: [
{
path: './abi/pretty',
pretty: true,
path: './abi/json',
format: "json",
},
{
path: './abi/ugly',
pretty: false,
path: './abi/minimal',
format: "minimal",
},
{
path: './abi/fullName',
format: "fullName",
},
]
```
Expand Down
4 changes: 2 additions & 2 deletions index.d.ts
Expand Up @@ -8,7 +8,7 @@ interface AbiExporterUserConfig {
only?: string[],
except?: string[],
spacing?: number,
pretty?: boolean,
format?: string,
filter?: (abiElement: any, index: number, abi: any, fullyQualifiedName: string) => boolean,
rename?: (sourceName: string, contractName: string) => string,
}
Expand All @@ -27,7 +27,7 @@ declare module 'hardhat/types/config' {
only: string[],
except: string[],
spacing: number,
pretty: boolean,
format: string,
filter: (abiElement: any, index: number, abi: any, fullyQualifiedName: string) => boolean,
rename: (sourceName: string, contractName: string) => string,
}[]
Expand Down
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -15,7 +15,7 @@ const DEFAULT_CONFIG = {
only: [],
except: [],
spacing: 2,
pretty: false,
format: "json",
thelostone-mc marked this conversation as resolved.
Show resolved Hide resolved
filter: () => true,
// `rename` is not defaulted as it may depend on `flat` option
};
Expand All @@ -42,7 +42,7 @@ extendConfig(function (config, userConfig) {
validate(conf, 'only', 'array');
validate(conf, 'except', 'array');
validate(conf, 'spacing', 'number');
validate(conf, 'pretty', 'boolean');
validate(conf, 'format', 'string');
validate(conf, 'filter', 'function');

if (conf.flat && typeof conf.rename !== 'undefined') {
Expand Down
4 changes: 3 additions & 1 deletion tasks/export_abi.js
Expand Up @@ -50,8 +50,10 @@ subtask(

abi = abi.filter((element, index, array) => config.filter(element, index, array, fullName));

if (config.pretty) {
if (config.format == "minimal") {
abi = new Interface(abi).format(FormatTypes.minimal);
} else if (config.format == "fullName") {
abi = new Interface(abi).format(FormatTypes.fullName);
}
thelostone-mc marked this conversation as resolved.
Show resolved Hide resolved

const destination = path.resolve(
Expand Down