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

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
wkozyra95 committed Aug 18, 2020
1 parent 51d7fdf commit d843712
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ function setupCredentialsConfig() {
});
}

const originalWarn = console.warn;
const originalLog = console.log;
beforeAll(() => {
console.warn = jest.fn();
console.log = jest.fn();
});
afterAll(() => {
console.warn = originalWarn;
console.log = originalLog;
});
beforeEach(() => {
vol.reset();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ function setupCredentialsConfig() {
});
}

const originalWarn = console.warn;
const originalLog = console.log;
beforeAll(() => {
console.warn = jest.fn();
console.log = jest.fn();
});
afterAll(() => {
console.warn = originalWarn;
console.log = originalLog;
});
beforeEach(() => {
vol.reset();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { BuildType, Job, Platform, iOS, sanitizeJob } from '@expo/build-tools';
import { IOSConfig } from '@expo/config';
import chalk from 'chalk';
import figures from 'figures';
import once from 'lodash/once';
import ora from 'ora';

import iOSCredentialsProvider, {
Expand All @@ -16,10 +15,10 @@ import {
iOSManagedBuildProfile,
} from '../../../../easJson';
import log from '../../../../log';
import prompts from '../../../../prompts';
import { ensureCredentialsAsync } from '../credentials';
import { Builder, BuilderContext } from '../types';
import * as gitUtils from '../utils/git';
import { getBundleIdentifier } from '../utils/xcode';

interface CommonJobProperties {
platform: Platform.iOS;
Expand Down Expand Up @@ -58,7 +57,7 @@ class iOSBuilder implements Builder {
if (!this.shouldLoadCredentials()) {
return;
}
const bundleIdentifier = await getBundleIdentifier(this.ctx);
const bundleIdentifier = await getBundleIdentifier(this.ctx.projectDir, this.ctx.exp);
const provider = new iOSCredentialsProvider(this.ctx.projectDir, {
projectName: this.ctx.projectName,
accountName: this.ctx.accountName,
Expand All @@ -80,7 +79,7 @@ class iOSBuilder implements Builder {
if (!this.credentials) {
throw new Error('Call ensureCredentialsAsync first!');
}
const bundleIdentifier = await getBundleIdentifier(this.ctx);
const bundleIdentifier = await getBundleIdentifier(this.ctx.projectDir, this.ctx.exp);

const spinner = ora('Making sure your iOS project is set up properly');

Expand Down Expand Up @@ -173,69 +172,5 @@ class iOSBuilder implements Builder {
);
}
}
const getBundleIdentifier = once(_getBundleIdentifier);

async function _getBundleIdentifier(ctx: BuilderContext): Promise<string> {
const bundleIdentifierFromPbxproj = IOSConfig.BundleIdenitifer.getBundleIdentifierFromPbxproj(
ctx.projectDir
);
const bundleIdentifierFromConfig = IOSConfig.BundleIdenitifer.getBundleIdentifier(ctx.exp);
if (bundleIdentifierFromPbxproj !== null && bundleIdentifierFromConfig !== null) {
if (bundleIdentifierFromPbxproj === bundleIdentifierFromConfig) {
return bundleIdentifierFromPbxproj;
} else {
log.newLine();
log(
log.chalk.yellow(
`We detected that your Xcode project is configured with a different bundle identifier than the one defined in app.json/app.config.js.
If you choose the one defined in app.json/app.config.js we'll automatically configure your Xcode project with it.
However, if you choose the one defined in the Xcode project you'll have to update app.json/app.config.js on your own.
Otherwise, you'll see this prompt again in the future.`
)
);
log.newLine();
const { bundleIdentifier } = await prompts({
type: 'select',
name: 'bundleIdentifier',
message: 'Which bundle identifier should we use?',
choices: [
{
title: `Defined in the Xcode project: ${log.chalk.bold(bundleIdentifierFromPbxproj)}`,
value: bundleIdentifierFromPbxproj,
},
{
title: `Defined in app.json/app.config.js: ${log.chalk.bold(
bundleIdentifierFromConfig
)}`,
value: bundleIdentifierFromConfig,
},
],
});
return bundleIdentifier;
}
} else if (bundleIdentifierFromPbxproj === null && bundleIdentifierFromConfig === null) {
throw new Error('Please define "expo.ios.bundleIdentifier" in app.json/app.config.js');
} else {
if (bundleIdentifierFromPbxproj !== null) {
log(
`Using ${log.chalk.bold(
bundleIdentifierFromPbxproj
)} as the bundle identifier (read from the Xcode project).`
);
return bundleIdentifierFromPbxproj;
} else {
// bundleIdentifierFromConfig is never null in this case
// the following line is to satisfy TS
const bundleIdentifier = bundleIdentifierFromConfig ?? '';
log(
`Using ${log.chalk.bold(
bundleIdentifier
)} as the bundle identifier (read from app.json/app.config.js).
We'll automatically configure your Xcode project using this value.`
);
return bundleIdentifier;
}
}
}

export default iOSBuilder;
70 changes: 70 additions & 0 deletions packages/expo-cli/src/commands/eas-build/build/utils/xcode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { ExpoConfig, IOSConfig } from '@expo/config';
import once from 'lodash/once';

import log from '../../../../log';
import prompts from '../../../../prompts';

export const getBundleIdentifier = once(_getBundleIdentifier);

async function _getBundleIdentifier(projectDir: string, manifest: ExpoConfig): Promise<string> {
const bundleIdentifierFromPbxproj = IOSConfig.BundleIdenitifer.getBundleIdentifierFromPbxproj(
projectDir
);
const bundleIdentifierFromConfig = IOSConfig.BundleIdenitifer.getBundleIdentifier(manifest);
if (bundleIdentifierFromPbxproj !== null && bundleIdentifierFromConfig !== null) {
if (bundleIdentifierFromPbxproj === bundleIdentifierFromConfig) {
return bundleIdentifierFromPbxproj;
} else {
log.newLine();
log(
log.chalk.yellow(
`We detected that your Xcode project is configured with a different bundle identifier than the one defined in app.json/app.config.js.
If you choose the one defined in app.json/app.config.js we'll automatically configure your Xcode project with it.
However, if you choose the one defined in the Xcode project you'll have to update app.json/app.config.js on your own.
Otherwise, you'll see this prompt again in the future.`
)
);
log.newLine();
const { bundleIdentifier } = await prompts({
type: 'select',
name: 'bundleIdentifier',
message: 'Which bundle identifier should we use?',
choices: [
{
title: `Defined in the Xcode project: ${log.chalk.bold(bundleIdentifierFromPbxproj)}`,
value: bundleIdentifierFromPbxproj,
},
{
title: `Defined in app.json/app.config.js: ${log.chalk.bold(
bundleIdentifierFromConfig
)}`,
value: bundleIdentifierFromConfig,
},
],
});
return bundleIdentifier;
}
} else if (bundleIdentifierFromPbxproj === null && bundleIdentifierFromConfig === null) {
throw new Error('Please define "expo.ios.bundleIdentifier" in app.json/app.config.js');
} else {
if (bundleIdentifierFromPbxproj !== null) {
log(
`Using ${log.chalk.bold(
bundleIdentifierFromPbxproj
)} as the bundle identifier (read from the Xcode project).`
);
return bundleIdentifierFromPbxproj;
} else {
// bundleIdentifierFromConfig is never null in this case
// the following line is to satisfy TS
const bundleIdentifier = bundleIdentifierFromConfig ?? '';
log(
`Using ${log.chalk.bold(
bundleIdentifier
)} as the bundle identifier (read from app.json/app.config.js).
We'll automatically configure your Xcode project using this value.`
);
return bundleIdentifier;
}
}
}
51 changes: 38 additions & 13 deletions packages/expo-cli/src/commands/eas-build/credentialsSync/action.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import CommandError from '../../../CommandError';
import { Context } from '../../../credentials/context';
import { updateLocalCredentialsJsonAsync } from '../../../credentials/local';
import * as credentialsJson from '../../../credentials/credentialsJson/update';
import { runCredentialsManager } from '../../../credentials/route';
import { SetupAndroidBuildCredentialsFromLocal } from '../../../credentials/views/SetupAndroidKeystore';
import { SetupIosBuildCredentialsFromLocal } from '../../../credentials/views/SetupIosBuildCredentials';
import log from '../../../log';
import prompts from '../../../prompts';
import { getBundleIdentifier } from '../build/utils/xcode';
import { BuildCommandPlatform } from '../types';

interface Options {
Expand All @@ -24,31 +26,37 @@ export default async function credentialsSyncAction(projectDir: string, options:
message: 'What do you want to do?',
choices: [
{
title: 'Update credentials on Expo servers with local credentials.json content',
title: 'Update credentials on the Expo servers with local credentials.json contents',
value: 'remote',
},
{ title: 'Update local credentials.json with values from Expo servers', value: 'local' },
{
title: 'Update or create local credentials.json with credentials from Expo servers',
value: 'local',
},
],
},
{
type: 'select',
name: 'platform',
message: 'Do you want to update credentials for both platforms?',
message: 'Which platform would you like to update?',
choices: [
{ title: 'Android & iOS', value: BuildCommandPlatform.ALL },
{ title: 'only Android', value: BuildCommandPlatform.ANDROID },
{ title: 'only iOS', value: BuildCommandPlatform.IOS },
{ title: 'Android', value: BuildCommandPlatform.ANDROID },
{ title: 'iOS', value: BuildCommandPlatform.IOS },
{ title: 'both', value: BuildCommandPlatform.ALL },
],
},
]);
if (update === 'local') {
await updateLocalCredentialsJsonAsync(projectDir, platform);
await updateLocalCredentialsAsync(projectDir, platform);
} else {
await updateRemoteCredentialsAsync(projectDir, platform);
}
}

async function updateRemoteCredentialsAsync(projectDir: string, platform: BuildCommandPlatform) {
async function updateRemoteCredentialsAsync(
projectDir: string,
platform: BuildCommandPlatform
): Promise<void> {
const ctx = new Context();
await ctx.init(projectDir);
if (!ctx.hasProjectContext) {
Expand All @@ -59,10 +67,7 @@ async function updateRemoteCredentialsAsync(projectDir: string, platform: BuildC
await runCredentialsManager(ctx, new SetupAndroidBuildCredentialsFromLocal(experienceName));
}
if (['all', 'ios'].includes(platform)) {
const bundleIdentifier = ctx.manifest.ios?.bundleIdentifier;
if (!bundleIdentifier) {
throw new Error('"expo.ios.bundleIdentifier" field is required in your app.json');
}
const bundleIdentifier = await getBundleIdentifier(projectDir, ctx.manifest);
const appLookupParams = {
accountName: ctx.manifest.owner ?? ctx.user.username,
projectName: ctx.manifest.slug,
Expand All @@ -71,3 +76,23 @@ async function updateRemoteCredentialsAsync(projectDir: string, platform: BuildC
await runCredentialsManager(ctx, new SetupIosBuildCredentialsFromLocal(appLookupParams));
}
}

export async function updateLocalCredentialsAsync(
projectDir: string,
platform: BuildCommandPlatform
): Promise<void> {
const ctx = new Context();
await ctx.init(projectDir);
if (!ctx.hasProjectContext) {
throw new Error('project context is required'); // should be checked earlier
}
if ([BuildCommandPlatform.ALL, BuildCommandPlatform.ANDROID].includes(platform)) {
log('Updating Android credentials in credentials.json');
await credentialsJson.updateAndroidCredentialsAsync(ctx);
}
if ([BuildCommandPlatform.ALL, BuildCommandPlatform.IOS].includes(platform)) {
const bundleIdentifier = await getBundleIdentifier(projectDir, ctx.manifest);
log('Updating iOS credentials in credentials.json');
await credentialsJson.updateIosCredentialsAsync(ctx, bundleIdentifier);
}
}
Loading

0 comments on commit d843712

Please sign in to comment.