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 477
[expo-cli] detect git changes on credentials.json update #2482
Merged
wkozyra95
merged 2 commits into
master
from
@wkozyra95/detect-git-change-one-credentials-update
Aug 21, 2020
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||||||||
import fs from 'fs-extra'; | ||||||||||
import path from 'path'; | ||||||||||
|
||||||||||
import { gitStatusAsync } from '../../git'; | ||||||||||
import log from '../../log'; | ||||||||||
import prompts from '../../prompts'; | ||||||||||
import { Context } from '../context'; | ||||||||||
|
@@ -42,9 +43,10 @@ export async function updateAndroidCredentialsAsync(ctx: Context) { | |||||||||
} | ||||||||||
|
||||||||||
const keystorePath = | ||||||||||
rawCredentialsJsonObject?.android?.keystore?.keystorePath ?? './android/keystores/keystore.jks'; | ||||||||||
rawCredentialsJsonObject?.android?.keystore?.keystorePath ?? 'android/keystores/keystore.jks'; | ||||||||||
log(`Writing Keystore to ${keystorePath}`); | ||||||||||
await updateFileAsync(ctx.projectDir, keystorePath, keystore.keystore); | ||||||||||
const shouldWarnKeystore = await isFileUntrackedAsync(keystorePath); | ||||||||||
|
||||||||||
rawCredentialsJsonObject.android = { | ||||||||||
keystore: { | ||||||||||
|
@@ -57,6 +59,12 @@ export async function updateAndroidCredentialsAsync(ctx: Context) { | |||||||||
await fs.writeJson(credentialsJsonFilePath, rawCredentialsJsonObject, { | ||||||||||
spaces: 2, | ||||||||||
}); | ||||||||||
const shouldWarnCredentialsJson = await isFileUntrackedAsync('credentials.json'); | ||||||||||
const newFilePaths = [ | ||||||||||
shouldWarnKeystore && keystorePath, | ||||||||||
shouldWarnCredentialsJson && 'credentials.json', | ||||||||||
].filter(i => i); | ||||||||||
displayUntrackedFilesWarning(newFilePaths); | ||||||||||
} | ||||||||||
|
||||||||||
export async function updateIosCredentialsAsync(ctx: Context, bundleIdentifier: string) { | ||||||||||
|
@@ -79,9 +87,9 @@ export async function updateIosCredentialsAsync(ctx: Context, bundleIdentifier: | |||||||||
bundleIdentifier, | ||||||||||
}; | ||||||||||
const pprofilePath = | ||||||||||
rawCredentialsJsonObject?.ios?.provisioningProfilePath ?? './ios/certs/profile.mobileprovision'; | ||||||||||
rawCredentialsJsonObject?.ios?.provisioningProfilePath ?? 'ios/certs/profile.mobileprovision'; | ||||||||||
const distCertPath = | ||||||||||
rawCredentialsJsonObject?.ios?.distributionCertificate?.path ?? './ios/certs/dist-cert.p12'; | ||||||||||
rawCredentialsJsonObject?.ios?.distributionCertificate?.path ?? 'ios/certs/dist-cert.p12'; | ||||||||||
const appCredentials = await ctx.ios.getAppCredentials(appLookupParams); | ||||||||||
const distCredentials = await ctx.ios.getDistCert(appLookupParams); | ||||||||||
if (!appCredentials?.credentials?.provisioningProfile && !distCredentials) { | ||||||||||
|
@@ -113,8 +121,11 @@ export async function updateIosCredentialsAsync(ctx: Context, bundleIdentifier: | |||||||||
pprofilePath, | ||||||||||
appCredentials?.credentials?.provisioningProfile | ||||||||||
); | ||||||||||
const shouldWarnPProfile = await isFileUntrackedAsync(pprofilePath); | ||||||||||
|
||||||||||
log(`Writing Distribution Certificate to ${distCertPath}`); | ||||||||||
await updateFileAsync(ctx.projectDir, distCertPath, distCredentials?.certP12); | ||||||||||
const shouldWarnDistCert = await isFileUntrackedAsync(distCertPath); | ||||||||||
|
||||||||||
rawCredentialsJsonObject.ios = { | ||||||||||
...(appCredentials?.credentials?.provisioningProfile | ||||||||||
|
@@ -132,6 +143,14 @@ export async function updateIosCredentialsAsync(ctx: Context, bundleIdentifier: | |||||||||
await fs.writeJson(credentialsJsonFilePath, rawCredentialsJsonObject, { | ||||||||||
spaces: 2, | ||||||||||
}); | ||||||||||
const shouldWarnCredentialsJson = await isFileUntrackedAsync('credentials.json'); | ||||||||||
|
||||||||||
const newFilePaths = [ | ||||||||||
shouldWarnPProfile && pprofilePath, | ||||||||||
shouldWarnDistCert && distCertPath, | ||||||||||
shouldWarnCredentialsJson && 'credentials.json', | ||||||||||
].filter(i => i); | ||||||||||
displayUntrackedFilesWarning(newFilePaths); | ||||||||||
} | ||||||||||
|
||||||||||
async function updateFileAsync(projectDir: string, filePath: string, base64Data?: string) { | ||||||||||
|
@@ -144,3 +163,27 @@ async function updateFileAsync(projectDir: string, filePath: string, base64Data? | |||||||||
await fs.writeFile(filePath, Buffer.from(base64Data, 'base64')); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
async function isFileUntrackedAsync(path: string): Promise<boolean> { | ||||||||||
const withUntrackedFiles = await gitStatusAsync({ showUntracked: true }); | ||||||||||
const trackedFiles = await gitStatusAsync({ showUntracked: false }); | ||||||||||
const pathWithouLeadingDot = path.replace(/^\.\//, ''); // remove leading './' from path | ||||||||||
return ( | ||||||||||
withUntrackedFiles.includes(pathWithouLeadingDot) && | ||||||||||
!trackedFiles.includes(pathWithouLeadingDot) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
); | ||||||||||
} | ||||||||||
|
||||||||||
function displayUntrackedFilesWarning(newFilePaths: string[]) { | ||||||||||
if (newFilePaths.length === 1) { | ||||||||||
log.warn( | ||||||||||
`File ${newFilePaths[0]} is currently untracked, remember to add it to .gitignore or to encrypt it.` | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
); | ||||||||||
} else if (newFilePaths.length > 1) { | ||||||||||
log.warn( | ||||||||||
`Files ${newFilePaths.join( | ||||||||||
', ' | ||||||||||
)} are currently untracked, remember to add them to .gitignore or to encrypt them.` | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
); | ||||||||||
} | ||||||||||
} |
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,24 @@ | ||
import spawnAsync from '@expo/spawn-async'; | ||
|
||
interface GitStatusOptions { | ||
showUntracked?: boolean; | ||
} | ||
|
||
export async function gitStatusAsync({ showUntracked }: GitStatusOptions = {}): Promise<string> { | ||
return (await spawnAsync('git', ['status', '-s', showUntracked ? '-uall' : '-uno'])).stdout; | ||
} | ||
|
||
export async function gitDiffAsync(): Promise<void> { | ||
await spawnAsync('git', ['--no-pager', 'diff'], { stdio: ['ignore', 'inherit', 'inherit'] }); | ||
} | ||
|
||
export async function gitAddAsync( | ||
file: string, | ||
options?: { intentToAdd?: boolean } | ||
): Promise<void> { | ||
if (options?.intentToAdd) { | ||
await spawnAsync('git', ['add', '--intent-to-add', file]); | ||
} else { | ||
await spawnAsync('git', ['add', file]); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.