summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/ios/cordova/lib/run.js
diff options
context:
space:
mode:
Diffstat (limited to 'StoneIsland/platforms/ios/cordova/lib/run.js')
-rw-r--r--[-rwxr-xr-x]StoneIsland/platforms/ios/cordova/lib/run.js168
1 files changed, 92 insertions, 76 deletions
diff --git a/StoneIsland/platforms/ios/cordova/lib/run.js b/StoneIsland/platforms/ios/cordova/lib/run.js
index 3a6246e1..f7fd8c13 100755..100644
--- a/StoneIsland/platforms/ios/cordova/lib/run.js
+++ b/StoneIsland/platforms/ios/cordova/lib/run.js
@@ -17,23 +17,23 @@
under the License.
*/
-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');
+const path = require('path');
+const build = require('./build');
+const {
+ CordovaError,
+ events,
+ superspawn: { spawn }
+} = require('cordova-common');
+const check_reqs = require('./check_reqs');
+const fs = require('fs-extra');
-var events = require('cordova-common').events;
-
-var cordovaPath = path.join(__dirname, '..');
-var projectPath = path.join(__dirname, '..', '..');
-
-module.exports.run = function (runOptions) {
+const cordovaPath = path.join(__dirname, '..');
+const projectPath = path.join(__dirname, '..', '..');
+module.exports.run = runOptions => {
// Validate args
if (runOptions.device && runOptions.emulator) {
- return Q.reject('Only one of "device"/"emulator" options should be specified');
+ return Promise.reject(new CordovaError('Only one of "device"/"emulator" options should be specified'));
}
// support for CB-8168 `cordova/run --list`
@@ -41,15 +41,13 @@ module.exports.run = function (runOptions) {
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 module.exports.listDevices().then(function () {
- return module.exports.listEmulators();
- });
+ return module.exports.listDevices().then(() => module.exports.listEmulators());
}
- var useDevice = !!runOptions.device;
+ let useDevice = !!runOptions.device;
- return require('./list-devices').run()
- .then(function (devices) {
+ return require('./listDevices').run()
+ .then(devices => {
if (devices.length > 0 && !(runOptions.emulator)) {
useDevice = true;
// we also explicitly set device flag in options as we pass
@@ -57,58 +55,56 @@ module.exports.run = function (runOptions) {
runOptions.device = true;
return check_reqs.check_ios_deploy();
}
- }).then(function () {
+ }).then(() => {
if (!runOptions.nobuild) {
return build.run(runOptions);
} else {
- return Q.resolve();
+ return Promise.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(() => build.findXCodeProjectIn(projectPath))
+ .then(projectName => {
+ let appPath = path.join(projectPath, 'build', 'emulator', `${projectName}.app`);
+ const buildOutputDir = path.join(projectPath, 'build', 'device');
// select command to run and arguments depending whether
// we're running on device/emulator
if (useDevice) {
return module.exports.checkDeviceConnected()
- .then(function () {
+ .then(() => {
// Unpack IPA
- var ipafile = path.join(buildOutputDir, projectName + '.ipa');
+ const 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);
+ return spawn('unzip', ['-o', '-qq', ipafile], { cwd: buildOutputDir, printCommand: true, stdio: 'inherit' });
})
- .then(function () {
+ .then(() => {
// 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');
+ const appFileInflated = path.join(buildOutputDir, 'Payload', `${projectName}.app`);
+ const appFile = path.join(buildOutputDir, `${projectName}.app`);
+ const 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);
- })
- .then(function () {
- // delete the platform/ios/build/device/Payload folder
- return spawn('rm', [ '-rf', payloadFolder ], buildOutputDir);
- });
+ fs.removeSync(appFile);
+ // move the platform/ios/build/device/Payload/appname.app to parent
+ fs.moveSync(appFileInflated, appFile);
+ // delete the platform/ios/build/device/Payload folder
+ fs.removeSync(payloadFolder);
+
+ return null;
})
- .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 () {
+ .then(
+ () => {
+ appPath = path.join(projectPath, 'build', 'device', `${projectName}.app`);
+ let 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);
+ },
// if device connection check failed use emulator then
- return module.exports.deployToSim(appPath, runOptions.target);
- });
+ () => module.exports.deployToSim(appPath, runOptions.target)
+ );
} else {
return module.exports.deployToSim(appPath, runOptions.target);
}
@@ -129,11 +125,11 @@ module.exports.listEmulators = listEmulators;
* @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('|'));
+ const filtered = [];
+ const sargs = ['--device', '--emulator', '--nobuild', '--list', '--target', '--debug', '--release'];
+ const re = new RegExp(sargs.join('|'));
- args.forEach(function (element) {
+ args.forEach(element => {
// supported args not found, we add
// we do a regex search because --target can be "--target=XXX"
if (element.search(re) === -1) {
@@ -149,7 +145,7 @@ function filterSupportedArgs (args) {
* @return {Promise} Fullfilled when any device is connected, rejected otherwise
*/
function checkDeviceConnected () {
- return spawn('ios-deploy', ['-c', '-t', '1']);
+ return spawn('ios-deploy', ['-c', '-t', '1'], { printCommand: true, stdio: 'inherit' });
}
/**
@@ -159,11 +155,12 @@ 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 spawn('ios-deploy', ['--justlaunch', '-d', '-b', appPath, '-i', target].concat(extraArgs));
+ return spawn('ios-deploy', ['--justlaunch', '-d', '-b', appPath, '-i', target].concat(extraArgs), { printCommand: true, stdio: 'inherit' });
} else {
- return spawn('ios-deploy', ['--justlaunch', '--no-wifi', '-d', '-b', appPath].concat(extraArgs));
+ return spawn('ios-deploy', ['--justlaunch', '--no-wifi', '-d', '-b', appPath].concat(extraArgs), { printCommand: true, stdio: 'inherit' });
}
}
@@ -174,19 +171,20 @@ 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) {
- return require('./list-emulator-images').run()
- .then(function (emulators) {
+ // Select target device for emulator
+ return require('./listEmulatorImages').run()
+ .then(emulators => {
if (emulators.length > 0) {
target = emulators[0];
}
- emulators.forEach(function (emulator) {
+ emulators.forEach(emulator => {
if (emulator.indexOf('iPhone') === 0) {
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 {
@@ -195,32 +193,50 @@ function deployToSim (appPath, target) {
}
function startSim (appPath, target) {
- var logPath = path.join(cordovaPath, 'console.log');
+ const logPath = path.join(cordovaPath, 'console.log');
- return iossim.launch(appPath, 'com.apple.CoreSimulator.SimDeviceType.' + target, logPath, '--exit');
+ return iossimLaunch(appPath, `com.apple.CoreSimulator.SimDeviceType.${target}`, logPath, '--exit');
+}
+
+function iossimLaunch (appPath, devicetypeid, log, exit) {
+ return spawn(
+ require.resolve('ios-sim/bin/ios-sim'),
+ ['launch', appPath, '--devicetypeid', devicetypeid, '--log', log, exit],
+ { cwd: projectPath, printCommand: true }
+ ).progress(stdio => {
+ if (stdio.stderr) {
+ events.emit('error', `[ios-sim] ${stdio.stderr}`);
+ }
+ if (stdio.stdout) {
+ events.emit('log', `[ios-sim] ${stdio.stdout.trim()}`);
+ }
+ })
+ .then(result => {
+ events.emit('log', 'Simulator successfully started via `ios-sim`.');
+ });
}
function listDevices () {
- return require('./list-devices').run()
- .then(function (devices) {
+ return require('./listDevices').run()
+ .then(devices => {
events.emit('log', 'Available iOS Devices:');
- devices.forEach(function (device) {
- events.emit('log', '\t' + device);
+ devices.forEach(device => {
+ events.emit('log', `\t${device}`);
});
});
}
function listEmulators () {
- return require('./list-emulator-images').run()
- .then(function (emulators) {
+ return require('./listEmulatorImages').run()
+ .then(emulators => {
events.emit('log', 'Available iOS Simulators:');
- emulators.forEach(function (emulator) {
- events.emit('log', '\t' + emulator);
+ emulators.forEach(emulator => {
+ events.emit('log', `\t${emulator}`);
});
});
}
-module.exports.help = function () {
+module.exports.help = () => {
console.log('\nUsage: run [ --device | [ --emulator [ --target=<id> ] ] ] [ --debug | --release | --nobuild ]');
// TODO: add support for building different archs
// console.log(" [ --archs=\"<list of target architectures>\" ] ");