From ac602472e1f1f118f2d75c3a342ca487295d5e60 Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Mon, 19 Jul 2021 19:21:11 -0400 Subject: [PATCH] Allow disabling prettier --- lib/defaults.ts | 1 + lib/solidity.ts | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/defaults.ts b/lib/defaults.ts index bb15aaa..e7e1c8e 100644 --- a/lib/defaults.ts +++ b/lib/defaults.ts @@ -1,3 +1,4 @@ export const name = "MyInterface"; export const license = "UNLICENSED"; export const solidityVersion = ">=0.5.0 <0.8.0"; +export const prettifyOutput = true; diff --git a/lib/solidity.ts b/lib/solidity.ts index a6156dc..1332ca9 100644 --- a/lib/solidity.ts +++ b/lib/solidity.ts @@ -19,24 +19,34 @@ export interface GenerateSolidityOptions { name?: string; solidityVersion?: string; license?: string; + prettifyOutput?: boolean; } export const generateSolidity = ({ abi, - ...options + name = defaults.name, + solidityVersion = defaults.solidityVersion, + license = defaults.license, + prettifyOutput = defaults.prettifyOutput, }: GenerateSolidityOptions) => { const generated = dispatch({ node: abi, visitor: new SolidityGenerator({ - ...options, + name, + solidityVersion, + license, declarations: collectDeclarations(abi), }), }); + if (!prettifyOutput) { + return generated; + } + try { return prettier.format(generated, { plugins: ["prettier-plugin-solidity"], - // @ts-ignore + // @ts-expect-error parser: "solidity-parse", }); } catch (error) { @@ -50,9 +60,8 @@ interface Context { type Visit = VisitOptions; -type ConstructorOptions = {declarations: Declarations} & Omit< - GenerateSolidityOptions, - "abi" +type ConstructorOptions = {declarations: Declarations} & Required< + Omit >; class SolidityGenerator implements Visitor { @@ -66,9 +75,9 @@ class SolidityGenerator implements Visitor { constructor({ declarations, - name = defaults.name, - license = defaults.license, - solidityVersion = defaults.solidityVersion, + name, + license, + solidityVersion, }: ConstructorOptions) { this.name = name; this.license = license;