forked from microsoft/react-native-code-push
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recordFilesBeforeBundleCommand.js
41 lines (32 loc) · 1.37 KB
/
recordFilesBeforeBundleCommand.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* This script creates a snapshot of the contents in the resource directory
* by creating a map with the modified time of all the files in the directory
* and saving it to a temp file. This snapshot is later referenced in
* "generatePackageHash.js" to figure out which files have changed or were
* newly generated by the "react-native bundle" command.
*/
var fs = require("fs");
var path = require("path");
var getFilesInFolder = require("./getFilesInFolder");
var resourcesDir = process.argv[2];
var tempFileName = process.argv[3];
var tempFileLocalPath = path.join(require("os").tmpdir(), tempFileName);
var resourceFiles = [];
try {
getFilesInFolder(resourcesDir, resourceFiles);
} catch(error) {
var targetPathNotFoundExceptionMessage = "\nResources directory path does not exist.\n";
targetPathNotFoundExceptionMessage += "Unable to find '" + resourcesDir;
targetPathNotFoundExceptionMessage += "' directory. Please check version of Android Plugin for Gradle.";
error.message += targetPathNotFoundExceptionMessage;
throw error;
}
var fileToModifiedTimeMap = {};
resourceFiles.forEach(function(resourceFile) {
fileToModifiedTimeMap[resourceFile.path.substring(resourcesDir.length)] = resourceFile.mtime.getTime();
});
fs.writeFile(tempFileLocalPath, JSON.stringify(fileToModifiedTimeMap), function(err) {
if (err) {
throw err;
}
});