Skip to content

Commit

Permalink
Merge pull request #14 from gnidan/disable-prettier
Browse files Browse the repository at this point in the history
Allow disabling prettier
  • Loading branch information
gnidan authored Jul 19, 2021
2 parents 3940bf8 + ac60247 commit 6d9cfa4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/defaults.ts
Original file line number Diff line number Diff line change
@@ -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;
27 changes: 18 additions & 9 deletions lib/solidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -50,9 +60,8 @@ interface Context {

type Visit<N extends Node> = VisitOptions<N, Context | undefined>;

type ConstructorOptions = {declarations: Declarations} & Omit<
GenerateSolidityOptions,
"abi"
type ConstructorOptions = {declarations: Declarations} & Required<
Omit<GenerateSolidityOptions, "abi" | "prettifyOutput">
>;

class SolidityGenerator implements Visitor<string, Context | undefined> {
Expand All @@ -66,9 +75,9 @@ class SolidityGenerator implements Visitor<string, Context | undefined> {

constructor({
declarations,
name = defaults.name,
license = defaults.license,
solidityVersion = defaults.solidityVersion,
name,
license,
solidityVersion,
}: ConstructorOptions) {
this.name = name;
this.license = license;
Expand Down

0 comments on commit 6d9cfa4

Please sign in to comment.