@appzung/react-native-code-push 5.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AlertAdapter.js +24 -0
- package/CONTRIBUTING.md +136 -0
- package/CodePush.js +666 -0
- package/CodePush.podspec +27 -0
- package/LICENSE.md +13 -0
- package/README.md +386 -0
- package/RestartManager.js +59 -0
- package/android/app/build.gradle +31 -0
- package/android/app/proguard-rules.pro +25 -0
- package/android/app/src/main/AndroidManifest.xml +10 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +395 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushBuilder.java +37 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java +34 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java +102 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInstallMode.java +16 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidPublicKeyException.java +12 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidUpdateException.java +7 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushMalformedDataException.java +12 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +641 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNotInitializedException.java +12 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushTelemetryManager.java +175 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUnknownException.java +12 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java +369 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateState.java +15 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java +267 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUtils.java +236 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgress.java +30 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/DownloadProgressCallback.java +5 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/FileUtils.java +190 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/ReactInstanceHolder.java +17 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/SettingsManager.java +173 -0
- package/android/build.gradle +20 -0
- package/android/codepush.gradle +113 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradle.properties +20 -0
- package/android/gradlew +164 -0
- package/android/gradlew.bat +90 -0
- package/android/settings.gradle +1 -0
- package/docs/api-android.md +65 -0
- package/docs/api-ios.md +31 -0
- package/docs/api-js.md +592 -0
- package/docs/multi-deployment-testing-android.md +107 -0
- package/docs/multi-deployment-testing-ios.md +53 -0
- package/docs/setup-android.md +406 -0
- package/docs/setup-ios.md +229 -0
- package/docs/setup-windows.md +65 -0
- package/gulpfile.js +302 -0
- package/ios/CodePush/Base64/Base64/MF_Base64Additions.h +34 -0
- package/ios/CodePush/Base64/Base64/MF_Base64Additions.m +252 -0
- package/ios/CodePush/Base64/README.md +47 -0
- package/ios/CodePush/CodePush.h +235 -0
- package/ios/CodePush/CodePush.m +1041 -0
- package/ios/CodePush/CodePushConfig.m +116 -0
- package/ios/CodePush/CodePushDownloadHandler.m +130 -0
- package/ios/CodePush/CodePushErrorUtils.m +20 -0
- package/ios/CodePush/CodePushPackage.m +598 -0
- package/ios/CodePush/CodePushTelemetryManager.m +175 -0
- package/ios/CodePush/CodePushUpdateUtils.m +376 -0
- package/ios/CodePush/CodePushUtils.m +9 -0
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithm.h +69 -0
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.h +16 -0
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.m +51 -0
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.h +15 -0
- package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.m +55 -0
- package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.h +24 -0
- package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.m +41 -0
- package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.h +28 -0
- package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.m +205 -0
- package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.h +103 -0
- package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.m +322 -0
- package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.h +37 -0
- package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.m +145 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.h +35 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.m +551 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTRSAlgorithm.h +23 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.h +43 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.m +230 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.h +31 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.m +113 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.h +38 -0
- package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.m +500 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.h +18 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.m +214 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.h +23 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.m +29 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.h +19 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.m +68 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.h +18 -0
- package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.m +72 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.h +67 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.m +111 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.h +119 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.m +307 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.h +94 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.m +619 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.h +164 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.m +514 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding.h +24 -0
- package/ios/CodePush/JWT/Core/Coding/JWTCoding.m +11 -0
- package/ios/CodePush/JWT/Core/FrameworkSupplement/JWT.h +52 -0
- package/ios/CodePush/JWT/Core/FrameworkSupplement/Map.modulemap +5 -0
- package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.h +28 -0
- package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.m +70 -0
- package/ios/CodePush/JWT/Core/Supplement/JWTDeprecations.h +22 -0
- package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.h +34 -0
- package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.m +73 -0
- package/ios/CodePush/JWT/LICENSE +19 -0
- package/ios/CodePush/JWT/README.md +489 -0
- package/ios/CodePush/RCTConvert+CodePushInstallMode.m +20 -0
- package/ios/CodePush/RCTConvert+CodePushUpdateState.m +20 -0
- package/ios/CodePush/SSZipArchive/Common.h +81 -0
- package/ios/CodePush/SSZipArchive/README.md +1 -0
- package/ios/CodePush/SSZipArchive/SSZipArchive.h +76 -0
- package/ios/CodePush/SSZipArchive/SSZipArchive.m +691 -0
- package/ios/CodePush/SSZipArchive/aes/aes.h +198 -0
- package/ios/CodePush/SSZipArchive/aes/aes_via_ace.h +541 -0
- package/ios/CodePush/SSZipArchive/aes/aescrypt.c +294 -0
- package/ios/CodePush/SSZipArchive/aes/aeskey.c +548 -0
- package/ios/CodePush/SSZipArchive/aes/aesopt.h +739 -0
- package/ios/CodePush/SSZipArchive/aes/aestab.c +391 -0
- package/ios/CodePush/SSZipArchive/aes/aestab.h +173 -0
- package/ios/CodePush/SSZipArchive/aes/brg_endian.h +126 -0
- package/ios/CodePush/SSZipArchive/aes/brg_types.h +219 -0
- package/ios/CodePush/SSZipArchive/aes/entropy.c +54 -0
- package/ios/CodePush/SSZipArchive/aes/entropy.h +16 -0
- package/ios/CodePush/SSZipArchive/aes/fileenc.c +144 -0
- package/ios/CodePush/SSZipArchive/aes/fileenc.h +121 -0
- package/ios/CodePush/SSZipArchive/aes/hmac.c +145 -0
- package/ios/CodePush/SSZipArchive/aes/hmac.h +103 -0
- package/ios/CodePush/SSZipArchive/aes/prng.c +155 -0
- package/ios/CodePush/SSZipArchive/aes/prng.h +82 -0
- package/ios/CodePush/SSZipArchive/aes/pwd2key.c +103 -0
- package/ios/CodePush/SSZipArchive/aes/pwd2key.h +57 -0
- package/ios/CodePush/SSZipArchive/aes/sha1.c +258 -0
- package/ios/CodePush/SSZipArchive/aes/sha1.h +73 -0
- package/ios/CodePush/SSZipArchive/minizip/crypt.h +130 -0
- package/ios/CodePush/SSZipArchive/minizip/ioapi.c +369 -0
- package/ios/CodePush/SSZipArchive/minizip/ioapi.h +175 -0
- package/ios/CodePush/SSZipArchive/minizip/mztools.c +284 -0
- package/ios/CodePush/SSZipArchive/minizip/mztools.h +31 -0
- package/ios/CodePush/SSZipArchive/minizip/unzip.c +1839 -0
- package/ios/CodePush/SSZipArchive/minizip/unzip.h +248 -0
- package/ios/CodePush/SSZipArchive/minizip/zip.c +1910 -0
- package/ios/CodePush/SSZipArchive/minizip/zip.h +202 -0
- package/ios/CodePush.xcodeproj/project.pbxproj +937 -0
- package/ios/CodePush.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/CodePush.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/logging.js +6 -0
- package/package-mixins.js +69 -0
- package/package.json +47 -0
- package/request-fetch-adapter.js +52 -0
- package/scripts/generateBundledResourcesHash.js +125 -0
- package/scripts/getFilesInFolder.js +19 -0
- package/scripts/postlink/android/postlink.js +87 -0
- package/scripts/postlink/ios/postlink.js +116 -0
- package/scripts/postlink/run.js +11 -0
- package/scripts/postunlink/android/postunlink.js +74 -0
- package/scripts/postunlink/ios/postunlink.js +87 -0
- package/scripts/postunlink/run.js +11 -0
- package/scripts/recordFilesBeforeBundleCommand.js +41 -0
- package/scripts/tools/linkToolsAndroid.js +57 -0
- package/scripts/tools/linkToolsIos.js +130 -0
- package/typings/react-native-code-push.d.ts +446 -0
- package/windows/CodePush/CodePush.csproj +128 -0
- package/windows/CodePush/CodePushUtils.cs +47 -0
- package/windows/CodePush/FileUtils.cs +40 -0
- package/windows/CodePush/Properties/AssemblyInfo.cs +29 -0
- package/windows/CodePush/Properties/CodePush.rd.xml +33 -0
- package/windows/CodePush/UpdateManager.cs +305 -0
- package/windows/CodePush/UpdateUtils.cs +46 -0
- package/windows/CodePush.Net46/Adapters/Http/HttpProgress.cs +28 -0
- package/windows/CodePush.Net46/Adapters/Storage/ApplicationDataContainer.cs +106 -0
- package/windows/CodePush.Net46/CodePush.Net46.csproj +103 -0
- package/windows/CodePush.Net46/CodePushUtils.cs +158 -0
- package/windows/CodePush.Net46/FileUtils.cs +55 -0
- package/windows/CodePush.Net46/Properties/AssemblyInfo.cs +36 -0
- package/windows/CodePush.Net46/UpdateManager.cs +330 -0
- package/windows/CodePush.Net46/UpdateUtils.cs +70 -0
- package/windows/CodePush.Net46/packages.config +5 -0
- package/windows/CodePush.Shared/CodePush.Shared.projitems +22 -0
- package/windows/CodePush.Shared/CodePush.Shared.shproj +13 -0
- package/windows/CodePush.Shared/CodePushConstants.cs +35 -0
- package/windows/CodePush.Shared/CodePushNativeModule.cs +329 -0
- package/windows/CodePush.Shared/CodePushReactPackage.cs +235 -0
- package/windows/CodePush.Shared/CodePushUtils.cs +70 -0
- package/windows/CodePush.Shared/InstallMode.cs +9 -0
- package/windows/CodePush.Shared/MinimumBackgroundListener.cs +44 -0
- package/windows/CodePush.Shared/SettingsManager.cs +148 -0
- package/windows/CodePush.Shared/TelemetryManager.cs +250 -0
- package/windows/CodePush.Shared/UpdateState.cs +9 -0
package/logging.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { NativeEventEmitter } from "react-native";
|
|
2
|
+
import RestartManager from "./RestartManager";
|
|
3
|
+
import log from "./logging";
|
|
4
|
+
|
|
5
|
+
// This function is used to augment remote and local
|
|
6
|
+
// package objects with additional functionality/properties
|
|
7
|
+
// beyond what is included in the metadata sent by the server.
|
|
8
|
+
module.exports = (NativeCodePush) => {
|
|
9
|
+
const remote = (reportStatusDownload) => {
|
|
10
|
+
return {
|
|
11
|
+
async download(downloadProgressCallback) {
|
|
12
|
+
if (!this.downloadUrl) {
|
|
13
|
+
throw new Error("Cannot download an update without a download url");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let downloadProgressSubscription;
|
|
17
|
+
if (downloadProgressCallback) {
|
|
18
|
+
const codePushEventEmitter = new NativeEventEmitter(NativeCodePush);
|
|
19
|
+
// Use event subscription to obtain download progress.
|
|
20
|
+
downloadProgressSubscription = codePushEventEmitter.addListener(
|
|
21
|
+
"CodePushDownloadProgress",
|
|
22
|
+
downloadProgressCallback
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Use the downloaded package info. Native code will save the package info
|
|
27
|
+
// so that the client knows what the current package version is.
|
|
28
|
+
try {
|
|
29
|
+
const updatePackageCopy = Object.assign({}, this);
|
|
30
|
+
Object.keys(updatePackageCopy).forEach((key) => (typeof updatePackageCopy[key] === 'function') && delete updatePackageCopy[key]);
|
|
31
|
+
|
|
32
|
+
const downloadedPackage = await NativeCodePush.downloadUpdate(updatePackageCopy, !!downloadProgressCallback);
|
|
33
|
+
|
|
34
|
+
if (reportStatusDownload) {
|
|
35
|
+
reportStatusDownload(this)
|
|
36
|
+
.catch((err) => {
|
|
37
|
+
log(`Report download status failed: ${err}`);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return { ...downloadedPackage, ...local };
|
|
42
|
+
} finally {
|
|
43
|
+
downloadProgressSubscription && downloadProgressSubscription.remove();
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
isPending: false // A remote package could never be in a pending state
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const local = {
|
|
52
|
+
async install(installMode = NativeCodePush.codePushInstallModeOnNextRestart, minimumBackgroundDuration = 0, updateInstalledCallback) {
|
|
53
|
+
const localPackage = this;
|
|
54
|
+
const localPackageCopy = Object.assign({}, localPackage); // In dev mode, React Native deep freezes any object queued over the bridge
|
|
55
|
+
await NativeCodePush.installUpdate(localPackageCopy, installMode, minimumBackgroundDuration);
|
|
56
|
+
updateInstalledCallback && updateInstalledCallback();
|
|
57
|
+
if (installMode == NativeCodePush.codePushInstallModeImmediate) {
|
|
58
|
+
RestartManager.restartApp(false);
|
|
59
|
+
} else {
|
|
60
|
+
RestartManager.clearPendingRestart();
|
|
61
|
+
localPackage.isPending = true; // Mark the package as pending since it hasn't been applied yet
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
isPending: false // A local package wouldn't be pending until it was installed
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
return { local, remote };
|
|
69
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@appzung/react-native-code-push",
|
|
3
|
+
"version": "5.7.1",
|
|
4
|
+
"description": "React Native plugin for the CodePush service",
|
|
5
|
+
"main": "CodePush.js",
|
|
6
|
+
"typings": "typings/react-native-code-push.d.ts",
|
|
7
|
+
"author": "Louis Lagrange <lagrange.louis@gmail.com> (https://github.com/Minishlink)",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"code-push": "^3.0.1",
|
|
11
|
+
"glob": "^5.0.15",
|
|
12
|
+
"hoist-non-react-statics": "^2.3.1",
|
|
13
|
+
"inquirer": "^1.1.2",
|
|
14
|
+
"plist": "3.0.1",
|
|
15
|
+
"semver": "^5.6.0",
|
|
16
|
+
"xcode": "1.0.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"archiver": "latest",
|
|
20
|
+
"body-parser": "latest",
|
|
21
|
+
"code-push-plugin-testing-framework": "file:./code-push-plugin-testing-framework",
|
|
22
|
+
"del": "latest",
|
|
23
|
+
"express": "latest",
|
|
24
|
+
"gulp-insert": "latest",
|
|
25
|
+
"gulp-tslint": "latest",
|
|
26
|
+
"gulp-typescript": "^5.0.1",
|
|
27
|
+
"mkdirp": "latest",
|
|
28
|
+
"q": "^1.5.1",
|
|
29
|
+
"run-sequence": "latest",
|
|
30
|
+
"tslint": "^5.18.0",
|
|
31
|
+
"typescript": "^2.9.2"
|
|
32
|
+
},
|
|
33
|
+
"rnpm": {
|
|
34
|
+
"android": {
|
|
35
|
+
"packageInstance": "new CodePush(getResources().getString(R.string.reactNativeCodePush_androidDeploymentKey), getApplicationContext(), BuildConfig.DEBUG)"
|
|
36
|
+
},
|
|
37
|
+
"ios": {
|
|
38
|
+
"sharedLibraries": [
|
|
39
|
+
"libz"
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
"commands": {
|
|
43
|
+
"postlink": "node node_modules/react-native-code-push/scripts/postlink/run",
|
|
44
|
+
"postunlink": "node node_modules/react-native-code-push/scripts/postunlink/run"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const packageJson = require("./package.json");
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
async request(verb, url, requestBody, callback) {
|
|
5
|
+
if (typeof requestBody === "function") {
|
|
6
|
+
callback = requestBody;
|
|
7
|
+
requestBody = null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const headers = {
|
|
11
|
+
"Accept": "application/json",
|
|
12
|
+
"Content-Type": "application/json",
|
|
13
|
+
"X-CodePush-Plugin-Name": packageJson.name,
|
|
14
|
+
"X-CodePush-Plugin-Version": packageJson.version,
|
|
15
|
+
"X-CodePush-SDK-Version": packageJson.dependencies["code-push"]
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
if (requestBody && typeof requestBody === "object") {
|
|
19
|
+
requestBody = JSON.stringify(requestBody);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const response = await fetch(url, {
|
|
24
|
+
method: getHttpMethodName(verb),
|
|
25
|
+
headers: headers,
|
|
26
|
+
body: requestBody
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const statusCode = response.status;
|
|
30
|
+
const body = await response.text();
|
|
31
|
+
callback(null, { statusCode, body });
|
|
32
|
+
} catch (err) {
|
|
33
|
+
callback(err);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
function getHttpMethodName(verb) {
|
|
39
|
+
// Note: This should stay in sync with the enum definition in
|
|
40
|
+
// https://github.com/Microsoft/code-push/blob/master/sdk/script/acquisition-sdk.ts#L6
|
|
41
|
+
return [
|
|
42
|
+
"GET",
|
|
43
|
+
"HEAD",
|
|
44
|
+
"POST",
|
|
45
|
+
"PUT",
|
|
46
|
+
"DELETE",
|
|
47
|
+
"TRACE",
|
|
48
|
+
"OPTIONS",
|
|
49
|
+
"CONNECT",
|
|
50
|
+
"PATCH"
|
|
51
|
+
][verb];
|
|
52
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This script generates a hash of all the React Native bundled assets and writes it into
|
|
3
|
+
* into the APK. The hash in "updateCheck" requests to prevent downloading an identical
|
|
4
|
+
* update to the one already present in the binary.
|
|
5
|
+
*
|
|
6
|
+
* It first creates a snapshot of the contents in the resource directory by creating
|
|
7
|
+
* a map with the modified time of all the files in the directory. It then compares this
|
|
8
|
+
* snapshot with the one saved earlier in "recordFilesBeforeBundleCommand.js" to figure
|
|
9
|
+
* out which files were generated by the "react-native bundle" command. It then computes
|
|
10
|
+
* the hash for each file to generate a manifest, and then computes a hash over the entire
|
|
11
|
+
* manifest to generate the final hash, which is saved to the APK's assets directory.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
var crypto = require("crypto");
|
|
15
|
+
var fs = require("fs");
|
|
16
|
+
var path = require("path");
|
|
17
|
+
|
|
18
|
+
var getFilesInFolder = require("./getFilesInFolder");
|
|
19
|
+
|
|
20
|
+
var CODE_PUSH_FOLDER_PREFIX = "CodePush";
|
|
21
|
+
var CODE_PUSH_HASH_FILE_NAME = "CodePushHash";
|
|
22
|
+
var CODE_PUSH_HASH_OLD_FILE_NAME = "CodePushHash.json";
|
|
23
|
+
var HASH_ALGORITHM = "sha256";
|
|
24
|
+
|
|
25
|
+
var resourcesDir = process.argv[2];
|
|
26
|
+
var jsBundleFilePath = process.argv[3];
|
|
27
|
+
var assetsDir = process.argv[4];
|
|
28
|
+
var tempFileName = process.argv[5];
|
|
29
|
+
|
|
30
|
+
var oldFileToModifiedTimeMap = {};
|
|
31
|
+
var tempFileLocalPath = null;
|
|
32
|
+
if (tempFileName) {
|
|
33
|
+
tempFileLocalPath = path.join(require("os").tmpdir(), tempFileName);
|
|
34
|
+
oldFileToModifiedTimeMap = require(tempFileLocalPath);
|
|
35
|
+
}
|
|
36
|
+
var resourceFiles = [];
|
|
37
|
+
|
|
38
|
+
getFilesInFolder(resourcesDir, resourceFiles);
|
|
39
|
+
|
|
40
|
+
var newFileToModifiedTimeMap = {};
|
|
41
|
+
|
|
42
|
+
resourceFiles.forEach(function(resourceFile) {
|
|
43
|
+
newFileToModifiedTimeMap[resourceFile.path.substring(resourcesDir.length)] = resourceFile.mtime;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
var bundleGeneratedAssetFiles = [];
|
|
47
|
+
|
|
48
|
+
for (var newFilePath in newFileToModifiedTimeMap) {
|
|
49
|
+
if (!oldFileToModifiedTimeMap[newFilePath] || oldFileToModifiedTimeMap[newFilePath] < newFileToModifiedTimeMap[newFilePath].getTime()) {
|
|
50
|
+
bundleGeneratedAssetFiles.push(newFilePath);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
var manifest = [];
|
|
55
|
+
|
|
56
|
+
if (bundleGeneratedAssetFiles.length) {
|
|
57
|
+
bundleGeneratedAssetFiles.forEach(function(assetFile) {
|
|
58
|
+
// Generate hash for each asset file
|
|
59
|
+
addFileToManifest(resourcesDir, assetFile, manifest, function() {
|
|
60
|
+
if (manifest.length === bundleGeneratedAssetFiles.length) {
|
|
61
|
+
addJsBundleAndMetaToManifest();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
} else {
|
|
66
|
+
addJsBundleAndMetaToManifest();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function addJsBundleAndMetaToManifest() {
|
|
70
|
+
addFileToManifest(path.dirname(jsBundleFilePath), path.basename(jsBundleFilePath), manifest, function() {
|
|
71
|
+
var jsBundleMetaFilePath = jsBundleFilePath + ".meta";
|
|
72
|
+
addFileToManifest(path.dirname(jsBundleMetaFilePath), path.basename(jsBundleMetaFilePath), manifest, function() {
|
|
73
|
+
manifest = manifest.sort();
|
|
74
|
+
var finalHash = crypto.createHash(HASH_ALGORITHM)
|
|
75
|
+
.update(JSON.stringify(manifest))
|
|
76
|
+
.digest("hex");
|
|
77
|
+
|
|
78
|
+
console.log(finalHash);
|
|
79
|
+
|
|
80
|
+
var savedResourcesManifestPath = assetsDir + "/" + CODE_PUSH_HASH_FILE_NAME;
|
|
81
|
+
fs.writeFileSync(savedResourcesManifestPath, finalHash);
|
|
82
|
+
|
|
83
|
+
// "CodePushHash.json" file name breaks flow type checking.
|
|
84
|
+
// To fix the issue we need to delete "CodePushHash.json" file and
|
|
85
|
+
// use "CodePushHash" file name instead to store the hash value.
|
|
86
|
+
// Relates to https://github.com/Microsoft/react-native-code-push/issues/577
|
|
87
|
+
var oldSavedResourcesManifestPath = assetsDir + "/" + CODE_PUSH_HASH_OLD_FILE_NAME;
|
|
88
|
+
if (fs.existsSync(oldSavedResourcesManifestPath)) {
|
|
89
|
+
fs.unlinkSync(oldSavedResourcesManifestPath);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function addFileToManifest(folder, assetFile, manifest, done) {
|
|
96
|
+
var fullFilePath = path.join(folder, assetFile);
|
|
97
|
+
if (!fileExists(fullFilePath)) {
|
|
98
|
+
done();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
var readStream = fs.createReadStream(path.join(folder, assetFile));
|
|
103
|
+
var hashStream = crypto.createHash(HASH_ALGORITHM);
|
|
104
|
+
|
|
105
|
+
readStream.pipe(hashStream)
|
|
106
|
+
.on("error", function(error) {
|
|
107
|
+
throw error;
|
|
108
|
+
})
|
|
109
|
+
.on("finish", function() {
|
|
110
|
+
hashStream.end();
|
|
111
|
+
var buffer = hashStream.read();
|
|
112
|
+
var fileHash = buffer.toString("hex");
|
|
113
|
+
manifest.push(path.join(CODE_PUSH_FOLDER_PREFIX, assetFile).replace(/\\/g, "/") + ":" + fileHash);
|
|
114
|
+
done();
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function fileExists(file) {
|
|
119
|
+
try { return fs.statSync(file).isFile(); }
|
|
120
|
+
catch (e) { return false; }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (tempFileLocalPath) {
|
|
124
|
+
fs.unlinkSync(tempFileLocalPath);
|
|
125
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var fs = require("fs");
|
|
2
|
+
var path = require("path");
|
|
3
|
+
|
|
4
|
+
// Utility function that collects the stats of every file in a directory
|
|
5
|
+
// as well as in its subdirectories.
|
|
6
|
+
function getFilesInFolder(folderName, fileList) {
|
|
7
|
+
var folderFiles = fs.readdirSync(folderName);
|
|
8
|
+
folderFiles.forEach(function(file) {
|
|
9
|
+
var fileStats = fs.statSync(path.join(folderName, file));
|
|
10
|
+
if (fileStats.isDirectory()) {
|
|
11
|
+
getFilesInFolder(path.join(folderName, file), fileList);
|
|
12
|
+
} else {
|
|
13
|
+
fileStats.path = path.join(folderName, file);
|
|
14
|
+
fileList.push(fileStats);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = getFilesInFolder;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
var linkTools = require('../../tools/linkToolsAndroid');
|
|
2
|
+
var fs = require("fs");
|
|
3
|
+
var inquirer = require('inquirer');
|
|
4
|
+
|
|
5
|
+
module.exports = () => {
|
|
6
|
+
|
|
7
|
+
console.log("Running android postlink script");
|
|
8
|
+
|
|
9
|
+
var buildGradlePath = linkTools.getBuildGradlePath();
|
|
10
|
+
var mainApplicationPath = linkTools.getMainApplicationLocation();
|
|
11
|
+
|
|
12
|
+
// 1. Add the getJSBundleFile override
|
|
13
|
+
var getJSBundleFileOverride = linkTools.getJSBundleFileOverride;
|
|
14
|
+
|
|
15
|
+
if (mainApplicationPath) {
|
|
16
|
+
var mainApplicationContents = fs.readFileSync(mainApplicationPath, "utf8");
|
|
17
|
+
if (linkTools.isJsBundleOverridden(mainApplicationContents)) {
|
|
18
|
+
console.log(`"getJSBundleFile" is already overridden`);
|
|
19
|
+
} else {
|
|
20
|
+
var reactNativeHostInstantiation = linkTools.reactNativeHostInstantiation;
|
|
21
|
+
mainApplicationContents = mainApplicationContents.replace(reactNativeHostInstantiation,
|
|
22
|
+
`${reactNativeHostInstantiation}${getJSBundleFileOverride}`);
|
|
23
|
+
fs.writeFileSync(mainApplicationPath, mainApplicationContents);
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
var mainActivityPath = linkTools.getMainActivityPath();
|
|
27
|
+
if (mainActivityPath) {
|
|
28
|
+
var mainActivityContents = fs.readFileSync(mainActivityPath, "utf8");
|
|
29
|
+
if (linkTools.isJsBundleOverridden(mainActivityContents)) {
|
|
30
|
+
console.log(`"getJSBundleFile" is already overridden`);
|
|
31
|
+
} else {
|
|
32
|
+
var mainActivityClassDeclaration = linkTools.mainActivityClassDeclaration;
|
|
33
|
+
mainActivityContents = mainActivityContents.replace(mainActivityClassDeclaration,
|
|
34
|
+
`${mainActivityClassDeclaration}${getJSBundleFileOverride}`);
|
|
35
|
+
fs.writeFileSync(mainActivityPath, mainActivityContents);
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
return Promise.reject(`Couldn't find Android application entry point. You might need to update it manually. \
|
|
39
|
+
Please refer to plugin configuration section for Android at \
|
|
40
|
+
https://github.com/microsoft/react-native-code-push#plugin-configuration-android for more details`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!fs.existsSync(buildGradlePath)) {
|
|
45
|
+
return Promise.reject(`Couldn't find build.gradle file. You might need to update it manually. \
|
|
46
|
+
Please refer to plugin installation section for Android at \
|
|
47
|
+
https://github.com/microsoft/react-native-code-push#plugin-installation-android---manual`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 2. Add the codepush.gradle build task definitions
|
|
51
|
+
var buildGradleContents = fs.readFileSync(buildGradlePath, "utf8");
|
|
52
|
+
var reactGradleLink = buildGradleContents.match(/\napply from: ["'].*?react\.gradle["']/)[0];
|
|
53
|
+
var codePushGradleLink = linkTools.codePushGradleLink;
|
|
54
|
+
if (~buildGradleContents.indexOf(codePushGradleLink)) {
|
|
55
|
+
console.log(`"codepush.gradle" is already linked in the build definition`);
|
|
56
|
+
} else {
|
|
57
|
+
buildGradleContents = buildGradleContents.replace(reactGradleLink,
|
|
58
|
+
`${reactGradleLink}${codePushGradleLink}`);
|
|
59
|
+
fs.writeFileSync(buildGradlePath, buildGradleContents);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//3. Add deployment key
|
|
63
|
+
var stringsResourcesPath = linkTools.getStringsResourcesPath();
|
|
64
|
+
if (!stringsResourcesPath) {
|
|
65
|
+
return Promise.reject(new Error(`Couldn't find strings.xml. You might need to update it manually.`));
|
|
66
|
+
} else {
|
|
67
|
+
var stringsResourcesContent = fs.readFileSync(stringsResourcesPath, "utf8");
|
|
68
|
+
var deploymentKeyName = linkTools.deploymentKeyName;
|
|
69
|
+
if (~stringsResourcesContent.indexOf(deploymentKeyName)) {
|
|
70
|
+
console.log(`${deploymentKeyName} already specified in the strings.xml`);
|
|
71
|
+
} else {
|
|
72
|
+
return inquirer.prompt({
|
|
73
|
+
"type": "input",
|
|
74
|
+
"name": "androidDeploymentKey",
|
|
75
|
+
"message": "What is your CodePush deployment key for Android (hit <ENTER> to ignore)"
|
|
76
|
+
}).then(function(answer) {
|
|
77
|
+
var insertAfterString = "<resources>";
|
|
78
|
+
var deploymentKeyString = `\t<string moduleConfig="true" name="${deploymentKeyName}">${answer.androidDeploymentKey || "deployment-key-here"}</string>`;
|
|
79
|
+
stringsResourcesContent = stringsResourcesContent.replace(insertAfterString,`${insertAfterString}\n${deploymentKeyString}`);
|
|
80
|
+
fs.writeFileSync(stringsResourcesPath, stringsResourcesContent);
|
|
81
|
+
return Promise.resolve();
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return Promise.resolve();
|
|
87
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
|
|
2
|
+
var linkTools = require('../../tools/linkToolsIos');
|
|
3
|
+
var fs = require("fs");
|
|
4
|
+
var inquirer = require('inquirer');
|
|
5
|
+
var plist = require("plist");
|
|
6
|
+
var semver = require('semver');
|
|
7
|
+
|
|
8
|
+
var package = require('../../../../../package.json');
|
|
9
|
+
|
|
10
|
+
module.exports = () => {
|
|
11
|
+
|
|
12
|
+
console.log("Running ios postlink script");
|
|
13
|
+
|
|
14
|
+
var appDelegatePath = linkTools.getAppDeletePath();
|
|
15
|
+
|
|
16
|
+
if (!appDelegatePath) {
|
|
17
|
+
return Promise.reject(`Couldn't find AppDelegate. You might need to update it manually \
|
|
18
|
+
Please refer to plugin configuration section for iOS at \
|
|
19
|
+
https://github.com/microsoft/react-native-code-push#plugin-configuration-ios`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
var appDelegateContents = fs.readFileSync(appDelegatePath, "utf8");
|
|
23
|
+
|
|
24
|
+
// 1. Add the header import statement
|
|
25
|
+
if (~appDelegateContents.indexOf(linkTools.codePushHeaderImportStatement)) {
|
|
26
|
+
console.log(`"CodePush.h" header already imported.`);
|
|
27
|
+
} else {
|
|
28
|
+
var appDelegateHeaderImportStatement = `#import "AppDelegate.h"`;
|
|
29
|
+
appDelegateContents = appDelegateContents.replace(appDelegateHeaderImportStatement,
|
|
30
|
+
`${appDelegateHeaderImportStatement}${linkTools.codePushHeaderImportStatementFormatted}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 2. Modify jsCodeLocation value assignment
|
|
34
|
+
var reactNativeVersion = package && package.dependencies && package.dependencies["react-native"];
|
|
35
|
+
|
|
36
|
+
if (!reactNativeVersion) {
|
|
37
|
+
console.log(`Can't take react-native version from package.json`);
|
|
38
|
+
} else if (semver.gte(semver.coerce(reactNativeVersion), "0.59.0")) {
|
|
39
|
+
var oldBundleUrl = linkTools.oldBundleUrl;
|
|
40
|
+
var codePushBundleUrl = linkTools.codePushBundleUrl;
|
|
41
|
+
|
|
42
|
+
if (~appDelegateContents.indexOf(codePushBundleUrl)) {
|
|
43
|
+
console.log(`"BundleUrl" already pointing to "[CodePush bundleURL]".`);
|
|
44
|
+
} else {
|
|
45
|
+
if (~appDelegateContents.indexOf(oldBundleUrl)) {
|
|
46
|
+
appDelegateContents = appDelegateContents.replace(oldBundleUrl, codePushBundleUrl);
|
|
47
|
+
} else {
|
|
48
|
+
console.log(`AppDelegate isn't compatible for linking`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
var jsCodeLocations = appDelegateContents.match(/(jsCodeLocation = .*)/g);
|
|
53
|
+
|
|
54
|
+
if (!jsCodeLocations) {
|
|
55
|
+
console.log('Couldn\'t find jsCodeLocation setting in AppDelegate.');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
var newJsCodeLocationAssignmentStatement = linkTools.codePushGradleLink;
|
|
59
|
+
if (~appDelegateContents.indexOf(newJsCodeLocationAssignmentStatement)) {
|
|
60
|
+
console.log(`"jsCodeLocation" already pointing to "[CodePush bundleURL]".`);
|
|
61
|
+
} else {
|
|
62
|
+
if (jsCodeLocations.length === 1) {
|
|
63
|
+
// If there is one `jsCodeLocation` it means that react-native app version is not the 0.57.8 or 0.57.0 and lower than 0.59
|
|
64
|
+
// and we should replace this line with DEBUG ifdef statement and add CodePush call for Release case
|
|
65
|
+
|
|
66
|
+
var oldJsCodeLocationAssignmentStatement = jsCodeLocations[0];
|
|
67
|
+
var jsCodeLocationPatch = linkTools.getJsCodeLocationPatch(oldJsCodeLocationAssignmentStatement);
|
|
68
|
+
appDelegateContents = appDelegateContents.replace(oldJsCodeLocationAssignmentStatement,
|
|
69
|
+
jsCodeLocationPatch);
|
|
70
|
+
} else if (jsCodeLocations.length === 2) {
|
|
71
|
+
// If there are two `jsCodeLocation` it means that react-native app version is higher than 0.57.8 or equal
|
|
72
|
+
// and we should replace the second one(Release case) with CodePush call
|
|
73
|
+
|
|
74
|
+
appDelegateContents = appDelegateContents.replace(jsCodeLocations[1],
|
|
75
|
+
newJsCodeLocationAssignmentStatement);
|
|
76
|
+
} else {
|
|
77
|
+
console.log(`AppDelegate isn't compatible for linking`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
var plistPath = linkTools.getPlistPath();
|
|
83
|
+
|
|
84
|
+
if (!plistPath) {
|
|
85
|
+
return Promise.reject(`Couldn't find .plist file. You might need to update it manually \
|
|
86
|
+
Please refer to plugin configuration section for iOS at \
|
|
87
|
+
https://github.com/microsoft/react-native-code-push#plugin-configuration-ios`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
var plistContents = fs.readFileSync(plistPath, "utf8");
|
|
91
|
+
|
|
92
|
+
// 3. Add CodePushDeploymentKey to plist file
|
|
93
|
+
var parsedInfoPlist = plist.parse(plistContents);
|
|
94
|
+
if (parsedInfoPlist.CodePushDeploymentKey) {
|
|
95
|
+
console.log(`"CodePushDeploymentKey" already specified in the plist file.`);
|
|
96
|
+
writePatches();
|
|
97
|
+
return Promise.resolve();
|
|
98
|
+
} else {
|
|
99
|
+
return inquirer.prompt({
|
|
100
|
+
"type": "input",
|
|
101
|
+
"name": "iosDeploymentKey",
|
|
102
|
+
"message": "What is your CodePush deployment key for iOS (hit <ENTER> to ignore)"
|
|
103
|
+
}).then(function(answer) {
|
|
104
|
+
parsedInfoPlist.CodePushDeploymentKey = answer.iosDeploymentKey || "deployment-key-here";
|
|
105
|
+
plistContents = plist.build(parsedInfoPlist);
|
|
106
|
+
|
|
107
|
+
writePatches();
|
|
108
|
+
return Promise.resolve();
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function writePatches() {
|
|
113
|
+
fs.writeFileSync(appDelegatePath, appDelegateContents);
|
|
114
|
+
fs.writeFileSync(plistPath, plistContents);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
var linkTools = require('../../tools/linkToolsAndroid');
|
|
2
|
+
var fs = require("fs");
|
|
3
|
+
|
|
4
|
+
module.exports = () => {
|
|
5
|
+
|
|
6
|
+
console.log("Running android postunlink script");
|
|
7
|
+
|
|
8
|
+
var mainApplicationPath = linkTools.getMainApplicationLocation();
|
|
9
|
+
|
|
10
|
+
// 1. Remove the getJSBundleFile override
|
|
11
|
+
var getJSBundleFileOverride = linkTools.getJSBundleFileOverride;
|
|
12
|
+
|
|
13
|
+
if (mainApplicationPath) {
|
|
14
|
+
var mainApplicationContents = fs.readFileSync(mainApplicationPath, "utf8");
|
|
15
|
+
if (!linkTools.isJsBundleOverridden(mainApplicationContents)) {
|
|
16
|
+
console.log(`"getJSBundleFile" is already removed`);
|
|
17
|
+
} else {
|
|
18
|
+
mainApplicationContents = mainApplicationContents.replace(`${getJSBundleFileOverride}`, "");
|
|
19
|
+
fs.writeFileSync(mainApplicationPath, mainApplicationContents);
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
var mainActivityPath = linkTools.getMainActivityPath();
|
|
23
|
+
if (mainActivityPath) {
|
|
24
|
+
var mainActivityContents = fs.readFileSync(mainActivityPath, "utf8");
|
|
25
|
+
if (!linkTools.isJsBundleOverridden(mainActivityContents)) {
|
|
26
|
+
console.log(`"getJSBundleFile" is already removed`);
|
|
27
|
+
} else {
|
|
28
|
+
mainActivityContents = mainActivityContents.replace(getJSBundleFileOverride, "");
|
|
29
|
+
fs.writeFileSync(mainActivityPath, mainActivityContents);
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
console.log(`Couldn't find Android application entry point. You might need to update it manually. \
|
|
33
|
+
Please refer to plugin configuration section for Android at \
|
|
34
|
+
https://github.com/microsoft/react-native-code-push#plugin-configuration-android for more details`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 2. Remove the codepush.gradle build task definitions
|
|
39
|
+
var buildGradlePath = linkTools.getBuildGradlePath();
|
|
40
|
+
|
|
41
|
+
if (!fs.existsSync(buildGradlePath)) {
|
|
42
|
+
console.log(`Couldn't find build.gradle file. You might need to update it manually. \
|
|
43
|
+
Please refer to plugin installation section for Android at \
|
|
44
|
+
https://github.com/microsoft/react-native-code-push#plugin-installation-android---manual`);
|
|
45
|
+
} else {
|
|
46
|
+
var buildGradleContents = fs.readFileSync(buildGradlePath, "utf8");
|
|
47
|
+
var codePushGradleLink = linkTools.codePushGradleLink;
|
|
48
|
+
if (!~buildGradleContents.indexOf(codePushGradleLink)) {
|
|
49
|
+
console.log(`"codepush.gradle" is already unlinked in the build definition`);
|
|
50
|
+
} else {
|
|
51
|
+
buildGradleContents = buildGradleContents.replace(`${codePushGradleLink}`,"");
|
|
52
|
+
fs.writeFileSync(buildGradlePath, buildGradleContents);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 3. Remove deployment key
|
|
57
|
+
var stringsResourcesPath = linkTools.getStringsResourcesPath();
|
|
58
|
+
if (!stringsResourcesPath) {
|
|
59
|
+
return Promise.reject(new Error("Couldn't find strings.xml. You might need to update it manually."));
|
|
60
|
+
} else {
|
|
61
|
+
var stringsResourcesContent = fs.readFileSync(stringsResourcesPath, "utf8");
|
|
62
|
+
var deploymentKeyName = linkTools.deploymentKeyName;
|
|
63
|
+
if (!~stringsResourcesContent.indexOf(deploymentKeyName)) {
|
|
64
|
+
console.log(`${deploymentKeyName} already removed from the strings.xml`);
|
|
65
|
+
} else {
|
|
66
|
+
var AndroidDeploymentKey = stringsResourcesContent.match(/(<string moduleConfig="true" name="reactNativeCodePush_androidDeploymentKey">.*<\/string>)/);
|
|
67
|
+
if (AndroidDeploymentKey) {
|
|
68
|
+
stringsResourcesContent = stringsResourcesContent.replace(`\n\t${AndroidDeploymentKey[0]}`,"");
|
|
69
|
+
fs.writeFileSync(stringsResourcesPath, stringsResourcesContent);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return Promise.resolve();
|
|
74
|
+
}
|