CLI リファレンス
EmDash CLIは、EmDash CMSインスタンスの管理 — データベース設定、型生成、コンテンツCRUD、スキーマ管理、メディアなど — のためのコマンドを提供します。
インストール
Section titled “インストール”CLIはemdashパッケージに含まれています:
npm install emdashコマンドはnpx emdashで実行するか、package.jsonにスクリプトを追加します。バイナリは簡潔さのためにemとしても利用可能です。
実行中のEmDashインスタンスと通信するコマンド(init、seed、export-seed、auth secretを除くすべて)は、以下の順序で認証を解決します:
--tokenフラグ — コマンドラインでの明示的なトークンEMDASH_TOKEN環境変数- 保存された認証情報
~/.config/emdash/auth.jsonから(emdash loginで保存) - 開発バイパス — URLがlocalhostでトークンが利用できない場合、開発バイパスエンドポイントを介して自動的に認証
ほとんどのコマンドは--url(デフォルトhttp://localhost:4321)と--tokenフラグを受け付けます。ローカルの開発サーバーを対象とする場合、トークンは必要ありません。
これらのフラグはすべてのリモートコマンドで利用可能です:
| フラグ | エイリアス | 説明 | デフォルト |
|---|---|---|---|
--url | -u | EmDashインスタンスURL | http://localhost:4321 |
--token | -t | 認証トークン | 環境変数/保存済み認証情報から |
--json | JSONとして出力(パイプ用) | TTYから自動検出 |
標準出力がTTYの場合、CLIはconsolaで結果を整形表示します。パイプされた場合や--jsonが設定されている場合、標準出力に生のJSONを出力します — jqや他のツールに適しています。
emdash init
Section titled “emdash init”コアスキーマとオプションのテンプレートデータでデータベースを初期化します。
npx emdash init [options]| オプション | エイリアス | 説明 | デフォルト |
|---|---|---|---|
--database | -d | データベースファイルパス | ./data.db |
--cwd | 作業ディレクトリ | カレントディレクトリ | |
--force | -f | スキーマとシードを再実行 | false |
package.jsonからemdash設定を読み取る- 必要に応じてデータベースファイルを作成
- コアマイグレーションを実行(システムテーブルを作成)
- 設定されている場合、テンプレート
schema.sqlを実行 - 設定されている場合、テンプレート
seed.sqlを実行
emdash dev
Section titled “emdash dev”自動データベース設定で開発サーバーを起動します。
npx emdash dev [options]| オプション | エイリアス | 説明 | デフォルト |
|---|---|---|---|
--database | -d | データベースファイルパス | ./data.db |
--types | -t | 起動前にリモートから型を生成 | false |
--port | -p | 開発サーバーポート | 4321 |
--cwd | 作業ディレクトリ | カレントディレクトリ |
# Start dev servernpx emdash dev
# カスタムポートnpx emdash dev --port 3000
# 起動前にリモートから型を生成npx emdash dev --types- 保留中のデータベースマイグレーションをチェックして実行
--typesが設定されている場合、リモートインスタンスからTypeScript型を生成(URLはEMDASH_URL環境変数またはpackage.jsonのemdash.urlから)EMDASH_DATABASE_URLを設定してAstro開発サーバーを起動
emdash types
Section titled “emdash types”実行中のEmDashインスタンスのスキーマからTypeScript型を生成します。
npx emdash types [options]| オプション | エイリアス | 説明 | デフォルト |
|---|---|---|---|
--url | -u | EmDashインスタンスURL | http://localhost:4321 |
--token | -t | 認証トークン | 環境変数/保存済み認証情報から |
--output | -o | 型の出力パス | .emdash/types.ts |
--cwd | 作業ディレクトリ | カレントディレクトリ |
# Generate types from local dev servernpx emdash types
# リモートインスタンスから生成npx emdash types --url https://my-site.pages.dev
# カスタム出力パスnpx emdash types --output src/types/emdash.ts- インスタンスからスキーマを取得
- TypeScript型定義を生成
- 出力ファイルに型を書き込み
- 参照用に
schema.jsonを隣接して書き込み
emdash login
Section titled “emdash login”OAuth Device Flowを使用してEmDashインスタンスにログインします。
npx emdash login [options]| オプション | エイリアス | 説明 | デフォルト |
|---|---|---|---|
--url | -u | EmDashインスタンスURL | http://localhost:4321 |
- インスタンスから認証エンドポイントを検出
- localhostで認証が設定されていない場合、自動的に開発バイパスを使用
- それ以外の場合、OAuth Device Flowを開始 — コードを表示しブラウザを開く
- 認可をポーリングし、認証情報を
~/.config/emdash/auth.jsonに保存
保存された認証情報は、同じインスタンスを対象とするすべての後続コマンドで自動的に使用されます。
emdash logout
Section titled “emdash logout”ログアウトして保存された認証情報を削除します。
npx emdash logout [options]| オプション | エイリアス | 説明 | デフォルト |
|---|---|---|---|
--url | -u | EmDashインスタンスURL | http://localhost:4321 |
emdash whoami
Section titled “emdash whoami”現在認証されているユーザーを表示します。
npx emdash whoami [options]| オプション | エイリアス | 説明 | デフォルト |
|---|---|---|---|
--url | -u | EmDashインスタンスURL | http://localhost:4321 |
--token | -t | 認証トークン | 環境変数/保存済み認証情報から |
--json | JSONとして出力 |
メールアドレス、名前、ロール、認証方法、インスタンスURLを表示します。
emdash content
Section titled “emdash content”コンテンツアイテムを管理します。すべてのサブコマンドはEmDashClientを介してリモートAPIを使用します。
content list <collection>
Section titled “content list <collection>”npx emdash content list postsnpx emdash content list posts --status published --limit 10| オプション | 説明 |
|---|---|
--status | ステータスでフィルタ |
--limit | 最大アイテム数 |
--cursor | ページネーションカーソル |
content get <collection> <id>
Section titled “content get <collection> <id>”npx emdash content get posts 01ABC123npx emdash content get posts 01ABC123 --raw| オプション | 説明 |
|---|---|
--raw | 生のPortable Textを返す(マークダウン変換をスキップ) |
レスポンスには _rev トークンが含まれます — content update に渡して、上書きする前に現在の状態を確認したことを証明します。
content create <collection>
Section titled “content create <collection>”npx emdash content create posts --data '{"title": "Hello"}'npx emdash content create posts --file post.json --slug hello-worldcat post.json | npx emdash content create posts --stdin| オプション | 説明 |
|---|---|
--data | コンテンツデータを含むJSON文字列 |
--file | JSONファイルからデータを読み込む |
--stdin | 標準入力からデータを読み込む |
--slug | コンテンツスラッグ |
--status | 初期ステータス(draft, published) |
データは --data、--file、--stdin のうちのいずれか1つを介して提供してください。
content update <collection> <id>
Section titled “content update <collection> <id>”書き込み前に読み取りが必要なファイルエディターのように — 現在の状態を確認したことを証明するために、事前の get から取得した _rev トークンを提供する必要があります。これにより、未確認の変更を誤って上書きすることを防ぎます。
# 1. Read the item, note the _revnpx emdash content get posts 01ABC123
# 2. ステップ1の _rev を使用して更新npx emdash content update posts 01ABC123 \ --rev MToyMDI2LTAyLTE0... \ --data '{"title": "Updated"}'| オプション | 説明 |
|---|---|
--rev | get から取得したリビジョントークン(必須) |
--data | コンテンツデータを含むJSON文字列 |
--file | JSONファイルからデータを読み込む |
アイテムが get 実行後に変更されている場合、サーバーは409 Conflictを返します — 再読み込みして再度試してください。
content delete <collection> <id>
Section titled “content delete <collection> <id>”npx emdash content delete posts 01ABC123コンテンツアイテムをソフト削除します(ゴミ箱に移動)。
content publish <collection> <id>
Section titled “content publish <collection> <id>”npx emdash content publish posts 01ABC123content unpublish <collection> <id>
Section titled “content unpublish <collection> <id>”npx emdash content unpublish posts 01ABC123content schedule <collection> <id>
Section titled “content schedule <collection> <id>”npx emdash content schedule posts 01ABC123 --at 2026-03-01T09:00:00Z| オプション | 説明 |
|---|---|
--at | ISO 8601日時形式(必須) |
content restore <collection> <id>
Section titled “content restore <collection> <id>”npx emdash content restore posts 01ABC123ゴミ箱にあるコンテンツアイテムを復元します。
emdash schema
Section titled “emdash schema”コレクションとフィールドを管理します。
schema list
Section titled “schema list”npx emdash schema listすべてのコレクションを一覧表示します。
schema get <collection>
Section titled “schema get <collection>”npx emdash schema get postsコレクションとそのすべてのフィールドを表示します。
schema create <collection>
Section titled “schema create <collection>”npx emdash schema create articles --label Articlesnpx emdash schema create articles --label Articles --label-singular Article --description "Blog articles"| オプション | 説明 |
|---|---|
--label | コレクションラベル(必須) |
--label-singular | 単数形ラベル |
--description | コレクション説明 |
schema delete <collection>
Section titled “schema delete <collection>”npx emdash schema delete articlesnpx emdash schema delete articles --force| オプション | 説明 |
|---|---|
--force | 確認をスキップ |
--force が設定されていない限り、確認を求めます。
schema add-field <collection> <field>
Section titled “schema add-field <collection> <field>”npx emdash schema add-field posts body --type portableText --label "Body Content"npx emdash schema add-field posts featured --type boolean --required| オプション | 説明 |
|---|---|
--type | フィールドタイプ: string, text, number, integer, boolean, datetime, image, reference, portableText, json(必須) |
--label | フィールドラベル(デフォルトはフィールドスラッグ) |
--required | フィールドが必須かどうか |
schema remove-field <collection> <field>
Section titled “schema remove-field <collection> <field>”npx emdash schema remove-field posts featuredemdash media
Section titled “emdash media”メディアアイテムを管理します。
media list
Section titled “media list”npx emdash media listnpx emdash media list --mime image/png --limit 20| オプション | 説明 |
|---|---|
--mime | MIMEタイプでフィルタリング |
--limit | アイテム数 |
--cursor | ページネーションカーソル |
media upload <file>
Section titled “media upload <file>”npx emdash media upload ./photo.jpgnpx emdash media upload ./photo.jpg --alt "A sunset" --caption "Taken in Bristol"| オプション | 説明 |
|---|---|
--alt | 代替テキスト |
--caption | キャプションテキスト |
media get <id>
Section titled “media get <id>”npx emdash media get 01MEDIA123media delete <id>
Section titled “media delete <id>”npx emdash media delete 01MEDIA123emdash search
Section titled “emdash search”コンテンツ全体で全文検索を実行します。
npx emdash search "hello world"npx emdash search "hello" --collection posts --limit 5| オプション | エイリアス | 説明 |
|---|---|---|
--collection | -c | コレクションでフィルタリング |
--limit | -l | 最大結果数 |
emdash taxonomy
Section titled “emdash taxonomy”タクソノミーとタームを管理します。
taxonomy list
Section titled “taxonomy list”npx emdash taxonomy listtaxonomy terms <name>
Section titled “taxonomy terms <name>”npx emdash taxonomy terms categoriesnpx emdash taxonomy terms tags --limit 50| オプション | エイリアス | 説明 |
|---|---|---|
--limit | -l | 最大ターム数 |
--cursor | ページネーションカーソル |
taxonomy add-term <taxonomy>
Section titled “taxonomy add-term <taxonomy>”npx emdash taxonomy add-term categories --name "Tech" --slug technpx emdash taxonomy add-term categories --name "Frontend" --parent 01PARENT123| オプション | 説明 |
|---|---|
--name | タームラベル(必須) |
--slug | タームスラッグ(デフォルトはスラッグ化された名前) |
--parent | 親タームID(階層型タクソノミー用) |
emdash menu
Section titled “emdash menu”ナビゲーションメニューを管理します。
menu list
Section titled “menu list”npx emdash menu listmenu get <name>
Section titled “menu get <name>”npx emdash menu get primaryメニューとそのすべてのアイテムを返します。
emdash seed
Section titled “emdash seed”シードファイルをデータベースに適用します。このコマンドはローカルのSQLiteファイルに対して直接動作します(実行中のサーバーは不要です)。
npx emdash seed [path] [options]| 引数 | 説明 | デフォルト |
|---|---|---|
path | シードファイルへのパス | .emdash/seed.json |
| Option | Alias | Description | Default |
|---|---|---|---|
--database | -d | データベースファイルパス | ./data.db |
--cwd | 作業ディレクトリ | カレントディレクトリ | |
--validate | 検証のみ、適用しない | false | |
--no-content | サンプルコンテンツをスキップ | false | |
--on-conflict | 競合処理: skip, update, error | skip | |
--uploads-dir | メディアアップロード用ディレクトリ | .emdash/uploads | |
--media-base-url | メディアファイルのベースURL | /_emdash/api/media/file | |
--base-url | サイトのベースURL (絶対メディアURL用) |
シードファイルの解決
Section titled “シードファイルの解決”コマンドは以下の順序でシードファイルを探します:
- 位置引数 (指定された場合)
.emdash/seed.json(慣例)package.jsonのemdash.seedフィールドからのパス
emdash export-seed
Section titled “emdash export-seed”データベーススキーマとコンテンツをシードファイルとしてエクスポートします。ローカルのSQLiteファイルに対して直接動作します。
npx emdash export-seed [options] > seed.json| Option | Alias | Description | Default |
|---|---|---|---|
--database | -d | データベースファイルパス | ./data.db |
--cwd | 作業ディレクトリ | カレントディレクトリ | |
--with-content | コンテンツを含める (all またはカンマ区切りのコレクション) | ||
--no-pretty | JSONフォーマットを無効化 | false |
エクスポートされたシードファイルには以下が含まれます:
- 設定: サイトタイトル、タグライン、ソーシャルリンク
- コレクション: フィールドを含むすべてのコレクション定義
- タクソノミー: タクソノミー定義と用語
- メニュー: アイテムを含むナビゲーションメニュー
- ウィジェットエリア: ウィジェットエリアとウィジェット
- コンテンツ (要求された場合):
$media参照と移植性のための$ref:構文を含むエントリ
emdash auth secret
Section titled “emdash auth secret”デプロイメント用の安全な認証シークレットを生成します。
npx emdash auth secretEMDASH_AUTH_SECRET に適したランダムなシークレットを出力します。
生成されるファイル
Section titled “生成されるファイル”.emdash/types.ts
Section titled “.emdash/types.ts”emdash types によって生成されるTypeScriptインターフェース:
// Generated by EmDash CLI// Do not edit manually - run `emdash types` to regenerate
import type { PortableTextBlock } from "emdash";
export interface Post { id: string; title: string; content: PortableTextBlock[]; publishedAt: Date | null;}.emdash/schema.json
Section titled “.emdash/schema.json”ツーリング用の生のスキーマエクスポート:
{ "version": "a1b2c3d4", "collections": [ { "slug": "posts", "label": "Posts", "fields": [...] } ]}| Variable | Description |
|---|---|
EMDASH_DATABASE_URL | データベースURL (dev によって自動的に設定) |
EMDASH_TOKEN | リモート操作用の認証トークン |
EMDASH_URL | types および dev --types 用のデフォルトリモートURL |
EMDASH_AUTH_SECRET | パスキー認証用のシークレット |
EMDASH_PREVIEW_SECRET | プレビュートークン生成用のシークレット |
パッケージスクリプト
Section titled “パッケージスクリプト”{ "scripts": { "dev": "emdash dev", "init": "emdash init", "types": "emdash types", "seed": "emdash seed", "export-seed": "emdash export-seed", "db:reset": "rm -f data.db && emdash init" }}| Code | Description |
|---|---|
0 | 成功 |
1 | エラー (設定、ネットワーク、データベース) |