From 6b8ee75c85810e0097cf146bc4fb07a5e2b345e7 Mon Sep 17 00:00:00 2001 From: Trevor Brindle Date: Tue, 22 Aug 2017 13:57:31 -0400 Subject: [PATCH 1/9] use xcpretty if installed --- local-cli/runIOS/runIOS.js | 41 +++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/local-cli/runIOS/runIOS.js b/local-cli/runIOS/runIOS.js index a5672316631f72..33be84f6c5ee82 100644 --- a/local-cli/runIOS/runIOS.js +++ b/local-cli/runIOS/runIOS.js @@ -18,6 +18,17 @@ const findMatchingSimulator = require('./findMatchingSimulator'); const getBuildPath = function(configuration = 'Debug', appName, isDevice) { return `build/Build/Products/${configuration}-${isDevice ? 'iphoneos' : 'iphonesimulator'}/${appName}.app`; }; +const xcprettyAvailable = function() { + try { + child_process.execSync('xcpretty --version', { + stdio: [ 0, 'pipe', 'ignore', ] + }); + } catch (error) { + console.log(error) + return false; + } + return true; +}; function runIOS(argv, config, args) { if (!fs.existsSync(args.projectPath)) { @@ -48,7 +59,7 @@ function runIOS(argv, config, args) { if (args.device) { const selectedDevice = matchingDevice(devices, args.device); if (selectedDevice){ - return runOnDevice(selectedDevice, scheme, xcodeProject, args.configuration, args.packager); + return runOnDevice(selectedDevice, scheme, xcodeProject, args.configuration, args.packager, args.verbose); } else { if (devices){ console.log('Could not find device with the name: "' + args.device + '".'); @@ -68,7 +79,7 @@ function runIOS(argv, config, args) { function runOnDeviceByUdid(args, scheme, xcodeProject, devices) { const selectedDevice = matchingDeviceByUdid(devices, args.udid); if (selectedDevice){ - return runOnDevice(selectedDevice, scheme, xcodeProject, args.configuration, args.packager); + return runOnDevice(selectedDevice, scheme, xcodeProject, args.configuration, args.packager, args.verbose); } else { if (devices){ console.log('Could not find device with the udid: "' + args.udid + '".'); @@ -105,7 +116,7 @@ function runOnSimulator(xcodeProject, args, scheme){ } resolve(selectedSimulator.udid) }) - .then((udid) => buildProject(xcodeProject, udid, scheme, args.configuration, args.packager)) + .then((udid) => buildProject(xcodeProject, udid, scheme, args.configuration, args.packager, args.verbose)) .then((appName) => { if (!appName) { appName = scheme; @@ -125,8 +136,8 @@ function runOnSimulator(xcodeProject, args, scheme){ }) } -function runOnDevice(selectedDevice, scheme, xcodeProject, configuration, launchPackager) { - return buildProject(xcodeProject, selectedDevice.udid, scheme, configuration, launchPackager) +function runOnDevice(selectedDevice, scheme, xcodeProject, configuration, launchPackager, verbose) { + return buildProject(xcodeProject, selectedDevice.udid, scheme, configuration, launchPackager, verbose) .then((appName) => { if (!appName) { appName = scheme; @@ -149,7 +160,7 @@ function runOnDevice(selectedDevice, scheme, xcodeProject, configuration, launch }); } -function buildProject(xcodeProject, udid, scheme, configuration = 'Debug', launchPackager = false) { +function buildProject(xcodeProject, udid, scheme, configuration = 'Debug', launchPackager = false, verbose) { return new Promise((resolve,reject) => { var xcodebuildArgs = [ @@ -160,16 +171,29 @@ function buildProject(xcodeProject, udid, scheme, configuration = 'Debug', launc '-derivedDataPath', 'build', ]; console.log(`Building using "xcodebuild ${xcodebuildArgs.join(' ')}"`); + if (!verbose) { + var xcpretty = xcprettyAvailable(); + if (xcpretty) { + var xcprettyProcess = child_process.spawn('xcpretty', [], { stdio: ['pipe', process.stdout, process.stderr] }); + } + } const buildProcess = child_process.spawn('xcodebuild', xcodebuildArgs, getProcessOptions(launchPackager)); let buildOutput = ""; buildProcess.stdout.on('data', function(data) { - console.log(data.toString()); buildOutput += data.toString(); + if (xcpretty && !verbose) { + xcprettyProcess.stdin.write(data); + } else { + console.log(data.toString()); + } }); buildProcess.stderr.on('data', function(data) { console.error(data.toString()); }); buildProcess.on('close', function(code) { + if (xcpretty && !verbose) { + xcprettyProcess.stdin.end(); + } //FULL_PRODUCT_NAME is the actual file name of the app, which actually comes from the Product Name in the build config, which does not necessary match a scheme name, example output line: export FULL_PRODUCT_NAME="Super App Dev.app" let productNameMatch = /export FULL_PRODUCT_NAME="?(.+).app"?$/m.exec(buildOutput); if (productNameMatch && productNameMatch.length && productNameMatch.length > 1) { @@ -263,5 +287,8 @@ module.exports = { }, { command: '--no-packager', description: 'Do not launch packager while building', + }, { + command: '--verbose', + description: 'Do not use xcpretty even if installed', }], }; From d96a5faf30a7047173d86652d69f8afca0962caf Mon Sep 17 00:00:00 2001 From: Trevor Brindle Date: Tue, 22 Aug 2017 15:09:54 -0400 Subject: [PATCH 2/9] accidentally a semicolon --- local-cli/runIOS/runIOS.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/local-cli/runIOS/runIOS.js b/local-cli/runIOS/runIOS.js index 33be84f6c5ee82..a0524854cf1c36 100644 --- a/local-cli/runIOS/runIOS.js +++ b/local-cli/runIOS/runIOS.js @@ -24,7 +24,7 @@ const xcprettyAvailable = function() { stdio: [ 0, 'pipe', 'ignore', ] }); } catch (error) { - console.log(error) + console.log(error); return false; } return true; From 5175aa21f4228f36cf3da975073f89ca8bd55b68 Mon Sep 17 00:00:00 2001 From: Trevor Brindle Date: Tue, 22 Aug 2017 15:12:05 -0400 Subject: [PATCH 3/9] fix other lint errors in runIOS.js --- local-cli/runIOS/runIOS.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/local-cli/runIOS/runIOS.js b/local-cli/runIOS/runIOS.js index a0524854cf1c36..77b969549494cc 100644 --- a/local-cli/runIOS/runIOS.js +++ b/local-cli/runIOS/runIOS.js @@ -114,7 +114,7 @@ function runOnSimulator(xcodeProject, args, scheme){ // instruments always fail with 255 because it expects more arguments, // but we want it to only launch the simulator } - resolve(selectedSimulator.udid) + resolve(selectedSimulator.udid); }) .then((udid) => buildProject(xcodeProject, udid, scheme, args.configuration, args.packager, args.verbose)) .then((appName) => { @@ -133,7 +133,7 @@ function runOnSimulator(xcodeProject, args, scheme){ console.log(`Launching ${bundleID}`); child_process.spawnSync('xcrun', ['simctl', 'launch', 'booted', bundleID], {stdio: 'inherit'}); - }) + }); } function runOnDevice(selectedDevice, scheme, xcodeProject, configuration, launchPackager, verbose) { @@ -199,7 +199,7 @@ function buildProject(xcodeProject, udid, scheme, configuration = 'Debug', launc if (productNameMatch && productNameMatch.length && productNameMatch.length > 1) { return resolve(productNameMatch[1]);//0 is the full match, 1 is the app name } - return buildProcess.error? reject(buildProcess.error) : resolve(); + return buildProcess.error ? reject(buildProcess.error) : resolve(); }); }); } From 57ef7f5cf23da1cf75383ecd6329e1c54559fe75 Mon Sep 17 00:00:00 2001 From: Trevor Brindle Date: Tue, 22 Aug 2017 15:16:25 -0400 Subject: [PATCH 4/9] runIOS.js linting --- local-cli/runIOS/runIOS.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/local-cli/runIOS/runIOS.js b/local-cli/runIOS/runIOS.js index 77b969549494cc..def401956d9ea8 100644 --- a/local-cli/runIOS/runIOS.js +++ b/local-cli/runIOS/runIOS.js @@ -178,7 +178,7 @@ function buildProject(xcodeProject, udid, scheme, configuration = 'Debug', launc } } const buildProcess = child_process.spawn('xcodebuild', xcodebuildArgs, getProcessOptions(launchPackager)); - let buildOutput = ""; + let buildOutput = ''; buildProcess.stdout.on('data', function(data) { buildOutput += data.toString(); if (xcpretty && !verbose) { @@ -207,7 +207,7 @@ function buildProject(xcodeProject, udid, scheme, configuration = 'Debug', launc function matchingDevice(devices, deviceName) { if (deviceName === true && devices.length === 1) { - console.log(`Using first available device ${devices[0].name} due to lack of name supplied.`) + console.log(`Using first available device ${devices[0].name} due to lack of name supplied.`); return devices[0]; } for (let i = devices.length - 1; i >= 0; i--) { From 4f3a1921d4975766129a66b6a9d4f542933eeecd Mon Sep 17 00:00:00 2001 From: Trevor Brindle Date: Tue, 22 Aug 2017 17:03:39 -0400 Subject: [PATCH 5/9] remove error logging for xcprettyAvailable() --- local-cli/runIOS/runIOS.js | 1 - 1 file changed, 1 deletion(-) diff --git a/local-cli/runIOS/runIOS.js b/local-cli/runIOS/runIOS.js index def401956d9ea8..eb374cda775ae8 100644 --- a/local-cli/runIOS/runIOS.js +++ b/local-cli/runIOS/runIOS.js @@ -24,7 +24,6 @@ const xcprettyAvailable = function() { stdio: [ 0, 'pipe', 'ignore', ] }); } catch (error) { - console.log(error); return false; } return true; From dde8fe95de4001ec307f74732748eeaab32ec721 Mon Sep 17 00:00:00 2001 From: Trevor Brindle Date: Wed, 23 Aug 2017 12:52:27 -0400 Subject: [PATCH 6/9] use let instead of var --- local-cli/runIOS/runIOS.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/local-cli/runIOS/runIOS.js b/local-cli/runIOS/runIOS.js index eb374cda775ae8..d498758f4b9270 100644 --- a/local-cli/runIOS/runIOS.js +++ b/local-cli/runIOS/runIOS.js @@ -170,10 +170,11 @@ function buildProject(xcodeProject, udid, scheme, configuration = 'Debug', launc '-derivedDataPath', 'build', ]; console.log(`Building using "xcodebuild ${xcodebuildArgs.join(' ')}"`); + let xcpretty, xcprettyProcess; if (!verbose) { - var xcpretty = xcprettyAvailable(); + xcpretty = xcprettyAvailable(); if (xcpretty) { - var xcprettyProcess = child_process.spawn('xcpretty', [], { stdio: ['pipe', process.stdout, process.stderr] }); + xcprettyProcess = child_process.spawn('xcpretty', [], { stdio: ['pipe', process.stdout, process.stderr] }); } } const buildProcess = child_process.spawn('xcodebuild', xcodebuildArgs, getProcessOptions(launchPackager)); From 2361aeac9c67160a03cb9f146bc9e92c7b8a1a8b Mon Sep 17 00:00:00 2001 From: Trevor Brindle Date: Wed, 23 Aug 2017 12:55:19 -0400 Subject: [PATCH 7/9] fix if block spacing --- local-cli/runIOS/runIOS.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/local-cli/runIOS/runIOS.js b/local-cli/runIOS/runIOS.js index d498758f4b9270..41ac965a84ee6a 100644 --- a/local-cli/runIOS/runIOS.js +++ b/local-cli/runIOS/runIOS.js @@ -57,7 +57,7 @@ function runIOS(argv, config, args) { ); if (args.device) { const selectedDevice = matchingDevice(devices, args.device); - if (selectedDevice){ + if (selectedDevice) { return runOnDevice(selectedDevice, scheme, xcodeProject, args.configuration, args.packager, args.verbose); } else { if (devices){ @@ -77,7 +77,7 @@ function runIOS(argv, config, args) { function runOnDeviceByUdid(args, scheme, xcodeProject, devices) { const selectedDevice = matchingDeviceByUdid(devices, args.udid); - if (selectedDevice){ + if (selectedDevice) { return runOnDevice(selectedDevice, scheme, xcodeProject, args.configuration, args.packager, args.verbose); } else { if (devices){ From 1cd2cbe9fc26c149c5da339c4e51cfdf53aa9124 Mon Sep 17 00:00:00 2001 From: Trevor Brindle Date: Tue, 29 Aug 2017 15:08:20 -0400 Subject: [PATCH 8/9] remove extra xcprettyProcess variable just use xcpretty - either is falsy or contains the process --- local-cli/runIOS/runIOS.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/local-cli/runIOS/runIOS.js b/local-cli/runIOS/runIOS.js index 6f775c40ecc896..e2943b6fbcbea7 100644 --- a/local-cli/runIOS/runIOS.js +++ b/local-cli/runIOS/runIOS.js @@ -170,19 +170,18 @@ function buildProject(xcodeProject, udid, scheme, configuration = 'Debug', launc '-derivedDataPath', 'build', ]; console.log(`Building using "xcodebuild ${xcodebuildArgs.join(' ')}"`); - let xcpretty, xcprettyProcess; + let xcpretty; if (!verbose) { - xcpretty = xcprettyAvailable(); - if (xcpretty) { - xcprettyProcess = child_process.spawn('xcpretty', [], { stdio: ['pipe', process.stdout, process.stderr] }); - } + xcpretty = xcprettyAvailable() + ? child_process.spawn('xcpretty', [], { stdio: ['pipe', process.stdout, process.stderr] }) + : false; } const buildProcess = child_process.spawn('xcodebuild', xcodebuildArgs, getProcessOptions(launchPackager)); let buildOutput = ''; buildProcess.stdout.on('data', function(data) { buildOutput += data.toString(); - if (xcpretty && !verbose) { - xcprettyProcess.stdin.write(data); + if (xcpretty) { + xcpretty.stdin.write(data); } else { console.log(data.toString()); } @@ -191,8 +190,8 @@ function buildProject(xcodeProject, udid, scheme, configuration = 'Debug', launc console.error(data.toString()); }); buildProcess.on('close', function(code) { - if (xcpretty && !verbose) { - xcprettyProcess.stdin.end(); + if (xcpretty) { + xcpretty.stdin.end(); } //FULL_PRODUCT_NAME is the actual file name of the app, which actually comes from the Product Name in the build config, which does not necessary match a scheme name, example output line: export FULL_PRODUCT_NAME="Super App Dev.app" let productNameMatch = /export FULL_PRODUCT_NAME="?(.+).app"?$/m.exec(buildOutput); From 2fef71af232caa7d188c814369bf420394edbc0c Mon Sep 17 00:00:00 2001 From: Trevor Brindle Date: Tue, 29 Aug 2017 15:21:25 -0400 Subject: [PATCH 9/9] remove unnecessary ternary --- local-cli/runIOS/runIOS.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/local-cli/runIOS/runIOS.js b/local-cli/runIOS/runIOS.js index e2943b6fbcbea7..cfa9ac630db2bc 100644 --- a/local-cli/runIOS/runIOS.js +++ b/local-cli/runIOS/runIOS.js @@ -172,9 +172,7 @@ function buildProject(xcodeProject, udid, scheme, configuration = 'Debug', launc console.log(`Building using "xcodebuild ${xcodebuildArgs.join(' ')}"`); let xcpretty; if (!verbose) { - xcpretty = xcprettyAvailable() - ? child_process.spawn('xcpretty', [], { stdio: ['pipe', process.stdout, process.stderr] }) - : false; + xcpretty = xcprettyAvailable() && child_process.spawn('xcpretty', [], { stdio: ['pipe', process.stdout, process.stderr] }); } const buildProcess = child_process.spawn('xcodebuild', xcodebuildArgs, getProcessOptions(launchPackager)); let buildOutput = '';