forked from microsoft/react-native-code-push
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathcode-push.config.ts
More file actions
112 lines (94 loc) · 2.69 KB
/
code-push.config.ts
File metadata and controls
112 lines (94 loc) · 2.69 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import axios from "axios";
import {
CliConfigInterface,
ReleaseHistoryInterface,
} from "@bravemobile/react-native-code-push";
import {invalidateCloudfrontCache} from "./scripts/invalidateCloudfrontCache";
import {uploadFileToS3} from "./scripts/uploadFileToS3";
export const CDN_HOST = "https://your.cdn.provider.com";
function historyJsonFileRemotePath(
platform: "ios" | "android",
identifier: string,
binaryVersion: string,
) {
return `histories/${platform}/${identifier}/${binaryVersion}.json`;
}
function bundleFileRemotePath(
platform: "ios" | "android",
identifier: string,
fileName: string,
) {
return `bundles/${platform}/${identifier}/${fileName}`;
}
const Config: CliConfigInterface = {
bundleUploader: async (
source: string,
platform: "ios" | "android",
identifier = "staging",
): Promise<{downloadUrl: string}> => {
const fileName = source.split("/").pop();
const remoteBundlePath = bundleFileRemotePath(
platform,
identifier,
fileName!,
);
await uploadFileToS3({
pathToLocalFile: source,
key: remoteBundlePath,
});
const downloadUrl = `${CDN_HOST}/${remoteBundlePath}`;
console.log("🎉 Bundle File uploaded:", downloadUrl);
return {
downloadUrl: downloadUrl,
};
},
getReleaseHistory: async (
targetBinaryVersion: string,
platform: "ios" | "android",
identifier = "staging",
): Promise<ReleaseHistoryInterface> => {
const remoteJsonPath = historyJsonFileRemotePath(
platform,
identifier,
targetBinaryVersion,
);
const jsonUrl = `${CDN_HOST}/${remoteJsonPath}`;
try {
const {data} = await axios.get(jsonUrl);
return data as ReleaseHistoryInterface;
} catch (error) {
if (
axios.isAxiosError(error) &&
error.response != null &&
[403, 404].includes(error.response.status)
) {
console.error("Release history file not found at", jsonUrl);
}
throw error;
}
},
setReleaseHistory: async (
targetBinaryVersion: string,
jsonFilePath: string,
releaseInfo: ReleaseHistoryInterface,
platform: "ios" | "android",
identifier = "staging",
): Promise<void> => {
// upload JSON file or call API using `releaseInfo` metadata.
const remoteJsonPath = historyJsonFileRemotePath(
platform,
identifier,
targetBinaryVersion,
);
await uploadFileToS3({
pathToLocalFile: jsonFilePath,
key: remoteJsonPath,
});
await invalidateCloudfrontCache({
key: remoteJsonPath,
});
const jsonUrl = `${CDN_HOST}/${remoteJsonPath}`;
console.log("🎉 Release history File uploaded:", jsonUrl);
},
};
module.exports = Config;