@uzuhq/code-cli 0.5.8 → 0.5.10
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 +59 -27
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// src/cli.ts
|
|
4
4
|
import { Command, Option } from "commander";
|
|
5
5
|
import { execSync } from "child_process";
|
|
6
|
-
import { readFileSync as
|
|
6
|
+
import { readFileSync as readFileSync7, existsSync as existsSync4, unlinkSync, createWriteStream } from "fs";
|
|
7
7
|
import { dirname as dirname5, resolve as resolve5 } from "path";
|
|
8
8
|
import { ZipArchive } from "archiver";
|
|
9
9
|
import { fileURLToPath as fileURLToPath4, pathToFileURL as pathToFileURL2 } from "url";
|
|
@@ -348,17 +348,26 @@ var uploadGameToR2 = async (env, zipPath, outputDir) => {
|
|
|
348
348
|
});
|
|
349
349
|
return { resourceId: session.resourceId, revisionId: session.revisionId, token: session.token };
|
|
350
350
|
};
|
|
351
|
-
var uploadLogicToR2 = async (env, token, logicJs) => {
|
|
351
|
+
var uploadLogicToR2 = async (env, token, logicJs, meta) => {
|
|
352
352
|
const session = await createUploadSession({
|
|
353
353
|
env,
|
|
354
354
|
token,
|
|
355
|
-
files: [
|
|
355
|
+
files: [
|
|
356
|
+
{ path: "logic.js", contentType: "application/javascript" },
|
|
357
|
+
{ path: "meta.json", contentType: "application/json" }
|
|
358
|
+
]
|
|
356
359
|
});
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
360
|
+
const uploadByPath = new Map(session.uploads.map((u) => [u.path, u]));
|
|
361
|
+
const logicUpload = uploadByPath.get("logic.js");
|
|
362
|
+
const metaUpload = uploadByPath.get("meta.json");
|
|
363
|
+
if (!logicUpload || !metaUpload) {
|
|
364
|
+
throw new Error("logic.js / meta.json \u306E\u30A2\u30C3\u30D7\u30ED\u30FC\u30C9 URL \u304C\u767A\u884C\u3055\u308C\u3066\u3044\u307E\u305B\u3093");
|
|
365
|
+
}
|
|
366
|
+
await Promise.all([
|
|
367
|
+
putToPresignedURL(logicUpload, logicJs),
|
|
368
|
+
putToPresignedURL(metaUpload, JSON.stringify(meta))
|
|
369
|
+
]);
|
|
370
|
+
console.log(`Uploaded logic.js / meta.json to R2: ${session.revisionId}/`);
|
|
362
371
|
};
|
|
363
372
|
|
|
364
373
|
// src/rest-register.ts
|
|
@@ -409,6 +418,8 @@ var registerRevision = async (params) => {
|
|
|
409
418
|
|
|
410
419
|
// src/build-server-logic.ts
|
|
411
420
|
import { build } from "esbuild";
|
|
421
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
422
|
+
var SDK_PACKAGES = ["@uzuhq/code-sdk", "@uzupj/uzu-sdk"];
|
|
412
423
|
var buildServerLogic = async (logicPath, outPath) => {
|
|
413
424
|
await build({
|
|
414
425
|
entryPoints: [logicPath],
|
|
@@ -419,13 +430,24 @@ var buildServerLogic = async (logicPath, outPath) => {
|
|
|
419
430
|
platform: "neutral",
|
|
420
431
|
// SDK の type-only import は tsc で消えるが安全のため external 指定。
|
|
421
432
|
// @uzupj/uzu-sdk は旧パッケージ名 (未移行 scenario 向けの両対応)
|
|
422
|
-
external:
|
|
433
|
+
external: SDK_PACKAGES
|
|
423
434
|
});
|
|
435
|
+
assertNoSdkRuntimeImport(outPath);
|
|
424
436
|
console.log(`Built server logic: ${logicPath} \u2192 ${outPath}`);
|
|
425
437
|
};
|
|
438
|
+
var assertNoSdkRuntimeImport = (outPath) => {
|
|
439
|
+
const built = readFileSync2(outPath, "utf-8");
|
|
440
|
+
const found = SDK_PACKAGES.find((pkg) => built.includes(pkg));
|
|
441
|
+
if (!found) return;
|
|
442
|
+
throw new Error(
|
|
443
|
+
`logic \u304C ${found} \u304B\u3089\u5024\u3092 import \u3057\u3066\u3044\u307E\u3059\u3002
|
|
444
|
+
logic \u304B\u3089 SDK \u3078\u5411\u3051\u3066\u3088\u3044\u306E\u306F\u578B\u3060\u3051\u3067\u3059 (import type)\u3002
|
|
445
|
+
\u5B9F\u884C\u6642\u306B\u5FC5\u8981\u306A\u3082\u306E (serverOnly / SERVER_TIME \u7B49) \u306F @uzuhq/code-engine-core \u304B\u3089 import \u3057\u3066\u304F\u3060\u3055\u3044\u3002`
|
|
446
|
+
);
|
|
447
|
+
};
|
|
426
448
|
|
|
427
449
|
// src/create-2d-game.ts
|
|
428
|
-
import { mkdirSync, readFileSync as
|
|
450
|
+
import { mkdirSync, readFileSync as readFileSync3, writeFileSync, readdirSync, statSync } from "fs";
|
|
429
451
|
import { resolve, dirname, join as join3 } from "path";
|
|
430
452
|
import { fileURLToPath } from "url";
|
|
431
453
|
var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
@@ -439,13 +461,13 @@ var copyDir = (src, dest, replacements) => {
|
|
|
439
461
|
continue;
|
|
440
462
|
}
|
|
441
463
|
if (entry.endsWith(".tpl")) {
|
|
442
|
-
let content =
|
|
464
|
+
let content = readFileSync3(srcPath, "utf-8");
|
|
443
465
|
for (const [key, value] of Object.entries(replacements)) {
|
|
444
466
|
content = content.replaceAll(`{{${key}}}`, value);
|
|
445
467
|
}
|
|
446
468
|
writeFileSync(join3(dest, entry.replace(/\.tpl$/, "")), content);
|
|
447
469
|
} else {
|
|
448
|
-
const content =
|
|
470
|
+
const content = readFileSync3(srcPath, "utf-8");
|
|
449
471
|
let output = content;
|
|
450
472
|
for (const [key, value] of Object.entries(replacements)) {
|
|
451
473
|
output = output.replaceAll(`{{${key}}}`, value);
|
|
@@ -472,7 +494,7 @@ Next steps:`);
|
|
|
472
494
|
};
|
|
473
495
|
|
|
474
496
|
// src/cf-images-upload.ts
|
|
475
|
-
import { readFileSync as
|
|
497
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
476
498
|
import { basename as basename2 } from "path";
|
|
477
499
|
var parseUploadedImageId = (v) => {
|
|
478
500
|
if (typeof v === "object" && v !== null && "success" in v && v.success === true && "result" in v && typeof v.result === "object" && v.result !== null && "id" in v.result && typeof v.result.id === "string" && v.result.id !== "") {
|
|
@@ -491,7 +513,7 @@ var uploadIconsToCfImages = async (env, token, filePaths) => {
|
|
|
491
513
|
filePaths.map(async (filePath, i) => {
|
|
492
514
|
const image = session.images[i];
|
|
493
515
|
const formData = new FormData();
|
|
494
|
-
formData.append("file", new Blob([
|
|
516
|
+
formData.append("file", new Blob([readFileSync4(filePath)]), basename2(filePath));
|
|
495
517
|
const res = await fetch(image.uploadURL, { method: "POST", body: formData });
|
|
496
518
|
if (!res.ok) {
|
|
497
519
|
const detail = (await res.text()).trim();
|
|
@@ -508,7 +530,7 @@ var uploadIconsToCfImages = async (env, token, filePaths) => {
|
|
|
508
530
|
|
|
509
531
|
// src/dev.ts
|
|
510
532
|
import { spawn } from "child_process";
|
|
511
|
-
import { readFileSync as
|
|
533
|
+
import { readFileSync as readFileSync5, existsSync as existsSync2 } from "fs";
|
|
512
534
|
import { dirname as dirname3, resolve as resolve3 } from "path";
|
|
513
535
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
514
536
|
import { createInterface } from "readline";
|
|
@@ -650,6 +672,10 @@ function parseRoster(rosterParam) {
|
|
|
650
672
|
}));
|
|
651
673
|
}
|
|
652
674
|
|
|
675
|
+
// ../engine-core/src/versions.ts
|
|
676
|
+
var BRIDGE_VERSION = 1;
|
|
677
|
+
var WIRE_VERSION = 1;
|
|
678
|
+
|
|
653
679
|
// src/dev-server/admin-state-patch.ts
|
|
654
680
|
var MERGE_PATCH_ARRAY_REJECT = "[applyJsonMergePatch] cannot merge a non-array patch into an array target";
|
|
655
681
|
function applyJsonMergePatch(target, patch) {
|
|
@@ -821,7 +847,7 @@ var GameRoom = class _GameRoom {
|
|
|
821
847
|
maybeStartGame() {
|
|
822
848
|
if (this.gameState !== null) return;
|
|
823
849
|
if (this.players.length === 0) return;
|
|
824
|
-
this.seed =
|
|
850
|
+
this.seed = Math.floor(Math.random() * 4294967295);
|
|
825
851
|
this.random = new SeededRandomImpl(this.seed);
|
|
826
852
|
this.gameState = this.logic.setup(this.setupArgs(this.random));
|
|
827
853
|
this.stateInitialized = true;
|
|
@@ -1910,7 +1936,7 @@ async function runDevCommand() {
|
|
|
1910
1936
|
console.error("manifest.json \u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002 scenario \u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u3067\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\u3002");
|
|
1911
1937
|
process.exit(1);
|
|
1912
1938
|
}
|
|
1913
|
-
const manifest = JSON.parse(
|
|
1939
|
+
const manifest = JSON.parse(readFileSync5(manifestPath, "utf-8"));
|
|
1914
1940
|
const playerCount = manifest.characters?.length ?? manifest.playerCount ?? 2;
|
|
1915
1941
|
const orientation = manifest.orientation ?? "portrait";
|
|
1916
1942
|
const devCommand = manifest.dev?.command ?? DEFAULT_DEV_COMMAND;
|
|
@@ -2085,7 +2111,7 @@ async function findFreePort() {
|
|
|
2085
2111
|
}
|
|
2086
2112
|
|
|
2087
2113
|
// src/sdk-version.ts
|
|
2088
|
-
import { existsSync as existsSync3, readFileSync as
|
|
2114
|
+
import { existsSync as existsSync3, readFileSync as readFileSync6 } from "fs";
|
|
2089
2115
|
import { dirname as dirname4, resolve as resolve4 } from "path";
|
|
2090
2116
|
var SDK_PACKAGE_PATHS = [
|
|
2091
2117
|
["@uzuhq", "code-sdk"],
|
|
@@ -2098,7 +2124,7 @@ var readInstalledSdkVersion = (cwd) => {
|
|
|
2098
2124
|
"@uzuhq/code-sdk \u304C node_modules \u306B\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002\u4F9D\u5B58\u3092 install \u3057\u3066\u304B\u3089 publish \u3057\u3066\u304F\u3060\u3055\u3044\u3002"
|
|
2099
2125
|
);
|
|
2100
2126
|
}
|
|
2101
|
-
const version = JSON.parse(
|
|
2127
|
+
const version = JSON.parse(readFileSync6(pkgPath, "utf-8")).version;
|
|
2102
2128
|
if (!version) {
|
|
2103
2129
|
throw new Error(`${pkgPath} \u306B version \u304C\u3042\u308A\u307E\u305B\u3093\u3002`);
|
|
2104
2130
|
}
|
|
@@ -2278,7 +2304,7 @@ var runLoginFlow = async (env, onURL) => {
|
|
|
2278
2304
|
var envOption = () => new Option("--env <env>", "\u63A5\u7D9A\u5148\u74B0\u5883 (dev | stg | prd)").default(DEFAULT_ENV).hideHelp();
|
|
2279
2305
|
var readOwnCliVersion = () => {
|
|
2280
2306
|
const pkgPath = resolve5(dirname5(fileURLToPath4(import.meta.url)), "..", "package.json");
|
|
2281
|
-
const version = JSON.parse(
|
|
2307
|
+
const version = JSON.parse(readFileSync7(pkgPath, "utf-8")).version;
|
|
2282
2308
|
if (!version) {
|
|
2283
2309
|
throw new Error("uzu-cli \u306E package.json \u306B version \u304C\u3042\u308A\u307E\u305B\u3093\u3002");
|
|
2284
2310
|
}
|
|
@@ -2308,7 +2334,7 @@ program.command("publish").description("\u30B2\u30FC\u30E0\u3092\u30D3\u30EB\u30
|
|
|
2308
2334
|
console.error("manifest.json \u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002\u30B2\u30FC\u30E0\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u3067\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\u3002");
|
|
2309
2335
|
process.exit(1);
|
|
2310
2336
|
}
|
|
2311
|
-
const manifest = JSON.parse(
|
|
2337
|
+
const manifest = JSON.parse(readFileSync7(manifestPath, "utf-8"));
|
|
2312
2338
|
if (typeof manifest !== "object" || manifest === null) {
|
|
2313
2339
|
console.error("manifest.json \u304C\u4E0D\u6B63\u306A\u5F62\u5F0F\u3067\u3059\u3002");
|
|
2314
2340
|
process.exit(1);
|
|
@@ -2345,12 +2371,13 @@ program.command("publish").description("\u30B2\u30FC\u30E0\u3092\u30D3\u30EB\u30
|
|
|
2345
2371
|
console.log(
|
|
2346
2372
|
`Publishing game: ${gameId} (players: ${playerCount}, orientation: ${orientation})`
|
|
2347
2373
|
);
|
|
2348
|
-
let sdkVersion;
|
|
2374
|
+
let sdkVersion = "";
|
|
2349
2375
|
try {
|
|
2350
2376
|
sdkVersion = readInstalledSdkVersion(cwd);
|
|
2351
2377
|
} catch (e) {
|
|
2352
|
-
console.
|
|
2353
|
-
|
|
2378
|
+
console.warn(
|
|
2379
|
+
`SDK \u306E\u30D0\u30FC\u30B8\u30E7\u30F3\u3092\u7279\u5B9A\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F (\u8A18\u9332\u306F\u7A7A\u306B\u306A\u308A\u307E\u3059): ${e instanceof Error ? e.message : String(e)}`
|
|
2380
|
+
);
|
|
2354
2381
|
}
|
|
2355
2382
|
await getValidIdToken(env).catch((e) => {
|
|
2356
2383
|
console.error(e instanceof Error ? e.message : String(e));
|
|
@@ -2393,8 +2420,8 @@ program.command("publish").description("\u30B2\u30FC\u30E0\u3092\u30D3\u30EB\u30
|
|
|
2393
2420
|
process.exit(1);
|
|
2394
2421
|
}
|
|
2395
2422
|
console.log("Uploading logic.js to R2...");
|
|
2396
|
-
const logicJsContent =
|
|
2397
|
-
await uploadLogicToR2(env, token, logicJsContent);
|
|
2423
|
+
const logicJsContent = readFileSync7(logicOutPath, "utf-8");
|
|
2424
|
+
await uploadLogicToR2(env, token, logicJsContent, { wireVersion: WIRE_VERSION });
|
|
2398
2425
|
} finally {
|
|
2399
2426
|
if (existsSync4(logicOutPath)) unlinkSync(logicOutPath);
|
|
2400
2427
|
}
|
|
@@ -2434,7 +2461,12 @@ program.command("publish").description("\u30B2\u30FC\u30E0\u3092\u30D3\u30EB\u30
|
|
|
2434
2461
|
orientation,
|
|
2435
2462
|
characters: resolvedCharacters,
|
|
2436
2463
|
manifest,
|
|
2437
|
-
publishMeta: {
|
|
2464
|
+
publishMeta: {
|
|
2465
|
+
sdkVersion,
|
|
2466
|
+
cliVersion: OWN_CLI_VERSION,
|
|
2467
|
+
bridgeVersion: BRIDGE_VERSION,
|
|
2468
|
+
wireVersion: WIRE_VERSION
|
|
2469
|
+
}
|
|
2438
2470
|
});
|
|
2439
2471
|
console.log(`Registered revision: ${revId}`);
|
|
2440
2472
|
unlinkSync(zipPath);
|