feat(mobile): add built-in themes (#6619)
This commit is contained in:
1 parent
3583cd27dc
commit
d23b181da0
76 files changed
+3089
-837
No files matched your search
@@ -1,3 +1,9 @@
|
||||
import {
|
||||
MOBILE_DEFAULT_THEME_ID,
|
||||
MOBILE_THEME_IDS,
|
||||
type MobileThemeId,
|
||||
} from "@t3tools/shared/themePalettes";
|
||||
|
||||
import { SHOWCASE_SCENES, type ShowcaseScene } from "./mobile-showcase-environment.ts";
|
||||
|
||||
export { SHOWCASE_SCENES };
|
||||
@@ -5,6 +11,11 @@ export type { ShowcaseScene };
|
||||
|
||||
export type ShowcaseAppearance = "light" | "dark";
|
||||
|
||||
/** Every palette the mobile appearance settings can select. */
|
||||
export const SHOWCASE_THEMES = MOBILE_THEME_IDS;
|
||||
export const DEFAULT_SHOWCASE_THEME = MOBILE_DEFAULT_THEME_ID;
|
||||
export type ShowcaseTheme = MobileThemeId;
|
||||
|
||||
export interface ShowcaseStoreAssetSpec {
|
||||
readonly store: "apple" | "google-play";
|
||||
/** Device directory relative to ShowcaseConfig.outputDirectory. */
|
||||
@@ -25,6 +36,8 @@ export interface ShowcaseIosDevice {
|
||||
readonly simulatorDeviceType?: string;
|
||||
/** Appearance used when the CLI does not pass --appearance. */
|
||||
readonly appearance: ShowcaseAppearance;
|
||||
/** Palette used when the CLI does not pass --theme. */
|
||||
readonly theme: ShowcaseTheme;
|
||||
/** Orientation applied by the capture harness. Defaults to portrait. */
|
||||
readonly orientation?: "portrait" | "landscape";
|
||||
readonly scenes: ReadonlyArray<ShowcaseScene>;
|
||||
@@ -38,6 +51,8 @@ export interface ShowcaseAndroidDevice {
|
||||
readonly avd: string;
|
||||
/** Appearance used when the CLI does not pass --appearance. */
|
||||
readonly appearance: ShowcaseAppearance;
|
||||
/** Palette used when the CLI does not pass --theme. */
|
||||
readonly theme: ShowcaseTheme;
|
||||
/** Native ABI used by the AVD, from its config.ini `abi.type`. */
|
||||
readonly abi?: "arm64-v8a" | "x86_64" | "x86" | "armeabi-v7a";
|
||||
readonly scenes: ReadonlyArray<ShowcaseScene>;
|
||||
@@ -92,6 +107,7 @@ const config: ShowcaseConfig = {
|
||||
simulator: "iPhone 17 Pro Max",
|
||||
simulatorDeviceType: "com.apple.CoreSimulator.SimDeviceType.iPhone-17-Pro-Max",
|
||||
appearance: "dark",
|
||||
theme: DEFAULT_SHOWCASE_THEME,
|
||||
scenes: ["thread", "terminal", "review", "threads", "environments"],
|
||||
storeAsset: {
|
||||
store: "apple",
|
||||
@@ -108,6 +124,7 @@ const config: ShowcaseConfig = {
|
||||
simulator: "T3 Showcase iPhone 14 Plus",
|
||||
simulatorDeviceType: "com.apple.CoreSimulator.SimDeviceType.iPhone-14-Plus",
|
||||
appearance: "dark",
|
||||
theme: DEFAULT_SHOWCASE_THEME,
|
||||
scenes: ["thread", "terminal", "review", "threads", "environments"],
|
||||
storeAsset: {
|
||||
store: "apple",
|
||||
@@ -124,6 +141,7 @@ const config: ShowcaseConfig = {
|
||||
simulator: "iPad Pro 13-inch (M5)",
|
||||
simulatorDeviceType: "com.apple.CoreSimulator.SimDeviceType.iPad-Pro-13-inch-M5-16GB",
|
||||
appearance: "dark",
|
||||
theme: DEFAULT_SHOWCASE_THEME,
|
||||
orientation: "landscape",
|
||||
scenes: ["thread", "terminal", "review", "threads", "environments"],
|
||||
storeAsset: {
|
||||
@@ -143,6 +161,7 @@ const config: ShowcaseConfig = {
|
||||
// Blacksmith Linux runner can use KVM acceleration.
|
||||
abi: resolveShowcaseAndroidAbi(process.env.T3_SHOWCASE_ANDROID_ABI),
|
||||
appearance: "dark",
|
||||
theme: DEFAULT_SHOWCASE_THEME,
|
||||
viewport: {
|
||||
width: 1080,
|
||||
height: 1920,
|
||||
@@ -165,6 +184,7 @@ const config: ShowcaseConfig = {
|
||||
avd: "Pixel_10_Pro",
|
||||
abi: resolveShowcaseAndroidAbi(process.env.T3_SHOWCASE_ANDROID_ABI),
|
||||
appearance: "dark",
|
||||
theme: DEFAULT_SHOWCASE_THEME,
|
||||
viewport: {
|
||||
width: 1080,
|
||||
height: 1920,
|
||||
@@ -187,6 +207,7 @@ const config: ShowcaseConfig = {
|
||||
avd: "Pixel_10_Pro",
|
||||
abi: resolveShowcaseAndroidAbi(process.env.T3_SHOWCASE_ANDROID_ABI),
|
||||
appearance: "dark",
|
||||
theme: DEFAULT_SHOWCASE_THEME,
|
||||
viewport: {
|
||||
width: 1440,
|
||||
height: 2560,
|
||||
|
||||
@@ -2,7 +2,9 @@ import { assert, it } from "@effect/vitest";
|
||||
import { PNG } from "pngjs";
|
||||
|
||||
import showcaseConfig, {
|
||||
DEFAULT_SHOWCASE_THEME,
|
||||
resolveShowcaseAndroidAbi,
|
||||
SHOWCASE_THEMES,
|
||||
type ShowcaseConfig,
|
||||
type ShowcaseStoreAssetSpec,
|
||||
} from "./mobile-showcase.config.ts";
|
||||
@@ -55,6 +57,7 @@ const config: ShowcaseConfig = {
|
||||
platform: "ios",
|
||||
simulator: "iPhone Test",
|
||||
appearance: "dark",
|
||||
theme: "t3-code",
|
||||
scenes: ["thread", "review"],
|
||||
storeAsset: appleSpec,
|
||||
},
|
||||
@@ -63,6 +66,7 @@ const config: ShowcaseConfig = {
|
||||
platform: "android",
|
||||
avd: "Pixel_Test",
|
||||
appearance: "light",
|
||||
theme: "t3-code",
|
||||
scenes: ["thread", "terminal"],
|
||||
storeAsset: googleSpec,
|
||||
},
|
||||
@@ -95,6 +99,23 @@ it("rejects unsupported system appearances", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("parses repeatable and expanded theme filters", () => {
|
||||
assert.deepStrictEqual(
|
||||
[...parseShowcaseCliArgs(["--theme", "ocean", "--theme", "ember"]).themes],
|
||||
["ocean", "ember"],
|
||||
);
|
||||
assert.deepStrictEqual(
|
||||
[...parseShowcaseCliArgs(["--theme", "all"]).themes],
|
||||
[...SHOWCASE_THEMES],
|
||||
);
|
||||
});
|
||||
|
||||
// The app normalizes an unknown id back to its default palette, so a typo here
|
||||
// would otherwise produce screenshots labeled with a theme they do not show.
|
||||
it("rejects unsupported themes instead of capturing the default palette", () => {
|
||||
assert.throws(() => parseShowcaseCliArgs(["--theme", "sunset"]), /Unsupported theme 'sunset'/u);
|
||||
});
|
||||
|
||||
it("parses validation-only mode", () => {
|
||||
assert.equal(parseShowcaseCliArgs(["--validate-only"]).validateOnly, true);
|
||||
});
|
||||
@@ -146,8 +167,35 @@ it("expands both appearances into independent upload-ready directories", () => {
|
||||
directory: showcaseCaptureDirectory("/captures", capture),
|
||||
})),
|
||||
[
|
||||
{ appearance: "light", directory: "/captures/apple/iphone-test/light" },
|
||||
{ appearance: "dark", directory: "/captures/apple/iphone-test/dark" },
|
||||
{ appearance: "light", directory: "/captures/apple/iphone-test/light/t3-code" },
|
||||
{ appearance: "dark", directory: "/captures/apple/iphone-test/dark/t3-code" },
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
// Every palette needs its own leaf folder: one directory holding several themes
|
||||
// would mix upload slots and break the per-store screenshot count limits.
|
||||
it("expands themes into independent upload-ready directories per appearance", () => {
|
||||
const options = parseShowcaseCliArgs([
|
||||
"--device",
|
||||
"phone",
|
||||
"--appearance",
|
||||
"both",
|
||||
"--theme",
|
||||
"ocean",
|
||||
"--theme",
|
||||
"ember",
|
||||
]);
|
||||
|
||||
assert.deepStrictEqual(
|
||||
planShowcaseCaptures(config, options).map((capture) =>
|
||||
showcaseCaptureDirectory("/captures", capture),
|
||||
),
|
||||
[
|
||||
"/captures/apple/iphone-test/light/ocean",
|
||||
"/captures/apple/iphone-test/light/ember",
|
||||
"/captures/apple/iphone-test/dark/ocean",
|
||||
"/captures/apple/iphone-test/dark/ember",
|
||||
],
|
||||
);
|
||||
});
|
||||
@@ -211,6 +259,14 @@ it("enforces store screenshot count limits", () => {
|
||||
assert.throws(() => validateStoreAssetCount(googleSpec, 9, false), /allows at most 8/u);
|
||||
});
|
||||
|
||||
it("defaults every device to the app's own palette", () => {
|
||||
assert.equal(DEFAULT_SHOWCASE_THEME, "t3-code");
|
||||
assert.equal(
|
||||
showcaseConfig.devices.every((device) => device.theme === DEFAULT_SHOWCASE_THEME),
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it("configures every default device with an exact upload-ready store target", () => {
|
||||
assert.deepStrictEqual(
|
||||
showcaseConfig.devices.map((device) => [
|
||||
|
||||
+48
-12
@@ -20,6 +20,8 @@ import showcaseConfig, {
|
||||
type ShowcaseStoreAssetSpec,
|
||||
SHOWCASE_SCENES,
|
||||
type ShowcaseScene,
|
||||
SHOWCASE_THEMES,
|
||||
type ShowcaseTheme,
|
||||
} from "./mobile-showcase.config.ts";
|
||||
import {
|
||||
SHOWCASE_ENVIRONMENTS,
|
||||
@@ -76,6 +78,7 @@ interface CliOptions {
|
||||
readonly deviceIds: ReadonlySet<string>;
|
||||
readonly scenes: ReadonlySet<ShowcaseScene>;
|
||||
readonly appearances: ReadonlySet<ShowcaseAppearance>;
|
||||
readonly themes: ReadonlySet<ShowcaseTheme>;
|
||||
readonly skipBuild: boolean;
|
||||
readonly skipMetro: boolean;
|
||||
readonly keepRunning: boolean;
|
||||
@@ -87,6 +90,7 @@ export interface ShowcaseCapture {
|
||||
readonly device: ShowcaseDevice;
|
||||
readonly scenes: ReadonlyArray<ShowcaseScene>;
|
||||
readonly appearance: ShowcaseAppearance;
|
||||
readonly theme: ShowcaseTheme;
|
||||
}
|
||||
|
||||
interface IosCaptureCleanup {
|
||||
@@ -223,9 +227,16 @@ export function validateStoreAssetCount(
|
||||
|
||||
export function showcaseCaptureDirectory(
|
||||
outputDirectory: string,
|
||||
capture: Pick<ShowcaseCapture, "device" | "appearance">,
|
||||
capture: Pick<ShowcaseCapture, "device" | "appearance" | "theme">,
|
||||
): string {
|
||||
return NodePath.join(outputDirectory, capture.device.storeAsset.directory, capture.appearance);
|
||||
// Each palette owns a leaf folder so one upload slot never mixes themes and
|
||||
// every folder keeps a store-legal screenshot count of its own.
|
||||
return NodePath.join(
|
||||
outputDirectory,
|
||||
capture.device.storeAsset.directory,
|
||||
capture.appearance,
|
||||
capture.theme,
|
||||
);
|
||||
}
|
||||
|
||||
async function finalizeCapture(destination: string, device: ShowcaseDevice): Promise<void> {
|
||||
@@ -276,6 +287,7 @@ export function parseShowcaseCliArgs(args: ReadonlyArray<string>): CliOptions {
|
||||
const deviceIds = new Set<string>();
|
||||
const scenes = new Set<ShowcaseScene>();
|
||||
const appearances = new Set<ShowcaseAppearance>();
|
||||
const themes = new Set<ShowcaseTheme>();
|
||||
let skipBuild = false;
|
||||
let skipMetro = false;
|
||||
let keepRunning = false;
|
||||
@@ -318,6 +330,18 @@ export function parseShowcaseCliArgs(args: ReadonlyArray<string>): CliOptions {
|
||||
appearances.add(value);
|
||||
}
|
||||
index += 1;
|
||||
} else if (argument === "--theme") {
|
||||
const value = argumentValue(args, index, argument);
|
||||
if (value === "all") {
|
||||
for (const theme of SHOWCASE_THEMES) themes.add(theme);
|
||||
} else if (SHOWCASE_THEMES.some((theme) => theme === value)) {
|
||||
themes.add(value as ShowcaseTheme);
|
||||
} else {
|
||||
// The app silently falls back to its default palette for an unknown id,
|
||||
// so reject it here rather than shipping a mislabeled screenshot.
|
||||
throw new Error(`Unsupported theme '${value}'. Use ${SHOWCASE_THEMES.join(", ")}, or all.`);
|
||||
}
|
||||
index += 1;
|
||||
} else if (argument === "--skip-build") {
|
||||
skipBuild = true;
|
||||
} else if (argument === "--skip-metro") {
|
||||
@@ -340,6 +364,7 @@ export function parseShowcaseCliArgs(args: ReadonlyArray<string>): CliOptions {
|
||||
deviceIds,
|
||||
scenes,
|
||||
appearances,
|
||||
themes,
|
||||
skipBuild,
|
||||
skipMetro,
|
||||
keepRunning,
|
||||
@@ -350,7 +375,7 @@ export function parseShowcaseCliArgs(args: ReadonlyArray<string>): CliOptions {
|
||||
|
||||
export function planShowcaseCaptures(
|
||||
config: ShowcaseConfig,
|
||||
options: Pick<CliOptions, "platforms" | "deviceIds" | "scenes" | "appearances">,
|
||||
options: Pick<CliOptions, "platforms" | "deviceIds" | "scenes" | "appearances" | "themes">,
|
||||
): ReadonlyArray<ShowcaseCapture> {
|
||||
const captures = config.devices
|
||||
.filter((device) => options.platforms.size === 0 || options.platforms.has(device.platform))
|
||||
@@ -358,14 +383,18 @@ export function planShowcaseCaptures(
|
||||
.flatMap((device) => {
|
||||
const appearances =
|
||||
options.appearances.size === 0 ? [device.appearance] : options.appearances;
|
||||
return [...appearances].map((appearance) => ({
|
||||
device,
|
||||
appearance,
|
||||
scenes:
|
||||
options.scenes.size === 0
|
||||
? device.scenes
|
||||
: device.scenes.filter((scene) => options.scenes.has(scene)),
|
||||
}));
|
||||
const themes = options.themes.size === 0 ? [device.theme] : options.themes;
|
||||
return [...appearances].flatMap((appearance) =>
|
||||
[...themes].map((theme) => ({
|
||||
device,
|
||||
appearance,
|
||||
theme,
|
||||
scenes:
|
||||
options.scenes.size === 0
|
||||
? device.scenes
|
||||
: device.scenes.filter((scene) => options.scenes.has(scene)),
|
||||
})),
|
||||
);
|
||||
})
|
||||
.filter((capture) => capture.scenes.length > 0);
|
||||
|
||||
@@ -393,6 +422,7 @@ Options:
|
||||
--scene <name> Capture one scene (repeatable)
|
||||
--appearance light|dark|both
|
||||
Override the configured appearance
|
||||
--theme <id>|all Override the configured palette (repeatable)
|
||||
--skip-build Reuse the existing simulator app / debug APK
|
||||
--skip-metro Reuse an already running showcase Metro server
|
||||
--keep-running Leave devices and Metro running after capture
|
||||
@@ -400,12 +430,13 @@ Options:
|
||||
--list Print this help and the configured matrix
|
||||
|
||||
Scenes: ${SHOWCASE_SCENES.join(", ")}
|
||||
Themes: ${SHOWCASE_THEMES.join(", ")}
|
||||
|
||||
Configured devices:
|
||||
${config.devices
|
||||
.map((device) => {
|
||||
const target = device.platform === "ios" ? device.simulator : device.avd;
|
||||
return ` ${device.id.padEnd(18)} ${device.platform.padEnd(8)} ${target} -> ${device.storeAsset.directory}/{light|dark} (${device.storeAsset.width}×${device.storeAsset.height}, default ${device.appearance}) [${device.scenes.join(", ")}]`;
|
||||
return ` ${device.id.padEnd(18)} ${device.platform.padEnd(8)} ${target} -> ${device.storeAsset.directory}/{light|dark}/<theme> (${device.storeAsset.width}×${device.storeAsset.height}, default ${device.appearance} ${device.theme}) [${device.scenes.join(", ")}]`;
|
||||
})
|
||||
.join("\n")}
|
||||
`);
|
||||
@@ -946,6 +977,8 @@ async function captureIos(
|
||||
JSON.stringify(pairingUrls),
|
||||
"--showcaseScene",
|
||||
firstScene,
|
||||
"--showcaseTheme",
|
||||
capture.theme,
|
||||
// The app rotates itself; Simulator menu UI scripting needs macOS
|
||||
// Accessibility permission that CI runners do not grant to osascript.
|
||||
"--showcaseOrientation",
|
||||
@@ -1204,6 +1237,9 @@ async function captureAndroid(
|
||||
"--es",
|
||||
"showcaseScene",
|
||||
firstScene,
|
||||
"--es",
|
||||
"showcaseTheme",
|
||||
capture.theme,
|
||||
ANDROID_PACKAGE,
|
||||
]);
|
||||
for (const [sceneIndex, scene] of capture.scenes.entries()) {
|
||||
|
||||
Reference in new issue
Block a user