@uzuhq/code-cli 0.5.3 → 0.5.4

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.
package/dist/cli.js CHANGED
@@ -16,6 +16,7 @@ import { buildServerLogic } from './build-server-logic.js';
16
16
  import { create2dGame } from './create-2d-game.js';
17
17
  import { uploadIconsToCfImages } from './cf-images-upload.js';
18
18
  import { runDevCommand } from './dev.js';
19
+ import { readInstalledSdkVersion } from './sdk-version.js';
19
20
  import { DEFAULT_ENV, authBaseURL, resolveEnv, studioHost } from './auth/env.js';
20
21
  import { runLoginFlow } from './auth/login-flow.js';
21
22
  import { saveCredentials, clearCredentials, credentialsPath } from './auth/config.js';
@@ -23,27 +24,6 @@ import { getLoginIdToken, getValidIdToken } from './auth/token-cache.js';
23
24
  import { PUBLISH_TOKEN_ENV, createPublishToken, listPublishTokens, revokePublishToken, } from './auth/publish-token.js';
24
25
  // publish / login / logout 共通の env オプション。既定 dev・help には出さない (誤って本番へ publish しないため)。
25
26
  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
27
  /** publish に使われている uzu-cli 自身のバージョン (dist/../package.json)。 */
48
28
  const readOwnCliVersion = () => {
49
29
  const pkgPath = resolve(dirname(fileURLToPath(import.meta.url)), '..', 'package.json');
@@ -0,0 +1,41 @@
1
+ import { existsSync, readFileSync } from 'fs';
2
+ import { dirname, resolve } from 'path';
3
+ /** 新パッケージ名を先に見る。@uzupj/uzu-sdk は旧名 (未移行 scenario 向けの両対応)。 */
4
+ const SDK_PACKAGE_PATHS = [
5
+ ['@uzuhq', 'code-sdk'],
6
+ ['@uzupj', 'uzu-sdk'],
7
+ ];
8
+ /**
9
+ * ゲームの node_modules から SDK の実バージョンを読む。
10
+ * 開発者の自己申告ではなく install 済み実体から測ることで、backend に記録される
11
+ * sdkVersion (ホスト側のサポート範囲判定に使う) の信頼性を担保する。
12
+ *
13
+ * cwd の node_modules だけでなく親方向へ辿るのは、npm workspaces が依存の実体を
14
+ * リポジトリ root へ hoist するため。manifest.json のある packages/<game>/ で publish しても、
15
+ * そこに node_modules は無い。Node のモジュール解決と同じく「近い node_modules が勝つ」。
16
+ */
17
+ export const readInstalledSdkVersion = (cwd) => {
18
+ const pkgPath = findSdkPackageJson(cwd);
19
+ if (!pkgPath) {
20
+ throw new Error('@uzuhq/code-sdk が node_modules に見つかりません。依存を install してから publish してください。');
21
+ }
22
+ const version = JSON.parse(readFileSync(pkgPath, 'utf-8')).version;
23
+ if (!version) {
24
+ throw new Error(`${pkgPath} に version がありません。`);
25
+ }
26
+ return version;
27
+ };
28
+ const findSdkPackageJson = (cwd) => {
29
+ let dir = resolve(cwd);
30
+ for (;;) {
31
+ const found = SDK_PACKAGE_PATHS.map((segments) => resolve(dir, 'node_modules', ...segments, 'package.json')).find(existsSync);
32
+ if (found) {
33
+ return found;
34
+ }
35
+ const parent = dirname(dir);
36
+ if (parent === dir) {
37
+ return undefined;
38
+ }
39
+ dir = parent;
40
+ }
41
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uzuhq/code-cli",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "UZU ゲーム開発 CLI - ビルド・パブリッシュ・プロジェクト作成ツール",
5
5
  "type": "module",
6
6
  "bin": {