From 5730effc0d49c323589ec2c52ff2acb7cb0802ed Mon Sep 17 00:00:00 2001 From: ZeroEkkusu <94782988+ZeroEkkusu@users.noreply.github.com> Date: Mon, 26 Aug 2024 12:10:07 +0200 Subject: [PATCH] feat: sleek dx --- solx/hooks.sh | 6 +++--- solx/transpiler.ts | 34 ++++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/solx/hooks.sh b/solx/hooks.sh index 9ab031e..370d451 100644 --- a/solx/hooks.sh +++ b/solx/hooks.sh @@ -1,8 +1,8 @@ -# Override for 'forge build' and 'forge test' +# Override for 'forge build', 'forge test', 'forge b', and 'forge t' forge() { - if [ "$1" = "build" ]; then + if [ "$1" = "build" ] || [ "$1" = "b" ]; then bun solx/transpiler.ts && command forge build "${@:2}" - elif [ "$1" = "test" ]; then + elif [ "$1" = "test" ] || [ "$1" = "t" ]; then bun solx/transpiler.ts && command forge test "${@:2}" else command forge "$@" diff --git a/solx/transpiler.ts b/solx/transpiler.ts index 71156a9..6d9a90d 100644 --- a/solx/transpiler.ts +++ b/solx/transpiler.ts @@ -15,18 +15,31 @@ function processSolidityFile(inputPath: string): void { fs.mkdirSync(outputDir, { recursive: true }); } - const outputSolPath = path.join( - outputDir, - path.basename(inputPath).replace(".solx", ".sol") - ); - const outputTsPath = path.join(outputDir, "example.ts"); + if (solidity) { + // Write the processed Solidity file + const outputSolPath = path.join( + outputDir, + path.basename(inputPath).replace(".solx", ".sol") + ); + fs.writeFileSync(outputSolPath, solidity); + } - fs.writeFileSync(outputSolPath, solidity); - fs.writeFileSync(outputTsPath, typescript); + if (typescript) { + // Write the TypeScript file if it exists + const outputTsPath = path.join(outputDir, "example.ts"); + fs.writeFileSync(outputTsPath, typescript); + } + + // Exit silently if no TypeScript block was found + if (!typescript) { + return; + } - /*console.log(`Processed ${inputPath}`); + /* + console.log(`Processed ${inputPath}`); console.log(`Generated ${outputSolPath}`); - console.log(`Generated ${outputTsPath}`);*/ + console.log(`Generated ${outputTsPath}`); + */ } function extractTypeScriptBlock(content: string): ProcessedContent { @@ -35,7 +48,8 @@ function extractTypeScriptBlock(content: string): ProcessedContent { const match = tsBlockRegex.exec(content); if (!match) { - throw new Error("No TypeScript block found in the Solidity file."); + // If no TypeScript block is found, return the content as Solidity only + return { solidity: content, typescript: "" }; } const [fullMatch, inputVars, tsCode, outputVars] = match;