Since it is not necessary to have package.json file with deno, how can I as a developer have a similar experience just as we have with npm scripts in package.json?
velociraptor may be of help, especially if you want to run arbitrary shell scripts.
It accepts yaml, json and ts script configuration files. The following example illustrates the main features:
# scripts.yaml
scripts:
start: deno run server.ts # Scripts can be simple command strings
opts: # Or objects
cmd: deno run server.ts
desc: Starts the server
tsconfig: tsconfig.json # Deno cli options
imap: importmap.json
allow:
- read
- net
env: # Env vars
PORT: 8080
compact: server.ts # `deno run` is automatically prepended
# when the script starts with a .ts file
multiple: # Lists of commands are executed in series
- echo one
- echo two
concurrent: # Use the pll property to declare
pll: # concurrent scripts
- echo one
- echo two
env: # Top level options are sent to all the scripts
PORT: 3000
allow:
- write
Run vr without arguments to see a list of available scripts. To execute a script run:
$ vr <script name> [additional args]...
# or
$ vr run <script name> [additional args]...
# Additional args are passed to the script
ie
vr start
Disclaimer: I'm the author
deno installYou can create executable, aliased scripts with deno install.
It will provide a thin shell/cmd wrapper for the specified main module and CLI arguments. Example:
deno install --root . -n serve --allow-read --allow-net https://deno.land/[email protected]/http/file_server.ts
The result is a serve script, similar to npm "scripts": { "serve": ... }:
./bin/serve # run `serve` script (~ npm run serve)
If the project's bin folder is added to PATH environment, the command shortens up to serve.
deno install doesbin folder, if not existentserve/serve.cmd file with following content (Windows here):
% generated by deno install %
@deno.exe "run" "--allow-read" "--allow-net" "https://deno.land/[email protected]/http/file_server.ts" %* ```
-n is the command name used later on (can be left out)--root specifies the bin root location (otherwise ~/.deno)-f option overwrites an existent aliasSide note: Any .js/.ts script is a valid reference - source code location (local/URL) does not matter. If external shell scripts are to be included, you can also run them inside a subprocess.
npm run build
// ./scripts/build.ts
// create subprocess
const p = Deno.run({
cmd: ["deno", "cache", "-r", "--unstable", "main.ts"],
});
await p.status();
deno install --root . --allow-run scripts\build.ts
./bin/build # execute build script
deno commandsDeno already comes with built-in solutions for common ecosystem tasks, e.g. bundle, fmt, test and lint later on (see deno help). You can invoke these commands directly - no need to define custom scripts:
deno test
deno fmt
deno cache -r main.ts # similar to `npm run build` / `tsc`
# ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With