DEV Community

Cover image for Velociraptor, an alternative to npm scripts for Deno
Umberto Pepato
Umberto Pepato

Posted on • Edited on

Velociraptor, an alternative to npm scripts for Deno

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
Enter fullscreen mode Exit fullscreen mode

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 jurassiscripts / velociraptor

The npm-style script runner 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 git hooks.

CI Version GitHub stars vr scripts

Documentation

To get started visit velociraptor.run.

Help

If you need any help feel free to ask in discussions or in the chat.

Badge

Show your collaborators/users you use velociraptor:

[![vr scripts](https://badges.velociraptor.run/flat.svg)](https://velociraptor.run)
Enter fullscreen mode Exit fullscreen mode

vr scripts

Contributing

Feedback and PRs are welcome! Take a look at the contributing guidelines.

License

This project is licensed under the MIT License. See LICENSE for details.






To get started, install it with deno install:

deno install -qA -n vr https://deno.land/x/velociraptor/cli.ts
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

and run the start command

$ vr start
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Compound scripts

A list of commands is executed in series

scripts:
  start:
    - deno run one.ts
    - deno run two.ts
Enter fullscreen mode Exit fullscreen mode

and parallel commands are supported as well

scripts:
  start:
    pll:
      - deno run one.ts
      - deno run two.ts
Enter fullscreen mode Exit fullscreen mode

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! 🙌

Top comments (4)

Collapse
 
fisherozzo profile image
Mimmo

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

Collapse
 
nastradoomus profile image
Helppo Elämä

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.

Collapse
 
umbo profile image
Umberto Pepato

@nastradoomus since 1.0.0-beta.14 you can also use the watch property 👀

scripts:
  start:
    cmd: server.ts
    watch: true
Enter fullscreen mode Exit fullscreen mode
Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

Just like Robo, but with concurrently.