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

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
esamelson committed Aug 29, 2020
1 parent 3039766 commit 3225546
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 50 deletions.
63 changes: 31 additions & 32 deletions packages/xdl/src/detach/AndroidShellApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,6 @@ function xmlWeirdAndroidEscape(original) {
return replaceString(noApos, "'", "\\'");
}

function getManifestFileNameForSdkVersion(sdkVersion) {
if (parseSdkMajorVersion(sdkVersion) < 39) {
return 'shell-app-manifest.json';
} else {
return 'app.manifest';
}
}

function getBundleFileNameForSdkVersion(sdkVersion) {
if (parseSdkMajorVersion(sdkVersion) < 39) {
return 'shell-app.bundle';
} else {
return 'app.bundle';
}
}

exports.updateAndroidShellAppAsync = async function updateAndroidShellAppAsync(args) {
let { url, sdkVersion, releaseChannel, workingDir } = args;

Expand All @@ -82,7 +66,7 @@ exports.updateAndroidShellAppAsync = async function updateAndroidShellAppAsync(a
'src',
'main',
'assets',
getManifestFileNameForSdkVersion(sdkVersion)
ExponentTools.getManifestFileNameForSdkVersion(sdkVersion)
)
);
await fs.writeFileSync(
Expand All @@ -92,16 +76,30 @@ exports.updateAndroidShellAppAsync = async function updateAndroidShellAppAsync(a
'src',
'main',
'assets',
getManifestFileNameForSdkVersion(sdkVersion)
ExponentTools.getManifestFileNameForSdkVersion(sdkVersion)
),
JSON.stringify(manifest)
);
await fs.remove(
path.join(shellPath, 'app', 'src', 'main', 'assets', getBundleFileNameForSdkVersion(sdkVersion))
path.join(
shellPath,
'app',
'src',
'main',
'assets',
ExponentTools.getBundleFileNameForSdkVersion(sdkVersion)
)
);
await saveUrlToPathAsync(
bundleUrl,
path.join(shellPath, 'app', 'src', 'main', 'assets', getBundleFileNameForSdkVersion(sdkVersion))
path.join(
shellPath,
'app',
'src',
'main',
'assets',
ExponentTools.getBundleFileNameForSdkVersion(sdkVersion)
)
);

