Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Print transformed result to stdout if no output dir is given #897

Merged
merged 5 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from 'fs';
import * as path from 'path';
import { Command } from 'commander';
import { replaceSuffix, isValidSolFile, outputResult } from './io';
import { isValidSolFile, outputResult } from './io';
import { compileSolFiles } from './solCompile';
import { handleTranspilationError, transform, transpile } from './transpiler';
import { analyseSol } from './utils/analyseSol';
Expand Down Expand Up @@ -176,7 +176,7 @@ export function runTransform(file: string, options: CliOptions) {
const mFile = path.relative(process.cwd(), file);
const ast = compileSolFiles([mFile], options);
transform(ast, options).map(([name, solidity]) => {
outputResult(replaceSuffix(name, '_warp.sol'), solidity, options, ast);
outputResult(name, solidity, options, ast, true);
});
} catch (e) {
handleTranspilationError(e);
Expand Down
9 changes: 7 additions & 2 deletions src/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export function outputResult(
code: string,
options: OutputOptions & TranspilationOptions,
ast: AST,
_transform = false,
): void {
if (options.outputDir !== undefined) {
if (fs.existsSync(options.outputDir)) {
Expand All @@ -82,12 +83,16 @@ export function outputResult(
abiOutPath,
JSON.stringify(ast.solidityABI.contracts[solFilePath][contractName]['abi'], null, 2),
);
outputFileSync(fullCodeOutPath, code);

outputFileSync(
_transform ? replaceSuffix(fullCodeOutPath, '_warp.cairo') : fullCodeOutPath,
rjnrohit marked this conversation as resolved.
Show resolved Hide resolved
code,
);
// Cairo-format is disabled, as it has a bug
// if (options.formatCairo || options.dev) {
// const warpVenvPrefix = `PATH=${path.resolve(__dirname, '..', 'warp_venv', 'bin')}:$PATH`;
// execSync(`${warpVenvPrefix} cairo-format -i ${fullCodeOutPath}`);
// }
} else {
console.log(`//--- ${outputPath} ---\n${code}\n//---`);
}
}