Skip to content

Commit

Permalink
fix: Fix logging (#311)
Browse files Browse the repository at this point in the history
Use local instances of signale to scope them to commands and make them
interactive
  • Loading branch information
petarvujovic98 authored Nov 28, 2022
1 parent b0b0f50 commit 0a68418
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 38 deletions.
2 changes: 1 addition & 1 deletion examples/src/cross-contract-call-loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const NO_ARGS = "";
const THIRTY_TGAS = BigInt("30" + "0".repeat(12));

@NearBindgen({})
class LoopXCC {
export class LoopXCC {
constructor() {
this.count = 0;
}
Expand Down
4 changes: 0 additions & 4 deletions jsconfig.json

This file was deleted.

2 changes: 1 addition & 1 deletion lib/cli/cli.d.ts

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

31 changes: 18 additions & 13 deletions lib/cli/cli.js

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

45 changes: 28 additions & 17 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ program
.argument("[source]", "Contract to build.", "src/index.js")
.argument("[target]", "Target file path and name. The default corresponds to contract.js", "build/contract.wasm")
.option("--verbose", "Whether to print more verbose output.", false)
.action(createJsFileWithRullupCom)
.action(createJsFileWithRollupCom)
)
.addCommand(
new Command("transpileJsAndBuildWasm")
Expand Down Expand Up @@ -83,7 +83,7 @@ function getRollupTarget(target: string): string {
return `${getTargetDir(target)}/${getTargetFileName(target)}.js`
}

function getQjscTarget(target:string): string {
function getQjscTarget(target: string): string {
return `${getTargetDir(target)}/${getTargetFileName(target)}.h`;
}

Expand Down Expand Up @@ -112,68 +112,79 @@ function ensureTargetDirExists(target: string): void {
fs.mkdirSync(targetDir, {});
}

export async function validateCom(source: string, { verbose = false}: {verbose: boolean}): Promise<void> {
signal.await(`Validating ${source} contract...`);
export async function validateCom(source: string, { verbose = false }: { verbose: boolean }): Promise<void> {
const signale = new Signale({ scope: "validate", interactive: !verbose });

signale.await(`Validating ${source} contract...`);

if (!await validateContract(source, verbose)) {
process.exit(1);
}
}

export async function checkTypescriptCom(source: string, { verbose = false}: {verbose: boolean}): Promise<void> {
export async function checkTypescriptCom(source: string, { verbose = false }: { verbose: boolean }): Promise<void> {
const signale = new Signale({ scope: "checkTypescript", interactive: !verbose });

const sourceExt = source.split(".").pop();
if (sourceExt !== "ts") {
signal.info(`Source file is not a typescript file ${source}`)
signale.info(`Source file is not a typescript file ${source}`)
return;
}

signal.await(`Typechecking ${source} with tsc...`);
signale.await(`Typechecking ${source} with tsc...`);
await checkTsBuildWithTsc(source, verbose);
}

export async function createJsFileWithRullupCom(source: string, target: string, { verbose = false}: {verbose: boolean}): Promise<void> {
export async function createJsFileWithRollupCom(source: string, target: string, { verbose = false }: { verbose: boolean }): Promise<void> {
const signale = new Signale({ scope: "createJsFileWithRollup", interactive: !verbose });

requireTargetExt(target);
ensureTargetDirExists(target);

signal.await(`Creating ${source} file with Rollup...`);
signale.await(`Creating ${source} file with Rollup...`);
await createJsFileWithRullup(source, getRollupTarget(target), verbose);
}


export async function transpileJsAndBuildWasmCom(target: string, { verbose = false}: {verbose: boolean}): Promise<void> {
export async function transpileJsAndBuildWasmCom(target: string, { verbose = false }: { verbose: boolean }): Promise<void> {
const signale = new Signale({ scope: "transpileJsAndBuildWasm", interactive: !verbose });

requireTargetExt(target);
ensureTargetDirExists(target);

signal.await(`Creating ${getQjscTarget(target)} file with QJSC...`);
signale.await(`Creating ${getQjscTarget(target)} file with QJSC...`);
await createHeaderFileWithQjsc(getRollupTarget(target), getQjscTarget(target), verbose);

signal.await("Generating methods.h file...");
signale.await("Generating methods.h file...");
await createMethodsHeaderFile(getRollupTarget(target), verbose);

signal.await(`Creating ${getContractTarget(target)} contract...`);
signale.await(`Creating ${getContractTarget(target)} contract...`);
await createWasmContract(getQjscTarget(target), getContractTarget(target), verbose);

signal.await("Executing wasi-stub...");
signale.await("Executing wasi-stub...");
await wasiStubContract(getContractTarget(target), verbose);

signal.success(`Generated ${getContractTarget(target)} contract successfully!`);
signale.success(`Generated ${getContractTarget(target)} contract successfully!`);
}

export async function buildCom(
source: string,
target: string,
{ verbose = false }: { verbose: boolean }
): Promise<void> {
const signale = new Signale({ scope: "build", interactive: !verbose });

requireTargetExt(target);

signal.await(`Building ${source} contract...`);
signale.await(`Building ${source} contract...`);

await checkTypescriptCom(source, { verbose });

ensureTargetDirExists(target);

await validateCom(source, { verbose });

await createJsFileWithRullupCom(source, target, { verbose });
await createJsFileWithRollupCom(source, target, { verbose });

await transpileJsAndBuildWasmCom(target, { verbose });
}
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@
"src/build-tools/include-bytes.ts",
"src/cli/cli.ts",
"src/cli/post-install.ts"
],
"exclude": ["src/cli/**/*"]
]
}

0 comments on commit 0a68418

Please sign in to comment.