loading...
Cover image for Velociraptor, an alternative to npm scripts for Deno

Velociraptor, an alternative to npm scripts for Deno

umbo profile image Umberto Pepato Updated on ・2 min read

I've been playing around with Deno in the last few months (if you haven't already, try it out, it's awesome) and one of the things that frustrated me the most was that I easily ended up writing endless deno cli commands, like this:

deno run --allow-read --allow-write --allow-net --config tsconfig.json --importmap importmap.json --reload file.ts

I mean... I just wrote it and I've already forgotten it 🤦‍♂️

The instinctive reaction of my webdev-y brain was:

Easy. Let's write it down in a package.json script.

Yeah, no. There ain't no package.json in the land of Deno.

So I left aside my acute npm run nostalgia and started working on an alternative for Deno, and after some weeks of coding here it is:

GitHub logo umbopepato / velociraptor

An alternative to npm scripts for Deno

Velociraptor is a script runner for Deno, inspired by npm's package.json scripts. It offers a similar experience but with out-of-the-box support for declarative deno cli options, environment variables, concurrency and (soon) git hooks

CI Version GitHub stars vr scripts

Motivation

Deno doesn't have a dedicated package manager like npm. While this simplifies many aspects of development, working without the added tooling that npm comes with (such as scripts) may turn out to be challenging: as projects grow Deno cli commands can become quite long and difficult to track and there's not an easy way to share workflow scripts, git hooks and external tooling with collaborators. Velociraptor tries to provide a relatively lightweight solution to these problems by expanding the concept of npm scripts.

Install

Deno.land

$ deno
…

To get started, install it with deno install:

deno install -qA -n vr https://deno.land/x/velociraptor/cli.ts

Then create a file called scripts.yaml (.json and .ts are supported as well) in your project folder

scripts:
  start: deno run my-script-file.ts

and run the start command

$ vr start

In this form script files are essentially a remake of the scripts section of package.json: keys are script names, values are arbitrary shell scripts. But there's more.

More script options

Use objects to superpower your scripts:

scripts:
  start:
    cmd: deno run server.ts
    desc: Starts the server # This description is shown in the list
                            # of available scripts when running vr
                            # without arguments

Compact deno run

When a script starts with a .ts or .js file, deno run is automatically prepended:

scripts:
  start: server.ts # Equivalent to deno run server.ts

Env variables

Use env to pass env variables to the scripts

env: # Sent to all the scripts
  PORT: 80
scripts:
  start-dev:
    cmd: server.ts
    env: # script-specific override
      PORT: 8080
  start-prod: deno run server.ts

Deno cli options

A subset of deno cli options can be passed to the scripts (to name a few: --allow-* permissions, tsconfig.json, import maps, lock files...)

scripts:
  start:
    cmd: server.ts
    allow:
      - net
      - read
    tsconfig: tsconfig.json
    imap: importmap.json

allow: # Global options
  - write

Compound scripts

A list of commands is executed in series

scripts:
  start:
    - deno run one.ts
    - deno run two.ts

and parallel commands are supported as well

scripts:
  start:
    pll:
      - deno run one.ts
      - deno run two.ts

Bonus

Support for husky-style git hooks is coming soon! 🐶

Check out the documentation in the repo for more details.

Hope you'll find it useful! 🙌

Posted on by:

umbo profile

Umberto Pepato

@umbo

Full stack engineer @ CircleR • Dev team @ Google Developer Group Torino #webcomponents #usetheplatform

Discussion

pic
Editor guide
 

This was Eazy. Thank you!
Denon didn't watch subfolders (windows 10). deno --watch released about <30 minutes ago. Compiled latest .exe but couldn't get denon to launch deno anymore but this works like a charm.

 

Whoa great job, very useful and easy to use without overkill features. Should become Deno official script runner! Looking forward to husky-style git hooks

 

Just like Robo, but with concurrently.