Skip to content

Commit

Permalink
refactor: use platformInfo utility
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski committed Dec 19, 2023
1 parent 91f2604 commit e19db37
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import os from 'os';
import path from 'path';
import getSimulators from '../../tools/getSimulators';
import listDevices from '../../tools/listDevices';
import getPlatformReadableName from '../runCommand/getPlatformReadableName';
import getSDKNamefromPlatform from '../runCommand/getSDKNameFromPlatform';
import {getPlatformInfo} from '../runCommand/getPlatformInfo';
import {BuilderCommand} from '../../types';

/**
Expand All @@ -21,7 +20,7 @@ const createLog =
({platformName}: BuilderCommand) =>
async (_: Array<string>, ctx: Config, args: Args) => {
const platform = ctx.project[platformName] as IOSProjectConfig;
const platformReadableName = getPlatformReadableName(platformName);
const {readableName: platformReadableName} = getPlatformInfo(platformName);

if (platform === undefined) {
throw new CLIError(`Unable to find ${platform} platform config`);
Expand All @@ -34,7 +33,7 @@ const createLog =
.reduce((acc, val) => acc.concat(val), [])
.filter(({state}) => state === 'Booted');

const sdkNames = getSDKNamefromPlatform(platformName);
const {sdkNames} = getPlatformInfo(platformName);
const devices = await listDevices(sdkNames);

const availableSimulators = devices.filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ import {buildProject} from '../buildCommand/buildProject';
import {getConfiguration} from '../buildCommand/getConfiguration';
import {getXcodeProjectAndDir} from '../buildCommand/getXcodeProjectAndDir';
import {getFallbackSimulator} from './getFallbackSimulator';
import getPlatformReadableName from './getPlatformReadableName';
import getSDKNamefromPlatform from './getSDKNameFromPlatform';
import {getPlatformInfo} from './getPlatformInfo';
import {printFoundDevices, matchingDevice} from './matchingDevice';
import {runOnDevice} from './runOnDevice';
import {runOnSimulator} from './runOnSimulator';
Expand All @@ -53,7 +52,8 @@ const createRun =
// React Native docs assume platform is always ios/android
link.setPlatform('ios');
const platform = ctx.project[platformName] as IOSProjectConfig;
const platformReadableName = getPlatformReadableName(platformName);
const {sdkNames, readableName: platformReadableName} =
getPlatformInfo(platformName);

if (platform === undefined) {
throw new CLIError(
Expand Down Expand Up @@ -133,7 +133,6 @@ const createRun =
return;
}

const sdkNames = getSDKNamefromPlatform(platformName);
const devices = await listDevices(sdkNames);

const availableDevices = devices.filter(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
interface PlatformInfo {
readableName: string;
sdkNames: string[];
}

export function getPlatformInfo(platform: string): PlatformInfo {
const iosPlatformInfo: PlatformInfo = {
readableName: 'iOS',
sdkNames: ['iphonesimulator', 'iphoneos'],
};

switch (platform) {
case 'ios':
return iosPlatformInfo;
case 'tvos':
return {
readableName: 'tvOS',
sdkNames: ['appletvsimulator', 'appletvos'],
};
case 'visionos':
return {
readableName: 'visionOS',
sdkNames: ['xrsimulator', 'xros'],
};
case 'macos':
return {
readableName: 'macOS',
sdkNames: ['macosx'],
};
default:
return iosPlatformInfo;
}
}

This file was deleted.

This file was deleted.

0 comments on commit e19db37

Please sign in to comment.