Skip to content

Instantly share code, notes, and snippets.

@Vehmloewff
Created December 18, 2024 20:53
Show Gist options
  • Save Vehmloewff/cc4c7d9944739a39974f5e1f2fd723bd to your computer and use it in GitHub Desktop.
Save Vehmloewff/cc4c7d9944739a39974f5e1f2fd723bd to your computer and use it in GitHub Desktop.
Run a typescript function directly
#!/bin/bash
filepath=$1
funcname=$2
[[ $filepath != *.ts ]] && filepath="$filepath.ts"
dataurl='data:text/typescript,import { '$funcname' } from "file://'$(pwd)'/'$filepath'";console.log(await '$funcname'());'
deno run -A "$dataurl"
@Vehmloewff
Copy link
Author

Vehmloewff commented Dec 18, 2024

Install it like so:

sudo curl https://gist.githubusercontent.com/Vehmloewff/cc4c7d9944739a39974f5e1f2fd723bd/raw/1711ad92c397fcb3f2578233dcf074eee183dc1d/drun.sh -o /usr/local/bin/drun
sudo chmod 755 /usr/local/bin/drun

Then, assuming a foo.ts file exists in the cwd and that it exports a bar function, run it like so:

drun foo bar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment