Skip to content

feat: microCMSのTypeScript型生成CLIを追加 - #1

Merged
Sinhalite merged 12 commits into
mainfrom
codex/initial-implementation
Oct 14, 2026
Merged

Sinhalite merged 12 commits into
mainfrom
codex/initial-implementation

Conversation

@Sinhalite

Copy link
Copy Markdown
Collaborator

概要

microCMSのマネジメントAPIからスキーマを取得し、TypeScriptの型を生成するCLIを追加します。初回リリース候補は1.0.0です。

  • initで設定ファイルを作成し、generateで型を生成、checkで生成結果との差分を確認
  • TypeScriptの設定ファイルをsatisfies Configで検査し、複数サービスとAPIの絞り込みに対応
  • エンドポイントごとの標準型と、サービス単位の<ServiceKey>ServiceSchemaを生成
  • 参照の深さ、カスタムフィールド、空値、書き込み型、拡張フィールドのdata型を生成に反映
  • 型名の衝突はエラーとして検出
  • 保存済みスキーマによるテスト、生成例、開発ガイド、検証用GitHub Actionsを追加

レビューの進め方

まずREADMEで導入・設定・CLIの提供仕様を確認し、その後examples/README.mdとexamples/microcms-types.tsで入力スキーマと生成結果を確認してください。最初は利用者に提供する仕様や説明の分かりやすさを中心に見ていただきたいです。

  • 設定とCLIの使い方が自然か
  • 生成する公開型の命名、空値、参照、書き込みの扱いに問題がないか
  • エラーや上書き保護が適切か

SDKの型付きクライアントによる読み書き・クエリ推論・型抽出は、別途SDK側の変更で提供します。SDKの変更はこのPRには含めません。相互リンク先のmain/examplesは各リポジトリへの反映後に利用可能になるため、レビュー中はこのPR内のサンプルを参照してください。

検証

  • Node.js22.18.0でnpm test:49件成功
  • 開発用TypeScript7.0.2でnpm run test:types:成功
  • TypeScript6.0.2でnpm run test:types:成功
  • TypeScript7.0.2と6.0.2でnpm run test:package:成功
  • npm packの配布ファイル、サンプルの生成結果との一致、ローカルのMarkdownリンクとアンカーを確認
  • 公開するfixture内のURL・問い合わせ用アドレスをダミー化し、認証情報が含まれないことを確認

通常のテストは保存済みスキーマを使い、実サービスへのアクセスとAPIキーは不要です。GitHub ActionsではNode.js22.18.0・22系・24系とTypeScript6.0.2の互換性を検証します。

リリース前の検討事項

  • パッケージ名は未確定:microcms-typegenは候補です。npm上の利用可否とスコープを確認します。
  • npmアカウント・Organizationと公開権限の準備
  • リリース用CIは未実装:公開の認証方法、タグまたは手動実行による手順を決めます。

現在のCIはテストと配布内容の確認のみで、npmへの公開は行いません。レビュー通過後にリリース準備を進めます。これらの検討事項はDEVELOPMENT.mdにも記載しています。

@Sinhalite

Sinhalite commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator Author

事前にコメントいただいていた点は、以下の内容に調整しています!

  • SDK
    • クライアント生成時のスキーマ指定とInferMicroCMSContentを実装し、従来のメソッドごとの型指定も維持しています。
  • 型の制約
    • updateのcontentIdはリスト形式で必須、オブジェクト形式で指定不可にしました。
    • getAllContentIdsも登録済みのリスト形式のエンドポイントに限定しています。
  • 設定の型安全性
    • defineConfigもJSの設定ファイルで補完・型検査を利用できる点が魅力で迷いましたが、今回はTypeScriptの型生成ツールであることから、設定もTS形式を前提としました。
    • 公開したConfig型とsatisfies Configで補完・誤記検出を行う、シンプルな方式を採用しています。
  • 初期設定
    • initで設定ファイルを生成します。.env.exampleは生成せず、既存ファイルも上書きしません。
  • CLI
    • --api-keyなど設定を上書きするオプションを削除し、サービスID・APIキー・出力先などは設定ファイルに集約しました。

@dc7290 dc7290 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

良さそうです!

@wato787 wato787 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTMです!

@nemuvski

nemuvski commented Oct 5, 2026

Copy link
Copy Markdown
Member

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread src/cli.ts

@nemuvski nemuvski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/ をjsファイルにしていますが、tsファイルにしても良いのかなぁと思いました!
後からやるより、最初の時点でやってしまっても良いかもです。

@Sinhalite

Copy link
Copy Markdown
Collaborator Author

@nemuvski

src/ をjsファイルにしていますが、tsファイルにしても良いのかなぁと思いました! 後からやるより、最初の時点でやってしまっても良いかもです。

こちら特に意図はなかったので、対応しました!
ありがとうございます!

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 27d6343. Configure here.

Comment thread src/cli.ts

@nemuvski nemuvski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1点気になったのでコメントさせていただきました!

Comment thread src/generate.ts Outdated
Enforce required fields and nonempty minimum-count arrays in generated write types. Add nested read rules for trusting saved field constraints and reference availability, with conservative defaults.

Capture required-field and minimum-count API cases for offline regression tests, verify nested combinations and compiler compatibility, and document the configuration and SDK usage.
@nemuvski
nemuvski self-requested a review October 13, 2026 07:25
@Sinhalite
Sinhalite merged commit 912fd8c into main Oct 14, 2026
6 checks passed
@Sinhalite
Sinhalite deleted the codex/initial-implementation branch October 14, 2026 03:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants