Skip to content

Commit

Permalink
remove fs depedencies from modules
Browse files Browse the repository at this point in the history
  • Loading branch information
zianksm committed Oct 23, 2022
1 parent 9bc6279 commit 6bd7c69
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 25 deletions.
9 changes: 2 additions & 7 deletions src/implementation/reader.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import { ABI, abiChild, iochild, _function } from "./type-mapping";
import * as fs from "fs";

export default class AbiReader {
public static read(path: string, raw?: string) {
const abiString = raw ?? this.readFile(path);
public static read(abi: string) {
const abiString = abi;
const abiRaw = this.parseRaw(abiString);
const bindABI = this.bindABI(abiRaw);

return bindABI;
}

private static readFile(path: string): string {
return fs.readFileSync(path, "utf-8");
}

private static parseRaw(raw: string) {
return JSON.parse(raw);
}
Expand Down
22 changes: 5 additions & 17 deletions src/implementation/writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,16 @@ import IoParser from "./io_parser";
const TS = ".ts";
export default class Writer extends IoParser {
/**
* @param contractName The contract name (duh)
* @param abi the contracts function abi
* @param dirPath if provided, will write to this path using contract name parameter
* as filename.
* @param abi the contracts abi
*/
public write(contractName: string, abi: ABI, dirPath?: string) {
public write(abi: ABI) {
const fn = this.parse(abi);
const paths = this.suffixts(path.resolve(dirPath as string, contractName));
let contract: string = "";

for (const node of fn) {
fs.appendFileSync(paths, node.signatureLiteral as string);
contract = contract.concat(node.signatureLiteral as string);
}

return fn;
}

/**
*
* make sure ```.ts``` is appended to the filename
*/
private suffixts(name: string): string {
if (name.includes(TS)) return name;
else return name.concat(TS);
return contract;
}
}
1 change: 0 additions & 1 deletion test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ import AbiReader from "./src/implementation/reader";
import Writer from "./src/implementation/writer";

const abi = AbiReader.read("./abi/auctions/auction.json");
new Writer().write("auction", abi, "./");

0 comments on commit 6bd7c69

Please sign in to comment.