This repository has been archived by the owner on Jan 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[expo-cli] command for syncing credentials.json and credentials on www (
#2460) * [expo-cli] command for syncing credentials.json and credentials on www * review feedback * update CHANGELOG.md
- Loading branch information
Showing
15 changed files
with
446 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/expo-cli/src/commands/eas-build/build/utils/ios.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
packages/expo-cli/src/commands/eas-build/credentialsSync/action.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import CommandError from '../../../CommandError'; | ||
import { Context } from '../../../credentials/context'; | ||
import * as credentialsJsonUpdateUtils 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/ios'; | ||
import { BuildCommandPlatform } from '../types'; | ||
|
||
interface Options { | ||
parent: { | ||
nonInteractive?: boolean; | ||
}; | ||
} | ||
|
||
export default async function credentialsSyncAction(projectDir: string, options: Options) { | ||
if (options.parent.nonInteractive) { | ||
throw new CommandError('This command is not supported in --non-interactive mode'); | ||
} | ||
const { update, platform } = await prompts([ | ||
{ | ||
type: 'select', | ||
name: 'update', | ||
message: 'What do you want to do?', | ||
choices: [ | ||
{ | ||
title: 'Update credentials on the Expo servers with the local credentials.json contents', | ||
value: 'remote', | ||
}, | ||
{ | ||
title: 'Update or create local credentials.json with credentials from the Expo servers', | ||
value: 'local', | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'select', | ||
name: 'platform', | ||
message: 'Which platform would you like to update?', | ||
choices: [ | ||
{ title: 'Android', value: BuildCommandPlatform.ANDROID }, | ||
{ title: 'iOS', value: BuildCommandPlatform.IOS }, | ||
{ title: 'both', value: BuildCommandPlatform.ALL }, | ||
], | ||
}, | ||
]); | ||
if (update === 'local') { | ||
await updateLocalCredentialsAsync(projectDir, platform); | ||
} else { | ||
await updateRemoteCredentialsAsync(projectDir, platform); | ||
} | ||
} | ||
|
||
async function updateRemoteCredentialsAsync( | ||
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)) { | ||
const experienceName = `@${ctx.manifest.owner || ctx.user.username}/${ctx.manifest.slug}`; | ||
await runCredentialsManager(ctx, new SetupAndroidBuildCredentialsFromLocal(experienceName)); | ||
} | ||
if ([BuildCommandPlatform.ALL, BuildCommandPlatform.IOS].includes(platform)) { | ||
const bundleIdentifier = await getBundleIdentifier(projectDir, ctx.manifest); | ||
const appLookupParams = { | ||
accountName: ctx.manifest.owner ?? ctx.user.username, | ||
projectName: ctx.manifest.slug, | ||
bundleIdentifier, | ||
}; | ||
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 credentialsJsonUpdateUtils.updateAndroidCredentialsAsync(ctx); | ||
} | ||
if ([BuildCommandPlatform.ALL, BuildCommandPlatform.IOS].includes(platform)) { | ||
const bundleIdentifier = await getBundleIdentifier(projectDir, ctx.manifest); | ||
log('Updating iOS credentials in credentials.json'); | ||
await credentialsJsonUpdateUtils.updateIosCredentialsAsync(ctx, bundleIdentifier); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.