@uzuhq/code-cli 0.3.15 → 0.3.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,7 @@
9
9
  *
10
10
  * @docs
11
11
  * - 設計: docs/architecture/auth-platform.md
12
- * - 使い方: docs/play_screen_v3/sdk-guide/dev-tools.md
12
+ * - 使い方: docs/uzu_code/sdk-guide/dev-tools.md
13
13
  */
14
14
  /** CI に渡す環境変数名。 */
15
15
  export const PUBLISH_TOKEN_ENV = 'UZU_PUBLISH_TOKEN';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @docs
3
- * - ServerAction仕様: docs/docs/play_screen_v3/connection-method/arch3-authority.md
3
+ * - ServerAction仕様: docs/docs/uzu_code/connection-method/arch3-authority.md
4
4
  *
5
5
  * ゲームの logic.ts を ESM 形式の単一 logic.js にバンドルする。
6
6
  * 出力ファイルは R2 にアップロードされ、WfP デプロイ時にテンプレートとマージされる。
package/dist/cli.js CHANGED
@@ -1,15 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
3
  * @docs
4
- * - ゲーム仕様: docs/docs/play_screen_v3/games.md
5
- * - システム全体像: docs/docs/play_screen_v3/overview.md
4
+ * - ゲーム仕様: docs/docs/uzu_code/games.md
5
+ * - システム全体像: docs/docs/uzu_code/overview.md
6
6
  */
7
7
  import { Command, Option } from 'commander';
8
8
  import { execSync } from 'child_process';
9
9
  import { readFileSync, existsSync, unlinkSync, createWriteStream } from 'fs';
10
- import { resolve } from 'path';
10
+ import { dirname, resolve } from 'path';
11
11
  import { ZipArchive } from 'archiver';
12
- import { pathToFileURL } from 'url';
12
+ import { fileURLToPath, pathToFileURL } from 'url';
13
13
  import { uploadGameToR2, uploadLogicToR2 } from './r2-upload.js';
14
14
  import { registerRevision } from './rest-register.js';
15
15
  import { buildServerLogic } from './build-server-logic.js';
@@ -23,8 +23,39 @@ import { getLoginIdToken, getValidIdToken } from './auth/token-cache.js';
23
23
  import { PUBLISH_TOKEN_ENV, createPublishToken, listPublishTokens, revokePublishToken, } from './auth/publish-token.js';
24
24
  // publish / login / logout 共通の env オプション。既定 dev・help には出さない (誤って本番へ publish しないため)。
25
25
  const envOption = () => new Option('--env <env>', '接続先環境 (dev | stg | prd)').default(DEFAULT_ENV).hideHelp();
26
+ /**
27
+ * ゲームの node_modules から SDK の実バージョンを読む。
28
+ * 開発者の自己申告ではなく install 済み実体から測ることで、backend に記録される
29
+ * sdkVersion (ホスト側のサポート範囲判定に使う) の信頼性を担保する。
30
+ * @uzupj/uzu-sdk は旧パッケージ名 (未移行 scenario 向けの両対応)。
31
+ */
32
+ const readInstalledSdkVersion = (cwd) => {
33
+ const candidates = [
34
+ resolve(cwd, 'node_modules', '@uzuhq', 'code-sdk', 'package.json'),
35
+ resolve(cwd, 'node_modules', '@uzupj', 'uzu-sdk', 'package.json'),
36
+ ];
37
+ const pkgPath = candidates.find(existsSync);
38
+ if (!pkgPath) {
39
+ throw new Error('@uzuhq/code-sdk が node_modules に見つかりません。依存を install してから publish してください。');
40
+ }
41
+ const version = JSON.parse(readFileSync(pkgPath, 'utf-8')).version;
42
+ if (!version) {
43
+ throw new Error(`${pkgPath} に version がありません。`);
44
+ }
45
+ return version;
46
+ };
47
+ /** publish に使われている uzu-cli 自身のバージョン (dist/../package.json)。 */
48
+ const readOwnCliVersion = () => {
49
+ const pkgPath = resolve(dirname(fileURLToPath(import.meta.url)), '..', 'package.json');
50
+ const version = JSON.parse(readFileSync(pkgPath, 'utf-8')).version;
51
+ if (!version) {
52
+ throw new Error('uzu-cli の package.json に version がありません。');
53
+ }
54
+ return version;
55
+ };
56
+ const OWN_CLI_VERSION = readOwnCliVersion();
26
57
  const program = new Command();
