@bravemobile/react-native-code-push 8.3.1 → 9.0.0-alpha.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.
Files changed (53) hide show
  1. package/CodePush.js +107 -136
  2. package/README.md +0 -5
  3. package/babel.config.js +3 -0
  4. package/cli/commands/bundleCommand/bundleCodePush.js +49 -0
  5. package/cli/commands/bundleCommand/index.js +25 -0
  6. package/cli/commands/createHistoryCommand/createReleaseHistory.js +53 -0
  7. package/cli/commands/createHistoryCommand/index.js +28 -0
  8. package/cli/commands/releaseCommand/addToReleaseHistory.js +75 -0
  9. package/cli/commands/releaseCommand/index.js +61 -0
  10. package/cli/commands/releaseCommand/release.js +88 -0
  11. package/cli/commands/showHistoryCommand/index.js +28 -0
  12. package/cli/commands/updateHistoryCommand/index.js +49 -0
  13. package/cli/commands/updateHistoryCommand/updateReleaseHistory.js +62 -0
  14. package/cli/constant.js +3 -0
  15. package/cli/functions/getReactTempDir.js +16 -0
  16. package/cli/functions/makeCodePushBundle.js +27 -0
  17. package/cli/functions/prepareToBundleJS.js +12 -0
  18. package/cli/functions/runHermesEmitBinaryCommand.js +213 -0
  19. package/cli/functions/runReactNativeBundleCommand.js +59 -0
  20. package/cli/index.js +43 -0
  21. package/cli/utils/file-utils.js +42 -0
  22. package/cli/utils/fsUtils.js +49 -0
  23. package/cli/utils/hash-utils.js +227 -0
  24. package/cli/utils/promisfied-fs.js +29 -0
  25. package/cli/utils/showLogo.js +23 -0
  26. package/cli/utils/zip.js +89 -0
  27. package/code-push.config.example.supabase.ts +114 -0
  28. package/docs/setup-android.md +3 -11
  29. package/eslint.config.mjs +32 -0
  30. package/package-mixins.js +1 -8
  31. package/package.json +26 -23
  32. package/react-native.config.js +3 -1
  33. package/typings/react-native-code-push.d.ts +91 -16
  34. package/versioning/BaseVersioning.js +126 -0
  35. package/versioning/BaseVersioning.test.js +15 -0
  36. package/versioning/IncrementalVersioning.js +9 -0
  37. package/versioning/IncrementalVersioning.test.js +186 -0
  38. package/versioning/SemverVersioning.js +10 -0
  39. package/versioning/SemverVersioning.test.js +205 -0
  40. package/versioning/index.js +7 -0
  41. package/.azurepipelines/build-rn-code-push-1es.yml +0 -104
  42. package/.azurepipelines/test-rn-code-push.yml +0 -94
  43. package/.config/CredScanSuppressions.json +0 -14
  44. package/docs/setup-windows.md +0 -121
  45. package/request-fetch-adapter.js +0 -52
  46. package/scripts/postlink/android/postlink.js +0 -87
  47. package/scripts/postlink/ios/postlink.js +0 -116
  48. package/scripts/postlink/run.js +0 -11
  49. package/scripts/postunlink/android/postunlink.js +0 -74
  50. package/scripts/postunlink/ios/postunlink.js +0 -87
  51. package/scripts/postunlink/run.js +0 -11
  52. package/scripts/tools/linkToolsAndroid.js +0 -57
  53. package/scripts/tools/linkToolsIos.js +0 -130
