Skip to content

Commit

Permalink
feat: add ios platform as build parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
rams23 committed Mar 2, 2023
1 parent 199a399 commit 96e5164
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 34 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ Windows android support work in progress

| Feature | Android | iOS |
|------------------------------------| :---: | :---: |
| Run on device |||
| Run on emulator | | |
| Debug build | | |
| Build flavor/variants | | |
| Release build | | 🚧 |
| Sign application | | 🚧 |
| Incremental build | | 🚧 |
| Run on emulator | 🚧 ||
| Run on device | 🚧| 🚧 |
| Debug build | 🚧 | 🚧 |
| Build flavor/variants | 🚧 | 🚧 |
| Release build | 🚧 | 🚧 |
| Sign application | 🚧 | 🚧 |
| Incremental build | 🚧| 🚧 |
| Reversioning of incremental builds | 🚧 | 🚧 |
9 changes: 4 additions & 5 deletions src/application/buildIos.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path'
import {executeCommand, getAppName, getProjectRootDir, getRootDestinationFolder} from './utils'
import {ux} from '@oclif/core'
import {getIosBuildDestination, iosBuildPlatforms} from './iosUtils'
import {getIosBuildDestination, iosBuildPlatforms, IosPlatform} from './iosUtils'
import {getIosFlavors} from './config'

const appName = getAppName()
Expand All @@ -12,14 +12,13 @@ function installPods() {
executeCommand('pod install', {cwd: iosFolder})
}

function _buildIos(buildType?: string, platformName: keyof typeof iosBuildPlatforms = 'simulator') {
function _buildIos(buildType?: string, platform: IosPlatform = iosBuildPlatforms.simulator) {
const iosFolder = path.join(getProjectRootDir(), 'ios')
const workspacePath = path.join(iosFolder, `${appName}.xcworkspace`)
const buildFlavor = getIosFlavors(buildType)
if (!buildFlavor) {
throw new Error(`No build flavor found for ${buildType}`)
}
const platform = iosBuildPlatforms[platformName]

const archivePath = `${iosFolder}/build/Products/${appName}.xcarchive`

Expand Down Expand Up @@ -57,7 +56,7 @@ function _buildIos(buildType?: string, platformName: keyof typeof iosBuildPlatfo

}

export function buildIos(buildType?: string, platformName: keyof typeof iosBuildPlatforms = 'simulator') {
export function buildIos(buildType?: string, platform: IosPlatform = iosBuildPlatforms.simulator) {
installPods()
_buildIos(buildType, platformName)
_buildIos(buildType, platform)
}
6 changes: 6 additions & 0 deletions src/application/iosUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ export const iosBuildPlatforms = {
};


export type IosPlatform = {
name: string;
ext: string;
buildCmd: string;
}


export function getIosBuildDestination(platform: { ext: string; buildCmd: string; name: string }, buildType: string) {
// todo handle Debug/release
Expand Down
39 changes: 19 additions & 20 deletions src/application/runIos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import prompts from 'prompts'
import chalk from 'chalk'
import {executeCommand, getAppName, getProjectRootDir} from './utils'
import {buildIos} from './buildIos'
import {getIosBuildDestination, iosBuildPlatforms} from './iosUtils'
import {getIosBuildDestination, iosBuildPlatforms, IosPlatform} from './iosUtils'
import path from 'path'
import {getIosFlavors} from './config'
import logger from './logger'

// todo default app name improve passing from command line

Expand All @@ -24,13 +25,11 @@ function getDevices(): Device[] {
return Object.values(devicesJson.devices).flat() as Device[]
}

function getBootedDevicesIds(allDevices: Device[]) {
const bootedDevices = allDevices.filter(d => d.state === 'Booted')
return bootedDevices
function getBootedDevices(allDevices: Device[]) {
return allDevices.filter(d => d.state === 'Booted');
}

function checkBuildPresent(
engineDir: string,
buildType: string,
target: any,
) {
Expand All @@ -43,7 +42,6 @@ function checkBuildPresent(

function installApp(
deviceUdid: string,
engineDir: string,
buildType: string,
target: any,
) {
Expand Down Expand Up @@ -79,22 +77,27 @@ async function promptForDeviceSelection(allDevices: Device[]): Promise<Device[]>
return devices
}

export async function runApp(buildType?: string) {
export async function runApp(buildType?: string, iosPlatform: IosPlatform = iosBuildPlatforms.simulator) {

const buildFlavor = getIosFlavors(buildType)

// todo run on phisycal devices
if (!checkBuildPresent(getProjectRootDir(), buildFlavor.scheme, iosBuildPlatforms.simulator)) {
buildIos(buildType as any, 'simulator')
if (!checkBuildPresent(buildFlavor.scheme, iosPlatform)) {
logger.info('Build not present, starting build');
buildIos(buildType, iosPlatform)
} else {
logger.info('Build already present, skipping build');
}

const devices = getDevices()

if (devices.length === 0) {
throw new Error('No iOS devices available')
throw new Error('No iOS devices available');
}

let bootedDevices = getBootedDevicesIds(devices)
// todo improve run on device
executeCommand('open -a Simulator');

let bootedDevices = getBootedDevices(devices);

const devicesToRun: Device[] = []

Expand All @@ -105,7 +108,6 @@ export async function runApp(buildType?: string) {

for (const requestedDevice of requestedDevices) {
if (!(requestedDevice.state === 'Booted')) {

launchDevice(requestedDevice.udid)
}
}
Expand All @@ -114,22 +116,19 @@ export async function runApp(buildType?: string) {

}

// todo improve run on device
executeCommand('open -a Simulator')

const {destination} = getIosBuildDestination(
iosBuildPlatforms.simulator,
buildFlavor.scheme,
)

const bundleID = execFileSync('/usr/libexec/PlistBuddy', ['-c', 'Print:CFBundleIdentifier', path.join(destination, 'Info.plist')], {
encoding: 'utf8'
}).trim();
encoding: 'utf8',
}).trim()

for (const device of devicesToRun) {
const id = device.udid
installApp(id, getProjectRootDir(), buildFlavor.scheme, iosBuildPlatforms.simulator)
launchApp(id, bundleID);
installApp(id, buildFlavor.scheme, iosBuildPlatforms.simulator)
launchApp(id, bundleID)
}

}
5 changes: 3 additions & 2 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {runApp as runAndroid} from '../application/runAndroid'
import {runApp as runIos} from '../application/runIos'
import {startMetro, checkIsMetroRunning} from '../application/metroManager'
import logger from '../application/logger'
import {iosBuildPlatforms} from '../application/iosUtils'

export default class Run extends Command {
static description = 'Run the native app'
Expand All @@ -28,7 +29,7 @@ export default class Run extends Command {
const shouldRunAndroid = flags.android ?? flags.all
const shouldRunIos = flags.ios ?? flags.all
const buildFlavor = flags.flavor
const verbose = flags.verbose

logger.setVerbose(flags.verbose)
const start = performance.now()
logger.info('Checking if metro is running...')
Expand All @@ -46,7 +47,7 @@ export default class Run extends Command {
}
if (shouldRunIos) {
logger.info(`Running ios app ${buildFlavor ? `with flavor ${buildFlavor}` : ''}`)
await runIos(buildFlavor!)
await runIos(buildFlavor!, iosBuildPlatforms.simulator)
}
logger.info(`Run finished in ${((performance.now() - start) / 1000).toFixed(1)} seconds`)
}
Expand Down

0 comments on commit 96e5164

Please sign in to comment.