DEV Community

Shawn Bullock
Shawn Bullock

Posted on

A better way to launch Deno with many command options

Deno, like many other compiler or script runners, can require a complex list of options to type in at the command line. I wanted an easier to way run Deno.

I created Zap as a way to solve that problem (currently MacOS but I'm currently updating it to run on Windows -- stay tuned). Zap uses a configuration file to store all the options and launches Deno using them.

It also loads .env files to load environment variables.

To install, type:

$ deno install -Af -n zap https://deno.land/x/gh:deno-nonstd:zap/app.ts

NOTE: If you haven't previously added /.deno/bin to your $PATH variable, then you will need to or Deno won't run the utility. It seems to be different for everyone (even on OSX) but this worked for me:

$ echo '/User/<name>/.deno/bin' | sudo tee /etc/paths.d/deno

Then any NEW command window or app started will see the path.

To use, Instead of typing:

$ deno run --allow-env --allow-net=google.com,deno.land --allow-read unstable app.ts

You can provide a config file like this (default name is launch.yaml):

deno:
  run:
    main: app.ts
    dotenv: main.env
    security:
      allow-env: true
      allow-read: true
      allow-net:
        - google.com
        - deno.land

  install:
    main: app.ts
    security:
      allow-env: true

    options:
      force: true
      name: sampleApp

Notice there is a run and install. Each is called a profile. You can configure each of them separately.

You can launch your app now like any of the below:

$ zap run

Or

$ zap install

And Zap will do the rest.

To initialize with a default profile, type:

$ zap init launch.yaml

And it'll put a default file there named launch.yaml. launch is the default name that Zap looks for, so you won't need to provide it when running.

If you want to initialize a .dotenv file, just type:

$ zap init dev.env

And it'll create a file with that name. You can tell zap to load from the .dotenv file with an option named dotenv like this:

deno:
  run:
    main: app.ts
    dotenv: main.env
    ...

You can configure and use any of the valid Deno subcommands. The format for a launch file looks like this:

File Name: launch.yaml

deno:
  <command> # run, install, cache, test, fmt, etc
  main: <starting file name>
  dotenv: <file name> # if desired
  security:
    allow-all: true # true for on, empty for false
    allow-net: true # true for blanket enable OR...
    allow-net:
      - google.com
      - deno.land.  # to whitelist 
    ...             # any valid security option (--allow-...)
  options:
    ... any valid option, using same rules as above

There's a ton of more features currently in the works such as:

  • Embed zap into your own app
  • Add new features via extensibility
  • Daisy chaining and conditions pre/post launch

You can find the github repo here. This is an early release. Contributions are welcome if you're interested to help out.

Top comments (0)