octoherd / cli

CLI to run a octoherd scripts on one or multiple repositories
ISC License
103 stars 9 forks source link

Use Deno #5

Open gr2m opened 3 years ago

gr2m commented 3 years ago

I think the CLI would be a great use case to use Deno. Scripts and dependencies could be loaded directly from a remote URL, and Deno has a better security system.

gr2m commented 3 years ago

Something like this would be cool

deno run --allow-net=api.github.com https://octoherd.dev/scripts/star-or-unstar
jsg2021 commented 3 years ago

Isn't running a script from a url generally frowned on tho?

gr2m commented 3 years ago

not with deno. It has a similar sandbox as browsers do.

It's probably more secure than running

npx my-star-or-unstar-cli
jsg2021 commented 3 years ago

Awesome, I didn't know that about deno. :)

gr2m commented 3 years ago

The first step will be to create a deno version of the CLI.

Node introduced the convention of conditional exports. And skypack seems to support exports for different environments such as deno, they mention it at https://docs.skypack.dev/package-authors/package-checks#export-map

image

Changing

{ 
  "exports": "./bin/octoherd.js"
}

to

{ 
  "exports": {
    "node": "./bin/octoherd-node.js",
    "node": "./bin/octoherd-deno.js"
  }
}

Maybe we can also make the current CLI just work with Deno out of the box, but I'm not familiar enough with Deno to debug the errors I currently see.

Once we have a valid Deno export and Skypack supports it, a script such as the above mentiond https://octoherd.dev/scripts/star-or-unstar could

  1. import the CLI from https://cdn.skypack.dev/@octoherd/cli
  2. import the chosen script, e.g. if it's its own npm package it would import it from https://cdn.skypack.de/@octoherd/script-star-or-unstar
  3. then it would read the options such as the GitHub token, the repositories, and script options from CLI arguments or prompts and finally run the script

I'd love help with this.