@appzung/react-native-code-push 10.1.1 → 10.2.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/android/app/src/main/java/com/appzung/codepush/react/CodePushConstants.java +2 -0
- package/android/app/src/main/java/com/appzung/codepush/react/CodePushNativeModule.java +62 -0
- package/ios/CodePush/CodePush.h +2 -0
- package/ios/CodePush/CodePush.m +28 -0
- package/ios/CodePush/CodePushConfig.m +50 -0
- package/lib/commonjs/CodePush.js +5 -0
- package/lib/commonjs/CodePush.js.map +1 -1
- package/lib/commonjs/allowRestart.js +4 -2
- package/lib/commonjs/allowRestart.js.map +1 -1
- package/lib/commonjs/checkForUpdates.js +3 -2
- package/lib/commonjs/checkForUpdates.js.map +1 -1
- package/lib/commonjs/clearUpdates.js +4 -2
- package/lib/commonjs/clearUpdates.js.map +1 -1
- package/lib/commonjs/dataTransmission.js +28 -0
- package/lib/commonjs/dataTransmission.js.map +1 -0
- package/lib/commonjs/disallowRestart.js +4 -2
- package/lib/commonjs/disallowRestart.js.map +1 -1
- package/lib/commonjs/enums/LogLevel.enum.js +17 -0
- package/lib/commonjs/enums/LogLevel.enum.js.map +1 -0
- package/lib/commonjs/index.js +60 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/internals/CodePushApiSdk.js +23 -1
- package/lib/commonjs/internals/CodePushApiSdk.js.map +1 -1
- package/lib/commonjs/internals/CodePushApiSdk.types.js.map +1 -1
- package/lib/commonjs/internals/RemotePackageImplementation.js +2 -1
- package/lib/commonjs/internals/RemotePackageImplementation.js.map +1 -1
- package/lib/commonjs/internals/logger.js +51 -0
- package/lib/commonjs/internals/logger.js.map +1 -0
- package/lib/commonjs/internals/shouldUpdateBeIgnored.js +6 -5
- package/lib/commonjs/internals/shouldUpdateBeIgnored.js.map +1 -1
- package/lib/commonjs/internals/utils/log.js +10 -3
- package/lib/commonjs/internals/utils/log.js.map +1 -1
- package/lib/commonjs/internals/utils/requestFetchAdapter.js +5 -0
- package/lib/commonjs/internals/utils/requestFetchAdapter.js.map +1 -1
- package/lib/commonjs/internals/version.js +1 -1
- package/lib/commonjs/logLevel.js +15 -0
- package/lib/commonjs/logLevel.js.map +1 -0
- package/lib/commonjs/logger.js +19 -0
- package/lib/commonjs/logger.js.map +1 -0
- package/lib/commonjs/notifyAppReady.js +17 -8
- package/lib/commonjs/notifyAppReady.js.map +1 -1
- package/lib/commonjs/restartApp.js +2 -2
- package/lib/commonjs/restartApp.js.map +1 -1
- package/lib/commonjs/sync.js +32 -27
- package/lib/commonjs/sync.js.map +1 -1
- package/lib/commonjs/telemetry.js +28 -0
- package/lib/commonjs/telemetry.js.map +1 -0
- package/lib/module/CodePush.js +5 -0
- package/lib/module/CodePush.js.map +1 -1
- package/lib/module/allowRestart.js +3 -1
- package/lib/module/allowRestart.js.map +1 -1
- package/lib/module/checkForUpdates.js +3 -2
- package/lib/module/checkForUpdates.js.map +1 -1
- package/lib/module/clearUpdates.js +3 -1
- package/lib/module/clearUpdates.js.map +1 -1
- package/lib/module/dataTransmission.js +24 -0
- package/lib/module/dataTransmission.js.map +1 -0
- package/lib/module/disallowRestart.js +3 -1
- package/lib/module/disallowRestart.js.map +1 -1
- package/lib/module/enums/LogLevel.enum.js +13 -0
- package/lib/module/enums/LogLevel.enum.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/internals/CodePushApiSdk.js +23 -1
- package/lib/module/internals/CodePushApiSdk.js.map +1 -1
- package/lib/module/internals/CodePushApiSdk.types.js.map +1 -1
- package/lib/module/internals/RemotePackageImplementation.js +2 -1
- package/lib/module/internals/RemotePackageImplementation.js.map +1 -1
- package/lib/module/internals/logger.js +44 -0
- package/lib/module/internals/logger.js.map +1 -0
- package/lib/module/internals/shouldUpdateBeIgnored.js +6 -5
- package/lib/module/internals/shouldUpdateBeIgnored.js.map +1 -1
- package/lib/module/internals/utils/log.js +11 -3
- package/lib/module/internals/utils/log.js.map +1 -1
- package/lib/module/internals/utils/requestFetchAdapter.js +5 -0
- package/lib/module/internals/utils/requestFetchAdapter.js.map +1 -1
- package/lib/module/internals/version.js +1 -1
- package/lib/module/logLevel.js +9 -0
- package/lib/module/logLevel.js.map +1 -0
- package/lib/module/logger.js +4 -0
- package/lib/module/logger.js.map +1 -0
- package/lib/module/notifyAppReady.js +17 -8
- package/lib/module/notifyAppReady.js.map +1 -1
- package/lib/module/restartApp.js +2 -2
- package/lib/module/restartApp.js.map +1 -1
- package/lib/module/sync.js +32 -27
- package/lib/module/sync.js.map +1 -1
- package/lib/module/telemetry.js +24 -0
- package/lib/module/telemetry.js.map +1 -0
- package/lib/typescript/commonjs/src/CodePush.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/allowRestart.d.ts +1 -1
- package/lib/typescript/commonjs/src/allowRestart.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/checkForUpdates.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/clearUpdates.d.ts +1 -1
- package/lib/typescript/commonjs/src/clearUpdates.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/dataTransmission.d.ts +13 -0
- package/lib/typescript/commonjs/src/dataTransmission.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/disallowRestart.d.ts +1 -1
- package/lib/typescript/commonjs/src/disallowRestart.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/enums/LogLevel.enum.d.ts +10 -0
- package/lib/typescript/commonjs/src/enums/LogLevel.enum.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +5 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/internals/CodePushApiSdk.d.ts +3 -1
- package/lib/typescript/commonjs/src/internals/CodePushApiSdk.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/internals/CodePushApiSdk.types.d.ts +2 -0
- package/lib/typescript/commonjs/src/internals/CodePushApiSdk.types.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/internals/RNAppZungCodePushModuleSpec.d.ts +4 -0
- package/lib/typescript/commonjs/src/internals/RNAppZungCodePushModuleSpec.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/internals/RemotePackageImplementation.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/internals/logger.d.ts +33 -0
- package/lib/typescript/commonjs/src/internals/logger.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/internals/shouldUpdateBeIgnored.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/internals/utils/log.d.ts +2 -1
- package/lib/typescript/commonjs/src/internals/utils/log.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/internals/utils/requestFetchAdapter.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/internals/version.d.ts +1 -1
- package/lib/typescript/commonjs/src/logLevel.d.ts +4 -0
- package/lib/typescript/commonjs/src/logLevel.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/logger.d.ts +3 -0
- package/lib/typescript/commonjs/src/logger.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/notifyAppReady.d.ts +2 -0
- package/lib/typescript/commonjs/src/notifyAppReady.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/restartApp.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/sync.d.ts +2 -0
- package/lib/typescript/commonjs/src/sync.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/telemetry.d.ts +13 -0
- package/lib/typescript/commonjs/src/telemetry.d.ts.map +1 -0
- package/lib/typescript/module/src/CodePush.d.ts.map +1 -1
- package/lib/typescript/module/src/allowRestart.d.ts +1 -1
- package/lib/typescript/module/src/allowRestart.d.ts.map +1 -1
- package/lib/typescript/module/src/checkForUpdates.d.ts.map +1 -1
- package/lib/typescript/module/src/clearUpdates.d.ts +1 -1
- package/lib/typescript/module/src/clearUpdates.d.ts.map +1 -1
- package/lib/typescript/module/src/dataTransmission.d.ts +13 -0
- package/lib/typescript/module/src/dataTransmission.d.ts.map +1 -0
- package/lib/typescript/module/src/disallowRestart.d.ts +1 -1
- package/lib/typescript/module/src/disallowRestart.d.ts.map +1 -1
- package/lib/typescript/module/src/enums/LogLevel.enum.d.ts +10 -0
- package/lib/typescript/module/src/enums/LogLevel.enum.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +5 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/internals/CodePushApiSdk.d.ts +3 -1
- package/lib/typescript/module/src/internals/CodePushApiSdk.d.ts.map +1 -1
- package/lib/typescript/module/src/internals/CodePushApiSdk.types.d.ts +2 -0
- package/lib/typescript/module/src/internals/CodePushApiSdk.types.d.ts.map +1 -1
- package/lib/typescript/module/src/internals/RNAppZungCodePushModuleSpec.d.ts +4 -0
- package/lib/typescript/module/src/internals/RNAppZungCodePushModuleSpec.d.ts.map +1 -1
- package/lib/typescript/module/src/internals/RemotePackageImplementation.d.ts.map +1 -1
- package/lib/typescript/module/src/internals/logger.d.ts +33 -0
- package/lib/typescript/module/src/internals/logger.d.ts.map +1 -0
- package/lib/typescript/module/src/internals/shouldUpdateBeIgnored.d.ts.map +1 -1
- package/lib/typescript/module/src/internals/utils/log.d.ts +2 -1
- package/lib/typescript/module/src/internals/utils/log.d.ts.map +1 -1
- package/lib/typescript/module/src/internals/utils/requestFetchAdapter.d.ts.map +1 -1
- package/lib/typescript/module/src/internals/version.d.ts +1 -1
- package/lib/typescript/module/src/logLevel.d.ts +4 -0
- package/lib/typescript/module/src/logLevel.d.ts.map +1 -0
- package/lib/typescript/module/src/logger.d.ts +3 -0
- package/lib/typescript/module/src/logger.d.ts.map +1 -0
- package/lib/typescript/module/src/notifyAppReady.d.ts +2 -0
- package/lib/typescript/module/src/notifyAppReady.d.ts.map +1 -1
- package/lib/typescript/module/src/restartApp.d.ts.map +1 -1
- package/lib/typescript/module/src/sync.d.ts +2 -0
- package/lib/typescript/module/src/sync.d.ts.map +1 -1
- package/lib/typescript/module/src/telemetry.d.ts +13 -0
- package/lib/typescript/module/src/telemetry.d.ts.map +1 -0
- package/package.json +23 -14
- package/scripts/generateBundledResourcesHash.js +73 -68
- package/scripts/getFilesInFolder.js +12 -12
- package/scripts/recordFilesBeforeBundleCommand.js +19 -20
- package/src/CodePush.tsx +6 -0
- package/src/allowRestart.ts +3 -1
- package/src/checkForUpdates.ts +3 -2
- package/src/clearUpdates.ts +3 -1
- package/src/dataTransmission.ts +21 -0
- package/src/disallowRestart.ts +3 -1
- package/src/enums/LogLevel.enum.ts +9 -0
- package/src/index.ts +5 -0
- package/src/internals/CodePushApiSdk.ts +27 -0
- package/src/internals/CodePushApiSdk.types.ts +2 -0
- package/src/internals/RNAppZungCodePushModuleSpec.ts +6 -0
- package/src/internals/RemotePackageImplementation.ts +2 -1
- package/src/internals/logger.ts +46 -0
- package/src/internals/shouldUpdateBeIgnored.ts +6 -5
- package/src/internals/utils/log.ts +13 -3
- package/src/internals/utils/requestFetchAdapter.ts +8 -0
- package/src/internals/version.ts +1 -1
- package/src/logLevel.ts +9 -0
- package/src/logger.ts +2 -0
- package/src/notifyAppReady.ts +19 -7
- package/src/restartApp.ts +2 -2
- package/src/sync.ts +38 -26
- package/src/telemetry.ts +21 -0
- package/typedoc.json +0 -9
|
@@ -11,16 +11,16 @@
|
|
|
11
11
|
* manifest to generate the final hash, which is saved to the APK's assets directory.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
var crypto = require(
|
|
15
|
-
var fs = require(
|
|
16
|
-
var path = require(
|
|
14
|
+
var crypto = require('crypto');
|
|
15
|
+
var fs = require('fs');
|
|
16
|
+
var path = require('path');
|
|
17
17
|
|
|
18
|
-
var getFilesInFolder = require(
|
|
18
|
+
var getFilesInFolder = require('./getFilesInFolder');
|
|
19
19
|
|
|
20
|
-
var CODE_PUSH_FOLDER_PREFIX =
|
|
21
|
-
var CODE_PUSH_HASH_FILE_NAME =
|
|
22
|
-
var CODE_PUSH_HASH_OLD_FILE_NAME =
|
|
23
|
-
var HASH_ALGORITHM =
|
|
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
24
|
|
|
25
25
|
var resourcesDir = process.argv[2];
|
|
26
26
|
var jsBundleFilePath = process.argv[3];
|
|
@@ -30,8 +30,8 @@ var tempFileName = process.argv[5];
|
|
|
30
30
|
var oldFileToModifiedTimeMap = {};
|
|
31
31
|
var tempFileLocalPath = null;
|
|
32
32
|
if (tempFileName) {
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
tempFileLocalPath = path.join(require('os').tmpdir(), tempFileName);
|
|
34
|
+
oldFileToModifiedTimeMap = require(tempFileLocalPath);
|
|
35
35
|
}
|
|
36
36
|
var resourceFiles = [];
|
|
37
37
|
|
|
@@ -39,87 +39,92 @@ getFilesInFolder(resourcesDir, resourceFiles);
|
|
|
39
39
|
|
|
40
40
|
var newFileToModifiedTimeMap = {};
|
|
41
41
|
|
|
42
|
-
resourceFiles.forEach(function(resourceFile) {
|
|
43
|
-
|
|
42
|
+
resourceFiles.forEach(function (resourceFile) {
|
|
43
|
+
newFileToModifiedTimeMap[resourceFile.path.substring(resourcesDir.length)] = resourceFile.mtime;
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
var bundleGeneratedAssetFiles = [];
|
|
47
47
|
|
|
48
48
|
for (var newFilePath in newFileToModifiedTimeMap) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
if (
|
|
50
|
+
!oldFileToModifiedTimeMap[newFilePath] ||
|
|
51
|
+
oldFileToModifiedTimeMap[newFilePath] < newFileToModifiedTimeMap[newFilePath].getTime()
|
|
52
|
+
) {
|
|
53
|
+
bundleGeneratedAssetFiles.push(newFilePath);
|
|
54
|
+
}
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
var manifest = [];
|
|
55
58
|
|
|
56
59
|
if (bundleGeneratedAssetFiles.length) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
60
|
+
bundleGeneratedAssetFiles.forEach(function (assetFile) {
|
|
61
|
+
// Generate hash for each asset file
|
|
62
|
+
addFileToManifest(resourcesDir, assetFile, manifest, function () {
|
|
63
|
+
if (manifest.length === bundleGeneratedAssetFiles.length) {
|
|
64
|
+
addJsBundleAndMetaToManifest();
|
|
65
|
+
}
|
|
64
66
|
});
|
|
67
|
+
});
|
|
65
68
|
} else {
|
|
66
|
-
|
|
69
|
+
addJsBundleAndMetaToManifest();
|
|
67
70
|
}
|
|
68
71
|
|
|
69
72
|
function addJsBundleAndMetaToManifest() {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
fs.unlinkSync(oldSavedResourcesManifestPath);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
73
|
+
addFileToManifest(path.dirname(jsBundleFilePath), path.basename(jsBundleFilePath), manifest, function () {
|
|
74
|
+
var jsBundleMetaFilePath = jsBundleFilePath + '.meta';
|
|
75
|
+
addFileToManifest(path.dirname(jsBundleMetaFilePath), path.basename(jsBundleMetaFilePath), manifest, function () {
|
|
76
|
+
manifest = manifest.sort();
|
|
77
|
+
var finalHash = crypto.createHash(HASH_ALGORITHM).update(JSON.stringify(manifest)).digest('hex');
|
|
78
|
+
|
|
79
|
+
console.log(finalHash);
|
|
80
|
+
|
|
81
|
+
var savedResourcesManifestPath = assetsDir + '/' + CODE_PUSH_HASH_FILE_NAME;
|
|
82
|
+
fs.writeFileSync(savedResourcesManifestPath, finalHash);
|
|
83
|
+
|
|
84
|
+
// "CodePushHash.json" file name breaks flow type checking.
|
|
85
|
+
// To fix the issue we need to delete "CodePushHash.json" file and
|
|
86
|
+
// use "CodePushHash" file name instead to store the hash value.
|
|
87
|
+
// Relates to https://github.com/microsoft/react-native-code-push/issues/577
|
|
88
|
+
var oldSavedResourcesManifestPath = assetsDir + '/' + CODE_PUSH_HASH_OLD_FILE_NAME;
|
|
89
|
+
if (fs.existsSync(oldSavedResourcesManifestPath)) {
|
|
90
|
+
fs.unlinkSync(oldSavedResourcesManifestPath);
|
|
91
|
+
}
|
|
92
92
|
});
|
|
93
|
+
});
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
function addFileToManifest(folder, assetFile, manifest, done) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
97
|
+
var fullFilePath = path.join(folder, assetFile);
|
|
98
|
+
if (!fileExists(fullFilePath)) {
|
|
99
|
+
done();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
var readStream = fs.createReadStream(path.join(folder, assetFile));
|
|
104
|
+
var hashStream = crypto.createHash(HASH_ALGORITHM);
|
|
105
|
+
|
|
106
|
+
readStream
|
|
107
|
+
.pipe(hashStream)
|
|
108
|
+
.on('error', function (error) {
|
|
109
|
+
throw error;
|
|
110
|
+
})
|
|
111
|
+
.on('finish', function () {
|
|
112
|
+
hashStream.end();
|
|
113
|
+
var buffer = hashStream.read();
|
|
114
|
+
var fileHash = buffer.toString('hex');
|
|
115
|
+
manifest.push(path.join(CODE_PUSH_FOLDER_PREFIX, assetFile).replace(/\\/g, '/') + ':' + fileHash);
|
|
116
|
+
done();
|
|
117
|
+
});
|
|
116
118
|
}
|
|
117
119
|
|
|
118
120
|
function fileExists(file) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
+
try {
|
|
122
|
+
return fs.statSync(file).isFile();
|
|
123
|
+
} catch {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
121
126
|
}
|
|
122
127
|
|
|
123
128
|
if (tempFileLocalPath) {
|
|
124
|
-
|
|
129
|
+
fs.unlinkSync(tempFileLocalPath);
|
|
125
130
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
var fs = require(
|
|
2
|
-
var path = require(
|
|
1
|
+
var fs = require('fs');
|
|
2
|
+
var path = require('path');
|
|
3
3
|
|
|
4
4
|
// Utility function that collects the stats of every file in a directory
|
|
5
5
|
// as well as in its subdirectories.
|
|
6
6
|
function getFilesInFolder(folderName, fileList) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
17
|
}
|
|
18
18
|
|
|
19
19
|
module.exports = getFilesInFolder;
|
|
@@ -1,41 +1,40 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* This script creates a snapshot of the contents in the resource directory
|
|
3
3
|
* by creating a map with the modified time of all the files in the directory
|
|
4
|
-
* and saving it to a temp file. This snapshot is later referenced in
|
|
4
|
+
* and saving it to a temp file. This snapshot is later referenced in
|
|
5
5
|
* "generatePackageHash.js" to figure out which files have changed or were
|
|
6
6
|
* newly generated by the "react-native bundle" command.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
var fs = require(
|
|
10
|
-
var path = require(
|
|
11
|
-
|
|
12
|
-
var getFilesInFolder = require("./getFilesInFolder");
|
|
9
|
+
var fs = require('fs');
|
|
10
|
+
var path = require('path');
|
|
13
11
|
|
|
12
|
+
var getFilesInFolder = require('./getFilesInFolder');
|
|
14
13
|
|
|
15
14
|
var resourcesDir = process.argv[2];
|
|
16
15
|
var tempFileName = process.argv[3];
|
|
17
16
|
|
|
18
|
-
var tempFileLocalPath = path.join(require(
|
|
17
|
+
var tempFileLocalPath = path.join(require('os').tmpdir(), tempFileName);
|
|
19
18
|
var resourceFiles = [];
|
|
20
19
|
|
|
21
20
|
try {
|
|
22
|
-
|
|
23
|
-
} catch(error) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
getFilesInFolder(resourcesDir, resourceFiles);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
var targetPathNotFoundExceptionMessage = '\nResources directory path does not exist.\n';
|
|
24
|
+
targetPathNotFoundExceptionMessage += "Unable to find '" + resourcesDir;
|
|
25
|
+
targetPathNotFoundExceptionMessage += "' directory. Please check version of Android Plugin for Gradle.";
|
|
26
|
+
error.message += targetPathNotFoundExceptionMessage;
|
|
27
|
+
throw error;
|
|
29
28
|
}
|
|
30
29
|
|
|
31
30
|
var fileToModifiedTimeMap = {};
|
|
32
31
|
|
|
33
|
-
resourceFiles.forEach(function(resourceFile) {
|
|
34
|
-
|
|
32
|
+
resourceFiles.forEach(function (resourceFile) {
|
|
33
|
+
fileToModifiedTimeMap[resourceFile.path.substring(resourcesDir.length)] = resourceFile.mtime.getTime();
|
|
35
34
|
});
|
|
36
35
|
|
|
37
|
-
fs.writeFile(tempFileLocalPath, JSON.stringify(fileToModifiedTimeMap), function(err) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
});
|
|
36
|
+
fs.writeFile(tempFileLocalPath, JSON.stringify(fileToModifiedTimeMap), function (err) {
|
|
37
|
+
if (err) {
|
|
38
|
+
throw err;
|
|
39
|
+
}
|
|
40
|
+
});
|
package/src/CodePush.tsx
CHANGED
|
@@ -2,6 +2,8 @@ import hoistStatics from 'hoist-non-react-statics';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { AppState } from 'react-native';
|
|
4
4
|
import { CheckFrequency } from './enums/CheckFrequency.enum';
|
|
5
|
+
import { LogLevel } from './enums/LogLevel.enum';
|
|
6
|
+
import { log } from './internals/utils/log';
|
|
5
7
|
import { notifyAppReady } from './notifyAppReady';
|
|
6
8
|
import { sync } from './sync';
|
|
7
9
|
import type {
|
|
@@ -54,6 +56,8 @@ export function withCodePush<P extends object>(optionsOrComponent: CodePushOptio
|
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
componentDidMount() {
|
|
59
|
+
log(LogLevel.DEBUG, `withCodePush ${JSON.stringify(options)}`);
|
|
60
|
+
|
|
57
61
|
if (options.checkFrequency === CheckFrequency.MANUAL) {
|
|
58
62
|
notifyAppReady();
|
|
59
63
|
} else {
|
|
@@ -75,11 +79,13 @@ export function withCodePush<P extends object>(optionsOrComponent: CodePushOptio
|
|
|
75
79
|
rootComponentInstance.codePushOnBinaryVersionMismatch.bind(rootComponentInstance);
|
|
76
80
|
}
|
|
77
81
|
|
|
82
|
+
log(LogLevel.DEBUG, `sync on mount`);
|
|
78
83
|
sync(options, syncStatusCallback, downloadProgressCallback, handleBinaryVersionMismatchCallback);
|
|
79
84
|
|
|
80
85
|
if (options.checkFrequency === CheckFrequency.ON_APP_RESUME) {
|
|
81
86
|
AppState.addEventListener('change', (newState: string) => {
|
|
82
87
|
if (newState === 'active') {
|
|
88
|
+
log(LogLevel.DEBUG, `sync on active appState`);
|
|
83
89
|
sync(options, syncStatusCallback, downloadProgressCallback);
|
|
84
90
|
}
|
|
85
91
|
});
|
package/src/allowRestart.ts
CHANGED
|
@@ -5,4 +5,6 @@ import { NativeRNAppZungCodePushModule } from './internals/NativeRNAppZungCodePu
|
|
|
5
5
|
*
|
|
6
6
|
* This is an advanced API and is only necessary if your app explicitly disallowed restarts via the `disallowRestart` method.
|
|
7
7
|
*/
|
|
8
|
-
export
|
|
8
|
+
export function allowRestart() {
|
|
9
|
+
return NativeRNAppZungCodePushModule.allow();
|
|
10
|
+
}
|
package/src/checkForUpdates.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Platform } from 'react-native';
|
|
2
|
+
import { LogLevel } from './enums/LogLevel.enum';
|
|
2
3
|
import { CodePushApiSdk } from './internals/CodePushApiSdk';
|
|
3
4
|
import type { ApiSdkQueryUpdatePackageInfo } from './internals/CodePushApiSdk.types';
|
|
4
5
|
import { NativeRNAppZungCodePushModule } from './internals/NativeRNAppZungCodePushModule';
|
|
@@ -38,7 +39,7 @@ export async function checkForUpdate(
|
|
|
38
39
|
* release channels (e.g. an early access release channel for insiders).
|
|
39
40
|
*/
|
|
40
41
|
const config: Configuration = releaseChannelPublicId ? { ...nativeConfig, releaseChannelPublicId } : nativeConfig;
|
|
41
|
-
const sdk = new CodePushApiSdk(requestFetchAdapter, config);
|
|
42
|
+
const sdk = new CodePushApiSdk(requestFetchAdapter, log, config);
|
|
42
43
|
|
|
43
44
|
const localPackage = await getCurrentPackage();
|
|
44
45
|
|
|
@@ -84,7 +85,7 @@ export async function checkForUpdate(
|
|
|
84
85
|
throw new Error('updateAppVersion should never be false');
|
|
85
86
|
}
|
|
86
87
|
|
|
87
|
-
log('An update is available but it is not targeting the binary version of your app.');
|
|
88
|
+
log(LogLevel.INFO, 'An update is available but it is not targeting the binary version of your app.');
|
|
88
89
|
handleBinaryVersionMismatchCallback?.(update);
|
|
89
90
|
|
|
90
91
|
return null;
|
package/src/clearUpdates.ts
CHANGED
|
@@ -7,4 +7,6 @@ import { NativeRNAppZungCodePushModule } from './internals/NativeRNAppZungCodePu
|
|
|
7
7
|
* Note: we don’t recommend using this method in scenarios other than that (CodePush will call
|
|
8
8
|
* this method automatically when needed in other cases) as it could lead to unpredictable behavior.
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
10
|
+
export function clearUpdates() {
|
|
11
|
+
return NativeRNAppZungCodePushModule.clearUpdates();
|
|
12
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { NativeRNAppZungCodePushModule } from './internals/NativeRNAppZungCodePushModule';
|
|
2
|
+
import { reloadCachedConfiguration } from './internals/getConfiguration';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Controls data transmission for CodePush. This may be used for privacy optIn.
|
|
6
|
+
*
|
|
7
|
+
* @param enabled - When false, disables all external API calls to CodePush servers. Checking for updates will be disabled.
|
|
8
|
+
*/
|
|
9
|
+
export async function setDataTransmissionEnabled(enabled: boolean): Promise<void> {
|
|
10
|
+
await NativeRNAppZungCodePushModule.setDataTransmissionEnabled(enabled);
|
|
11
|
+
await reloadCachedConfiguration();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Gets the current data transmission status.
|
|
16
|
+
*
|
|
17
|
+
* When setDataTransmissionEnabled has never been called, returns the default value set in your configuration.
|
|
18
|
+
*/
|
|
19
|
+
export function getDataTransmissionEnabled(): Promise<boolean> {
|
|
20
|
+
return NativeRNAppZungCodePushModule.getDataTransmissionEnabled();
|
|
21
|
+
}
|
package/src/disallowRestart.ts
CHANGED
|
@@ -5,4 +5,6 @@ import { NativeRNAppZungCodePushModule } from './internals/NativeRNAppZungCodePu
|
|
|
5
5
|
*
|
|
6
6
|
* This is an advanced API, and is useful when a component within your app (for example an onboarding process) needs to ensure that no end-user interruptions can occur during its lifetime.
|
|
7
7
|
*/
|
|
8
|
-
export
|
|
8
|
+
export function disallowRestart() {
|
|
9
|
+
return NativeRNAppZungCodePushModule.disallow();
|
|
10
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,10 @@ export * from './restartApp';
|
|
|
10
10
|
export * from './sync';
|
|
11
11
|
export * from './getClientUniqueId';
|
|
12
12
|
export * from './resetClientUniqueId';
|
|
13
|
+
export * from './logLevel';
|
|
14
|
+
export * from './logger';
|
|
15
|
+
export * from './telemetry';
|
|
16
|
+
export * from './dataTransmission';
|
|
13
17
|
|
|
14
18
|
export * from './types';
|
|
15
19
|
|
|
@@ -18,3 +22,4 @@ export * from './enums/InstallMode.enum';
|
|
|
18
22
|
export * from './enums/UpdateState.enum';
|
|
19
23
|
export { DeploymentStatus } from './internals/CodePushApiSdk.types';
|
|
20
24
|
export * from './enums/CheckFrequency.enum';
|
|
25
|
+
export * from './enums/LogLevel.enum';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LogLevel } from '../enums/LogLevel.enum';
|
|
1
2
|
import { CodePushError, CodePushHttpError } from './CodePushApiSdk.errors';
|
|
2
3
|
import {
|
|
3
4
|
type ApiSdkConfiguration,
|
|
@@ -22,6 +23,7 @@ export class CodePushApiSdk {
|
|
|
22
23
|
|
|
23
24
|
constructor(
|
|
24
25
|
private readonly httpRequester: Http.Requester,
|
|
26
|
+
private readonly log: (level: LogLevel, message: string) => void,
|
|
25
27
|
configuration: ApiSdkConfiguration,
|
|
26
28
|
) {
|
|
27
29
|
this.configuration = { ...configuration };
|
|
@@ -34,6 +36,11 @@ export class CodePushApiSdk {
|
|
|
34
36
|
async queryUpdateWithCurrentPackage(
|
|
35
37
|
currentPackageInfo: ApiSdkQueryUpdatePackageInfo,
|
|
36
38
|
): Promise<ApiSdkRemotePackage | ApiSdkNativeUpdateNotification | null> {
|
|
39
|
+
if (!this.configuration.dataTransmissionEnabled) {
|
|
40
|
+
this.log(LogLevel.DEBUG, 'Skipped querying for update because data transmission is disabled');
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
37
44
|
const query: CheckUpdateRequestInput = {
|
|
38
45
|
deployment_key: this.configuration.releaseChannelPublicId,
|
|
39
46
|
app_version: currentPackageInfo.appVersion,
|
|
@@ -86,6 +93,16 @@ export class CodePushApiSdk {
|
|
|
86
93
|
previousLabelOrAppVersion: string | null,
|
|
87
94
|
previousDeploymentKey: string | null,
|
|
88
95
|
): Promise<void> {
|
|
96
|
+
if (!this.configuration.dataTransmissionEnabled) {
|
|
97
|
+
this.log(LogLevel.DEBUG, 'Skipped reporting deploy status because data transmission is disabled');
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!this.configuration.telemetryEnabled) {
|
|
102
|
+
this.log(LogLevel.DEBUG, 'Skipped reporting deploy status because telemetry is disabled');
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
89
106
|
const requestBody: ReportDeployInput = {
|
|
90
107
|
app_version: this.configuration.appVersion,
|
|
91
108
|
deployment_key: this.configuration.releaseChannelPublicId,
|
|
@@ -116,6 +133,16 @@ export class CodePushApiSdk {
|
|
|
116
133
|
}
|
|
117
134
|
|
|
118
135
|
async reportStatusDownload(downloadedPackage: ApiSdkDownloadReportPackageInfo): Promise<void> {
|
|
136
|
+
if (!this.configuration.dataTransmissionEnabled) {
|
|
137
|
+
this.log(LogLevel.DEBUG, 'Skipped reporting download because data transmission is disabled');
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (!this.configuration.telemetryEnabled) {
|
|
142
|
+
this.log(LogLevel.DEBUG, 'Skipped reporting download because telemetry is disabled');
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
119
146
|
const requestBody: ReportDownloadInput = {
|
|
120
147
|
client_unique_id: this.configuration.clientUniqueId,
|
|
121
148
|
deployment_key: this.configuration.releaseChannelPublicId,
|
|
@@ -52,4 +52,10 @@ export interface Spec extends TurboModule {
|
|
|
52
52
|
|
|
53
53
|
isFirstRun(packageHash: string): Promise<boolean>;
|
|
54
54
|
isFailedUpdate(packageHash: string): Promise<boolean>;
|
|
55
|
+
|
|
56
|
+
setTelemetryEnabled(enabled: boolean): Promise<void>;
|
|
57
|
+
getTelemetryEnabled(): Promise<boolean>;
|
|
58
|
+
|
|
59
|
+
setDataTransmissionEnabled(enabled: boolean): Promise<void>;
|
|
60
|
+
getDataTransmissionEnabled(): Promise<boolean>;
|
|
55
61
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NativeEventEmitter } from 'react-native';
|
|
2
|
+
import { LogLevel } from '../enums/LogLevel.enum';
|
|
2
3
|
import type { DownloadProgressCallback, LocalPackage, RemotePackage } from '../types';
|
|
3
4
|
import type { ApiSdkDownloadReportPackageInfo } from './CodePushApiSdk.types';
|
|
4
5
|
import { LocalPackageImplementation } from './LocalPackageImplementation';
|
|
@@ -42,7 +43,7 @@ export class RemotePackageImpl implements RemotePackage {
|
|
|
42
43
|
const reportPromise = reportStatusDownload({
|
|
43
44
|
label: this.label,
|
|
44
45
|
}).catch((error) => {
|
|
45
|
-
log(`Report download status failed: ${error}`);
|
|
46
|
+
log(LogLevel.ERROR, `Report download status failed: ${error}`);
|
|
46
47
|
});
|
|
47
48
|
await Promise.race([timeoutPromise, reportPromise]);
|
|
48
49
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { LogLevel } from '../enums/LogLevel.enum';
|
|
2
|
+
|
|
3
|
+
export type LoggerFunction = (level: LogLevel, message: string) => void;
|
|
4
|
+
|
|
5
|
+
const defaultLogger: LoggerFunction = (_level: LogLevel, message: string): void => {
|
|
6
|
+
console.log(`[CodePush] ${message}`);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
let currentLogger: LoggerFunction = defaultLogger;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Set a custom logger function to handle all CodePush logs
|
|
13
|
+
*
|
|
14
|
+
* @param logger A function that takes a log level and message and handles the logging
|
|
15
|
+
* @example
|
|
16
|
+
* ```
|
|
17
|
+
* import { setLogger, LogLevel } from '@appzung/react-native-code-push';
|
|
18
|
+
*
|
|
19
|
+
* // Custom logger that sends critical logs to a crash reporting service
|
|
20
|
+
* setLogger((level, message) => {
|
|
21
|
+
* // Always log to console
|
|
22
|
+
* console.log(`[CodePush] ${message}`);
|
|
23
|
+
*
|
|
24
|
+
* // Send error logs to crash reporting
|
|
25
|
+
* if (level === LogLevel.ERROR) {
|
|
26
|
+
* MyCrashReportingService.log(`CodePush error: ${message}`);
|
|
27
|
+
* }
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export const setLogger = (logger: LoggerFunction): void => {
|
|
32
|
+
currentLogger = logger;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Get the current logger function
|
|
37
|
+
* @returns The current logger function
|
|
38
|
+
*/
|
|
39
|
+
export const getLogger = (): LoggerFunction => currentLogger;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Reset the logger to the default implementation
|
|
43
|
+
*/
|
|
44
|
+
export const resetLogger = (): void => {
|
|
45
|
+
currentLogger = defaultLogger;
|
|
46
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LogLevel } from '../enums/LogLevel.enum';
|
|
1
2
|
import type { RemotePackage, RollbackRetryOptions, SyncOptions } from '../types';
|
|
2
3
|
import { NativeRNAppZungCodePushModule } from './NativeRNAppZungCodePushModule';
|
|
3
4
|
import type { LatestRollbackInfo } from './types';
|
|
@@ -20,17 +21,17 @@ function validateLatestRollbackInfo(latestRollbackInfo: LatestRollbackInfo, pack
|
|
|
20
21
|
|
|
21
22
|
function validateRollbackRetryOptions(rollbackRetryOptions: RollbackRetryOptions) {
|
|
22
23
|
if (typeof rollbackRetryOptions.delayInHours !== 'number') {
|
|
23
|
-
log("The 'delayInHours' rollback retry parameter must be a number.");
|
|
24
|
+
log(LogLevel.ERROR, "The 'delayInHours' rollback retry parameter must be a number.");
|
|
24
25
|
return false;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
if (typeof rollbackRetryOptions.maxRetryAttempts !== 'number') {
|
|
28
|
-
log("The 'maxRetryAttempts' rollback retry parameter must be a number.");
|
|
29
|
+
log(LogLevel.ERROR, "The 'maxRetryAttempts' rollback retry parameter must be a number.");
|
|
29
30
|
return false;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
if (rollbackRetryOptions.maxRetryAttempts < 1) {
|
|
33
|
-
log("The 'maxRetryAttempts' rollback retry parameter cannot be less then 1.");
|
|
34
|
+
log(LogLevel.ERROR, "The 'maxRetryAttempts' rollback retry parameter cannot be less then 1.");
|
|
34
35
|
return false;
|
|
35
36
|
}
|
|
36
37
|
|
|
@@ -61,14 +62,14 @@ export async function shouldUpdateBeIgnored(remotePackage: RemotePackage | null
|
|
|
61
62
|
|
|
62
63
|
const latestRollbackInfo = await NativeRNAppZungCodePushModule.getLatestRollbackInfo();
|
|
63
64
|
if (!validateLatestRollbackInfo(latestRollbackInfo, remotePackage.packageHash)) {
|
|
64
|
-
log('The latest rollback info is not valid.');
|
|
65
|
+
log(LogLevel.ERROR, 'The latest rollback info is not valid.');
|
|
65
66
|
return true;
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
const { delayInHours, maxRetryAttempts } = rollbackRetryOptions;
|
|
69
70
|
const hoursSinceLatestRollback = (Date.now() - latestRollbackInfo.time) / (1000 * 60 * 60);
|
|
70
71
|
if (hoursSinceLatestRollback >= delayInHours && maxRetryAttempts >= latestRollbackInfo.count) {
|
|
71
|
-
log('Previous rollback should be ignored due to rollback retry options.');
|
|
72
|
+
log(LogLevel.INFO, 'Previous rollback should be ignored due to rollback retry options.');
|
|
72
73
|
return false;
|
|
73
74
|
}
|
|
74
75
|
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { LogLevel } from '../../enums/LogLevel.enum';
|
|
2
|
+
import { getLogLevel } from '../../logLevel';
|
|
3
|
+
import { getLogger } from '../logger';
|
|
4
|
+
|
|
5
|
+
/* Logs messages using the configured logger */
|
|
6
|
+
export function log(level: LogLevel, message: string): void {
|
|
7
|
+
const currentLogLevel = getLogLevel();
|
|
8
|
+
if (level < currentLogLevel) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const logger = getLogger();
|
|
13
|
+
logger(level, message);
|
|
4
14
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { LogLevel } from '../../enums/LogLevel.enum';
|
|
1
2
|
import type { Http } from '../CodePushApiSdk.types';
|
|
2
3
|
import { version } from '../version';
|
|
3
4
|
import { fetchRetry } from './fetchRetry';
|
|
5
|
+
import { log } from './log';
|
|
4
6
|
|
|
5
7
|
export const requestFetchAdapter: Http.Requester = {
|
|
6
8
|
async request(method, url, requestBody) {
|
|
@@ -15,6 +17,9 @@ export const requestFetchAdapter: Http.Requester = {
|
|
|
15
17
|
requestBody = JSON.stringify(requestBody);
|
|
16
18
|
}
|
|
17
19
|
|
|
20
|
+
const requestId = Math.round(Math.random() * 10000);
|
|
21
|
+
log(LogLevel.DEBUG, `[${requestId}] Will fetch ${method} ${url}`);
|
|
22
|
+
|
|
18
23
|
const response = await fetchRetry(url, {
|
|
19
24
|
method,
|
|
20
25
|
headers,
|
|
@@ -22,6 +27,9 @@ export const requestFetchAdapter: Http.Requester = {
|
|
|
22
27
|
});
|
|
23
28
|
|
|
24
29
|
const statusCode = response.status;
|
|
30
|
+
|
|
31
|
+
log(LogLevel.DEBUG, `[${requestId}] Done fetching with status code ${statusCode}`);
|
|
32
|
+
|
|
25
33
|
const body = await response.text();
|
|
26
34
|
return { statusCode, body };
|
|
27
35
|
},
|
package/src/internals/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '10.
|
|
2
|
+
export const version = '10.2.1';
|