diff --git a/README.md b/README.md index ab86bc2..844bf4d 100644 --- a/README.md +++ b/README.md @@ -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 | 🚧 | 🚧 | diff --git a/src/application/buildIos.ts b/src/application/buildIos.ts index 36dc970..7b649e3 100644 --- a/src/application/buildIos.ts +++ b/src/application/buildIos.ts @@ -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() @@ -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` @@ -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) } diff --git a/src/application/iosUtils.ts b/src/application/iosUtils.ts index 89bc518..4f00c99 100644 --- a/src/application/iosUtils.ts +++ b/src/application/iosUtils.ts @@ -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 diff --git a/src/application/runIos.ts b/src/application/runIos.ts index 8c6dd37..f6a7b78 100644 --- a/src/application/runIos.ts +++ b/src/application/runIos.ts @@ -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 @@ -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, ) { @@ -43,7 +42,6 @@ function checkBuildPresent( function installApp( deviceUdid: string, - engineDir: string, buildType: string, target: any, ) { @@ -79,22 +77,27 @@ async function promptForDeviceSelection(allDevices: Device[]): Promise 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[] = [] @@ -105,7 +108,6 @@ export async function runApp(buildType?: string) { for (const requestedDevice of requestedDevices) { if (!(requestedDevice.state === 'Booted')) { - launchDevice(requestedDevice.udid) } } @@ -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) } } diff --git a/src/commands/run.ts b/src/commands/run.ts index c2dc884..43bc9ae 100644 --- a/src/commands/run.ts +++ b/src/commands/run.ts @@ -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' @@ -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...') @@ -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`) }