Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
[config] disjointed features from plugins ios (#2811)
Browse files Browse the repository at this point in the history
* Added invalid config warning

* Update Paths-test.ts

* unify utility

* Fix entitlements resolution

* Create react-native-project.ts

* Added deprecation warning for androidStatusBarColor
  • Loading branch information
EvanBacon authored Oct 19, 2020
1 parent f10da27 commit 6ba2cf1
Show file tree
Hide file tree
Showing 12 changed files with 898 additions and 51 deletions.
7 changes: 7 additions & 0 deletions packages/config/src/android/StatusBar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ExpoConfig } from '../Config.types';
import { addWarningAndroid } from '../WarningAggregator';
import { getProjectColorsXMLPathAsync, setColorItem } from './Colors';
import { buildResourceItem, readResourcesXMLAsync, ResourceItemXML } from './Resources';
import { getProjectStylesXMLPathAsync, setStylesItem } from './Styles';
Expand All @@ -9,6 +10,12 @@ const WINDOW_TRANSLUCENT_STATUS = 'android:windowTranslucentStatus';
const WINDOW_LIGHT_STATUS_BAR = 'android:windowLightStatusBar';

export function getStatusBarColor(config: ExpoConfig) {
if (config.androidStatusBarColor != null) {
addWarningAndroid(
'status-bar',
'`androidStatusBarColor` is deprecated, use `androidStatusBar.backgroundColor` instead.'
);
}
return config.androidStatusBar?.backgroundColor || 'translucent';
}

Expand Down
15 changes: 1 addition & 14 deletions packages/config/src/android/__tests__/Icon-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { fs, vol } from 'memfs';
import * as path from 'path';

