Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor product name for runIOS, enable multi-line #13826

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions local-cli/runIOS/__tests__/runIOS-test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
18 changes: 14 additions & 4 deletions local-cli/runIOS/runIOS.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -250,4 +259,5 @@ module.exports = {
command: '--no-packager',
description: 'Do not launch packager while building',
}],
getProductName
};