generated at
dax
概要
zxDenoに移植したライブラリ
dprintts-morphなどの作者であるdsherretさんが開発しています
deno taskの内部でも使用されているdeno_task_shellをベースに実装されており、Windowsにおいても様々なUnixコマンドが利用できます

インストール
shell
$ deno add jsr:@david/dax
deno addを実行しておくと、以下のようにしてdaxを読み込むことができます
typescript
import $ from "@david/dax"

ロギング
デフォルトでは標準エラーにログが出力されるようです ( $.setInfoLogger $.setWarnLogger などのAPIでカスタマイズ可能)
typescript
// 最初のワードが強調表示されます $.logStep("Downloading files..."); $.logError("Failed to download files");

ヘルパー
ファイルの存在を確認
typescript
await $.exists("./some-file.txt");
HTTPリクエストを送信
typescript
await $.request("https://dl.deno.land/canary-latest.txt").text();
Path
$.path により Path オブジェクトが返却されます
typescript
const tmpDir = $.path(new URL("../tmp", import.meta.url)); // ファイルシステム関連の操作 await tmpDir.ensureDir(); await tmpDir.exists(); // => true tmpDir.toString(); // => string // コマンドの引数として渡すこともできます await $`cat ${tmpDir}`;

deno replと併用すると、インタラクティブにdaxを試すことができます
shell
$ deno repl > import $ from "@david/dax" > await $`cat ${$.path("./mod.ts")}`


その他
.wasmファイルの保存場所
Linuxだと ~/.local/share/dax (XDG_DATA_HOME配下の dax ディレクトリ)

リンク
dax - Cross-platform shell tools for Node.js - 作者のdsherret氏による解説記事

関連パッケージ

関連ページ