Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions local-cli/runIOS/runIOS.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function runIOS(argv, config, args) {
throw new Error('Could not find Xcode project files in ios folder');
}

const buildConfig = getBuildConfig();
const inferredSchemeName = path.basename(xcodeProject.name, path.extname(xcodeProject.name));
const scheme = args.scheme || inferredSchemeName;
console.log(`Found Xcode ${xcodeProject.isWorkspace ? 'workspace' : 'project'} ${xcodeProject.name}`);
Expand All @@ -31,7 +32,7 @@ function runIOS(argv, config, args) {
if (args.device) {
const selectedDevice = matchingDevice(devices, args.device);
if (selectedDevice){
runOnDevice(selectedDevice, scheme, xcodeProject);
runOnDevice(selectedDevice, scheme, xcodeProject, buildConfig);
} else {
if (devices){
console.log('Could not find device with the name: "' + args.device + '".');
Expand All @@ -44,7 +45,7 @@ function runIOS(argv, config, args) {
} else if (args.udid) {
runOnDeviceByUdid(args.udid, scheme, xcodeProject, devices);
} else {
runOnSimulator(xcodeProject, args, inferredSchemeName, scheme);
runOnSimulator(xcodeProject, args, scheme, buildConfig);
}
}

Expand All @@ -63,7 +64,7 @@ function runOnDeviceByUdid(udid, scheme, xcodeProject, devices) {
}
}

function runOnSimulator(xcodeProject, args, inferredSchemeName, scheme){
function runOnSimulator(xcodeProject, args, scheme, buildConfig) {
try {
var simulators = JSON.parse(
child_process.execFileSync('xcrun', ['simctl', 'list', '--json', 'devices'], {encoding: 'utf8'})
Expand All @@ -88,7 +89,7 @@ function runOnSimulator(xcodeProject, args, inferredSchemeName, scheme){

buildProject(xcodeProject, selectedSimulator.udid, scheme);

const appPath = `build/Build/Products/Debug-iphonesimulator/${inferredSchemeName}.app`;
const appPath = 'build/Build/Products/Debug-iphonesimulator/' + buildConfig.EXECUTABLE_FOLDER_PATH;
console.log(`Installing ${appPath}`);
child_process.spawnSync('xcrun', ['simctl', 'install', 'booted', appPath], {stdio: 'inherit'});

Expand All @@ -102,10 +103,10 @@ function runOnSimulator(xcodeProject, args, inferredSchemeName, scheme){
child_process.spawnSync('xcrun', ['simctl', 'launch', 'booted', bundleID], {stdio: 'inherit'});
}

function runOnDevice(selectedDevice, scheme, xcodeProject){
function runOnDevice(selectedDevice, scheme, xcodeProject, buildConfig) {
buildProject(xcodeProject, selectedDevice.udid, scheme);
const iosDeployInstallArgs = [
'--bundle', 'build/Build/Products/Debug-iphoneos/' + scheme + '.app',
'--bundle', 'build/Build/Products/Debug-iphoneos/' + buildConfig.EXECUTABLE_FOLDER_PATH,
'--id' , selectedDevice.udid,
'--justlaunch'
];
Expand Down Expand Up @@ -152,12 +153,29 @@ function formattedDeviceName(simulator) {
return `${simulator.name} (${simulator.version})`;
}

function printFoundDevices(devices){
function printFoundDevices(devices) {
for (let i = devices.length - 1; i >= 0; i--) {
console.log(devices[i].name + ' Udid: ' + devices[i].udid);
}
}

function getBuildConfig() {
const result = child_process.execFileSync(
'xcodebuild',
['-showBuildSettings', '-configuration', 'Debug'],
Copy link
Contributor

@StevePotter StevePotter Oct 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-configuration Debug? What about production or other types? I would say that you should pass a scheme in and use that, like:
function getBuildConfig(scheme) {
const result = child_process.execFileSync(
'xcodebuild',
['-showBuildSettings', '-scheme', scheme],

{encoding: 'utf8'}
);
const config = {};
for (let x of result.trim().split('\n')) {
const keyValue = x.trim().split(' = ');
if (keyValue.length !== 2) {
continue;
}
config[keyValue[0]] = keyValue[1].trim("'");
}
return config;
}

module.exports = {
name: 'run-ios',
description: 'builds your app and starts it on iOS simulator',
Expand Down