From 0c2a70e2974ff05769945688f06505fab1292c25 Mon Sep 17 00:00:00 2001 From: Danny Palmer Date: Sun, 7 May 2017 15:39:20 -0700 Subject: [PATCH] Refactor product name for runIOS, enable multi-line Updated FULL_PRODUCT_NAME regex to match across multiple lines, which is the case for iOS build output. Includes refactor to export getProductName for testing. --- local-cli/runIOS/__tests__/runIOS-test.js | 41 +++++++++++++++++++++++ local-cli/runIOS/runIOS.js | 18 +++++++--- 2 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 local-cli/runIOS/__tests__/runIOS-test.js diff --git a/local-cli/runIOS/__tests__/runIOS-test.js b/local-cli/runIOS/__tests__/runIOS-test.js new file mode 100644 index 00000000000000..2478635aead98a --- /dev/null +++ b/local-cli/runIOS/__tests__/runIOS-test.js @@ -0,0 +1,41 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +'use strict'; + +jest.dontMock('../runIOS'); + +const { getProductName } = require('../runIOS'); + +describe('runIOS', () => { + it('Should get product name, single line', () => { + expect(getProductName('export FULL_PRODUCT_NAME="Super App Dev.app"')) + .toEqual('Super App Dev'); + }); + + it('Should get product name, multi line', () => { + expect(getProductName('export FRAMEWORK_VERSION=A\nexport FULL_PRODUCT_NAME="Super App Dev.app"\nexport GCC3_VERSION=3.3')) + .toEqual('Super App Dev'); + }); + + it('Should get the first product name if there are multiple', () => { + expect(getProductName('export FULL_PRODUCT_NAME="Super App Dev.app"\nexport FULL_PRODUCT_NAME="Super App Dev2.app"')) + .toEqual('Super App Dev'); + }); + + it('Should get product name and skip app extensions (.appex)', () => { + expect(getProductName('export FULL_PRODUCT_NAME="Evil App Dev.appex"\nexport FULL_PRODUCT_NAME="Super App Dev.app"\nexport FULL_PRODUCT_NAME="Evil App Dev2.appex"')) + .toEqual('Super App Dev'); + }); + + it('Should return null if no product name', () => { + expect(getProductName('export FRAMEWORK_VERSION=A\nexport FULL_PRODUCT_NAME="Super App Dev"\nexport GCC3_VERSION=3.3')) + .toEqual(null); + }); +}); diff --git a/local-cli/runIOS/runIOS.js b/local-cli/runIOS/runIOS.js index 01d83d900df72d..0f254473a8fa61 100644 --- a/local-cli/runIOS/runIOS.js +++ b/local-cli/runIOS/runIOS.js @@ -156,16 +156,25 @@ function buildProject(xcodeProject, udid, scheme, configuration = 'Debug', launc console.error(data.toString()); }); buildProcess.on('close', function(code) { - //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"?$/.exec(buildOutput); - if (productNameMatch && productNameMatch.length && productNameMatch.length > 1) { - return resolve(productNameMatch[1]);//0 is the full match, 1 is the app name + let productName = getProductName(buildOutput); + if (productName) { + return resolve(productName); } return buildProcess.error? reject(error) : resolve(); }); }); } +function getProductName(buildOutput) { + //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 productNameMatch[1]; //0 is the full match, 1 is the app name + } + + return null; +} + function matchingDevice(devices, deviceName) { if (deviceName === true && devices.length === 1) { @@ -250,4 +259,5 @@ module.exports = { command: '--no-packager', description: 'Do not launch packager while building', }], + getProductName };