Skip to content

Commit

Permalink
fix: add targeted device family to upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Murat Mehmet committed Jul 29, 2024
1 parent 6988d1c commit 04efcea
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ require('../../../../mocks/mockAll');
import { ImportGetter } from '../../../../../types/upgrade.types';
import { escapeRegExp } from '../../../../../utils/escapeRegExp';
import { getPbxProjectPath } from '../../../../../utils/getIosProjectPath';
import { importIosDevelopmentTeam } from '../../../../../utils/upgrade/ios/importIosDevelopmentTeam';
import { importIosBuildProperties } from '../../../../../utils/upgrade/ios/importIosBuildProperties';
import { mockFs } from '../../../../mocks/mockFs';
import { mockPbxProjTemplate } from '../../../../mocks/mockPbxProjTemplate';

describe('importIosDevelopmentTeam', () => {
describe('importIosBuildProperties', () => {
it('should get project version', async () => {
mockFs.writeFileSync(
getPbxProjectPath('/oldProject'),
Expand All @@ -17,7 +17,7 @@ describe('importIosDevelopmentTeam', () => {
);
mockFs.writeFileSync(getPbxProjectPath(), mockPbxProjTemplate);

const importGetter = importIosDevelopmentTeam(
const importGetter = importIosBuildProperties(
'/oldProject'
) as ImportGetter;
expect(importGetter).toBeTruthy();
Expand All @@ -31,7 +31,7 @@ describe('importIosDevelopmentTeam', () => {
it('should handle errors', () => {
mockFs.setReadPermission(false);

const importGetter = importIosDevelopmentTeam(
const importGetter = importIosBuildProperties(
'/oldProject'
) as ImportGetter;
expect(importGetter).toBeNull();
Expand All @@ -44,7 +44,7 @@ describe('importIosDevelopmentTeam', () => {
'random = "random"'
)
);
const importGetter = importIosDevelopmentTeam(
const importGetter = importIosBuildProperties(
'/oldProject'
) as ImportGetter;
expect(importGetter).toBeNull();
Expand Down
4 changes: 2 additions & 2 deletions src/utils/upgrade/importFromOldProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { importAndroidVersionCode } from './android/importAndroidVersionCode';
import { importAndroidVersionName } from './android/importAndroidVersionName';
import { importIosAssets } from './ios/importIosAssets';
import { importIosBundleId } from './ios/importIosBundleId';
import { importIosDevelopmentTeam } from './ios/importIosDevelopmentTeam';
import { importIosBuildProperties } from './ios/importIosBuildProperties';
import { importIosDisplayName } from './ios/importIosDisplayName';
import { importIosMarketingVersion } from './ios/importIosMarketingVersion';
import { importIosProjectVersion } from './ios/importIosProjectVersion';
Expand All @@ -39,7 +39,7 @@ export async function importFromOldProject(
importIosDisplayName(oldProjectPath),
importIosProjectVersion(oldProjectPath),
importIosMarketingVersion(oldProjectPath),
importIosDevelopmentTeam(oldProjectPath),
importIosBuildProperties(oldProjectPath),
importIosAssets(oldProjectPath),
importGitFolder(oldProjectPath),
].filter(d => d != null) as ImportGetter[];
Expand Down
79 changes: 79 additions & 0 deletions src/utils/upgrade/ios/importIosBuildProperties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import fs from 'fs';
import color from 'picocolors';
import xcode from 'xcode';
import { Constants } from '../../../constants';
import { logMessage } from '../../../prompter';
import '../../../tasks/xcode/xcodeTask.helpers';
import { ImportGetter } from '../../../types/upgrade.types';
import { getPbxProjectPath } from '../../getIosProjectPath';

export function importIosBuildProperties(
projectPath: string
): ImportGetter | null {
try {
const pbxFilePath = getPbxProjectPath(projectPath);
const proj = xcode.project(pbxFilePath);
proj.parseSync();
const nativeTarget = proj.getTarget(Constants.XCODE_APPLICATION_TYPE);
const propertyNames = ['DEVELOPMENT_TEAM', 'TARGETED_DEVICE_FAMILY'];
const buildProperties: BuildProperty[] = [];
for (const propertyName of propertyNames) {
const debugProperty = proj.getBuildProperty(
propertyName,
'Debug',
nativeTarget.target.name
);
if (debugProperty)
buildProperties.push({
name: propertyName,
value: debugProperty,
type: 'Debug',
});
const releaseProperty = proj.getBuildProperty(
propertyName,
'Release',
nativeTarget.target.name
);
if (releaseProperty)
buildProperties.push({
name: propertyName,
value: releaseProperty,
type: 'Release',
});
}
if (!buildProperties.length) return null;

return {
id: 'iosBuildProperties',
title: 'Ios Build Properties',
value: buildProperties.length + ' properties',
apply: () => setIosBuildProperties(buildProperties),
};
} catch (e) {
return null;
}
}

async function setIosBuildProperties(buildProperties: BuildProperty[]) {
const pbxFilePath = getPbxProjectPath();
const proj = xcode.project(pbxFilePath);
proj.parseSync();
const nativeTarget = proj.getTarget(Constants.XCODE_APPLICATION_TYPE);
for (const buildProperty of buildProperties) {
proj.updateBuildPropertyByTarget(
buildProperty.name,
buildProperty.value,
buildProperty.type,
nativeTarget.target
);
logMessage(
`set ${color.yellow(buildProperty.name)} (${buildProperty.type}) to ${color.yellow(buildProperty.value)}`
);
}

fs.writeFileSync(pbxFilePath, proj.writeSync(), 'utf-8');

return Promise.resolve();
}

type BuildProperty = { name: string; value: string; type: string };
61 changes: 0 additions & 61 deletions src/utils/upgrade/ios/importIosDevelopmentTeam.ts

This file was deleted.

0 comments on commit 04efcea

Please sign in to comment.