From ca32917519eb9065829f11af105abbbb31d6efa2 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Wed, 11 Oct 2023 11:09:32 +0100 Subject: [PATCH] feat(abi-ts): move logs to debug (#1736) --- .changeset/new-falcons-fail.md | 5 +++++ packages/abi-ts/package.json | 2 ++ packages/abi-ts/src/debug.ts | 3 +++ packages/abi-ts/src/index.ts | 6 +++--- pnpm-lock.yaml | 6 ++++++ 5 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 .changeset/new-falcons-fail.md create mode 100644 packages/abi-ts/src/debug.ts diff --git a/.changeset/new-falcons-fail.md b/.changeset/new-falcons-fail.md new file mode 100644 index 0000000000..4d6a43f6ef --- /dev/null +++ b/.changeset/new-falcons-fail.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/abi-ts": minor +--- + +Moves log output behind a debug flag. You can enable logging with `DEBUG=abi-ts` environment variable. diff --git a/packages/abi-ts/package.json b/packages/abi-ts/package.json index b34966591a..a2bd75a98b 100644 --- a/packages/abi-ts/package.json +++ b/packages/abi-ts/package.json @@ -32,11 +32,13 @@ }, "dependencies": { "chalk": "^5.3.0", + "debug": "^4.3.4", "execa": "^7.0.0", "glob": "^8.0.3", "yargs": "^17.7.1" }, "devDependencies": { + "@types/debug": "^4.1.7", "@types/glob": "^7.2.0", "@types/node": "^18.15.11", "@types/yargs": "^17.0.10", diff --git a/packages/abi-ts/src/debug.ts b/packages/abi-ts/src/debug.ts new file mode 100644 index 0000000000..0a6bdd3149 --- /dev/null +++ b/packages/abi-ts/src/debug.ts @@ -0,0 +1,3 @@ +import createDebug from "debug"; + +export const debug = createDebug("abi-ts"); diff --git a/packages/abi-ts/src/index.ts b/packages/abi-ts/src/index.ts index 1204b6381f..7ddf08332e 100644 --- a/packages/abi-ts/src/index.ts +++ b/packages/abi-ts/src/index.ts @@ -1,7 +1,7 @@ import type { CommandModule } from "yargs"; import { readFileSync, writeFileSync } from "fs"; import glob from "glob"; -import path from "path"; +import { debug } from "./debug"; type Options = { input: string; @@ -34,14 +34,14 @@ const commandModule: CommandModule = { for (const jsonFilename of files) { const json = readFileSync(jsonFilename, "utf8").trim(); if (json === "[]") { - console.log("Skipping empty ABI file", jsonFilename); + debug("Skipping empty ABI file", jsonFilename); continue; } const ts = `declare const abi: ${json}; export default abi;\n`; const tsFilename = `${jsonFilename}.d.ts`; - console.log("Writing", tsFilename); + debug("Writing", tsFilename); writeFileSync(tsFilename, ts); } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6e83dd89fb..6ef03bae2f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -56,6 +56,9 @@ importers: chalk: specifier: ^5.3.0 version: 5.3.0 + debug: + specifier: ^4.3.4 + version: 4.3.4(supports-color@8.1.1) execa: specifier: ^7.0.0 version: 7.0.0 @@ -66,6 +69,9 @@ importers: specifier: ^17.7.1 version: 17.7.1 devDependencies: + '@types/debug': + specifier: ^4.1.7 + version: 4.1.7 '@types/glob': specifier: ^7.2.0 version: 7.2.0