From 3672a6844bb3d5c8f558eadd89bff62ceba5983a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20Vujovi=C4=87?= Date: Mon, 17 Oct 2022 14:58:28 +0200 Subject: [PATCH] feat: Improve CLI output further Add proper logging to output shown when verbose flag is active --- lib/build-tools/near-bindgen-exporter.js | 6 +++++- lib/cli/cli.js | 4 ++-- lib/cli/utils.js | 11 +++++++---- src/build-tools/near-bindgen-exporter.ts | 7 ++++++- src/cli/cli.ts | 6 ++++-- src/cli/utils.ts | 13 +++++++++---- 6 files changed, 33 insertions(+), 14 deletions(-) diff --git a/lib/build-tools/near-bindgen-exporter.js b/lib/build-tools/near-bindgen-exporter.js index 7abffb2d5..18b0910ea 100644 --- a/lib/build-tools/near-bindgen-exporter.js +++ b/lib/build-tools/near-bindgen-exporter.js @@ -1,4 +1,6 @@ import * as t from "@babel/types"; +import signal from "signale"; +const { Signale } = signal; /** * A list of supported method types/decorators. */ @@ -238,7 +240,9 @@ export default function () { // Insert the method override into the class declaration. path.insertAfter(createDeclaration(classNode.id, child.key.name, methodType)); if (verbose) { - console.log(`Babel ${child.key.name} method export done`); + new Signale({ + scope: "near-bindgen-exporter", + }).info(`Babel ${child.key.name} method export done.`); } } } diff --git a/lib/cli/cli.js b/lib/cli/cli.js index 132b6c92c..e10292dae 100755 --- a/lib/cli/cli.js +++ b/lib/cli/cli.js @@ -30,7 +30,7 @@ export async function buildCom(source, target, { verbose = false }) { const TARGET_DIR = dirname(target); const TARGET_EXT = target.split(".").pop(); const TARGET_FILE_NAME = basename(target, `.${TARGET_EXT}`); - const signale = new Signale({ scope: "build", interactive: true }); + const signale = new Signale({ scope: "build", interactive: !verbose }); if (TARGET_EXT !== "wasm") { signale.error(`Unsupported target ${TARGET_EXT}, make sure target ends with .wasm!`); process.exit(1); @@ -94,7 +94,7 @@ async function createHeaderFileWithQjsc(rollupTarget, qjscTarget, verbose = fals async function createMethodsHeaderFile(rollupTarget, verbose = false) { const buildPath = path.dirname(rollupTarget); if (verbose) { - console.log(rollupTarget); + new Signale({ scope: "method-header" }).info(rollupTarget); } const mod = await import(`${PROJECT_DIR}/${rollupTarget}`); const exportNames = Object.keys(mod); diff --git a/lib/cli/utils.js b/lib/cli/utils.js index 725944ba1..f2967311d 100644 --- a/lib/cli/utils.js +++ b/lib/cli/utils.js @@ -1,22 +1,25 @@ import childProcess from "child_process"; import { promisify } from "util"; +import signal from "signale"; +const { Signale } = signal; const exec = promisify(childProcess.exec); export async function executeCommand(command, verbose = false) { + const signale = new Signale({ scope: "exec", interactive: !verbose }); if (verbose) { - console.log(command); + signale.info(`Running command: ${command}`); } try { const { stdout, stderr } = await exec(command); if (stderr && verbose) { - console.error(stderr); + signale.error(stderr); } if (verbose) { - console.log(stdout); + signale.info(`Command output: ${stdout}`); } return stdout.trim(); } catch (error) { - console.log(error); + signale.error(error); process.exit(1); } } diff --git a/src/build-tools/near-bindgen-exporter.ts b/src/build-tools/near-bindgen-exporter.ts index bcafae19c..94a0a0b19 100644 --- a/src/build-tools/near-bindgen-exporter.ts +++ b/src/build-tools/near-bindgen-exporter.ts @@ -1,6 +1,9 @@ import { PluginPass } from "@babel/core"; import { Node, Visitor } from "@babel/traverse"; import * as t from "@babel/types"; +import signal from "signale"; + +const { Signale } = signal; /** * A list of supported method types/decorators. @@ -388,7 +391,9 @@ export default function (): { visitor: Visitor } { ); if (verbose) { - console.log(`Babel ${child.key.name} method export done`); + new Signale({ + scope: "near-bindgen-exporter", + }).info(`Babel ${child.key.name} method export done.`); } } } diff --git a/src/cli/cli.ts b/src/cli/cli.ts index 5f1a7f84c..67609daff 100755 --- a/src/cli/cli.ts +++ b/src/cli/cli.ts @@ -43,7 +43,7 @@ export async function buildCom( const TARGET_DIR = dirname(target); const TARGET_EXT = target.split(".").pop(); const TARGET_FILE_NAME = basename(target, `.${TARGET_EXT}`); - const signale = new Signale({ scope: "build", interactive: true }); + const signale = new Signale({ scope: "build", interactive: !verbose }); if (TARGET_EXT !== "wasm") { signale.error( @@ -143,7 +143,9 @@ async function createMethodsHeaderFile(rollupTarget: string, verbose = false) { const buildPath = path.dirname(rollupTarget); if (verbose) { - console.log(rollupTarget); + new Signale({scope: "method-header"}).info( +rollupTarget + ) } const mod = await import(`${PROJECT_DIR}/${rollupTarget}`); diff --git a/src/cli/utils.ts b/src/cli/utils.ts index 40d59b896..4c8f2e6e1 100644 --- a/src/cli/utils.ts +++ b/src/cli/utils.ts @@ -1,5 +1,8 @@ import childProcess from "child_process"; import { promisify } from "util"; +import signal from "signale" + +const {Signale} = signal; const exec = promisify(childProcess.exec); @@ -7,24 +10,26 @@ export async function executeCommand( command: string, verbose = false ): Promise { + const signale = new Signale({scope: "exec", interactive: !verbose}) + if (verbose) { - console.log(command); + signale.info(`Running command: ${command}`); } try { const { stdout, stderr } = await exec(command); if (stderr && verbose) { - console.error(stderr); + signale.error(stderr); } if (verbose) { - console.log(stdout); + signale.info(`Command output: ${stdout}`); } return stdout.trim(); } catch (error) { - console.log(error); + signale.error(error); process.exit(1); } }