安装Denon
deno install --allow-read --allow-run --allow-write --allow-net -f -q --unstable https://deno.land/x/denon@2.4.0/denon.ts
用法
可以直接使用denon命令运行程序,可以传递deno命令支持的所有参数:
$ denon run --allow-env app.ts --arg-for-my-app
更常用来运行script:
$ denon [script name]
配置
支持json和yaml两种格式的配置文件。
运行如下命令创建denon.json文件:
$ denon --init
生成的文件内容如下:
{
// optional but highly recommended
"$schema": "https://deno.land/x/denon/schema.json",
"scripts": {
"start": {
"cmd": "deno run app.ts",
"desc": "run my app.ts file"
}
}
}
也可以使用denon.yml文件:
scripts:
start:
cmd: "deno run app.ts"
desc: "run my app.ts file"
Script选项
简单的scripts:
{
"scripts": {
// they all resolve to `deno run app.ts` when you run `denon start`
"start": "app.ts",
// OR
"start": "run app.ts",
// OR
"start": "deno run app.ts"
}
}
也可以定义复杂的script对象。denon script支持环境变量、权限、tsconfig、imap、log等选项,可以配置是否监视文件,详细信息请查阅官方文档,一些选项的含义可以查看下节Deno CLI。
{
// globally applied to all scripts
// now denon will essentialy be a script runner
"watch": false
// globally applied to all scripts
"env": {
"TOKEN": "SUPER SECRET TOKEN",
},
// globally applied to all scripts
// as object ...
"allow": {
"read": "/etc,/tmp", // --allow-read=/etc,/tmp
"env": true // --allow-env
},
// ... or as array
"allow": [
"run", // --allow-run
"net" // --allow-net
]
"scripts": {
"start": {
"cmd": "deno run app.ts",
"desc": "Run the main server.",
"importmap": "importmap.json",
"tsconfig": "tsconfig.json",
"log": "debug", // or "info"
"unstable": true,
// you can still enable watch on a script-by-script basis
"watch": true,
"inspect": "127.0.0.1:9229",
// OR
"inspectBrk": "127.0.0.1:9229"
"env": {
"PORT": 3000
},
// specific for a single script
// as object ...
"allow": {
"read": "/etc,/tmp", // --allow-read=/etc,/tmp
"env": true // --allow-env
},
// ... or as array
"allow": [
"run", // --allow-run
"net" // --allow-net
]
}
}
}