await deleteLinesInFileAsync(
Expand All @@ -126,10 +124,10 @@ exports.updateAndroidShellAppAsync = async function updateAndroidShellAppAsync(a
`
// ADD EMBEDDED RESPONSES HERE
// START EMBEDDED RESPONSES
embeddedResponses.add(new Constants.EmbeddedResponse("${fullManifestUrl}", "assets://${getManifestFileNameForSdkVersion(
embeddedResponses.add(new Constants.EmbeddedResponse("${fullManifestUrl}", "assets://${ExponentTools.getManifestFileNameForSdkVersion(
sdkVersion
)}", "application/json"));
embeddedResponses.add(new Constants.EmbeddedResponse("${bundleUrl}", "assets://${getBundleFileNameForSdkVersion(
embeddedResponses.add(new Constants.EmbeddedResponse("${bundleUrl}", "assets://${ExponentTools.getBundleFileNameForSdkVersion(
sdkVersion
)}", "application/javascript"));
// END EMBEDDED RESPONSES`,
Expand Down Expand Up @@ -455,6 +453,7 @@ export async function runShellAppModificationsAsync(context, sdkVersion, buildMo
const updatesCheckAutomaticallyDisabled =
manifest.updates && manifest.checkAutomatically === 'ON_ERROR_RECOVERY';
const fallbackToCacheTimeout = manifest.updates && manifest.updates.fallbackToCacheTimeout;
const majorSdkVersion = parseSdkMajorVersion(sdkVersion);

// Clean build directories
await fs.remove(path.join(shellPath, 'app', 'build'));
Expand Down Expand Up @@ -482,7 +481,7 @@ export async function runShellAppModificationsAsync(context, sdkVersion, buildMo
appBuildGradle
);

if (ExponentTools.parseSdkMajorVersion(sdkVersion) >= 33) {
if (majorSdkVersion >= 33) {
const settingsGradle = path.join(shellPath, 'settings.gradle');
await deleteLinesInFileAsync(
'WHEN_DISTRIBUTING_REMOVE_FROM_HERE',
Expand Down Expand Up @@ -560,7 +559,7 @@ export async function runShellAppModificationsAsync(context, sdkVersion, buildMo
);

// Remove Exponent build script, since SDK32 expoview comes precompiled
if (parseSdkMajorVersion(sdkVersion) < 32 && !isRunningInUserContext) {
if (majorSdkVersion < 32 && !isRunningInUserContext) {
await regexFileAsync(
`preBuild.dependsOn generateDynamicMacros`,
``,
Expand All @@ -582,7 +581,7 @@ export async function runShellAppModificationsAsync(context, sdkVersion, buildMo
path.join(shellPath, 'app', 'src', 'main', 'AndroidManifest.xml')
);
// Since SDK32 expoview comes precompiled
if (parseSdkMajorVersion(sdkVersion) < 32 && !isRunningInUserContext) {
if (majorSdkVersion < 32 && !isRunningInUserContext) {
await regexFileAsync(
/host\.exp\.exponent\.permission\.C2D_MESSAGE/g,
`${javaPackage}.permission.C2D_MESSAGE`,
Expand Down Expand Up @@ -654,7 +653,7 @@ export async function runShellAppModificationsAsync(context, sdkVersion, buildMo
}

// In SDK32 this field got removed from AppConstants
if (parseSdkMajorVersion(sdkVersion) < 32 && isRunningInUserContext) {
if (majorSdkVersion < 32 && isRunningInUserContext) {
await regexFileAsync(
'IS_DETACHED = false',
`IS_DETACHED = true`,
Expand Down Expand Up @@ -690,7 +689,7 @@ export async function runShellAppModificationsAsync(context, sdkVersion, buildMo
)
);
}
if (parseSdkMajorVersion(sdkVersion) >= 39 && updatesCheckAutomaticallyDisabled) {
if (majorSdkVersion >= 39 && updatesCheckAutomaticallyDisabled) {
await regexFileAsync(
'UPDATES_CHECK_AUTOMATICALLY = true',
'UPDATES_CHECK_AUTOMATICALLY = false',
Expand All @@ -708,7 +707,7 @@ export async function runShellAppModificationsAsync(context, sdkVersion, buildMo
)
);
}
if (parseSdkMajorVersion(sdkVersion) >= 39 && fallbackToCacheTimeout) {
if (majorSdkVersion >= 39 && fallbackToCacheTimeout) {
await regexFileAsync(
'UPDATES_FALLBACK_TO_CACHE_TIMEOUT = 0',
`UPDATES_FALLBACK_TO_CACHE_TIMEOUT = ${fallbackToCacheTimeout}`,
Expand Down Expand Up @@ -938,7 +937,7 @@ export async function runShellAppModificationsAsync(context, sdkVersion, buildMo
'src',
'main',
'assets',
getManifestFileNameForSdkVersion(sdkVersion)
ExponentTools.getManifestFileNameForSdkVersion(sdkVersion)
),
JSON.stringify(manifest)
);
Expand All @@ -950,18 +949,18 @@ export async function runShellAppModificationsAsync(context, sdkVersion, buildMo
'src',
'main',
'assets',
getBundleFileNameForSdkVersion(sdkVersion)
ExponentTools.getBundleFileNameForSdkVersion(sdkVersion)
)
);

await regexFileAsync(
'// START EMBEDDED RESPONSES',
`
// START EMBEDDED RESPONSES
embeddedResponses.add(new Constants.EmbeddedResponse("${fullManifestUrl}", "assets://${getManifestFileNameForSdkVersion(
embeddedResponses.add(new Constants.EmbeddedResponse("${fullManifestUrl}", "assets://${ExponentTools.getManifestFileNameForSdkVersion(
sdkVersion
)}", "application/json"));
embeddedResponses.add(new Constants.EmbeddedResponse("${bundleUrl}", "assets://${getBundleFileNameForSdkVersion(
embeddedResponses.add(new Constants.EmbeddedResponse("${bundleUrl}", "assets://${ExponentTools.getBundleFileNameForSdkVersion(
sdkVersion
)}", "application/javascript"));`,
path.join(
Expand Down
18 changes: 18 additions & 0 deletions packages/xdl/src/detach/ExponentTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ import { Readable } from 'stream';
import XDLError from '../XDLError';
import LoggerDetach, { Logger, pipeOutputToLogger } from './Logger';

function getManifestFileNameForSdkVersion(sdkVersion: string) {
if (parseSdkMajorVersion(sdkVersion) < 39) {
return 'shell-app-manifest.json';
} else {
return 'app.manifest';
}
}

function getBundleFileNameForSdkVersion(sdkVersion: string) {
if (parseSdkMajorVersion(sdkVersion) < 39) {
return 'shell-app.bundle';
} else {
return 'app.bundle';
}
}

function parseSdkMajorVersion(expSdkVersion: string) {
// We assume that the unversioned SDK is the latest
if (expSdkVersion === 'UNVERSIONED') {
Expand Down Expand Up @@ -247,4 +263,6 @@ export {
regexFileAsync,
deleteLinesInFileAsync,
createSpawner,
getManifestFileNameForSdkVersion,
getBundleFileNameForSdkVersion,
};
22 changes: 4 additions & 18 deletions packages/xdl/src/detach/IosNSBundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import path from 'path';

import * as AssetBundle from './AssetBundle';
import {
getBundleFileNameForSdkVersion,
getManifestAsync,
getManifestFileNameForSdkVersion,
manifestUsesSplashApi,
parseSdkMajorVersion,
saveUrlToPathAsync,
Expand Down Expand Up @@ -32,22 +34,6 @@ const DEFAULT_FABRIC_KEY = '81130e95ea13cd7ed9a4f455e96214902c721c99';
const DEFAULT_GAD_APPLICATION_ID = 'ca-app-pub-3940256099942544~1458002511';
const KERNEL_URL = 'https://expo.io/@exponent/home';

export function getManifestFileNameForSdkVersion(sdkVersion: string) {
if (parseSdkMajorVersion(sdkVersion) < 39) {
return 'shell-app-manifest.json';
} else {
return 'app.manifest';
}
}

export function getBundleFileNameForSdkVersion(sdkVersion: string) {
if (parseSdkMajorVersion(sdkVersion) < 39) {
return 'shell-app.bundle';
} else {
return 'app.bundle';
}
}

function _configureInfoPlistForLocalDevelopment(config: any, exp: ExpoConfig): ExpoConfig {
// add detached scheme
if (exp.isDetached && exp.detach?.scheme) {
Expand Down Expand Up @@ -506,11 +492,11 @@ async function _configureShellPlistAsync(context: AnyStandaloneContext): Promise
// enable/disable code push if the developer provided specific behavior
shellPlist.areRemoteUpdatesEnabled = config.updates.enabled;
}
if (config.updates && config.updates.hasOwnProperty('checkAutomatically')) {
if (config.updates?.hasOwnProperty('checkAutomatically')) {
shellPlist.updatesCheckAutomatically =
config.updates.checkAutomatically !== 'ON_ERROR_RECOVERY';
}
if (config.updates && config.updates.hasOwnProperty('fallbackToCacheTimeout')) {
if (config.updates?.hasOwnProperty('fallbackToCacheTimeout')) {
shellPlist.updatesFallbackToCacheTimeout = config.updates.fallbackToCacheTimeout;
}
if (!manifestUsesSplashApi(config, 'ios') && parseSdkMajorVersion(config.sdkVersion) < 28) {
Expand Down

0 comments on commit 3225546

Please sign in to comment.