27
- program.name('uzu').description('UZU ゲーム開発 CLI').version('0.2.0');
58
+ program.name('uzu').description('UZU ゲーム開発 CLI').version(OWN_CLI_VERSION);
28
59
  program
29
60
  .command('create-2d-game')
30
61
  .description('2D エンジンを使ったゲームプロジェクトの雛形を作成')
@@ -94,6 +125,16 @@ program
94
125
  const buildCommand = manifest.build;
95
126
  const outputDir = manifest.output;
96
127
  console.log(`Publishing game: ${gameId} (players: ${playerCount}, orientation: ${orientation})`);
128
+ // SDK バージョンも認証と同じくビルド前に実測する。登録直前に失敗すると
129
+ // ビルド・R2 アップロード・upload session の消費が全て無駄になるため。
130
+ let sdkVersion;
131
+ try {
132
+ sdkVersion = readInstalledSdkVersion(cwd);
133
+ }
134
+ catch (e) {
135
+ console.error(e instanceof Error ? e.message : String(e));
136
+ process.exit(1);
137
+ }
97
138
  // 認証はビルド前に確認する。未ログインのまま重いビルド・アップロードまで進むと、
98
139
  // 完了後に登録で失敗して成果物が無駄になるため、ここで先に落とす。
99
140
  await getValidIdToken(env).catch((e) => {
@@ -144,7 +185,7 @@ program
144
185
  process.exit(1);
145
186
  }
146
187
  // ゲーム固有の logic.js のみを R2 に保存する。
147
- // ランタイムテンプレ(GameRoom エンジン)は v3-play-server が所有し、JIT デプロイ時に
188
+ // ランタイムテンプレ(GameRoom エンジン)は uzu-code play-server が所有し、JIT デプロイ時に
148
189
  // この logic.js と合成される。これによりテンプレ修正が再 publish 無しで伝播する。
149
190
  console.log('Uploading logic.js to R2...');
150
191
  const logicJsContent = readFileSync(logicOutPath, 'utf-8');
@@ -192,6 +233,8 @@ program
192
233
  playerCount,
193
234
  orientation,
194
235
  characters: resolvedCharacters,
236
+ manifest,
237
+ publishMeta: { sdkVersion, cliVersion: OWN_CLI_VERSION },
195
238
  });
196
239
  console.log(`Registered revision: ${revId}`);
197
240
  // 7. Cleanup
@@ -46,11 +46,6 @@ export const create2dGame = (name) => {
46
46
  console.log(`\nDone! Created ${name}/`);
47
47
  console.log(`\nNext steps:`);
48
48
  console.log(` cd ${name}`);
49
- console.log('');
50
- console.log(' # ~/.npmrc に GitHub Packages の認証設定がない場合:');
51
- console.log(' echo "//npm.pkg.github.com/:_authToken=YOUR_GITHUB_TOKEN" >> ~/.npmrc');
52
- console.log(' echo "@uzupj:registry=https://npm.pkg.github.com" >> ~/.npmrc');
53
- console.log('');
54
49
  console.log(` npm install`);
55
50
  console.log(` npm run dev`);
56
51
  };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * dev-server 版 GameRoom (ServerAction / run() モード用)。
3
3
  *
