diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2017-10-26 01:41:16 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2017-10-26 01:41:16 +0200 |
| commit | 8dae6a5044f9c1b7a8497cc1c96155fd262b40cf (patch) | |
| tree | 6f546503efcb198a193f919efafb83977abb9535 /StoneIsland/platforms/ios/cordova/lib/run.js | |
| parent | 531c60ee7ecbee516812d560b63a8317c3cf3590 (diff) | |
iphone x fixes
Diffstat (limited to 'StoneIsland/platforms/ios/cordova/lib/run.js')
| -rwxr-xr-x | StoneIsland/platforms/ios/cordova/lib/run.js | 226 |
1 files changed, 116 insertions, 110 deletions
diff --git a/StoneIsland/platforms/ios/cordova/lib/run.js b/StoneIsland/platforms/ios/cordova/lib/run.js index 0caadf06..3a6246e1 100755 --- a/StoneIsland/platforms/ios/cordova/lib/run.js +++ b/StoneIsland/platforms/ios/cordova/lib/run.js @@ -17,14 +17,12 @@ under the License. */ -/*jshint node: true*/ - -var Q = require('q'), - path = require('path'), - iossim = require('ios-sim'), - build = require('./build'), - spawn = require('./spawn'), - check_reqs = require('./check_reqs'); +var Q = require('q'); +var path = require('path'); +var iossim = require('ios-sim'); +var build = require('./build'); +var spawn = require('./spawn'); +var check_reqs = require('./check_reqs'); var events = require('cordova-common').events; @@ -40,109 +38,117 @@ module.exports.run = function (runOptions) { // support for CB-8168 `cordova/run --list` if (runOptions.list) { - if (runOptions.device) return listDevices(); - if (runOptions.emulator) return listEmulators(); + if (runOptions.device) return module.exports.listDevices(); + if (runOptions.emulator) return module.exports.listEmulators(); // if no --device or --emulator flag is specified, list both devices and emulators - return listDevices().then(function () { - return listEmulators(); + return module.exports.listDevices().then(function () { + return module.exports.listEmulators(); }); } var useDevice = !!runOptions.device; return require('./list-devices').run() - .then(function (devices) { - if (devices.length > 0 && !(runOptions.emulator)) { - useDevice = true; - // we also explicitly set device flag in options as we pass - // those parameters to other api (build as an example) - runOptions.device = true; - return check_reqs.check_ios_deploy(); - } - }).then(function () { - if (!runOptions.nobuild) { - return build.run(runOptions); - } else { - return Q.resolve(); - } - }).then(function () { - return build.findXCodeProjectIn(projectPath); - }).then(function (projectName) { - var appPath = path.join(projectPath, 'build', 'emulator', projectName + '.app'); - var buildOutputDir = path.join(projectPath, 'build', 'device'); + .then(function (devices) { + if (devices.length > 0 && !(runOptions.emulator)) { + useDevice = true; + // we also explicitly set device flag in options as we pass + // those parameters to other api (build as an example) + runOptions.device = true; + return check_reqs.check_ios_deploy(); + } + }).then(function () { + if (!runOptions.nobuild) { + return build.run(runOptions); + } else { + return Q.resolve(); + } + }).then(function () { + return build.findXCodeProjectIn(projectPath); + }).then(function (projectName) { + var appPath = path.join(projectPath, 'build', 'emulator', projectName + '.app'); + var buildOutputDir = path.join(projectPath, 'build', 'device'); - // select command to run and arguments depending whether - // we're running on device/emulator - if (useDevice) { - return checkDeviceConnected() - .then(function() { - // Unpack IPA - var ipafile = path.join(buildOutputDir, projectName + '.ipa'); + // select command to run and arguments depending whether + // we're running on device/emulator + if (useDevice) { + return module.exports.checkDeviceConnected() + .then(function () { + // Unpack IPA + var ipafile = path.join(buildOutputDir, projectName + '.ipa'); - // unpack the existing platform/ios/build/device/appname.ipa (zipfile), will create a Payload folder - return spawn('unzip', [ '-o', '-qq', ipafile ], buildOutputDir); - }) - .then(function() { - // Uncompress IPA (zip file) - var appFileInflated = path.join(buildOutputDir, 'Payload', projectName + '.app'); - var appFile = path.join(buildOutputDir, projectName + '.app'); - var payloadFolder = path.join(buildOutputDir, 'Payload'); + // unpack the existing platform/ios/build/device/appname.ipa (zipfile), will create a Payload folder + return spawn('unzip', [ '-o', '-qq', ipafile ], buildOutputDir); + }) + .then(function () { + // Uncompress IPA (zip file) + var appFileInflated = path.join(buildOutputDir, 'Payload', projectName + '.app'); + var appFile = path.join(buildOutputDir, projectName + '.app'); + var payloadFolder = path.join(buildOutputDir, 'Payload'); - // delete the existing platform/ios/build/device/appname.app - return spawn('rm', [ '-rf', appFile ], buildOutputDir) - .then(function() { - // move the platform/ios/build/device/Payload/appname.app to parent - return spawn('mv', [ '-f', appFileInflated, buildOutputDir ], buildOutputDir); + // delete the existing platform/ios/build/device/appname.app + return spawn('rm', [ '-rf', appFile ], buildOutputDir) + .then(function () { + // move the platform/ios/build/device/Payload/appname.app to parent + return spawn('mv', [ '-f', appFileInflated, buildOutputDir ], buildOutputDir); + }) + .then(function () { + // delete the platform/ios/build/device/Payload folder + return spawn('rm', [ '-rf', payloadFolder ], buildOutputDir); + }); }) - .then(function() { - // delete the platform/ios/build/device/Payload folder - return spawn('rm', [ '-rf', payloadFolder ], buildOutputDir); + .then(function () { + appPath = path.join(projectPath, 'build', 'device', projectName + '.app'); + var extraArgs = []; + if (runOptions.argv) { + // argv.slice(2) removes node and run.js, filterSupportedArgs removes the run.js args + extraArgs = module.exports.filterSupportedArgs(runOptions.argv.slice(2)); + } + return module.exports.deployToDevice(appPath, runOptions.target, extraArgs); + }, function () { + // if device connection check failed use emulator then + return module.exports.deployToSim(appPath, runOptions.target); }); - }) - .then(function() { - appPath = path.join(projectPath, 'build', 'device', projectName + '.app'); - var extraArgs = []; - if (runOptions.argv) { - // argv.slice(2) removes node and run.js, filterSupportedArgs removes the run.js args - extraArgs = filterSupportedArgs(runOptions.argv.slice(2)); - } - return deployToDevice(appPath, runOptions.target, extraArgs); - }, function () { - // if device connection check failed use emulator then - return deployToSim(appPath, runOptions.target); - }); - } else { - return deployToSim(appPath, runOptions.target); - } - }); + } else { + return module.exports.deployToSim(appPath, runOptions.target); + } + }); }; +module.exports.filterSupportedArgs = filterSupportedArgs; +module.exports.checkDeviceConnected = checkDeviceConnected; +module.exports.deployToDevice = deployToDevice; +module.exports.deployToSim = deployToSim; +module.exports.startSim = startSim; +module.exports.listDevices = listDevices; +module.exports.listEmulators = listEmulators; + /** * Filters the args array and removes supported args for the 'run' command. * * @return {Array} array with unsupported args for the 'run' command */ -function filterSupportedArgs(args) { - var filtered = []; - var sargs = ['--device', '--emulator', '--nobuild', '--list', '--target', '--debug', '--release']; - var re = new RegExp(sargs.join('|')); +function filterSupportedArgs (args) { + var filtered = []; + var sargs = ['--device', '--emulator', '--nobuild', '--list', '--target', '--debug', '--release']; + var re = new RegExp(sargs.join('|')); - args.forEach(function(element) { - // supported args not found, we add - // we do a regex search because --target can be "--target=XXX" - if (element.search(re) == -1) { - filtered.push(element); - } - }, this); + args.forEach(function (element) { + // supported args not found, we add + // we do a regex search because --target can be "--target=XXX" + if (element.search(re) === -1) { + filtered.push(element); + } + }, this); - return filtered; + return filtered; } /** * Checks if any iOS device is connected * @return {Promise} Fullfilled when any device is connected, rejected otherwise */ -function checkDeviceConnected() { +function checkDeviceConnected () { return spawn('ios-deploy', ['-c', '-t', '1']); } @@ -152,7 +158,7 @@ function checkDeviceConnected() { * @param {String} appPath Path to application package * @return {Promise} Resolves when deploy succeeds otherwise rejects */ -function deployToDevice(appPath, target, extraArgs) { +function deployToDevice (appPath, target, extraArgs) { // Deploying to device... if (target) { return spawn('ios-deploy', ['--justlaunch', '-d', '-b', appPath, '-i', target].concat(extraArgs)); @@ -167,51 +173,51 @@ function deployToDevice(appPath, target, extraArgs) { * @param {String} target Target device type * @return {Promise} Resolves when deploy succeeds otherwise rejects */ -function deployToSim(appPath, target) { +function deployToSim (appPath, target) { // Select target device for emulator. Default is 'iPhone-6' if (!target) { return require('./list-emulator-images').run() - .then(function (emulators) { - if (emulators.length > 0) { - target = emulators[0]; - } - emulators.forEach(function (emulator) { - if (emulator.indexOf('iPhone') === 0) { - target = emulator; + .then(function (emulators) { + if (emulators.length > 0) { + target = emulators[0]; } + emulators.forEach(function (emulator) { + if (emulator.indexOf('iPhone') === 0) { + target = emulator; + } + }); + events.emit('log', 'No target specified for emulator. Deploying to ' + target + ' simulator'); + return startSim(appPath, target); }); - events.emit('log','No target specified for emulator. Deploying to ' + target + ' simulator'); - return startSim(appPath, target); - }); } else { return startSim(appPath, target); } } -function startSim(appPath, target) { +function startSim (appPath, target) { var logPath = path.join(cordovaPath, 'console.log'); return iossim.launch(appPath, 'com.apple.CoreSimulator.SimDeviceType.' + target, logPath, '--exit'); } -function listDevices() { +function listDevices () { return require('./list-devices').run() - .then(function (devices) { - events.emit('log','Available iOS Devices:'); - devices.forEach(function (device) { - events.emit('log','\t' + device); + .then(function (devices) { + events.emit('log', 'Available iOS Devices:'); + devices.forEach(function (device) { + events.emit('log', '\t' + device); + }); }); - }); } -function listEmulators() { +function listEmulators () { return require('./list-emulator-images').run() - .then(function (emulators) { - events.emit('log','Available iOS Simulators:'); - emulators.forEach(function (emulator) { - events.emit('log','\t' + emulator); + .then(function (emulators) { + events.emit('log', 'Available iOS Simulators:'); + emulators.forEach(function (emulator) { + events.emit('log', '\t' + emulator); + }); }); - }); } module.exports.help = function () { @@ -230,7 +236,7 @@ module.exports.help = function () { console.log('Examples:'); console.log(' run'); console.log(' run --device'); - console.log(' run --emulator --target=\"iPhone-6-Plus\"'); + console.log(' run --emulator --target=\"iPhone-6-Plus\"'); /* eslint no-useless-escape : 0 */ console.log(' run --device --release'); console.log(' run --emulator --debug'); console.log(''); |
