命令行界面
Deno是一個命令行程序。到目前為止,您應(yīng)該已經(jīng)熟悉了一些簡單的命令,并且已經(jīng)了解了Shell使用的基本知識。
查看幫助的方法有多種:
# Using the subcommand.
deno help
# Using the short flag -- outputs the same as above.
deno -h
# Using the long flag -- outputs more detailed help text where available.
deno --help
Deno的CLI是基于子命令的。上面的命令應(yīng)該向您顯示受支持的列表,例如deno bundle。要查看針對的子命令特定的幫助 bundle,您可以類似地運(yùn)行以下之一:
deno help bundle
deno bundle -h
deno bundle --help
有關(guān)每個子命令的詳細(xì)指南,請參見此處。
腳本源
Deno可以從多個來源,文件名,URL和“-”中獲取腳本,以從stdin中讀取文件。最后一個對于與其他應(yīng)用程序集成很有用。
deno run main.ts
deno run https://mydomain.com/main.ts
cat main.ts | deno run -
腳本參數(shù)
與Deno運(yùn)行時標(biāo)志分開,可以通過在腳本名稱后指定用戶空間參數(shù)來將它們傳遞給正在運(yùn)行的腳本:
deno run main.ts a b -c --quiet
// main.ts
console.log(Deno.args);
// [ "a", "b", "-c", "--quiet" ]
請注意,在腳本名稱之后傳遞的所有內(nèi)容都將作為腳本參數(shù)傳遞,并且不用作Deno運(yùn)行時標(biāo)志。這導(dǎo)致了以下陷阱:
# Good. We grant net permission to net_client.ts.
deno run --allow-net net_client.ts
# Bad! --allow-net was passed to Deno.args, throws a net permission error.
deno run net_client.ts --allow-net
有人認(rèn)為這是非常規(guī)的:
非位置標(biāo)志的解析取決于其位置。
然而:
- 這是區(qū)分運(yùn)行時標(biāo)志和腳本參數(shù)的最合乎邏輯的方法。
- 這是區(qū)分運(yùn)行時標(biāo)志和腳本參數(shù)的最符合人體工程學(xué)的方法。
- 實際上,這是與任何其他流行的運(yùn)行時相同的行為。
- 嘗試
node -c index.js和node index.js -c。第一個將僅index.js根據(jù)Node的-c標(biāo)志進(jìn)行語法檢查。第二個將 執(zhí)行index.js與-c傳遞require("process").argv。
- 嘗試
存在相關(guān)子命令之間共享的邏輯標(biāo)志組。我們在下面討論這些。
觀看模式
您可以提供--watch標(biāo)志以deno run啟用內(nèi)置文件監(jiān)視程序。當(dāng)Deno使用此標(biāo)志啟動時,它將監(jiān)視入口點(diǎn),并且入口點(diǎn)將靜態(tài)導(dǎo)入所有本地文件。只要更改磁盤上的這些文件之一,該程序就會自動重新啟動。
注意:文件監(jiān)視程序是一項新功能,仍然不穩(wěn)定,因此需要 --unstable標(biāo)記
deno run --watch --unstable main.ts
完整性標(biāo)志
影響可以下載資源到緩存命令deno cache, deno run和deno test。
--lock <FILE> Check the specified lock file
--lock-write Write lock file. Use with --lock.
緩存和編譯標(biāo)志
影響可以填充緩存命令deno cache,deno run和 deno test。以及上面的標(biāo)志包括那些影響模塊分辨率,編譯配置等的標(biāo)志。
--config <FILE> Load tsconfig.json configuration file
--import-map <FILE> UNSTABLE: Load import map file
--no-remote Do not resolve remote modules
--reload=<CACHE_BLOCKLIST> Reload source code cache (recompile TypeScript)
--unstable Enable unstable APIs
運(yùn)行時標(biāo)志
影響執(zhí)行用戶代碼的命令:deno run和deno test。這些包括以上所有內(nèi)容以及以下內(nèi)容。
權(quán)限標(biāo)志
這些在這里列出。
其他運(yùn)行時標(biāo)志
更多影響執(zhí)行環(huán)境的標(biāo)志。
--cached-only Require that remote dependencies are already cached
--inspect=<HOST:PORT> activate inspector on host:port ...
--inspect-brk=<HOST:PORT> activate inspector on host:port and break at ...
--seed <NUMBER> Seed Math.random()
--v8-flags=<v8-flags> Set V8 command line options. For help: ...