Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More logging for simulator selection and deployment #596

Merged
merged 20 commits into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
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
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');
raphinesse marked this conversation as resolved.
Show resolved Hide resolved
// 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