@joiner-platform/cli 0.0.0-stage → 0.1.0
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/README.md +30 -2
- package/bundled-resources/poe-tile-templates/base/CLAUDE.md +72 -0
- package/bundled-resources/poe-tile-templates/base/README.md +7 -0
- package/bundled-resources/poe-tile-templates/base/_bunfig.toml +8 -0
- package/bundled-resources/poe-tile-templates/base/_gitignore +18 -0
- package/bundled-resources/poe-tile-templates/base/client.ts +12 -0
- package/bundled-resources/poe-tile-templates/base/package.json +36 -0
- package/bundled-resources/poe-tile-templates/base/playwright.config.ts +38 -0
- package/bundled-resources/poe-tile-templates/base/scripts/check-source.ts +148 -0
- package/bundled-resources/poe-tile-templates/base/scripts/dev.ts +19 -0
- package/bundled-resources/poe-tile-templates/base/scripts/doctor.sh +29 -0
- package/bundled-resources/poe-tile-templates/base/scripts/visual-check.ts +64 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/backend-config.ts +9 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/client-config.ts +8 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/data/items.ts +16 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/index.ts +10 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/remove-todo.ts +5 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/set-todo.ts +20 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators/types.ts +5 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/mutators.test.ts +138 -0
- package/bundled-resources/poe-tile-templates/base/synced-store/schema.ts +40 -0
- package/bundled-resources/poe-tile-templates/base/tests/e2e.test.playwright.ts +92 -0
- package/bundled-resources/poe-tile-templates/base/tests/mobile-viewport.test.playwright.ts +111 -0
- package/bundled-resources/poe-tile-templates/base/tests/render-check.test.playwright.ts +128 -0
- package/bundled-resources/poe-tile-templates/base/tests/screenshot.test.playwright.ts +86 -0
- package/bundled-resources/poe-tile-templates/base/tests/setup-dom.ts +70 -0
- package/bundled-resources/poe-tile-templates/base/tile/src/backend.ts +3 -0
- package/bundled-resources/poe-tile-templates/base/tile/styles.css +47 -0
- package/bundled-resources/poe-tile-templates/base/tsconfig.json +13 -0
- package/bundled-resources/poe-tile-templates/coverage.config.json +6 -0
- package/bundled-resources/poe-tile-templates/index.ts +27 -0
- package/bundled-resources/poe-tile-templates/package.json +31 -0
- package/bundled-resources/poe-tile-templates/phaserjs/package.partial.json +6 -0
- package/bundled-resources/poe-tile-templates/phaserjs/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/phaserjs/tile/src/entry.ts +35 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/App.test.happydom.tsx +98 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/App.ts +180 -0
- package/bundled-resources/poe-tile-templates/phaserjs/ui/phaser-scene.ts +174 -0
- package/bundled-resources/poe-tile-templates/phaserjs/vite.config.ts +28 -0
- package/bundled-resources/poe-tile-templates/preact/package.partial.json +9 -0
- package/bundled-resources/poe-tile-templates/preact/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/preact/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/preact/tile/src/entry.tsx +36 -0
- package/bundled-resources/poe-tile-templates/preact/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/preact/tsconfig.json +15 -0
- package/bundled-resources/poe-tile-templates/preact/ui/App.test.happydom.tsx +69 -0
- package/bundled-resources/poe-tile-templates/preact/ui/App.tsx +116 -0
- package/bundled-resources/poe-tile-templates/preact/vite.config.ts +18 -0
- package/bundled-resources/poe-tile-templates/react/package.partial.json +12 -0
- package/bundled-resources/poe-tile-templates/react/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/react/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/react/tile/src/entry.tsx +38 -0
- package/bundled-resources/poe-tile-templates/react/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/react/tsconfig.json +14 -0
- package/bundled-resources/poe-tile-templates/react/ui/App.test.happydom.tsx +71 -0
- package/bundled-resources/poe-tile-templates/react/ui/App.tsx +110 -0
- package/bundled-resources/poe-tile-templates/react/vite.config.ts +21 -0
- package/bundled-resources/poe-tile-templates/scripts/cleanup.ts +10 -0
- package/bundled-resources/poe-tile-templates/scripts/generate.ts +57 -0
- package/bundled-resources/poe-tile-templates/scripts/install-diagnostics.ts +52 -0
- package/bundled-resources/poe-tile-templates/scripts/paths.ts +7 -0
- package/bundled-resources/poe-tile-templates/scripts/sdk-dependency-key.ts +288 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-all-sdks.ts +132 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-command.ts +30 -0
- package/bundled-resources/poe-tile-templates/scripts/verify-local-sdk-tarball.ts +397 -0
- package/bundled-resources/poe-tile-templates/solidjs/_bunfig.toml +14 -0
- package/bundled-resources/poe-tile-templates/solidjs/package.partial.json +13 -0
- package/bundled-resources/poe-tile-templates/solidjs/postcss.config.js +5 -0
- package/bundled-resources/poe-tile-templates/solidjs/tests/solid-plugin.ts +49 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/src/entry.tsx +36 -0
- package/bundled-resources/poe-tile-templates/solidjs/tile/styles.css +51 -0
- package/bundled-resources/poe-tile-templates/solidjs/tsconfig.json +15 -0
- package/bundled-resources/poe-tile-templates/solidjs/ui/App.test.happydom.tsx +70 -0
- package/bundled-resources/poe-tile-templates/solidjs/ui/App.tsx +129 -0
- package/bundled-resources/poe-tile-templates/solidjs/vite.config.ts +18 -0
- package/bundled-resources/poe-tile-templates/tests/check-source.test.ts +131 -0
- package/bundled-resources/poe-tile-templates/tests/dev-script.test.slow.ts +166 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/customized-manager.ts +67 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/extended-mutators.ts.txt +106 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/multiplayer-verification.test.playwright.ts.txt +103 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/replace-starter-schema.ts +67 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/phaserjs.tsx.txt +85 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/preact.tsx.txt +69 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/react.tsx.txt +73 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/seating.ts.txt +54 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/solidjs.tsx.txt +70 -0
- package/bundled-resources/poe-tile-templates/tests/fixtures/starter-demo/vanilla-js.tsx.txt +85 -0
- package/bundled-resources/poe-tile-templates/tests/generated-templates.test.ts +278 -0
- package/bundled-resources/poe-tile-templates/tests/happy-dom-version.test.ts +27 -0
- package/bundled-resources/poe-tile-templates/tests/install-diagnostics.test.ts +99 -0
- package/bundled-resources/poe-tile-templates/tests/native-gesture-defaults.test.ts +23 -0
- package/bundled-resources/poe-tile-templates/tests/playwright-version.test.ts +84 -0
- package/bundled-resources/poe-tile-templates/tests/render-check-scaffold.test.ts +56 -0
- package/bundled-resources/poe-tile-templates/tests/sdk-dependency-key.test.ts +129 -0
- package/bundled-resources/poe-tile-templates/tests/visual-check.test.ts +90 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/package.partial.json +3 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/tile/index.html +14 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/tile/src/entry.ts +35 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/ui/App.test.happydom.tsx +96 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/ui/App.ts +113 -0
- package/bundled-resources/poe-tile-templates/vanilla-js/vite.config.ts +17 -0
- package/cli.ts +134 -0
- package/index.ts +96 -0
- package/package.json +48 -5
- package/skills/audio-generation/.generated-by-poe-templated-docs +0 -0
- package/skills/audio-generation/SKILL.md +125 -0
- package/skills/finish-prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/finish-prototype/SKILL.md +22 -0
- package/skills/help-me-build/.generated-by-poe-templated-docs +0 -0
- package/skills/help-me-build/SKILL.md +56 -0
- package/skills/image-generation/.generated-by-poe-templated-docs +0 -0
- package/skills/image-generation/SKILL.md +128 -0
- package/skills/one-shot/.generated-by-poe-templated-docs +0 -0
- package/skills/one-shot/SKILL.md +22 -0
- package/skills/platform-prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/platform-prototype/SKILL.md +60 -0
- package/skills/platform-subagent/.generated-by-poe-templated-docs +0 -0
- package/skills/platform-subagent/SKILL.md +16 -0
- package/skills/poe-tiles-cli/.generated-by-poe-templated-docs +0 -0
- package/skills/poe-tiles-cli/SKILL.md +609 -0
- package/skills/poe-tiles-cli/references/device-motion.md +40 -0
- package/skills/poe-tiles-cli/references/player-updates.md +41 -0
- package/skills/prototype/.generated-by-poe-templated-docs +0 -0
- package/skills/prototype/SKILL.md +148 -0
- package/skills/publish/.generated-by-poe-templated-docs +0 -0
- package/skills/publish/SKILL.md +73 -0
- package/skills/synced-store/.generated-by-poe-templated-docs +0 -0
- package/skills/synced-store/SKILL.md +583 -0
- package/skills/synced-store/references/actions.md +85 -0
- package/skills/synced-store/references/api-patterns.md +245 -0
- package/skills/synced-store/references/architecture-scaling-and-performance.md +280 -0
- package/skills/synced-store/references/client-api-reference.md +263 -0
- package/skills/synced-store/references/data-visibility.md +95 -0
- package/skills/synced-store/references/external-stores.md +162 -0
- package/skills/synced-store/references/file-uploads.md +216 -0
- package/skills/synced-store/references/getting-user-info-of-members.md +228 -0
- package/skills/synced-store/references/limitations.md +72 -0
- package/skills/synced-store/references/live-data-limit-hook.md +131 -0
- package/skills/synced-store/references/mutator-rules.md +169 -0
- package/skills/synced-store/references/platform.md +49 -0
- package/skills/synced-store/references/schema-and-bindings.md +85 -0
- package/skills/synced-store/references/schema-libraries.md +57 -0
- package/skills/synced-store/references/schema-migrations.md +119 -0
- package/skills/synced-store/references/searchable-tables.md +27 -0
- package/skills/synced-store/references/server-forking.md +115 -0
- package/skills/synced-store/references/singleton-tables.md +61 -0
- package/skills/synced-store/references/sort-keys.md +253 -0
- package/skills/synced-store/references/ui-patterns.md +95 -0
- package/skills/tile-creator/.generated-by-poe-templated-docs +0 -0
- package/skills/tile-creator/SKILL.md +196 -0
- package/skills/tile-creator/references/assets.md +124 -0
- package/skills/tile-creator/references/backend-api.md +308 -0
- package/skills/tile-creator/references/cli-limitations.md +64 -0
- package/skills/tile-creator/references/cli.md +604 -0
- package/skills/tile-creator/references/client-api.md +2407 -0
- package/skills/tile-creator/references/composing-apps.md +166 -0
- package/skills/tile-creator/references/e2e-tests.md +55 -0
- package/skills/tile-creator/references/game-ux-best-practices.md +57 -0
- package/skills/tile-creator/references/migrating-pre-rename-tiles.md +79 -0
- package/skills/tile-creator/references/multiplayer-api-recipe.md +205 -0
- package/skills/tile-creator/references/native-results.md +100 -0
- package/skills/tile-creator/references/platform-integration.md +201 -0
- package/skills/tile-creator/references/power-report.md +199 -0
- package/skills/tile-creator/references/publish-rollout.md +166 -0
- package/skills/tile-creator/references/publishing.md +33 -0
- package/skills/tile-creator/references/push-notification-guidelines.md +58 -0
- package/skills/tile-creator/references/render-check.md +266 -0
- package/skills/tile-creator/references/running-the-client-api-on-a-server-owned-by-the-user.md +95 -0
- package/skills/tile-creator/references/safe-area-insets.md +79 -0
- package/skills/tile-creator/references/sandbox-limitations.md +32 -0
- package/skills/tile-creator/references/scaffolded-tile-folder-structure.md +48 -0
- package/skills/tile-creator/references/scaffolding-a-new-app.md +202 -0
- package/skills/tile-creator/references/simulations.md +125 -0
- package/skills/tile-creator/references/synced-store-client-reference.md +92 -0
- package/skills/tile-creator/references/troubleshooting.md +22 -0
- package/skills/tile-creator/references/turn-based-mutator.md +43 -0
- package/skills/tile-creator/references/user-erasure.md +14 -0
- package/skills/tile-creator/references/vite-plugin.md +166 -0
- package/skills/tile-creator/references/workspace-retention.md +72 -0
- package/src/admin-conversions-client.ts +28 -0
- package/src/admin-reviews-client.ts +36 -0
- package/src/api.generated.ts +1527 -0
- package/src/auth-token.ts +198 -0
- package/src/bounded-read.ts +35 -0
- package/src/bun-version.ts +33 -0
- package/src/checkout-base.ts +207 -0
- package/src/cli-bun-version.ts +16 -0
- package/src/cli-env.ts +28 -0
- package/src/cli-name.ts +23 -0
- package/src/client.ts +2474 -0
- package/src/collect-files.ts +226 -0
- package/src/commands/accounts.ts +55 -0
- package/src/commands/admin-abandon-conversion.ts +60 -0
- package/src/commands/admin-reviews.ts +66 -0
- package/src/commands/admin.ts +219 -0
- package/src/commands/auth.ts +89 -0
- package/src/commands/checkout-prototype.ts +67 -0
- package/src/commands/creator-source-capability.ts +11 -0
- package/src/commands/doctor-bun.ts +145 -0
- package/src/commands/doctor-command.ts +64 -0
- package/src/commands/doctor-package-json.ts +47 -0
- package/src/commands/doctor-sdk-pin.ts +156 -0
- package/src/commands/doctor-store-keys-lexer.ts +213 -0
- package/src/commands/doctor-store-keys-scan.ts +262 -0
- package/src/commands/doctor-store-keys.ts +196 -0
- package/src/commands/doctor.ts +371 -0
- package/src/commands/init/blank-scaffold-templates.ts +397 -0
- package/src/commands/init/index.ts +170 -0
- package/src/commands/init/internal-toolchain.ts +49 -0
- package/src/commands/init/manager-test-template.ts +107 -0
- package/src/commands/init/multiplayer-test-template.ts +217 -0
- package/src/commands/init/name-input.tsx +167 -0
- package/src/commands/init/no-store-scaffold-templates.ts +281 -0
- package/src/commands/init/no-store-scaffold.ts +134 -0
- package/src/commands/init/package-json-scripts.ts +72 -0
- package/src/commands/init/scaffold.ts +960 -0
- package/src/commands/init/sdk-tarball-url.generated.ts +4 -0
- package/src/commands/init/sdk-tarball-url.ts +31 -0
- package/src/commands/init/template-picker.tsx +147 -0
- package/src/commands/inspect-child-entry.ts +107 -0
- package/src/commands/inspect-contract.ts +87 -0
- package/src/commands/inspect-freshness.ts +217 -0
- package/src/commands/inspect-lock.ts +201 -0
- package/src/commands/inspect-options.ts +360 -0
- package/src/commands/inspect-orchestrate.ts +375 -0
- package/src/commands/inspect-process.ts +172 -0
- package/src/commands/inspect-ready.ts +65 -0
- package/src/commands/inspect-report.ts +235 -0
- package/src/commands/inspect-run-state.ts +296 -0
- package/src/commands/inspect-run.ts +157 -0
- package/src/commands/inspect-watchdog.ts +74 -0
- package/src/commands/install-joiner.ts +208 -0
- package/src/commands/login.ts +308 -0
- package/src/commands/models.ts +40 -0
- package/src/commands/parse-options.ts +36 -0
- package/src/commands/remix-package-json.ts +64 -0
- package/src/commands/remix.ts +379 -0
- package/src/commands/sdk-url.ts +141 -0
- package/src/commands/simulations.ts +133 -0
- package/src/commands/skills.ts +108 -0
- package/src/commands/store-files.ts +92 -0
- package/src/commands/stores.ts +703 -0
- package/src/commands/tiles-channel-commands.ts +115 -0
- package/src/commands/tiles-checkout.ts +351 -0
- package/src/commands/tiles-gallery-command.ts +95 -0
- package/src/commands/tiles-get-helpers.ts +27 -0
- package/src/commands/tiles-inspect.ts +276 -0
- package/src/commands/tiles-power-command.ts +308 -0
- package/src/commands/tiles-power-format.ts +396 -0
- package/src/commands/tiles-power-versions.ts +299 -0
- package/src/commands/tiles-publish-helpers.ts +145 -0
- package/src/commands/tiles-upload-command.ts +277 -0
- package/src/commands/tiles-version-commands.ts +201 -0
- package/src/commands/tiles-visibility-command.ts +103 -0
- package/src/commands/tiles.ts +257 -0
- package/src/commands/upgrade.ts +307 -0
- package/src/commit-in-progress.ts +42 -0
- package/src/creator-source-context.ts +97 -0
- package/src/creator-source-publish.ts +52 -0
- package/src/deferred-assets.ts +125 -0
- package/src/distribution.ts +28 -0
- package/src/errors.ts +61 -0
- package/src/install-command.ts +43 -0
- package/src/output.ts +62 -0
- package/src/poe-tile-config-files.ts +100 -0
- package/src/poe-tile-config-players.ts +168 -0
- package/src/poe-tile-config-remix.ts +166 -0
- package/src/poe-tile-config.ts +831 -0
- package/src/power-report-client.ts +55 -0
- package/src/prototype-startup.ts +21 -0
- package/src/publish-change-summary.ts +55 -0
- package/src/publish-overrides-validation.ts +49 -0
- package/src/publish-pack.ts +167 -0
- package/src/publish-phases.ts +57 -0
- package/src/publish-retry.ts +51 -0
- package/src/publish-tile-from-config.ts +434 -0
- package/src/recorder-stream.ts +169 -0
- package/src/remix-provenance.ts +156 -0
- package/src/resolve-client-credential.ts +71 -0
- package/src/resolve-media-uploads.ts +147 -0
- package/src/sdk-dependency.ts +54 -0
- package/src/sdk-skills.ts +85 -0
- package/src/should-skip-client-setup.ts +20 -0
- package/src/simulation-snapshot.ts +123 -0
- package/src/simulation-types.ts +74 -0
- package/src/simulations-client.ts +112 -0
- package/src/source-bundle.ts +466 -0
- package/src/staged-publish-cleanup.ts +44 -0
- package/src/staged-publish-deferred.ts +160 -0
- package/src/staged-publish.ts +401 -0
- package/src/store-file-upload.ts +268 -0
- package/src/store-request.ts +168 -0
- package/src/tar-canonical.ts +41 -0
- package/src/tar-extensions.ts +159 -0
- package/src/tar-extract.ts +193 -0
- package/src/tar-parse.ts +224 -0
- package/src/tar.ts +231 -0
- package/src/template-check-scripts.ts +18 -0
- package/src/tile-gallery-client.ts +82 -0
- package/src/types.ts +258 -0
- package/src/upload-concurrency.ts +54 -0
- package/src/whole-tile.ts +52 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// owner: jyoung-q
|
|
2
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
3
|
+
import {
|
|
4
|
+
mkdirSync,
|
|
5
|
+
mkdtempSync,
|
|
6
|
+
readFileSync,
|
|
7
|
+
rmSync,
|
|
8
|
+
writeFileSync,
|
|
9
|
+
} from "node:fs";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import {
|
|
13
|
+
parseVerifyOptions,
|
|
14
|
+
renameSdkSelfImports,
|
|
15
|
+
rewriteSdkSpecifiers,
|
|
16
|
+
useSdkDependencyKey,
|
|
17
|
+
} from "../scripts/sdk-dependency-key";
|
|
18
|
+
|
|
19
|
+
const dirs: string[] = [];
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
for (const dir of dirs.splice(0))
|
|
22
|
+
rmSync(dir, { recursive: true, force: true });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe("parseVerifyOptions", () => {
|
|
26
|
+
test("defaults to the scaffold key and the packed name", () => {
|
|
27
|
+
expect(parseVerifyOptions([])).toEqual({
|
|
28
|
+
dependencyKey: "joiner-sdk",
|
|
29
|
+
tarballName: undefined,
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("reads both options", () => {
|
|
34
|
+
expect(
|
|
35
|
+
parseVerifyOptions([
|
|
36
|
+
"--dependency-key",
|
|
37
|
+
"poe-tiles-sdk",
|
|
38
|
+
"--tarball-name",
|
|
39
|
+
"poe-tiles-sdk",
|
|
40
|
+
]),
|
|
41
|
+
).toEqual({ dependencyKey: "poe-tiles-sdk", tarballName: "poe-tiles-sdk" });
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("rejects an unknown key or option", () => {
|
|
45
|
+
expect(() => parseVerifyOptions(["--dependency-key", "x-sdk"])).toThrow(
|
|
46
|
+
/--dependency-key must be one of/,
|
|
47
|
+
);
|
|
48
|
+
expect(() => parseVerifyOptions(["--key", "joiner-sdk"])).toThrow(
|
|
49
|
+
/Unknown option/,
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("rewriteSdkSpecifiers moves imports and installed paths, nothing else", () => {
|
|
55
|
+
const source = [
|
|
56
|
+
'import { a } from "joiner-sdk/v1/client.js";',
|
|
57
|
+
"import b from 'joiner-sdk/vite';",
|
|
58
|
+
"const c = await import(`joiner-sdk/v1/backend.js`);",
|
|
59
|
+
'/// <reference types="joiner-sdk/vite-client" />',
|
|
60
|
+
'"render-check": "bun node_modules/joiner-sdk/bin/x.js"',
|
|
61
|
+
"// The joiner-sdk docs stay as they are.",
|
|
62
|
+
'"@scope/joiner-sdk-extra"',
|
|
63
|
+
].join("\n");
|
|
64
|
+
expect(rewriteSdkSpecifiers(source, "poe-tiles-sdk")).toBe(
|
|
65
|
+
[
|
|
66
|
+
'import { a } from "poe-tiles-sdk/v1/client.js";',
|
|
67
|
+
"import b from 'poe-tiles-sdk/vite';",
|
|
68
|
+
"const c = await import(`poe-tiles-sdk/v1/backend.js`);",
|
|
69
|
+
'/// <reference types="poe-tiles-sdk/vite-client" />',
|
|
70
|
+
'"render-check": "bun node_modules/poe-tiles-sdk/bin/x.js"',
|
|
71
|
+
"// The joiner-sdk docs stay as they are.",
|
|
72
|
+
'"@scope/joiner-sdk-extra"',
|
|
73
|
+
].join("\n"),
|
|
74
|
+
);
|
|
75
|
+
expect(rewriteSdkSpecifiers(source, "joiner-sdk")).toBe(source);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("useSdkDependencyKey renames the dependency in place and rewrites source", () => {
|
|
79
|
+
const dir = mkdtempSync(join(tmpdir(), "sdk-key-"));
|
|
80
|
+
dirs.push(dir);
|
|
81
|
+
mkdirSync(join(dir, "src"));
|
|
82
|
+
mkdirSync(join(dir, "node_modules/x"), { recursive: true });
|
|
83
|
+
writeFileSync(
|
|
84
|
+
join(dir, "package.json"),
|
|
85
|
+
JSON.stringify({
|
|
86
|
+
dependencies: { a: "1", "joiner-sdk": "file:///sdk.tgz", z: "2" },
|
|
87
|
+
}),
|
|
88
|
+
);
|
|
89
|
+
writeFileSync(
|
|
90
|
+
join(dir, "src/entry.ts"),
|
|
91
|
+
'import { createPoe } from "joiner-sdk/v1/client.js";\n',
|
|
92
|
+
);
|
|
93
|
+
const vendored = 'import "joiner-sdk/v1/client.js";\n';
|
|
94
|
+
writeFileSync(join(dir, "node_modules/x/index.js"), vendored);
|
|
95
|
+
writeFileSync(join(dir, "README.md"), 'Run "joiner-sdk/vite".\n');
|
|
96
|
+
|
|
97
|
+
useSdkDependencyKey(dir, "poe-tiles-sdk");
|
|
98
|
+
|
|
99
|
+
const manifest = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
|
|
100
|
+
expect(Object.entries(manifest.dependencies)).toEqual([
|
|
101
|
+
["a", "1"],
|
|
102
|
+
["poe-tiles-sdk", "file:///sdk.tgz"],
|
|
103
|
+
["z", "2"],
|
|
104
|
+
]);
|
|
105
|
+
expect(readFileSync(join(dir, "src/entry.ts"), "utf8")).toBe(
|
|
106
|
+
'import { createPoe } from "poe-tiles-sdk/v1/client.js";\n',
|
|
107
|
+
);
|
|
108
|
+
expect(readFileSync(join(dir, "node_modules/x/index.js"), "utf8")).toBe(
|
|
109
|
+
vendored,
|
|
110
|
+
);
|
|
111
|
+
expect(readFileSync(join(dir, "README.md"), "utf8")).toBe(
|
|
112
|
+
'Run "joiner-sdk/vite".\n',
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("renameSdkSelfImports renames self-imports and keeps the wire specifier", () => {
|
|
117
|
+
const packed = [
|
|
118
|
+
'import { h } from "joiner-sdk/v1/test-utils/harness.js";',
|
|
119
|
+
"export * from 'joiner-sdk/v1/test-utils.js';",
|
|
120
|
+
'const sdk = await import("poe-tiles-sdk/v1/client.js");',
|
|
121
|
+
].join("\n");
|
|
122
|
+
expect(renameSdkSelfImports(packed, "poe-tiles-sdk")).toBe(
|
|
123
|
+
[
|
|
124
|
+
'import { h } from "poe-tiles-sdk/v1/test-utils/harness.js";',
|
|
125
|
+
"export * from 'poe-tiles-sdk/v1/test-utils.js';",
|
|
126
|
+
'const sdk = await import("poe-tiles-sdk/v1/client.js");',
|
|
127
|
+
].join("\n"),
|
|
128
|
+
);
|
|
129
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { existsSync, mkdtempSync, rmSync, statSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import {
|
|
6
|
+
VISUAL_CHECKS_DIR,
|
|
7
|
+
visualCheckPath,
|
|
8
|
+
} from "../base/scripts/visual-check";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Runs `body` inside `runVisualCheck` in a child process. The trailing
|
|
12
|
+
* "unreachable" line proves the wrapper ends the process: no case may print it.
|
|
13
|
+
*/
|
|
14
|
+
function spawnCheck(body: string) {
|
|
15
|
+
const wrapper = join(import.meta.dir, "../base/scripts/visual-check.ts");
|
|
16
|
+
return Bun.spawnSync(
|
|
17
|
+
[
|
|
18
|
+
process.execPath,
|
|
19
|
+
"--eval",
|
|
20
|
+
`import { runVisualCheck } from ${JSON.stringify(wrapper)}; await runVisualCheck(async () => { ${body} }); console.log("unreachable");`,
|
|
21
|
+
],
|
|
22
|
+
{ stdout: "pipe", stderr: "pipe", timeout: 5_000 },
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
test("a passing visual check exits 0 even when it leaves a server open", () => {
|
|
27
|
+
// A check that never closes its TestServer (or calls its nonexistent
|
|
28
|
+
// `stop`) kept the event loop alive after its last screenshot, so the
|
|
29
|
+
// command ran until a timeout killed it. spawnCheck's 5 s timeout kills
|
|
30
|
+
// such a child, which then has no exit code 0.
|
|
31
|
+
const result = spawnCheck(
|
|
32
|
+
'Bun.serve({ port: 0, fetch: () => new Response("ok") }); setInterval(() => {}, 1_000); console.log("checked");',
|
|
33
|
+
);
|
|
34
|
+
expect(result.exitCode).toBe(0);
|
|
35
|
+
expect(result.signalCode).toBeFalsy();
|
|
36
|
+
expect(result.stdout.toString()).toBe("checked\n");
|
|
37
|
+
expect(result.stderr.toString()).toBe("");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("a passing visual check waits for its async work before exiting", () => {
|
|
41
|
+
const result = spawnCheck(
|
|
42
|
+
'await new Promise((resolve) => setTimeout(resolve, 200)); console.log("after the wait");',
|
|
43
|
+
);
|
|
44
|
+
expect(result.exitCode).toBe(0);
|
|
45
|
+
expect(result.stdout.toString()).toBe("after the wait\n");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test.each([
|
|
49
|
+
{
|
|
50
|
+
expression: 'new Error("Locator failed\\nCall log:\\nwaiting for button")',
|
|
51
|
+
expected: "Locator failed\nCall log:\nwaiting for button\n",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
expression:
|
|
55
|
+
'Object.assign(new Error("Locator failed"), { callLog: ["Call log:", "waiting for button"] })',
|
|
56
|
+
expected: "Locator failed\nCall log:\nwaiting for button\n",
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
expression:
|
|
60
|
+
'Object.assign(new Error("Locator failed\\nwaiting for button"), { callLog: "waiting for button" })',
|
|
61
|
+
expected: "Locator failed\nwaiting for button\n",
|
|
62
|
+
},
|
|
63
|
+
{ expression: '"Visual check failed"', expected: "Visual check failed\n" },
|
|
64
|
+
])("visual-check failure exits 1 with only its message and call log: $expression", ({
|
|
65
|
+
expression,
|
|
66
|
+
expected,
|
|
67
|
+
}) => {
|
|
68
|
+
const result = spawnCheck(`throw ${expression};`);
|
|
69
|
+
expect(result.exitCode).toBe(1);
|
|
70
|
+
expect(result.stdout.toString()).toBe("");
|
|
71
|
+
expect(result.stderr.toString()).toBe(expected);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("visualCheckPath creates the ignored frames directory and names a file inside it", () => {
|
|
75
|
+
// `.visual-checks/` is what the scaffold's .gitignore and the CLI's source
|
|
76
|
+
// bundle both exclude, so frames written here never reach a publish.
|
|
77
|
+
const root = mkdtempSync(join(tmpdir(), "visual-check-"));
|
|
78
|
+
try {
|
|
79
|
+
const path = visualCheckPath("phone-dark.png", root);
|
|
80
|
+
expect(path).toBe(join(root, VISUAL_CHECKS_DIR, "phone-dark.png"));
|
|
81
|
+
expect(statSync(join(root, VISUAL_CHECKS_DIR)).isDirectory()).toBe(true);
|
|
82
|
+
expect(existsSync(path)).toBe(false);
|
|
83
|
+
// Idempotent: a second frame does not trip over the existing directory.
|
|
84
|
+
expect(visualCheckPath("phone-light.png", root)).toContain(
|
|
85
|
+
VISUAL_CHECKS_DIR,
|
|
86
|
+
);
|
|
87
|
+
} finally {
|
|
88
|
+
rmSync(root, { recursive: true, force: true });
|
|
89
|
+
}
|
|
90
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
|
6
|
+
<meta name="color-scheme" content="light dark">
|
|
7
|
+
<title>{{APP_NAME}}</title>
|
|
8
|
+
<link rel="stylesheet" href="styles.css">
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<div id="root"></div>
|
|
12
|
+
<script type="module" src="src/entry.ts"></script>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entry point — the only file that imports joiner-sdk.
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
applyNativeAppGestureOverrides,
|
|
6
|
+
createPoe,
|
|
7
|
+
createVerticalScrollBounceMount,
|
|
8
|
+
PostMessageEnvironment,
|
|
9
|
+
} from "joiner-sdk/v1/client.js";
|
|
10
|
+
import { todoClientConfig } from "../../client";
|
|
11
|
+
import { createApp } from "../../ui/App";
|
|
12
|
+
|
|
13
|
+
applyNativeAppGestureOverrides();
|
|
14
|
+
|
|
15
|
+
const environment = new PostMessageEnvironment();
|
|
16
|
+
const Poe = createPoe({ environment });
|
|
17
|
+
const store = Poe.setupStore(todoClientConfig);
|
|
18
|
+
|
|
19
|
+
const root = document.getElementById("root");
|
|
20
|
+
if (root) {
|
|
21
|
+
// Wait for authoritative data (cached locally OR first server pull —
|
|
22
|
+
// whichever wins) before mounting so the UI never paints with empty
|
|
23
|
+
// state on revisit. Resolves immediately when the host sets
|
|
24
|
+
// `is-new` on the parent <poe-tile>, since a fresh instance has no
|
|
25
|
+
// data to load.
|
|
26
|
+
void store.waitForBootstrap().then(
|
|
27
|
+
() => {
|
|
28
|
+
const appRoot = createVerticalScrollBounceMount(root);
|
|
29
|
+
createApp(appRoot, store);
|
|
30
|
+
},
|
|
31
|
+
() => {
|
|
32
|
+
// Client termination before bootstrap is handled by the host.
|
|
33
|
+
},
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Happy-dom UI tests for the vanilla-js todo app.
|
|
3
|
+
*
|
|
4
|
+
* Mounts `createApp(root, store)` against a real SyncedStoreClient via
|
|
5
|
+
* `createPoeTileTestHarness`. Two clients share the same in-memory backend,
|
|
6
|
+
* which lets us verify that a mutation made by user-2 flows through the sync
|
|
7
|
+
* protocol and appears in user-1's DOM — the core multi-user guarantee of
|
|
8
|
+
* synced-store.
|
|
9
|
+
*/
|
|
10
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
11
|
+
import { createPoeTileTestHarness, tick } from "joiner-sdk/v1/test-utils.js";
|
|
12
|
+
import { todoBackendConfig } from "../synced-store/backend-config";
|
|
13
|
+
import type { TodoSchema } from "../synced-store/schema";
|
|
14
|
+
import { createApp } from "./App";
|
|
15
|
+
|
|
16
|
+
const mounted: HTMLElement[] = [];
|
|
17
|
+
|
|
18
|
+
function mountApp(store: Parameters<typeof createApp>[1]): HTMLElement {
|
|
19
|
+
const container = document.createElement("div");
|
|
20
|
+
document.body.appendChild(container);
|
|
21
|
+
mounted.push(container);
|
|
22
|
+
createApp(container, store);
|
|
23
|
+
return container;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Yields with the SDK's `tick()` (a microtask plus a macrotask) instead of a
|
|
27
|
+
// raw `setTimeout`, which the repo's `.grit/no-settimeout-in-tests` plugin
|
|
28
|
+
// rejects, and retries by recursion because `noAwaitInLoops` bans `await`
|
|
29
|
+
// inside a loop body. A scaffold committed with `--internal-mono-repo` is
|
|
30
|
+
// linted by both rules on its first run.
|
|
31
|
+
async function waitFor(fn: () => boolean, timeoutMs = 2000): Promise<void> {
|
|
32
|
+
const deadline = Date.now() + timeoutMs;
|
|
33
|
+
const attempt = async (): Promise<void> => {
|
|
34
|
+
if (fn()) return;
|
|
35
|
+
if (Date.now() > deadline) {
|
|
36
|
+
throw new Error("waitFor: condition not met within timeout");
|
|
37
|
+
}
|
|
38
|
+
await tick();
|
|
39
|
+
return attempt();
|
|
40
|
+
};
|
|
41
|
+
return attempt();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe("Todo App UI", () => {
|
|
45
|
+
afterEach(() => {
|
|
46
|
+
for (const el of mounted) el.remove();
|
|
47
|
+
mounted.length = 0;
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("user-1 can add a todo from the UI", async () => {
|
|
51
|
+
const harness = createPoeTileTestHarness<TodoSchema>({
|
|
52
|
+
store: { backendConfig: todoBackendConfig },
|
|
53
|
+
});
|
|
54
|
+
const { store } = await harness.createClient({ userId: "user-1" });
|
|
55
|
+
|
|
56
|
+
const container = mountApp(store);
|
|
57
|
+
|
|
58
|
+
await waitFor(() => !!container.querySelector("#todo-input"));
|
|
59
|
+
expect(container.querySelector("#todo-input")).toBeInTheDocument();
|
|
60
|
+
|
|
61
|
+
const input = container.querySelector("#todo-input") as HTMLInputElement;
|
|
62
|
+
const addBtn = container.querySelector("#add-btn") as HTMLButtonElement;
|
|
63
|
+
|
|
64
|
+
input.value = "Buy milk";
|
|
65
|
+
addBtn.click();
|
|
66
|
+
|
|
67
|
+
await waitFor(() => (container.textContent ?? "").includes("Buy milk"));
|
|
68
|
+
expect(container).toHaveTextContent("Buy milk");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("todo added by user-2 appears in user-1's UI", async () => {
|
|
72
|
+
const harness = createPoeTileTestHarness<TodoSchema>({
|
|
73
|
+
store: { backendConfig: todoBackendConfig },
|
|
74
|
+
});
|
|
75
|
+
const { store: store1 } = await harness.createClient({ userId: "user-1" });
|
|
76
|
+
const { store: store2 } = await harness.createClient({ userId: "user-2" });
|
|
77
|
+
|
|
78
|
+
const container = mountApp(store1);
|
|
79
|
+
|
|
80
|
+
await waitFor(() => !!container.querySelector("#todo-input"));
|
|
81
|
+
expect(container.querySelector("#todo-input")).toBeInTheDocument();
|
|
82
|
+
|
|
83
|
+
await store2.mutate.setTodo({
|
|
84
|
+
id: "todo-from-user-2",
|
|
85
|
+
text: "Pick up groceries",
|
|
86
|
+
completed: false,
|
|
87
|
+
createdAt: 1000,
|
|
88
|
+
order: 1,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
await waitFor(() =>
|
|
92
|
+
(container.textContent ?? "").includes("Pick up groceries"),
|
|
93
|
+
);
|
|
94
|
+
expect(container).toHaveTextContent("Pick up groceries");
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { type PoeUserInfo, usableDisplayName } from "joiner-sdk/v1/shared.js";
|
|
2
|
+
import type { TodoItem, TodoStoreClient } from "../client";
|
|
3
|
+
|
|
4
|
+
function escapeHtml(text: string): string {
|
|
5
|
+
return text
|
|
6
|
+
.replace(/&/g, "&")
|
|
7
|
+
.replace(/</g, "<")
|
|
8
|
+
.replace(/>/g, ">")
|
|
9
|
+
.replace(/"/g, """);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function createApp(root: HTMLElement, store: TodoStoreClient): void {
|
|
13
|
+
let todos: TodoItem[] = [];
|
|
14
|
+
let userInfoMap = new Map<string, PoeUserInfo>();
|
|
15
|
+
|
|
16
|
+
function getDisplayName(userId: string): string {
|
|
17
|
+
const info = userInfoMap.get(userId);
|
|
18
|
+
// Never render an internal id (`u_<hex>` / `u_migrated_...` /
|
|
19
|
+
// `private-...`) as a name; the shared masker returns "" when nothing
|
|
20
|
+
// usable is present.
|
|
21
|
+
return usableDisplayName(info) || "Player";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function render(): void {
|
|
25
|
+
root.innerHTML = `
|
|
26
|
+
<h1>{{ APP_NAME }}</h1>
|
|
27
|
+
<div>
|
|
28
|
+
<input id="todo-input" placeholder="What needs to be done?" />
|
|
29
|
+
<button id="add-btn" type="button">Add</button>
|
|
30
|
+
</div>
|
|
31
|
+
<ul id="todo-list">
|
|
32
|
+
${todos
|
|
33
|
+
.map(
|
|
34
|
+
(t) => `
|
|
35
|
+
<li data-id="${escapeHtml(t.id)}">
|
|
36
|
+
<input type="checkbox" ${t.completed ? "checked" : ""} />
|
|
37
|
+
<span style="text-decoration: ${t.completed ? "line-through" : "none"}">${escapeHtml(t.text)}</span>
|
|
38
|
+
<span style="color: #888; font-size: 0.85em; margin-left: 8px">— ${escapeHtml(getDisplayName(t.createdBy))}</span>
|
|
39
|
+
<button type="button" class="delete-btn">Delete</button>
|
|
40
|
+
</li>`,
|
|
41
|
+
)
|
|
42
|
+
.join("")}
|
|
43
|
+
</ul>
|
|
44
|
+
`;
|
|
45
|
+
|
|
46
|
+
root.querySelector("#add-btn")?.addEventListener("click", addTodo);
|
|
47
|
+
root.querySelector("#todo-input")?.addEventListener("keydown", (e) => {
|
|
48
|
+
if ((e as KeyboardEvent).key === "Enter") addTodo();
|
|
49
|
+
});
|
|
50
|
+
for (const li of root.querySelectorAll("li")) {
|
|
51
|
+
const { id } = li.dataset;
|
|
52
|
+
if (!id) continue;
|
|
53
|
+
li.querySelector("input[type=checkbox]")?.addEventListener(
|
|
54
|
+
"change",
|
|
55
|
+
() => {
|
|
56
|
+
const todo = todos.find((t) => t.id === id);
|
|
57
|
+
if (todo) {
|
|
58
|
+
store.mutate.setTodo({
|
|
59
|
+
id: todo.id,
|
|
60
|
+
completed: !todo.completed,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
);
|
|
65
|
+
li.querySelector(".delete-btn")?.addEventListener("click", () =>
|
|
66
|
+
store.mutate.removeTodo({ id }),
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function addTodo(): void {
|
|
72
|
+
const input = root.querySelector("#todo-input") as HTMLInputElement;
|
|
73
|
+
const text = input.value.trim();
|
|
74
|
+
if (!text) return;
|
|
75
|
+
const now = Date.now();
|
|
76
|
+
const maxOrder = todos.reduce((max, t) => Math.max(max, t.order), 0);
|
|
77
|
+
store.mutate.setTodo({
|
|
78
|
+
id: crypto.randomUUID(),
|
|
79
|
+
text,
|
|
80
|
+
completed: false,
|
|
81
|
+
createdAt: now,
|
|
82
|
+
order: maxOrder + 1,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
store.subscribe(
|
|
87
|
+
(tx) => tx.table("items").entries().toArray(),
|
|
88
|
+
(entries) => {
|
|
89
|
+
todos = entries
|
|
90
|
+
.map(([, v]) => v as TodoItem)
|
|
91
|
+
.sort((a, b) => a.order - b.order);
|
|
92
|
+
render();
|
|
93
|
+
},
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
// Subscribe to the $userInfo system table for display names.
|
|
97
|
+
// $userInfo is auto-populated when a user first connects to the store.
|
|
98
|
+
store.subscribe(
|
|
99
|
+
(tx) => tx.table("$userInfo").entries().toArray(),
|
|
100
|
+
(entries) => {
|
|
101
|
+
const map = new Map<string, PoeUserInfo>();
|
|
102
|
+
for (const [, v] of entries) {
|
|
103
|
+
const info = v;
|
|
104
|
+
map.set(info.userId, info);
|
|
105
|
+
}
|
|
106
|
+
userInfoMap = map;
|
|
107
|
+
render();
|
|
108
|
+
},
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
// Initial render with loading state
|
|
112
|
+
render();
|
|
113
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { poeTile } from "joiner-sdk/vite";
|
|
2
|
+
import { defineConfig } from "vite";
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
root: "tile",
|
|
6
|
+
build: {
|
|
7
|
+
outDir: "../dist",
|
|
8
|
+
emptyOutDir: true,
|
|
9
|
+
rollupOptions: {
|
|
10
|
+
output: {
|
|
11
|
+
entryFileNames: "tile-frontend.js",
|
|
12
|
+
assetFileNames: "[name][extname]",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
plugins: [poeTile({ backendEntryPoint: "src/backend.ts" })],
|
|
17
|
+
});
|
package/cli.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// owner: jyoung-q
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* CLI entry point for joiner and the compatible poe-tiles command.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* poe-tiles [--json] [--server <url>] [--api-key <key>] <command> [args]
|
|
9
|
+
*
|
|
10
|
+
* Authentication:
|
|
11
|
+
* poe-tiles login — Creates a local session token.
|
|
12
|
+
* --api-key, POE_API_KEY, or ~/.poe-tiles/poe-tiles-api-key — Legacy API-key auth for API-backed commands.
|
|
13
|
+
* POE_TILES_SESSION_TOKEN or ~/.poe-tiles/poe-tiles-session-token — Session-token auth for API-backed commands.
|
|
14
|
+
* POE_SERVER_URL — Optional Tiles server URL override.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { Command } from "commander";
|
|
18
|
+
import { cliName } from "./src/cli-name.js";
|
|
19
|
+
import { SlopPoeClient } from "./src/client.js";
|
|
20
|
+
import { createAccountsCommands } from "./src/commands/accounts.js";
|
|
21
|
+
import { createAdminCommands } from "./src/commands/admin.js";
|
|
22
|
+
import { createAuthCommands } from "./src/commands/auth.js";
|
|
23
|
+
import { createCreatorSourceCapabilityCommand } from "./src/commands/creator-source-capability.js";
|
|
24
|
+
import { createDoctorCommand } from "./src/commands/doctor-command.js";
|
|
25
|
+
import { createInstallJoinerCommand } from "./src/commands/install-joiner.js";
|
|
26
|
+
import { createLoginCommand } from "./src/commands/login.js";
|
|
27
|
+
import { createModelsCommands } from "./src/commands/models.js";
|
|
28
|
+
import { createRemixCommand } from "./src/commands/remix.js";
|
|
29
|
+
import { createSdkUrlCommand } from "./src/commands/sdk-url.js";
|
|
30
|
+
import { createSimulationsCommands } from "./src/commands/simulations.js";
|
|
31
|
+
import { createSkillsCommands } from "./src/commands/skills.js";
|
|
32
|
+
import { createStoresCommands } from "./src/commands/stores.js";
|
|
33
|
+
import { createTilesCommands } from "./src/commands/tiles.js";
|
|
34
|
+
import { createUpgradeCommand } from "./src/commands/upgrade.js";
|
|
35
|
+
import { cliDistribution, CLI_VERSION } from "./src/distribution.js";
|
|
36
|
+
import { CliError } from "./src/errors.js";
|
|
37
|
+
import { resolveClientCredential } from "./src/resolve-client-credential.js";
|
|
38
|
+
import { shouldSkipClientSetup } from "./src/should-skip-client-setup.js";
|
|
39
|
+
|
|
40
|
+
const program = new Command();
|
|
41
|
+
|
|
42
|
+
program
|
|
43
|
+
.name(cliName())
|
|
44
|
+
.description("CLI for the Joiner REST API")
|
|
45
|
+
.version(CLI_VERSION)
|
|
46
|
+
.option("--json", "Output as JSON")
|
|
47
|
+
.option("--server <url>", "Server URL override")
|
|
48
|
+
.option("--api-key <key>", "Poe API key override")
|
|
49
|
+
.hook("preAction", (_thisCommand, actionCommand) => {
|
|
50
|
+
if (shouldSkipClientSetup(actionCommand)) return;
|
|
51
|
+
const root = rootCommand(actionCommand);
|
|
52
|
+
root.setOptionValue("_client", createClientForCommand(actionCommand, root));
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Lazy proxy: commands reference this at registration time, but the real
|
|
56
|
+
// client is only created by the preAction hook at execution time.
|
|
57
|
+
const clientProxy = new Proxy({} as SlopPoeClient, {
|
|
58
|
+
get(_target, prop) {
|
|
59
|
+
const opts = program.opts() as Record<string, unknown>;
|
|
60
|
+
const realClient = opts["_client"] as SlopPoeClient | undefined;
|
|
61
|
+
if (!realClient) {
|
|
62
|
+
throw new CliError("Client not initialized (this is a bug)");
|
|
63
|
+
}
|
|
64
|
+
// Cast through unknown to access dynamic properties on the typed client instance
|
|
65
|
+
const value = (realClient as unknown as Record<string | symbol, unknown>)[
|
|
66
|
+
prop
|
|
67
|
+
];
|
|
68
|
+
if (typeof value === "function") {
|
|
69
|
+
return value.bind(realClient);
|
|
70
|
+
}
|
|
71
|
+
return value;
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
program.addCommand(createAuthCommands(clientProxy));
|
|
76
|
+
program.addCommand(createLoginCommand(clientProxy));
|
|
77
|
+
program.addCommand(createTilesCommands(clientProxy));
|
|
78
|
+
program.addCommand(createRemixCommand(clientProxy));
|
|
79
|
+
program.addCommand(createModelsCommands(clientProxy));
|
|
80
|
+
program.addCommand(createAccountsCommands(clientProxy));
|
|
81
|
+
program.addCommand(createDoctorCommand());
|
|
82
|
+
program.addCommand(createSkillsCommands());
|
|
83
|
+
program.addCommand(createStoresCommands(clientProxy));
|
|
84
|
+
program.addCommand(createSimulationsCommands(clientProxy));
|
|
85
|
+
program.addCommand(createAdminCommands(clientProxy));
|
|
86
|
+
program.addCommand(createUpgradeCommand());
|
|
87
|
+
// The npm package already installs `joiner`; the launcher is for the tarball.
|
|
88
|
+
if (cliDistribution() === "tarball")
|
|
89
|
+
program.addCommand(createInstallJoinerCommand());
|
|
90
|
+
program.addCommand(createSdkUrlCommand());
|
|
91
|
+
program.addCommand(createCreatorSourceCapabilityCommand(), { hidden: true });
|
|
92
|
+
|
|
93
|
+
type RootOptions = {
|
|
94
|
+
apiKey?: string;
|
|
95
|
+
server?: string;
|
|
96
|
+
_client?: SlopPoeClient;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
function rootCommand(actionCommand: Command): Command {
|
|
100
|
+
let root = actionCommand;
|
|
101
|
+
while (root.parent) root = root.parent;
|
|
102
|
+
return root;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function createClientForCommand(
|
|
106
|
+
actionCommand: Command,
|
|
107
|
+
root: Command,
|
|
108
|
+
): SlopPoeClient {
|
|
109
|
+
const opts = root.opts() as RootOptions;
|
|
110
|
+
const commonOptions = {
|
|
111
|
+
serverUrl: opts.server ?? process.env["POE_SERVER_URL"],
|
|
112
|
+
};
|
|
113
|
+
if (actionCommand.name() === "login") {
|
|
114
|
+
return new SlopPoeClient(commonOptions);
|
|
115
|
+
}
|
|
116
|
+
return new SlopPoeClient({
|
|
117
|
+
...commonOptions,
|
|
118
|
+
...resolveClientCredential({ apiKey: opts.apiKey, env: process.env }),
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function main(): Promise<void> {
|
|
123
|
+
try {
|
|
124
|
+
await program.parseAsync(process.argv);
|
|
125
|
+
} catch (error) {
|
|
126
|
+
if (error instanceof CliError) {
|
|
127
|
+
console.error(`Error: ${error.message}`);
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
void main();
|