Skip to content

Commit

Permalink
More logging for simulator selection and deployment (#596)
Browse files Browse the repository at this point in the history
* remove wrong comment about default emulator

* add logging about deployment

* add comment back, minus wrong default

* quote target string

* log simulator start command

* prefix log from simulator to make it recognizable

* add missing space in command logging

* fix log prefix (data comes from ios-sim, not simulator)

* use patched ios-sim with additional output

* fix package.json maybe?

* switch to janpio/ios-sim#802

* better logging about target

* fix

* fix eslint stuff

* try to use superspawn instead of cp

* stdio=pipe

* iterate

* Update package.json

* review feedback

* Minor improvements to logging
  • Loading branch information
janpio authored and dpogue committed Apr 17, 2019
1 parent 875813a commit da5b69d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
6 changes: 4 additions & 2 deletions bin/templates/scripts/cordova/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,13 @@ module.exports.run = function (buildOpts) {
if (!theTarget) {
return getDefaultSimulatorTarget().then(function (defaultTarget) {
emulatorTarget = defaultTarget.name;
events.emit('log', 'Building for ' + emulatorTarget + ' Simulator');
events.emit('warn', `No simulator found for "${newTarget}. Falling back to the default target.`);
events.emit('log', `Building for "${emulatorTarget}" Simulator (${defaultTarget.identifier}, ${defaultTarget.simIdentifier}).`);
return emulatorTarget;
});
} else {
emulatorTarget = theTarget.name;
events.emit('log', 'Building for ' + emulatorTarget + ' Simulator');
events.emit('log', `Building for "${emulatorTarget}" Simulator (${theTarget.identifier}, ${theTarget.simIdentifier}).`);
return emulatorTarget;
}
});
Expand Down Expand Up @@ -217,6 +218,7 @@ module.exports.run = function (buildOpts) {
events.emit('log', 'Building project: ' + path.join(projectPath, projectName + '.xcworkspace'));
events.emit('log', '\tConfiguration: ' + configuration);
events.emit('log', '\tPlatform: ' + (buildOpts.device ? 'device' : 'emulator'));
events.emit('log', '\tTarget: ' + emulatorTarget);

var buildOutputDir = path.join(projectPath, 'build', (buildOpts.device ? 'device' : 'emulator'));

Expand Down
27 changes: 19 additions & 8 deletions bin/templates/scripts/cordova/lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

var Q = require('q');
var path = require('path');
var cp = require('child_process');
var build = require('./build');
var shell = require('shelljs');
var superspawn = require('cordova-common').superspawn;
Expand Down Expand Up @@ -159,6 +158,7 @@ function checkDeviceConnected () {
* @return {Promise} Resolves when deploy succeeds otherwise rejects
*/
function deployToDevice (appPath, target, extraArgs) {
events.emit('log', 'Deploying to device');
// Deploying to device...
if (target) {
return superspawn.spawn('ios-deploy', ['--justlaunch', '-d', '-b', appPath, '-i', target].concat(extraArgs), { printCommand: true, stdio: 'inherit' });
Expand All @@ -174,8 +174,9 @@ function deployToDevice (appPath, target, extraArgs) {
* @return {Promise} Resolves when deploy succeeds otherwise rejects
*/
function deployToSim (appPath, target) {
// Select target device for emulator. Default is 'iPhone-6'
events.emit('log', 'Deploying to simulator');
if (!target) {
// Select target device for emulator
return require('./list-emulator-images').run()
.then(function (emulators) {
if (emulators.length > 0) {
Expand All @@ -186,7 +187,7 @@ function deployToSim (appPath, target) {
target = emulator;
}
});
events.emit('log', 'No target specified for emulator. Deploying to ' + target + ' simulator');
events.emit('log', `No target specified for emulator. Deploying to "${target}" simulator.`);
return startSim(appPath, target);
});
} else {
Expand All @@ -200,12 +201,22 @@ function startSim (appPath, target) {
return iossimLaunch(appPath, 'com.apple.CoreSimulator.SimDeviceType.' + target, logPath, '--exit');
}

function iossimLaunch (app_path, devicetypeid, log, exit) {
function iossimLaunch (appPath, devicetypeid, log, exit) {
var f = path.resolve(path.dirname(require.resolve('ios-sim')), 'bin', 'ios-sim');
var proc = cp.spawn(f, ['launch', app_path, '--devicetypeid', devicetypeid, '--log', log, exit]);
proc.stdout.on('data', (data) => {
console.log(data.toString());
});
var params = ['launch', appPath, '--devicetypeid', devicetypeid, '--log', log, exit];

return superspawn.spawn(f, params, { cwd: projectPath, printCommand: true })
.progress(function (stdio) {
if (stdio.stderr) {
events.emit('error', `[ios-sim] ${stdio.stderr}`);
}
if (stdio.stdout) {
events.emit('log', `[ios-sim] ${stdio.stdout.trim()}`);
}
})
.then(function (result) {
events.emit('log', 'Simulator successfully started via `ios-sim`.');
});
}

function listDevices () {
Expand Down

0 comments on commit da5b69d

Please sign in to comment.