Skip to content

Commit

Permalink
chore: replace pretty with format parameter
Browse files Browse the repository at this point in the history
- udpate documentation
- set default format to json
- supported formats are json, fullName, minimal
  • Loading branch information
thelostone-mc committed Jul 2, 2022
1 parent 52d5adc commit 1884a08
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
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` |
| `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",
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);
}

const destination = path.resolve(
Expand Down

0 comments on commit 1884a08

Please sign in to comment.