|
| 1 | +import { PUBLIC_COMMANDS } from '../../command-catalog.ts'; |
| 2 | +import type { CommandCapability } from '../../core/capabilities.ts'; |
| 3 | +import { commandCapabilityMap, commandSchemaMap, defineCommand } from '../command-definition.ts'; |
| 4 | + |
| 5 | +const APP_RUNTIME_CAPABILITY = { |
| 6 | + apple: { simulator: true, device: true }, |
| 7 | + android: { emulator: true, device: true, unknown: true }, |
| 8 | + linux: { device: true }, |
| 9 | +} as const satisfies CommandCapability; |
| 10 | + |
| 11 | +const APP_INVENTORY_CAPABILITY = { |
| 12 | + apple: { simulator: true, device: true }, |
| 13 | + android: { emulator: true, device: true, unknown: true }, |
| 14 | + linux: {}, |
| 15 | +} as const satisfies CommandCapability; |
| 16 | + |
| 17 | +const APP_INSTALL_CAPABILITY = { |
| 18 | + apple: { simulator: true, device: true }, |
| 19 | + android: { emulator: true, device: true, unknown: true }, |
| 20 | + linux: {}, |
| 21 | + supports: (device) => device.platform !== 'macos', |
| 22 | +} as const satisfies CommandCapability; |
| 23 | + |
| 24 | +const openCommandDefinition = defineCommand({ |
| 25 | + name: PUBLIC_COMMANDS.open, |
| 26 | + schema: { |
| 27 | + helpDescription: |
| 28 | + 'Boot device/simulator; optionally launch app or deep link URL (macOS also supports --surface app|frontmost-app|desktop|menubar)', |
| 29 | + summary: 'Open an app, deep link or URL, save replays', |
| 30 | + positionalArgs: ['appOrUrl?', 'url?'], |
| 31 | + allowedFlags: ['activity', 'saveScript', 'relaunch', 'surface'], |
| 32 | + }, |
| 33 | + capability: APP_RUNTIME_CAPABILITY, |
| 34 | +}); |
| 35 | + |
| 36 | +const closeCommandDefinition = defineCommand({ |
| 37 | + name: PUBLIC_COMMANDS.close, |
| 38 | + schema: { |
| 39 | + helpDescription: 'Close app or just end session', |
| 40 | + summary: 'Close app or end session', |
| 41 | + positionalArgs: ['app?'], |
| 42 | + allowedFlags: ['saveScript', 'shutdown'], |
| 43 | + }, |
| 44 | + capability: APP_RUNTIME_CAPABILITY, |
| 45 | +}); |
| 46 | + |
| 47 | +const reinstallCommandDefinition = defineCommand({ |
| 48 | + name: PUBLIC_COMMANDS.reinstall, |
| 49 | + schema: { |
| 50 | + helpDescription: 'Uninstall + install app from binary path', |
| 51 | + summary: 'Reinstall app from binary path', |
| 52 | + positionalArgs: ['app', 'path'], |
| 53 | + allowedFlags: [], |
| 54 | + }, |
| 55 | + capability: APP_INSTALL_CAPABILITY, |
| 56 | +}); |
| 57 | + |
| 58 | +const installCommandDefinition = defineCommand({ |
| 59 | + name: PUBLIC_COMMANDS.install, |
| 60 | + schema: { |
| 61 | + helpDescription: 'Install app from binary path without uninstalling first', |
| 62 | + summary: 'Install app from binary path', |
| 63 | + positionalArgs: ['app', 'path'], |
| 64 | + allowedFlags: [], |
| 65 | + }, |
| 66 | + capability: APP_INSTALL_CAPABILITY, |
| 67 | +}); |
| 68 | + |
| 69 | +const installFromSourceCommandDefinition = defineCommand({ |
| 70 | + name: PUBLIC_COMMANDS.installFromSource, |
| 71 | + schema: { |
| 72 | + usageOverride: |
| 73 | + 'install-from-source <url> | install-from-source --github-actions-artifact <owner/repo:artifact>', |
| 74 | + listUsageOverride: 'install-from-source <url> | install-from-source --github-actions-artifact', |
| 75 | + helpDescription: 'Install app from a URL or remote-resolved source', |
| 76 | + summary: 'Install app from a source', |
| 77 | + positionalArgs: ['url?'], |
| 78 | + allowedFlags: [ |
| 79 | + 'header', |
| 80 | + 'githubActionsArtifact', |
| 81 | + 'installSource', |
| 82 | + 'retainPaths', |
| 83 | + 'retentionMs', |
| 84 | + ], |
| 85 | + }, |
| 86 | + capability: APP_INSTALL_CAPABILITY, |
| 87 | +}); |
| 88 | + |
| 89 | +const appsCommandDefinition = defineCommand({ |
| 90 | + name: PUBLIC_COMMANDS.apps, |
| 91 | + schema: { |
| 92 | + helpDescription: 'List installed apps (includes default/system apps by default)', |
| 93 | + summary: 'List installed apps', |
| 94 | + positionalArgs: [], |
| 95 | + allowedFlags: ['appsFilter'], |
| 96 | + defaults: { appsFilter: 'all' }, |
| 97 | + }, |
| 98 | + capability: APP_INVENTORY_CAPABILITY, |
| 99 | +}); |
| 100 | + |
| 101 | +export const SESSION_LIFECYCLE_COMMAND_DEFINITIONS = [ |
| 102 | + openCommandDefinition, |
| 103 | + closeCommandDefinition, |
| 104 | + reinstallCommandDefinition, |
| 105 | + installCommandDefinition, |
| 106 | + installFromSourceCommandDefinition, |
| 107 | + appsCommandDefinition, |
| 108 | +] as const; |
| 109 | + |
| 110 | +export const SESSION_LIFECYCLE_COMMAND_SCHEMAS = commandSchemaMap( |
| 111 | + SESSION_LIFECYCLE_COMMAND_DEFINITIONS, |
| 112 | +); |
| 113 | + |
| 114 | +export const SESSION_LIFECYCLE_COMMAND_CAPABILITIES = commandCapabilityMap( |
| 115 | + SESSION_LIFECYCLE_COMMAND_DEFINITIONS, |
| 116 | +); |
0 commit comments