Skip to content

Commit

Permalink
feat: Improve CLI output further
Browse files Browse the repository at this point in the history
Add proper logging to output shown when verbose flag is active
  • Loading branch information
petarvujovic98 committed Oct 17, 2022
1 parent 79a9ecb commit 3672a68
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 14 deletions.
6 changes: 5 additions & 1 deletion lib/build-tools/near-bindgen-exporter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/cli/cli.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions lib/cli/utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/build-tools/near-bindgen-exporter.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.`);
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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}`);
Expand Down
13 changes: 9 additions & 4 deletions src/cli/utils.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
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: string,
verbose = false
): Promise<string> {
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);
}
}

0 comments on commit 3672a68

Please sign in to comment.