@@ -1,87 +0,0 @@
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/blob/master/docs/setup-android.md#plugin-configuration-for-react-native-lower-than-060-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/blob/master/docs/setup-android.md#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
- }
@@ -1,116 +0,0 @@
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
- }
@@ -1,11 +0,0 @@
1
- var postlinks = [
2
- require("./android/postlink"),
3
- require("./ios/postlink")
4
- ];
5
-
6
- //run them sequentially
7
- postlinks
8
- .reduce((p, fn) => p.then(fn), Promise.resolve())
9
- .catch((err) => {
10
- console.error(err.message);
11
- });
@@ -1,74 +0,0 @@
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/blob/master/docs/setup-android.md#plugin-configuration-for-react-native-lower-than-060-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/blob/master/docs/setup-android.md#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="CodePushDeploymentKey">.*<\/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
- }
@@ -1,87 +0,0 @@
1
-
2
- var linkTools = require('../../tools/linkToolsIos');
3
- var fs = require("fs");
4
- var plist = require("plist");
5
- var semver = require('semver');
6
- var packageFile = require('../../../../../package.json');
7
-
8
- module.exports = () => {
9
-
10
- console.log("Running ios postunlink script");
11
-
12
- var appDelegatePath = linkTools.getAppDeletePath();
13
-
14
- if (!appDelegatePath) {
15
- console.log(`Couldn't find AppDelegate. You might need to update it manually \
16
- Please refer to plugin configuration section for iOS at \
17
- https://github.com/microsoft/react-native-code-push#plugin-configuration-ios`);
18
- } else {
19
- var appDelegateContents = fs.readFileSync(appDelegatePath, "utf8");
20
-
21
- // 1. Remove the header import statement
22
- if (!~appDelegateContents.indexOf(linkTools.codePushHeaderImportStatement)) {
23
- console.log(`"CodePush.h" header already removed.`);
24
- } else {
25
- appDelegateContents = appDelegateContents.replace(linkTools.codePushHeaderImportStatementFormatted, "");
26
- }
27
-
28
- // 2. Modify jsCodeLocation value assignment
29
- var codePushBundleUrl = linkTools.codePushBundleUrl;
30
- if (!~appDelegateContents.indexOf(codePushBundleUrl)) {
31
- console.log(`"jsCodeLocation" already not pointing to "[CodePush bundleURL]".`);
32
- } else {
33
- var reactNativeVersion = packageFile && packageFile.dependencies && packageFile.dependencies["react-native"];
34
- if (!reactNativeVersion) {
35
- console.log(`Can't take react-native version from package.json`);
36
- } else if (semver.gte(semver.coerce(reactNativeVersion), "0.59.0")) {
37
- var oldBundleUrl = linkTools.oldBundleUrl;
38
- appDelegateContents = appDelegateContents.replace(codePushBundleUrl, oldBundleUrl);
39
- fs.writeFileSync(appDelegatePath, appDelegateContents);
40
- } else {
41
- var linkedJsCodeLocationAssignmentStatement = linkTools.linkedJsCodeLocationAssignmentStatement;
42
- var jsCodeLocations = appDelegateContents.match(/(jsCodeLocation = .*)/g);
43
- if (!jsCodeLocations || jsCodeLocations.length !== 2 || !~appDelegateContents.indexOf(linkedJsCodeLocationAssignmentStatement)) {
44
- console.log(`AppDelegate isn't compatible for unlinking`);
45
- } else {
46
- if (semver.eq(semver.coerce(reactNativeVersion), "0.57.8") || semver.eq(semver.coerce(reactNativeVersion), "0.57.0")) {
47
- // If version of react-native application is 0.57.8 or 0.57 then by default there are two different
48
- // jsCodeLocation for debug and release and we should replace only release
49
- var unlinkedJsCodeLocations = `jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];`;
50
- appDelegateContents = appDelegateContents.replace(linkedJsCodeLocationAssignmentStatement,
51
- unlinkedJsCodeLocations);
52
- } else {
53
- // If version of react-native application is not 0.57.8 or 0.57 and lower than 0.59.0 then by default there is only one
54
- // jsCodeLocation and we should stay on only it
55
- var defaultJsCodeLocationAssignmentStatement = jsCodeLocations[0];
56
- var linkedCodeLocationPatch = linkTools.getJsCodeLocationPatch(defaultJsCodeLocationAssignmentStatement);
57
- appDelegateContents = appDelegateContents.replace(linkedCodeLocationPatch,
58
- defaultJsCodeLocationAssignmentStatement);
59
- }
60
- fs.writeFileSync(appDelegatePath, appDelegateContents);
61
- }
62
- }
63
- }
64
- }
65
-
66
- var plistPath = linkTools.getPlistPath();
67
-
68
- if (!plistPath) {
69
- return Promise.reject(`Couldn't find .plist file. You might need to update it manually \
70
- Please refer to plugin configuration section for iOS at \
71
- https://github.com/microsoft/react-native-code-push#plugin-configuration-ios`);
72
- }
73
-
74
- var plistContents = fs.readFileSync(plistPath, "utf8");
75
-
76
- // 3. Remove CodePushDeploymentKey from plist file
77
- var parsedInfoPlist = plist.parse(plistContents);
78
- if (!parsedInfoPlist.CodePushDeploymentKey) {
79
- console.log(`"CodePushDeploymentKey" already removed from the plist file.`);
80
- } else {
81
- delete parsedInfoPlist.CodePushDeploymentKey;
82
- plistContents = plist.build(parsedInfoPlist);
83
- fs.writeFileSync(plistPath, plistContents);
84
- }
85
-
86
- return Promise.resolve();
87
- }
@@ -1,11 +0,0 @@
1
- var postunlinks = [
2
- require("./ios/postunlink"),
3
- require("./android/postunlink")
4
- ];
5
-
6
- //run them sequentially
7
- postunlinks
8
- .reduce((p, fn) => p.then(fn), Promise.resolve())
9
- .catch((err) => {
10
- console.error(err.message);
11
- });
@@ -1,57 +0,0 @@
1
- var fs = require("fs");
2
- var glob = require("glob");
3
- var path = require("path");
4
-
5
- var ignoreFolders = { ignore: ["node_modules/**", "**/build/**"] };
6
- var manifestPath = glob.sync("**/AndroidManifest.xml", ignoreFolders)[0];
7
-
8
- exports.getJSBundleFileOverride = `
9
- @Override
10
- protected String getJSBundleFile(){
11
- return CodePush.getJSBundleFile();
12
- }
13
- `;
14
- exports.reactNativeHostInstantiation = "new ReactNativeHost(this) {";
15
- exports.mainActivityClassDeclaration = "public class MainActivity extends ReactActivity {";
16
- exports.codePushGradleLink = `\napply from: "../../node_modules/react-native-code-push/android/codepush.gradle"`;
17
- exports.deploymentKeyName = "CodePushDeploymentKey";
18
-
19
- exports.getMainApplicationLocation = function () {
20
- return findMainApplication() || glob.sync("**/MainApplication.java", ignoreFolders)[0];
21
- }
22
-
23
- exports.getMainActivityPath = function () {
24
- return glob.sync("**/MainActivity.java", ignoreFolders)[0]
25
- }
26
-
27
- exports.getStringsResourcesPath = function () {
28
- return glob.sync("**/strings.xml", ignoreFolders)[0];
29
- }
30
-
31
- exports.getBuildGradlePath = function () {
32
- return path.join("android", "app", "build.gradle");
33
- }
34
-
35
- exports.isJsBundleOverridden = function (codeContents) {
36
- return /@Override\s*\n\s*protected String getJSBundleFile\(\)\s*\{[\s\S]*?\}/.test(codeContents);
37
- }
38
-
39
- function findMainApplication() {
40
- if (!manifestPath) {
41
- return null;
42
- }
43
-
44
- var manifest = fs.readFileSync(manifestPath, "utf8");
45
-
46
- // Android manifest must include single 'application' element
47
- var matchResult = manifest.match(/application\s+android:name\s*=\s*"(.*?)"/);
48
- if (matchResult) {
49
- var appName = matchResult[1];
50
- } else {
51
- return null;
52
- }
53
-
54
- var nameParts = appName.split('.');
55
- var searchPath = glob.sync("**/" + nameParts[nameParts.length - 1] + ".java", ignoreFolders)[0];
56
- return searchPath;
57
- }
@@ -1,130 +0,0 @@
1
- var glob = require("glob");
2
- var path = require("path");
3
- var xcode = require("xcode");
4
- var packageFile = require('../../../../package.json');
5
-
6
- var ignoreNodeModules = { ignore: "node_modules/**" };
7
- var ignoreNodeModulesAndPods = { ignore: ["node_modules/**", "ios/Pods/**"] };
8
- var appDelegatePaths = glob.sync("**/AppDelegate.+(mm|m)", ignoreNodeModules);
9
-
10
- exports.codePushHeaderImportStatement = `#import <CodePush/CodePush.h>`;
11
- exports.codePushHeaderImportStatementFormatted = `\n${this.codePushHeaderImportStatement}`;
12
- exports.codePushBundleUrl = "[CodePush bundleURL]";
13
- exports.oldBundleUrl = "[[NSBundle mainBundle] URLForResource:@\"main\" withExtension:@\"jsbundle\"]";
14
- exports.linkedJsCodeLocationAssignmentStatement = "jsCodeLocation = [CodePush bundleURL];";
15
-
16
- exports.getJsCodeLocationPatch = function(defaultJsCodeLocationAssignmentStatement) {
17
- return `
18
- #ifdef DEBUG
19
- ${defaultJsCodeLocationAssignmentStatement}
20
- #else
21
- ${this.linkedJsCodeLocationAssignmentStatement}
22
- #endif`;
23
- }
24
-
25
- // Fix for https://github.com/microsoft/react-native-code-push/issues/477
26
- // Typical location of AppDelegate.m for newer RN versions: $PROJECT_ROOT/ios/<project_name>/AppDelegate.m
27
- // Let's try to find that path by filtering the whole array for any path containing <project_name>
28
- // If we can't find it there, play dumb and pray it is the first path we find.
29
- exports.getAppDeletePath = function() {
30
- return findFileByAppName(appDelegatePaths, packageFile ? packageFile.name : null) || appDelegatePaths[0];
31
- }
32
-
33
- exports.getPlistPath = function() {
34
- var xcodeProjectPaths = glob.sync(`**/*.xcodeproj/project.pbxproj`, ignoreNodeModulesAndPods);
35
- if (!xcodeProjectPaths){
36
- return getDefaultPlistPath();
37
- }
38
-
39
- if (xcodeProjectPaths.length !== 1) {
40
- console.log('Could not determine correct xcode proj path to retrieve related plist file, there are multiple xcodeproj under the solution.');
41
- return getDefaultPlistPath();
42
- }
43
-
44
- var xcodeProjectPath = xcodeProjectPaths[0];
45
- var parsedXCodeProj;
46
-
47
- try {
48
- var proj = xcode.project(xcodeProjectPath);
49
- //use sync version because there are some problems with async version of xcode lib as of current version
50
- parsedXCodeProj = proj.parseSync();
51
- }
52
- catch(e) {
53
- console.log('Couldn\'t read info.plist path from xcode project - error: ' + e.message);
54
- return getDefaultPlistPath();
55
- }
56
-
57
- var INFO_PLIST_PROJECT_KEY = 'INFOPLIST_FILE';
58
- var RELEASE_BUILD_PROPERTY_NAME = "Release";
59
- var targetProductName = packageFile ? packageFile.name : null;
60
-
61
- //Try to get 'Release' build of ProductName matching the package name first and if it doesn't exist then try to get any other if existing
62
- var plistPathValue = getBuildSettingsPropertyMatchingTargetProductName(parsedXCodeProj, INFO_PLIST_PROJECT_KEY, targetProductName, RELEASE_BUILD_PROPERTY_NAME) ||
63
- getBuildSettingsPropertyMatchingTargetProductName(parsedXCodeProj, INFO_PLIST_PROJECT_KEY, targetProductName) ||
64
- getBuildSettingsPropertyMatchingTargetProductName(parsedXCodeProj, INFO_PLIST_PROJECT_KEY, null, RELEASE_BUILD_PROPERTY_NAME) ||
65
- getBuildSettingsPropertyMatchingTargetProductName(parsedXCodeProj, INFO_PLIST_PROJECT_KEY) ||
66
- parsedXCodeProj.getBuildProperty(INFO_PLIST_PROJECT_KEY, RELEASE_BUILD_PROPERTY_NAME) ||
67
- parsedXCodeProj.getBuildProperty(INFO_PLIST_PROJECT_KEY);
68
-
69
- if (!plistPathValue){
70
- return getDefaultPlistPath();
71
- }
72
-
73
- //also remove surrounding quotes from plistPathValue to get correct path resolved
74
- //(see https://github.com/microsoft/react-native-code-push/issues/534#issuecomment-302069326 for details)
75
- return path.resolve(path.dirname(xcodeProjectPath), '..', plistPathValue.replace(/^"(.*)"$/, '$1'));
76
- }
77
-
78
- // Helper that filters an array with AppDelegate.m paths for a path with the app name inside it
79
- // Should cover nearly all cases
80
- function findFileByAppName(array, appName) {
81
- if (array.length === 0 || !appName) return null;
82
-
83
- for (var i = 0; i < array.length; i++) {
84
- var path = array[i];
85
- if (path && path.indexOf(appName) !== -1) {
86
- return path;
87
- }
88
- }
89
-
90
- return null;
91
- }
92
-
93
- function getDefaultPlistPath() {
94
- //this is old logic in case we are unable to find PLIST from xcode/pbxproj - at least we can fallback to default solution
95
- return glob.sync(`**/${packageFile.name}/*Info.plist`, ignoreNodeModules)[0];
96
- }
97
-
98
- // This is enhanced version of standard implementation of xcode 'getBuildProperty' function
99
- // but allows us to narrow results by PRODUCT_NAME property also.
100
- // So we suppose that proj name should be the same as package name, otherwise fallback to default plist path searching logic
101
- function getBuildSettingsPropertyMatchingTargetProductName(parsedXCodeProj, prop, targetProductName, build) {
102
- var target;
103
- var COMMENT_KEY = /_comment$/;
104
- var PRODUCT_NAME_PROJECT_KEY = 'PRODUCT_NAME';
105
- var TV_OS_DEPLOYMENT_TARGET_PROPERTY_NAME = 'TVOS_DEPLOYMENT_TARGET';
106
- var TEST_HOST_PROPERTY_NAME = 'TEST_HOST';
107
-
108
- var configs = parsedXCodeProj.pbxXCBuildConfigurationSection();
109
- for (var configName in configs) {
110
- if (!COMMENT_KEY.test(configName)) {
111
- var config = configs[configName];
112
- if ( (build && config.name === build) || (build === undefined) ) {
113
- if (targetProductName) {
114
- if (config.buildSettings[prop] !== undefined && config.buildSettings[PRODUCT_NAME_PROJECT_KEY] == targetProductName) {
115
- target = config.buildSettings[prop];
116
- }
117
- } else {
118
- if (config.buildSettings[prop] !== undefined &&
119
- //exclude tvOS projects
120
- config.buildSettings[TV_OS_DEPLOYMENT_TARGET_PROPERTY_NAME] == undefined &&
121
- //exclude test app
122
- config.buildSettings[TEST_HOST_PROPERTY_NAME] == undefined) {
123
- target = config.buildSettings[prop];
124
- }
125
- }
126
- }
127
- }
128
- }
129
- return target;
130
- }