Skip to content

Commit

Permalink
refactor: migrate sh script to mjs
Browse files Browse the repository at this point in the history
  • Loading branch information
alanrsoares committed Nov 8, 2023
1 parent a7af035 commit fe77f8e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 46 deletions.
49 changes: 49 additions & 0 deletions packages/evm/bin/cli.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env zx
import { $, argv } from "zx";

// List of valid commands
const VALID_COMMANDS = ["codegen"];

async function getNpxCompatibleCommand() {
const commands = ["npx", "pnpx", "bunx"];

for (const cmd of commands) {
try {
await $`command -v ${cmd}`;
return cmd; // Return early if the command is found
} catch {
continue; // Continue to the next iteration if the command is not found
}
}
}

async function run() {
const COMMAND = argv._[1];

const NPX_COMMAND = await getNpxCompatibleCommand();

switch (COMMAND) {
case "codegen":
{
const { src, out, flatten, exclude } = argv;

await $`${NPX_COMMAND} tsx ./scripts/codegen.ts --src ${src} --out ${out} --exclude ${exclude} ${
flatten ? "--flatten" : ""
}`;
}
break;
default:
await $`echo unknown command received: '${COMMAND}'`;
await $`echo valid commands:`;

// eslint-disable-next-line no-undef
VALID_COMMANDS.forEach((cmd) => console.log(` * ${cmd}`));
}
}

run().catch((e) => {
// eslint-disable-next-line no-undef
console.error(e);
// eslint-disable-next-line no-undef
process.exit(1);
});
45 changes: 0 additions & 45 deletions packages/evm/bin/cli.sh

This file was deleted.

2 changes: 1 addition & 1 deletion packages/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"./clients.js",
"./clients.d.ts"
],
"bin": "./bin/cli.sh",
"bin": "./bin/cli.mjs",
"exports": {
".": {
"import": "./build/module/index.js",
Expand Down

0 comments on commit fe77f8e

Please sign in to comment.