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

One of the things that many developers find disorientating about Deno is the fact that it doesn't have an external package manager like npm. On one side this new paradigm simplifies many aspects of development; on the other, the lack of some npm features - notably scripts - can be really limiting: Deno cli commands can become very long and difficult to track without a place to store them and there's not an easy way to share workflow scripts, git hooks and external tooling with contributors. Velociraptor…

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 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 May 14 by:

umbo profile

Umberto Pepato

@umbo

Web dev • Dev team @ Google Developer Group Torino #webcomponents #usetheplatform

Discussion

markdown guide
 

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