|
1 | 1 | import type { CliFlags } from './utils/command-schema.ts'; |
2 | 2 | import { formatSnapshotText, printJson } from './utils/output.ts'; |
3 | 3 | import { AppError } from './utils/errors.ts'; |
| 4 | +import { |
| 5 | + serializeCloseResult, |
| 6 | + serializeDeployResult, |
| 7 | + serializeDevice, |
| 8 | + serializeEnsureSimulatorResult, |
| 9 | + serializeOpenResult, |
| 10 | + serializeRuntimeResult, |
| 11 | + serializeSessionListEntry, |
| 12 | + serializeSnapshotResult, |
| 13 | +} from './client-shared.ts'; |
4 | 14 | import type { |
5 | 15 | AgentDeviceClient, |
6 | 16 | AgentDeviceDevice, |
7 | | - AgentDeviceSession, |
8 | | - AppCloseResult, |
9 | 17 | AppDeployResult, |
10 | | - AppOpenResult, |
11 | | - CaptureSnapshotResult, |
12 | | - EnsureSimulatorResult, |
13 | 18 | RuntimeResult, |
14 | | - SessionCloseResult, |
15 | 19 | } from './client.ts'; |
16 | 20 |
|
17 | 21 | export async function tryRunClientBackedCommand(params: { |
@@ -209,111 +213,9 @@ function buildSelectionOptions(flags: CliFlags): { |
209 | 213 | }; |
210 | 214 | } |
211 | 215 |
|
212 | | -function serializeSessionListEntry(session: AgentDeviceSession): Record<string, unknown> { |
213 | | - return { |
214 | | - name: session.name, |
215 | | - platform: session.device.platform, |
216 | | - target: session.device.target, |
217 | | - device: session.device.name, |
218 | | - id: session.device.id, |
219 | | - createdAt: session.createdAt, |
220 | | - ...(session.device.platform === 'ios' && { |
221 | | - device_udid: session.device.ios?.udid ?? session.device.id, |
222 | | - ios_simulator_device_set: session.device.ios?.simulatorSetPath ?? null, |
223 | | - }), |
224 | | - }; |
225 | | -} |
226 | | - |
227 | | -function serializeDevice(device: AgentDeviceDevice): Record<string, unknown> { |
228 | | - return { |
229 | | - platform: device.platform, |
230 | | - id: device.id, |
231 | | - name: device.name, |
232 | | - kind: device.kind, |
233 | | - target: device.target, |
234 | | - ...(typeof device.booted === 'boolean' ? { booted: device.booted } : {}), |
235 | | - }; |
236 | | -} |
237 | | - |
238 | 216 | function formatDeviceLine(device: AgentDeviceDevice): string { |
239 | 217 | const kind = device.kind ? ` ${device.kind}` : ''; |
240 | 218 | const target = device.target ? ` target=${device.target}` : ''; |
241 | 219 | const booted = typeof device.booted === 'boolean' ? ` booted=${device.booted}` : ''; |
242 | 220 | return `${device.name} (${device.platform}${kind}${target})${booted}`; |
243 | 221 | } |
244 | | - |
245 | | -function serializeEnsureSimulatorResult(result: EnsureSimulatorResult): Record<string, unknown> { |
246 | | - return { |
247 | | - udid: result.udid, |
248 | | - device: result.device, |
249 | | - runtime: result.runtime, |
250 | | - ios_simulator_device_set: result.iosSimulatorDeviceSet ?? null, |
251 | | - created: result.created, |
252 | | - booted: result.booted, |
253 | | - }; |
254 | | -} |
255 | | - |
256 | | -function serializeRuntimeResult(result: RuntimeResult): Record<string, unknown> { |
257 | | - return { |
258 | | - session: result.session, |
259 | | - configured: result.configured, |
260 | | - ...(result.cleared ? { cleared: true } : {}), |
261 | | - ...(result.runtime ? { runtime: result.runtime } : {}), |
262 | | - }; |
263 | | -} |
264 | | - |
265 | | -function serializeDeployResult(result: AppDeployResult): Record<string, unknown> { |
266 | | - return { |
267 | | - app: result.app, |
268 | | - appPath: result.appPath, |
269 | | - platform: result.platform, |
270 | | - ...(result.appId ? { appId: result.appId } : {}), |
271 | | - ...(result.bundleId ? { bundleId: result.bundleId } : {}), |
272 | | - ...(result.package ? { package: result.package } : {}), |
273 | | - }; |
274 | | -} |
275 | | - |
276 | | -function serializeOpenResult(result: AppOpenResult): Record<string, unknown> { |
277 | | - return { |
278 | | - session: result.session, |
279 | | - ...(result.appName ? { appName: result.appName } : {}), |
280 | | - ...(result.appBundleId ? { appBundleId: result.appBundleId } : {}), |
281 | | - ...(result.startup ? { startup: result.startup } : {}), |
282 | | - ...(result.runtime ? { runtime: result.runtime } : {}), |
283 | | - ...(result.device |
284 | | - ? { |
285 | | - platform: result.device.platform, |
286 | | - target: result.device.target, |
287 | | - device: result.device.name, |
288 | | - id: result.device.id, |
289 | | - } |
290 | | - : {}), |
291 | | - ...(result.device?.platform === 'ios' |
292 | | - ? { |
293 | | - device_udid: result.device.ios?.udid ?? result.device.id, |
294 | | - ios_simulator_device_set: result.device.ios?.simulatorSetPath ?? null, |
295 | | - } |
296 | | - : {}), |
297 | | - ...(result.device?.platform === 'android' |
298 | | - ? { |
299 | | - serial: result.device.android?.serial ?? result.device.id, |
300 | | - } |
301 | | - : {}), |
302 | | - }; |
303 | | -} |
304 | | - |
305 | | -function serializeCloseResult(result: SessionCloseResult | AppCloseResult): Record<string, unknown> { |
306 | | - return { |
307 | | - session: result.session, |
308 | | - ...(result.shutdown ? { shutdown: result.shutdown } : {}), |
309 | | - }; |
310 | | -} |
311 | | - |
312 | | -function serializeSnapshotResult(result: CaptureSnapshotResult): Record<string, unknown> { |
313 | | - return { |
314 | | - nodes: result.nodes, |
315 | | - truncated: result.truncated, |
316 | | - ...(result.appName ? { appName: result.appName } : {}), |
317 | | - ...(result.appBundleId ? { appBundleId: result.appBundleId } : {}), |
318 | | - }; |
319 | | -} |
0 commit comments