Skip to content

Commit

Permalink
feat: improve ios run app with flavor
Browse files Browse the repository at this point in the history
  • Loading branch information
rams23 committed Feb 27, 2023
1 parent 10b1107 commit 6ca36ff
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 12 deletions.
1 change: 1 addition & 0 deletions .idea/react-native-engine.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
"@oclif/plugin-plugins": "^2.3.2",
"@react-native-community/cli-platform-ios": "^10.2.0",
"axios": "^1.3.4",



"chalk": "^4.1.2",
"ios-deploy": "^1.12.1",
"prompts": "^2.4.2"
},
"devDependencies": {
Expand Down
22 changes: 16 additions & 6 deletions src/application/runIos.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import childProcess from 'child_process'
import childProcess, {execFileSync} from 'child_process'
import fs from 'fs'
import prompts from 'prompts'
import chalk from 'chalk'
import {executeCommand, getProjectRootDir} from './utils'
import {buildIos} from './buildIos'
import {getIosBuildDestination, iosBuildPlatforms} from './iosUtils'
import path from 'path'

// todo default app name improve passing from command line

Expand Down Expand Up @@ -78,16 +79,13 @@ async function promptForDeviceSelection(allDevices: Device[]): Promise<Device[]>
return devices
}

export async function runApp(buildType: string, appId: string) {
export async function runApp(buildType: string) {

// todo run on phisical devices
if (!checkBuildPresent(getProjectRootDir(), buildType, iosBuildPlatforms.simulator)) {
buildIos(buildType as any, 'simulator')
}

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

const devices = getDevices()

if (devices.length === 0) {
Expand Down Expand Up @@ -116,10 +114,22 @@ export async function runApp(buildType: string, appId: string) {

}

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

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

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

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

}
4 changes: 2 additions & 2 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export default class Build extends Command {
static description = 'Create native builds for android and ios'

static examples = [
'<%= config.bin %> <%= command.id %> -i -f dev',
'<%= config.bin %> <%= command.id %> -a -f prod',
'<%= config.bin %> <%= command.id %> -i -f=dev',
'<%= config.bin %> <%= command.id %> -a -f=prod',
'<%= config.bin %> <%= command.id %> -all',
]

Expand Down
4 changes: 3 additions & 1 deletion src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default class Run extends Command {
static flags = {
android: Flags.boolean({char: 'a', description: 'Run the android app'}),
ios: Flags.boolean({char: 'i', description: 'Run the ios app'}),
flavor: Flags.string({char: 'f', description: 'Specify flavor to build', default:'dev'}),
}

static args = {
Expand All @@ -24,6 +25,7 @@ export default class Run extends Command {

const shouldRunAndroid = flags.android ?? flags.all
const shouldRunIos = flags.ios ?? flags.all
const buildFlavor = flags.flavor;
this.log('Checking if metro is running...');

const isMetroRunning = await checkIsMetroRunning()
Expand All @@ -37,7 +39,7 @@ export default class Run extends Command {
runAndroid('dev', 'com.newrnarctest')
}
if (shouldRunIos) {
runIos('dev', 'org.reactjs.native.example.newRNArcTest')
runIos(buildFlavor)
}
}
}

0 comments on commit 6ca36ff

Please sign in to comment.