From 0a09b8bce57124718c1d880839f0e58f37904abc Mon Sep 17 00:00:00 2001 From: Angly Cat Date: Thu, 5 Apr 2018 15:56:07 +0600 Subject: [PATCH 1/2] Fix promise rejection on build fails --- local-cli/runIOS/runIOS.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/local-cli/runIOS/runIOS.js b/local-cli/runIOS/runIOS.js index 61b6795d5ab55b..a999e6a4974530 100644 --- a/local-cli/runIOS/runIOS.js +++ b/local-cli/runIOS/runIOS.js @@ -99,7 +99,8 @@ function runOnDeviceByUdid(args, scheme, xcodeProject, devices) { } function runOnSimulator(xcodeProject, args, scheme) { - return new Promise((resolve) => { + return Promise.resolve() + .then(() => { try { var simulators = JSON.parse( child_process.execFileSync('xcrun', ['simctl', 'list', '--json', 'devices'], {encoding: 'utf8'}) @@ -142,8 +143,8 @@ function runOnSimulator(xcodeProject, args, scheme) { } } - buildProject(xcodeProject, selectedSimulator.udid, scheme, args.configuration, args.packager, args.verbose, args.port) - .then((appName) => resolve({ udid: selectedSimulator.udid, appName })); + return buildProject(xcodeProject, selectedSimulator.udid, scheme, args.configuration, args.packager, args.verbose, args.port) + .then((appName) => ({ udid: selectedSimulator.udid, appName })); }) .then(({udid, appName}) => { if (!appName) { @@ -213,13 +214,17 @@ function buildProject(xcodeProject, udid, scheme, configuration = 'Debug', launc console.log(data.toString()); } }); + const errOutputChunks = []; buildProcess.stderr.on('data', function(data) { - console.error(data.toString()); + errOutputChunks.push(data.toString()); }); - buildProcess.on('close', function(code) { + buildProcess.on('close', function(exitCode) { if (xcpretty) { xcpretty.stdin.end(); } + if (exitCode !== 0) { + return reject(errOutputChunks.join('\n')); + } //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) { From 319f4469e6982fa6f01bb767e9c9680f4222d778 Mon Sep 17 00:00:00 2001 From: Angly Cat Date: Thu, 5 Apr 2018 15:56:34 +0600 Subject: [PATCH 2/2] Refactor product name resolving --- local-cli/runIOS/runIOS.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/local-cli/runIOS/runIOS.js b/local-cli/runIOS/runIOS.js index a999e6a4974530..0bc750f7262749 100644 --- a/local-cli/runIOS/runIOS.js +++ b/local-cli/runIOS/runIOS.js @@ -227,10 +227,8 @@ function buildProject(xcodeProject, udid, scheme, configuration = 'Debug', launc } //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) { - return resolve(productNameMatch[1]);//0 is the full match, 1 is the app name - } - return buildProcess.error ? reject(buildProcess.error) : resolve(); + //[0] of productNameMatch is the full match, [1] is the app name + return resolve(productNameMatch && productNameMatch.length && productNameMatch.length > 1 ? productNameMatch[1] : undefined); }); }); }