4
- * v3-play-server の `game-worker-template/game-room.ts` (Cloudflare Worker DO 版)
4
+ * uzu-code play-server の `game-worker-template/game-room.ts` (Cloudflare Worker DO 版)
5
5
  * と同一プロトコル (`__game_start` / `__tick` / `__tick_delta` / `__action_result` /
6
6
  * `__action_result_delta` / `__state` / `__room_init` / `__action_error`) を喋る
7
7
  * Node.js 版。 SDK 側の `runOnlineServerAction` client がそのまま接続できる。
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * @docs
3
- * - ServerAction仕様: docs/docs/play_screen_v3/connection-method/arch3-authority.md
3
+ * - ServerAction仕様: docs/docs/uzu_code/connection-method/arch3-authority.md
4
4
  *
5
5
  * Node 側 dev-server 用の game type 定義。
6
- * SDK `src/types.ts` および v3-play-server `game-worker-template/game-types.ts` と
6
+ * SDK `src/types.ts` および uzu-code play-server `game-worker-template/game-types.ts` と
7
7
  * 同一 shape。 CLI は browser 依存 (window etc) を持たない Node 環境で走るので、
8
8
  * SDK を直接 import できず、game-worker-template と同じく copy を持つ。
9
9
  * 3 か所いずれかを変更したら他 2 か所も同期させること。
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * JSON Patch ユーティリティ。
3
- * SDK `src/json-patch.ts` および v3-play-server `game-worker-template/json-patch.ts`
3
+ * SDK `src/json-patch.ts` および uzu-code play-server `game-worker-template/json-patch.ts`
4
4
  * と同一。 3 か所いずれかを変更したら他 2 か所も同期させること。
5
5
  */
