dax
#Deno #shell
概要
zxをDenoに移植したライブラリ
dprintやts-morphなどの作者であるdsherretさんが開発しています
deno taskの内部でも使用されているdeno_task_shellをベースに実装されており、Windowsにおいても様々なUnixコマンドが利用できます
インストール
code:shell
$ deno add jsr:@david/dax
deno addを実行しておくと、以下のようにしてdaxを読み込むことができます
code:typescript
import $ from "@david/dax"
ロギング
デフォルトでは標準エラーにログが出力されるようです ($.setInfoLoggerや$.setWarnLoggerなどのAPIでカスタマイズ可能)
code:typescript
// 最初のワードが強調表示されます
$.logStep("Downloading files...");
$.logError("Failed to download files");
ヘルパー
ファイルの存在を確認
code:typescript
await $.exists("./some-file.txt");
HTTPリクエストを送信
code:typescript
await $.request("https://dl.deno.land/canary-latest.txt").text();
Path
$.pathによりPathオブジェクトが返却されます
code:typescript
const tmpDir = $.path(new URL("../tmp", import.meta.url));
// ファイルシステム関連の操作
await tmpDir.ensureDir();
await tmpDir.exists(); // => true
tmpDir.toString(); // => string
// コマンドの引数として渡すこともできます
await $cat ${tmpDir};
REPL
deno replと併用すると、インタラクティブにdaxを試すことができます
code: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氏による解説記事
Lost scrobbles and JavaScript Jupyter Notebooks
Web APIs and Shell Scripts: Scripting with Deno
Deno first でやっていく
関連パッケージ
dax_extras
zx
関連ページ
dax, Bun Shell, zxの比較