Skip to content

Commit

Permalink
feat: sleek dx
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroEkkusu committed Aug 26, 2024
1 parent f920352 commit 5730eff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
6 changes: 3 additions & 3 deletions solx/hooks.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
Expand Down
34 changes: 24 additions & 10 deletions solx/transpiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down

0 comments on commit 5730eff

Please sign in to comment.