6
6
  function escapePointer(key) {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * dev-server 版 RelayRoom (init() 単独 relay mode 用)。
3
3
  *
4
- * v3-play-server の `relay-room.ts` (Cloudflare Worker DO 版) と同一プロトコル
4
+ * uzu-code play-server の `relay-room.ts` (Cloudflare Worker DO 版) と同一プロトコル
5
5
  * (`__room_init` + broadcast) を喋る Node.js 版。 SDK 側の Relay client
6
6
  * (`connectRoom` in `uzuhq-sdk/src/index.ts`) がそのまま接続できる。
7
7
  */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * dev-server: harness page HTML/JS を serve しつつ、
3
3
  * `/ws/games/:revisionId/:roomId` / `/ws/sync/:roomId` / `/ws/rooms/:roomId` を
4
- * 本番 (v3-play-server) と同一プロトコルで喋る Node.js HTTP + WebSocket server。
4
+ * 本番 (uzu-code play-server) と同一プロトコルで喋る Node.js HTTP + WebSocket server。
5
5
  *
6
6
  * さらに parent frame の `__uzu_dev` 用管理 channel `/dev/admin` を提供する。
7
7
  * game / sync / relay room はいずれも in-memory (CLI 停止で state 消失)。
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * dev-server 版 SyncRoom (sync() モード用)。
3
3
  *
4
- * v3-play-server の `sync-room.ts` (Cloudflare Worker DO 版) と同一プロトコル
4
+ * uzu-code play-server の `sync-room.ts` (Cloudflare Worker DO 版) と同一プロトコル
5
5
  * (`__state` / `__patch_ack` / `__patch_failed` / `__state_cleared` / `__init_state` /
6
6
  * `__patch` / `__request_state` / `__clear_state` / `__room_init`) を喋る Node.js 版。
7
7
  * SDK 側の `syncOnline` client がそのまま接続できる。
@@ -17,7 +17,7 @@ function isInspectorOpen() {
17
17
  * UZU ボタン (button 要素) にタップメニューを配線する。 メニューはボタン直下に出る。
18
18
  */
19
19
  export function attachUzuMenu(button, opts = {}) {
20
- const { stateGetter, playerCount, resetGame, onOpenMobile } = opts;
20
+ const { stateGetter, playerCount, adminEnabled, resetGame, onOpenMobile } = opts;
21
21
  let popup = null;
22
22
  const closePopup = () => {
23
23
  popup?.remove();
@@ -96,6 +96,9 @@ export function attachUzuMenu(button, opts = {}) {
96
96
  if (playerCount) {
97
97
  emulatorUrl.searchParams.set('player_count', String(playerCount));
98
98
  }
99
+ if (adminEnabled) {
100
+ emulatorUrl.searchParams.set('admin', '1');
101
+ }
99
102
  window.open(emulatorUrl.toString(), '_blank');
100
103
  });
101
104
  if (stateGetter) {
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import qrcode from 'qrcode-generator';
9
9
  import { attachUzuMenu } from './dev-button.js';
10
- // ── 本番アプリ (Flutter play_screen_v3 GamePlayScreen) の overlay 仕様に合わせた定数 ──
10
+ // ── 本番アプリ (Flutter uzu_code GamePlayScreen) の overlay 仕様に合わせた定数 ──
11
11
  // SafeArea 内 top:8 / left:12、 UZU ボタン 44、 gap 6、 ActionBar は height:36 の
12
12
  // ピル。 アイコン size:18 / 左右 padding:10。 game 側は SDK が uzuHudInsetX/Y から
13
13
  // --uzu-hud-inset-x/y を立て、 この矩形を避ける。
@@ -457,6 +457,7 @@ onUzuClick) {
457
457
  stateGetter: opts.stateGetter,
458
458
  resetGame: opts.resetGame,
459
459
  playerCount: opts.playerCount,
460
+ adminEnabled: opts.seats.some((s) => s.kind === 'admin'),
460
461
  });
461
462
  }
462
463
  wrap.appendChild(uzu);
package/dist/r2-upload.js CHANGED
@@ -76,7 +76,7 @@ export const uploadGameToR2 = async (env, zipPath, outputDir) => {
76
76
  * ゲーム固有の logic.js を R2 にアップロードする。
77
77
  * ストレージ形式: {revisionId}/logic.js
78
78
  *
79
- * ランタイムテンプレ(GameRoom エンジン)は v3-play-server が所有し、JIT デプロイ時に
79
+ * ランタイムテンプレ(GameRoom エンジン)は uzu-code play-server が所有し、JIT デプロイ時に
80
80
  * この logic.js と合成される。R2 にはゲーム固有の logic のみを置く(テンプレは焼き込まない)。
81
81
  */
82
82
  export const uploadLogicToR2 = async (env, token, logicJs) => {
@@ -40,6 +40,8 @@ export const registerRevision = async (params) => {
40
40
  changeNotes: params.changeNotes,
41
41
  orientation: params.orientation,
42
42
  characters: buildCharacters(params),
43
+ uzuCodeManifest: params.manifest,
44
+ uzuCodePublishMeta: params.publishMeta,
43
45
  }),
44
46
  });
45
47
  if (!res.ok) {
@@ -12,7 +12,7 @@
12
12
  "preview": "vite preview"
13
13
  },
14
14
  "dependencies": {
15
- "@uzupj/engine-2d": "*",
15
+ "@uzuhq/engine-2d": "*",
16
16
  "@uzuhq/code-sdk": "*"
17
17
  },
18
18
  "devDependencies": {
@@ -1,4 +1,4 @@
1
- import { createEngine } from '@uzupj/engine-2d';
1
+ import { createEngine } from '@uzuhq/engine-2d';
2
2
  import { init } from '@uzuhq/code-sdk';
3
3
 
4
4
  // SDK 初期化
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uzuhq/code-cli",
3
- "version": "0.3.15",
3
+ "version": "0.3.17",
4
4
  "description": "UZU ゲーム開発 CLI - ビルド・パブリッシュ・プロジェクト作成ツール",
5
5
  "type": "module",
6
6
  "bin": {