@gfean/react-native-bundle-drop 0.1.38 → 0.1.47
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/CLIENT_README.md +21 -12
- package/README.md +19 -12
- package/lib/CLI/cli.js +6 -6
- package/lib/api/client.d.ts +1 -0
- package/lib/api/client.js +24 -0
- package/lib/api/clientApi.d.ts +8 -0
- package/lib/api/clientApi.js +42 -0
- package/lib/api/types.d.ts +36 -0
- package/lib/api/types.js +2 -0
- package/lib/api/utils.d.ts +1 -0
- package/lib/api/utils.js +8 -0
- package/lib/bootstrap.d.ts +1 -0
- package/lib/bootstrap.js +10 -0
- package/lib/context.d.ts +5 -0
- package/lib/context.js +16 -0
- package/lib/errors.d.ts +16 -0
- package/lib/errors.js +18 -0
- package/lib/fs/fsUtils.d.ts +4 -0
- package/lib/fs/fsUtils.js +38 -0
- package/lib/fs/iosPointer.d.ts +1 -0
- package/lib/fs/iosPointer.js +20 -0
- package/lib/index.d.ts +7 -49
- package/lib/index.js +18 -414
- package/lib/install/installFromZip.d.ts +12 -0
- package/lib/install/installFromZip.js +117 -0
- package/lib/manager/downloadAndInstall.d.ts +14 -0
- package/lib/manager/downloadAndInstall.js +144 -0
- package/lib/manager/initUpdateManager.d.ts +7 -0
- package/lib/manager/initUpdateManager.js +60 -0
- package/lib/manager/reporting.d.ts +5 -0
- package/lib/manager/reporting.js +40 -0
- package/lib/manager/updateCheck.d.ts +5 -0
- package/lib/manager/updateCheck.js +58 -0
- package/lib/manager/updateState.d.ts +14 -0
- package/lib/manager/updateState.js +62 -0
- package/lib/native/bundleDropNative.d.ts +2 -0
- package/lib/native/bundleDropNative.js +22 -0
- package/lib/scripts/download-bundle.js +29 -12
- package/lib/scripts/upload-bundle.js +26 -19
- package/lib/useBundleDrop.d.ts +21 -20
- package/lib/useBundleDrop.js +67 -73
- package/package.json +1 -1
package/lib/useBundleDrop.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useBundleDrop = useBundleDrop;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
-
const
|
|
5
|
+
const updateCheck_1 = require("./manager/updateCheck");
|
|
6
|
+
const downloadAndInstall_1 = require("./manager/downloadAndInstall");
|
|
7
|
+
const updateState_1 = require("./manager/updateState");
|
|
6
8
|
function useBundleDrop(options) {
|
|
7
9
|
const channelName = options?.channelName || 'General';
|
|
8
10
|
const [status, setStatus] = (0, react_1.useState)('Click the button to check for updates');
|
|
@@ -10,8 +12,9 @@ function useBundleDrop(options) {
|
|
|
10
12
|
const [pendingApply, setPendingApply] = (0, react_1.useState)(false);
|
|
11
13
|
const [hasBundle, setHasBundle] = (0, react_1.useState)(false);
|
|
12
14
|
const [isBusy, setIsBusy] = (0, react_1.useState)(false);
|
|
15
|
+
const [availableChannels, setAvailableChannels] = (0, react_1.useState)([]);
|
|
13
16
|
const refresh = (0, react_1.useCallback)(async () => {
|
|
14
|
-
const state = await (0,
|
|
17
|
+
const state = await (0, updateState_1.getUpdateState)();
|
|
15
18
|
setInstalledInfo(state.info || null);
|
|
16
19
|
setPendingApply(state.pendingApply);
|
|
17
20
|
setHasBundle(state.hasBundle);
|
|
@@ -19,102 +22,94 @@ function useBundleDrop(options) {
|
|
|
19
22
|
const withBusy = (0, react_1.useCallback)(async (fn) => {
|
|
20
23
|
setIsBusy(true);
|
|
21
24
|
try {
|
|
22
|
-
await fn();
|
|
25
|
+
const result = await fn();
|
|
23
26
|
await refresh();
|
|
27
|
+
return result;
|
|
24
28
|
}
|
|
25
29
|
finally {
|
|
26
30
|
setIsBusy(false);
|
|
27
31
|
}
|
|
28
32
|
}, [refresh]);
|
|
29
33
|
const checkLatest = (0, react_1.useCallback)(async () => {
|
|
30
|
-
|
|
31
|
-
const res = await (0,
|
|
34
|
+
return withBusy(async () => {
|
|
35
|
+
const res = await (0, updateCheck_1.checkForUpdate)(channelName, msg => setStatus(msg));
|
|
32
36
|
if (!res) {
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
const nextStatus = '⚠️ Unable to check for updates. Try again.';
|
|
38
|
+
setStatus(nextStatus);
|
|
39
|
+
return { response: null, status: nextStatus };
|
|
35
40
|
}
|
|
36
41
|
if (res.upToDate) {
|
|
37
|
-
|
|
38
|
-
|
|
42
|
+
const nextStatus = '✅ You have the latest version';
|
|
43
|
+
setStatus(nextStatus);
|
|
44
|
+
return { response: res, status: nextStatus };
|
|
39
45
|
}
|
|
40
46
|
if (res.incompatible) {
|
|
41
|
-
|
|
42
|
-
|
|
47
|
+
const nextStatus = '⛔️ No compatible update for this binary';
|
|
48
|
+
setStatus(nextStatus);
|
|
49
|
+
return { response: res, status: nextStatus };
|
|
43
50
|
}
|
|
44
51
|
const nextLabel = res.bundleVersion
|
|
45
52
|
? `⬇️ Update available${res.bundleVersion ? ` (v${res.bundleVersion})` : ''}`
|
|
46
53
|
: '⬇️ Update available';
|
|
47
54
|
setStatus(nextLabel);
|
|
55
|
+
return { response: res, status: nextLabel };
|
|
48
56
|
});
|
|
49
57
|
}, [channelName, withBusy]);
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
await (0,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}, [channelName, withBusy]);
|
|
58
|
-
const downloadForNextLaunch = (0, react_1.useCallback)(async () => {
|
|
59
|
-
await withBusy(async () => {
|
|
60
|
-
const check = await (0, index_1.checkForUpdate)(channelName, msg => setStatus(msg));
|
|
61
|
-
if (check?.upToDate) {
|
|
62
|
-
setStatus('✅ You have the latest version');
|
|
63
|
-
return;
|
|
58
|
+
const downloadAndStage = (0, react_1.useCallback)(async () => {
|
|
59
|
+
return withBusy(async () => {
|
|
60
|
+
const result = await (0, downloadAndInstall_1.downloadUpdate)({ channelName }, msg => setStatus(msg));
|
|
61
|
+
if (result.status === 'upToDate') {
|
|
62
|
+
const nextStatus = '✅ You have the latest version';
|
|
63
|
+
setStatus(nextStatus);
|
|
64
|
+
return { result, status: nextStatus };
|
|
64
65
|
}
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
if (result.status === 'incompatible') {
|
|
67
|
+
const nextStatus = '⛔️ No compatible update for this binary';
|
|
68
|
+
setStatus(nextStatus);
|
|
69
|
+
return { result, status: nextStatus };
|
|
68
70
|
}
|
|
69
|
-
|
|
70
|
-
setStatus(
|
|
71
|
+
const nextStatus = '✅ Update downloaded. Will apply on next launch or when you call applyUpdate.';
|
|
72
|
+
setStatus(nextStatus);
|
|
73
|
+
return { result, status: nextStatus };
|
|
71
74
|
});
|
|
72
75
|
}, [channelName, withBusy]);
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
const applyUpdate = (0, react_1.useCallback)(async () => {
|
|
77
|
+
return withBusy(async () => {
|
|
78
|
+
const applied = await (0, updateState_1.applyUpdate)(msg => setStatus(msg));
|
|
79
|
+
let nextStatus;
|
|
80
|
+
if (applied.status === 'applied') {
|
|
81
|
+
nextStatus = '✅ Update applied, reloading...';
|
|
82
|
+
setStatus(nextStatus);
|
|
79
83
|
}
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
84
|
+
if (applied.status === 'noBundle') {
|
|
85
|
+
nextStatus = '⚠️ No downloaded bundle to apply';
|
|
86
|
+
setStatus(nextStatus);
|
|
83
87
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}, [channelName, withBusy]);
|
|
88
|
-
const applyPending = (0, react_1.useCallback)(async () => {
|
|
89
|
-
await withBusy(async () => {
|
|
90
|
-
const applied = await (0, index_1.applyReadyUpdate)(msg => setStatus(msg));
|
|
91
|
-
if (applied) {
|
|
92
|
-
setStatus('✅ Update applied, reloading...');
|
|
88
|
+
if (applied.status === 'alreadyApplied') {
|
|
89
|
+
nextStatus = 'ℹ️ Bundle already applied';
|
|
90
|
+
setStatus(nextStatus);
|
|
93
91
|
}
|
|
92
|
+
return { result: applied, status: nextStatus };
|
|
94
93
|
});
|
|
95
94
|
}, [withBusy]);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
finally {
|
|
109
|
-
await refresh();
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
run();
|
|
95
|
+
const fetchAvailableChannels = (0, react_1.useCallback)(async () => {
|
|
96
|
+
setIsBusy(true);
|
|
97
|
+
try {
|
|
98
|
+
const channels = await (0, updateCheck_1.getAvailableChannels)();
|
|
99
|
+
setAvailableChannels(channels);
|
|
100
|
+
return channels;
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
setStatus('⚠️ Unable to fetch channels.');
|
|
104
|
+
return [];
|
|
113
105
|
}
|
|
114
|
-
|
|
115
|
-
|
|
106
|
+
finally {
|
|
107
|
+
setIsBusy(false);
|
|
116
108
|
}
|
|
117
|
-
}, [
|
|
109
|
+
}, [setAvailableChannels, setStatus]);
|
|
110
|
+
(0, react_1.useEffect)(() => {
|
|
111
|
+
refresh();
|
|
112
|
+
}, [refresh]);
|
|
118
113
|
return {
|
|
119
114
|
status,
|
|
120
115
|
isBusy,
|
|
@@ -122,10 +117,9 @@ function useBundleDrop(options) {
|
|
|
122
117
|
pendingApply,
|
|
123
118
|
hasBundle,
|
|
124
119
|
checkLatest,
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
refresh,
|
|
120
|
+
downloadUpdate: downloadAndStage,
|
|
121
|
+
applyUpdate,
|
|
122
|
+
fetchAvailableChannels,
|
|
123
|
+
availableChannels,
|
|
130
124
|
};
|
|
131
125
|
}
|