From e6f707d65be6f4ac8c82065ac4e56d6c8cc048df Mon Sep 17 00:00:00 2001 From: Aditya Anand M C Date: Fri, 1 Jul 2022 19:55:46 +0530 Subject: [PATCH] chore: replace pretty with format parameter - udpate documentation - set default format to json - supported formats are json, fullName, minimal --- README.md | 16 ++++++++++------ index.d.ts | 4 ++-- index.js | 4 ++-- tasks/export_abi.js | 4 +++- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 3bf66aa..883a359 100644 --- a/README.md +++ b/README.md @@ -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` | @@ -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/humanReadable', + format: "fullName", }, ] ``` diff --git a/index.d.ts b/index.d.ts index 074655d..1c55b24 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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, } @@ -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, }[] diff --git a/index.js b/index.js index 78b2e71..97b0b62 100644 --- a/index.js +++ b/index.js @@ -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 }; @@ -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') { diff --git a/tasks/export_abi.js b/tasks/export_abi.js index bb1a316..b6c3a4c 100644 --- a/tasks/export_abi.js +++ b/tasks/export_abi.js @@ -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(