import { ExpoConfig } from '../../Config.types';
import { getDirFromFS } from '../../ios/__tests__/utils/getDirFromFS';
import { createAdaptiveIconXmlString, getAdaptiveIcon, getIcon, setIconAsync } from '../Icon';
import {
ADAPTIVE_ICON_XML_WITH_BACKGROUND_COLOR,
Expand All @@ -28,20 +29,6 @@ afterAll(() => {
jest.unmock('fs');
});

function getDirFromFS(fsJSON: Record<string, string | null>, rootDir: string) {
return Object.entries(fsJSON)
.filter(([path, value]) => value !== null && path.startsWith(rootDir))
.reduce<Record<string, string>>(
(acc, [path, fileContent]) => ({
...acc,
[path.substring(rootDir.length).startsWith('/')
? path.substring(rootDir.length + 1)
: path.substring(rootDir.length)]: fileContent,
}),
{}
);
}

function setUpMipmapDirectories() {
vol.mkdirpSync('/app/android/app/src/main/res/mipmap-mdpi');
vol.mkdirpSync('/app/android/app/src/main/res/mipmap-hdpi');
Expand Down
8 changes: 8 additions & 0 deletions packages/config/src/ios/DeviceFamily.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { XcodeProject } from 'xcode';

import { ExpoConfig } from '../Config.types';
import { addWarningIOS } from '../WarningAggregator';

export function getSupportsTablet(config: ExpoConfig): boolean {
return !!config.ios?.supportsTablet;
Expand All @@ -14,6 +15,13 @@ export function getDeviceFamilies(config: ExpoConfig): number[] {
const supportsTablet = getSupportsTablet(config);
const isTabletOnly = getIsTabletOnly(config);

if (isTabletOnly && config.ios?.supportsTablet === false) {
addWarningIOS(
'device-family',
`Found contradictory values: \`{ ios: { isTabletOnly: true, supportsTablet: false } }\`. Using \`{ isTabletOnly: true }\`.`
);
}

// 1 is iPhone, 2 is iPad
if (isTabletOnly) {
return [2];
Expand Down
3 changes: 2 additions & 1 deletion packages/config/src/ios/Entitlements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { InfoPlist } from './IosConfig.types';
import * as Paths from './Paths';
import {
getPbxproj,
getProductName,
getProjectName,
isBuildConfig,
isNotComment,
Expand Down Expand Up @@ -98,7 +99,7 @@ export function getEntitlementsPath(projectRoot: string): string {
*/
const project = getPbxproj(projectRoot);
const projectName = getProjectName(projectRoot);
const productName = project.productName;
const productName = getProductName(project);

const entitlementsRelativePath = path.join(projectName, `${productName}.entitlements`);
const entitlementsPath = path.normalize(path.join(projectRoot, 'ios', entitlementsRelativePath));
Expand Down
11 changes: 11 additions & 0 deletions packages/config/src/ios/__tests__/DeviceFamily-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ExpoConfig } from '@expo/config-types';
import { fs, vol } from 'memfs';
import * as path from 'path';

import { addWarningIOS } from '../../WarningAggregator';
import {
formatDeviceFamilies,
getDeviceFamilies,
Expand All @@ -28,6 +29,16 @@ const TABLET_AND_PHONE_SUPPORTED = [1, 2];
const ONLY_PHONE_SUPPORTED = [1];
const ONLY_TABLET_SUPPORTED = [2];

describe(getDeviceFamilies, () => {
it(`warns about invalid config`, () => {
getDeviceFamilies({ ios: { isTabletOnly: true, supportsTablet: false } } as any);
expect(addWarningIOS).toHaveBeenLastCalledWith(
'device-family',
'Found contradictory values: `{ ios: { isTabletOnly: true, supportsTablet: false } }`. Using `{ isTabletOnly: true }`.'
);
});
});

describe('device family', () => {
it(`returns false ios.isTabletOnly is not provided`, () => {
expect(getIsTabletOnly({ ios: {} })).toBe(false);
Expand Down
15 changes: 1 addition & 14 deletions packages/config/src/ios/__tests__/Icons-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { fs, vol } from 'memfs';
import * as path from 'path';

import { getIcons, ICON_CONTENTS, setIconsAsync } from '../Icons';
import { getDirFromFS } from './utils/getDirFromFS';
const actualFs = jest.requireActual('fs') as typeof fs;

jest.mock('fs');
Expand All @@ -18,20 +19,6 @@ afterAll(() => {
jest.unmock('fs');
});

function getDirFromFS(fsJSON: Record<string, string | null>, rootDir: string) {
return Object.entries(fsJSON)
.filter(([path, value]) => value !== null && path.startsWith(rootDir))
.reduce<Record<string, string>>(
(acc, [path, fileContent]) => ({
...acc,
[path.substring(rootDir.length).startsWith('/')
? path.substring(rootDir.length + 1)
: path.substring(rootDir.length)]: fileContent,
}),
{}
);
}

describe('iOS Icons', () => {
it(`returns null if no icon values provided`, () => {
expect(getIcons({})).toBeNull();
Expand Down
15 changes: 1 addition & 14 deletions packages/config/src/ios/__tests__/Locales-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as path from 'path';
import { addWarningIOS } from '../../WarningAggregator';
import { getLocales, setLocalesAsync } from '../Locales';
import { getPbxproj } from '../utils/Xcodeproj';
import { getDirFromFS } from './utils/getDirFromFS';
const actualFs = jest.requireActual('fs') as typeof fs;

jest.mock('fs');
Expand All @@ -17,20 +18,6 @@ afterAll(() => {
jest.unmock('../../WarningAggregator');
});

function getDirFromFS(fsJSON: Record<string, string | null>, rootDir: string) {
return Object.entries(fsJSON)
.filter(([path, value]) => value !== null && path.startsWith(rootDir))
.reduce<Record<string, string>>(
(acc, [path, fileContent]) => ({
...acc,
[path.substring(rootDir.length).startsWith('/')
? path.substring(rootDir.length + 1)
: path.substring(rootDir.length)]: fileContent,
}),
{}
);
}

describe('iOS Locales', () => {
it(`returns null if no values are provided`, () => {
expect(getLocales({})).toBeNull();
Expand Down
14 changes: 7 additions & 7 deletions packages/config/src/ios/__tests__/Paths-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe(getXcodeProjectPath, () => {
'ios/testproject.xcodeproj/project.pbxproj': actualFs.readFileSync(
path.join(__dirname, 'fixtures/project.pbxproj'),
'utf-8'
),
) as string,
'ios/Podfile': 'content',
'ios/TestPod.podspec': 'noop',
'ios/testproject/AppDelegate.m': '',
Expand All @@ -38,11 +38,11 @@ describe(getXcodeProjectPath, () => {
'ios/otherproject.xcodeproj/project.pbxproj': actualFs.readFileSync(
path.join(__dirname, 'fixtures/project.pbxproj'),
'utf-8'
),
) as string,
'ios/testproject.xcodeproj/project.pbxproj': actualFs.readFileSync(
path.join(__dirname, 'fixtures/project.pbxproj'),
'utf-8'
),
) as string,
'ios/testproject/AppDelegate.m': '',
},
'/multiple'
Expand Down Expand Up @@ -77,7 +77,7 @@ describe(getAppDelegate, () => {
'ios/testproject.xcodeproj/project.pbxproj': actualFs.readFileSync(
path.join(__dirname, 'fixtures/project.pbxproj'),
'utf-8'
),
) as string,
'ios/Podfile': 'content',
'ios/TestPod.podspec': 'noop',
'ios/testproject/AppDelegate.m': '',
Expand All @@ -91,7 +91,7 @@ describe(getAppDelegate, () => {
'ios/testproject.xcodeproj/project.pbxproj': actualFs.readFileSync(
path.join(__dirname, 'fixtures/project.pbxproj'),
'utf-8'
),
) as string,
'ios/Podfile': 'content',
'ios/TestPod.podspec': 'noop',
'ios/testproject/AppDelegate.swift': '',
Expand All @@ -104,7 +104,7 @@ describe(getAppDelegate, () => {
'ios/testproject.xcodeproj/project.pbxproj': actualFs.readFileSync(
path.join(__dirname, 'fixtures/project.pbxproj'),
'utf-8'
),
) as string,
'ios/Podfile': 'content',
'ios/TestPod.podspec': 'noop',
},
Expand All @@ -116,7 +116,7 @@ describe(getAppDelegate, () => {
'ios/testproject.xcodeproj/project.pbxproj': actualFs.readFileSync(
path.join(__dirname, 'fixtures/project.pbxproj'),
'utf-8'
),
) as string,
'ios/Podfile': 'content',
'ios/TestPod.podspec': 'noop',
'ios/testproject/AppDelegate.swift': '',
Expand Down
13 changes: 13 additions & 0 deletions packages/config/src/ios/__tests__/utils/getDirFromFS.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export function getDirFromFS(fsJSON: Record<string, string | null>, rootDir: string) {
return Object.entries(fsJSON)
.filter(([path, value]) => value !== null && path.startsWith(rootDir))
.reduce<Record<string, string>>(
(acc, [path, fileContent]) => ({
...acc,
[path.substring(rootDir.length).startsWith('/')
? path.substring(rootDir.length + 1)
: path.substring(rootDir.length)]: fileContent,
}),
{}
);
}
16 changes: 16 additions & 0 deletions packages/config/src/ios/utils/Xcodeproj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,22 @@ export function getPbxproj(projectRoot: string): XcodeProject {
return project;
}

/**
* Get the productName for a project, if the name is using a variable `$(TARGET_NAME)`, then attempt to get the value of that variable.
*
* @param project
*/
export function getProductName(project: XcodeProject): string {
let productName = project.productName;

if (productName === '$(TARGET_NAME)') {
const targetName = project.getFirstTarget()?.firstTarget?.productName;
productName = targetName ?? project.productName;
}

return productName;
}

export function getProjectSection(project: XcodeProject) {
return project.pbxProjectSection();
}
Expand Down
Loading

0 comments on commit 6ba2cf1

Please sign in to comment.