DEV Community

A simple way to replace npm scripts in Deno

Heiker on May 14, 2020

Update 2022-04-13: Since version 1.20 deno now includes a task runner. You can find the details in the release note: new subcommand deno task. F...
Collapse
 
bentoumitech profile image
Khaled Bentoumi

Thanks for the article, I've been also working on a tool to replace npm scripts in Deno.

It uses YAML and currently supports permissions github.com/BentoumiTech/denox/

Collapse
 
vintprox profile image
Rodion Borisov

AFAIK, they are going to make denox run as alias to denox run default, so it's even faster to type than denox start. Clear and concise IMO!

Collapse
 
vintprox profile image
Rodion Borisov

denon, velociraptor, and trex seem promising. I think that they have more chances to be widespread.

Collapse
 
vonheikemen profile image
Heiker

Looks really good. I see that it can run a selected file with the permissions, but what about random commands? Is there a plan for that?

Collapse
 
09wattry profile image
Ryan

I was able to use the code from this article and the denox package to create a similar npm feel. If you pass your script in as a string then split the script on the spaces to get your arguments it becomes much more usable.

If Khaled added a logical check on the config file to check if a file or script is being provided I'm sure we could achieve the desired outcome.

async function exec(script: String): Promise<any> {
  const args = script.split(' ');
  const proc = await Deno.run({ cmd: args }).status();

  if(proc.success == false) {
    Deno.exit(proc.code);
  }

  return proc;
}

export default exec;
Collapse
 
09wattry profile image
Ryan

github.com/BentoumiTech/denox/pull/15 I took the liberty to add the functionality you're looking for. Denox is a pretty awesome package so hopefully, this gets picked up.

Collapse
 
nepalilab profile image
Nepali Lab

Yeah, so much true. I was learning Deno and the pain of writing flags for each network or dotenv files burns me up. Was looking for a solution. Thank you for the article.

Collapse
 
44a6z22 profile image
HAMDAOUI Hamza • Edited

Thanks for your Article.
Here's a tutorial on how to make an Alias in PowerShell

Collapse
 
vonheikemen profile image
Heiker

Thanks.

I've added the alias example on powershell. I hope I got it right.

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

I think robo is nice. YAML is so much better than JSON, only inferior to real scripts.

Collapse
 
vonheikemen profile image
Heiker

It does look nice. I've been using task, it also uses YAML but I think it has more features. But really like how robo handle the arguments for the subcommands.

While on the subject of task runners, a few days ago I saw this one: mask. It uses markdown files to define the options of the subcommands. I haven't use it but it looks really cool.

Collapse
 
kerryboyko profile image
Kerry Boyko

Hey, I turned Taskfile.js into Taskfile.ts and added some typing info. Let me know what you think.
gist.github.com/brianboyko/735c9d9...

Collapse
 
vonheikemen profile image
Heiker

It's awesome. May I suggest a "task" to list the other available tasks in the object. I do something like this:

run(Deno.args, {
  start(...args) {
    exec(["deno", "run", entrypoint, ...args]);
  },
  // others tasks....
  list() {
    Object.keys(this).forEach((k) => console.log(k));
  },
});
Enter fullscreen mode Exit fullscreen mode