@gfean/react-native-bundle-drop 0.1.48 â 0.1.82
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 +254 -84
- package/README.md +145 -14
- package/android/src/main/java/com/bundledrop/BundleDropModule.kt +9 -22
- package/ios/BundleDropLocator.swift +0 -6
- package/lib/CLI/cli.js +48 -39
- package/lib/CLI/scripts/init-config.d.ts +1 -0
- package/lib/CLI/scripts/init-config.js +42 -2
- package/lib/CLI/scripts/init-native-config.js +428 -45
- package/lib/CLI/scripts/login-cli.js +6 -2
- package/lib/CLI/scripts/post-init.d.ts +1 -0
- package/lib/CLI/scripts/post-init.js +42 -0
- package/lib/CLI/scripts/upload-cli.d.ts +2 -0
- package/lib/CLI/scripts/upload-cli.js +11 -5
- package/lib/api/client.d.ts +1 -1
- package/lib/api/client.js +2 -2
- package/lib/api/clientApi.d.ts +3 -6
- package/lib/api/clientApi.js +7 -18
- package/lib/api/types.d.ts +33 -18
- package/lib/context.js +1 -1
- package/lib/errors.d.ts +2 -2
- package/lib/fs/bundlePointer.d.ts +14 -0
- package/lib/fs/bundlePointer.js +77 -0
- package/lib/fs/installId.d.ts +1 -0
- package/lib/fs/installId.js +29 -0
- package/lib/fs/userProperties.d.ts +6 -0
- package/lib/fs/userProperties.js +100 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +8 -3
- package/lib/install/installFromZip.js +7 -18
- package/lib/loadConfig.d.ts +5 -0
- package/lib/manager/downloadAndInstall.d.ts +10 -0
- package/lib/manager/downloadAndInstall.js +50 -42
- package/lib/manager/initUpdateManager.js +46 -10
- package/lib/manager/reporting.js +5 -3
- package/lib/manager/rollbackState.d.ts +30 -0
- package/lib/manager/rollbackState.js +186 -0
- package/lib/manager/updateCheck.js +57 -18
- package/lib/scripts/download-bundle.js +19 -8
- package/lib/useBundleDrop.js +14 -2
- package/package.json +3 -3
- package/lib/api/utils.d.ts +0 -1
- package/lib/api/utils.js +0 -8
- package/lib/fs/iosPointer.d.ts +0 -1
- package/lib/fs/iosPointer.js +0 -20
|
@@ -62,6 +62,12 @@ class BundleDropModule(reactContext: ReactApplicationContext) :
|
|
|
62
62
|
null
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
+
|
|
66
|
+
@JvmStatic
|
|
67
|
+
fun resolveJSBundleFile(context: Context, fallback: String?): String? {
|
|
68
|
+
val path = getDownloadedBundlePath(context)
|
|
69
|
+
return if (!path.isNullOrEmpty()) path else fallback
|
|
70
|
+
}
|
|
65
71
|
}
|
|
66
72
|
|
|
67
73
|
override fun getName(): String = "BundleDrop"
|
|
@@ -76,7 +82,8 @@ class BundleDropModule(reactContext: ReactApplicationContext) :
|
|
|
76
82
|
|
|
77
83
|
@ReactMethod
|
|
78
84
|
fun restartReactNative() {
|
|
79
|
-
|
|
85
|
+
// â
Only change: don't access `currentActivity` directly; use reactApplicationContext.currentActivity
|
|
86
|
+
val activity = reactApplicationContext.currentActivity ?: return
|
|
80
87
|
val context = reactApplicationContext
|
|
81
88
|
|
|
82
89
|
val intent = context.packageManager.getLaunchIntentForPackage(context.packageName)
|
|
@@ -118,26 +125,6 @@ class BundleDropModule(reactContext: ReactApplicationContext) :
|
|
|
118
125
|
}
|
|
119
126
|
}
|
|
120
127
|
|
|
121
|
-
// @ReactMethod
|
|
122
|
-
// fun forceReloadJS() {
|
|
123
|
-
// val manager = (reactApplicationContext.currentActivity?.application as? ReactApplication)
|
|
124
|
-
// ?.reactNativeHost?.reactInstanceManager
|
|
125
|
-
//
|
|
126
|
-
// if (manager != null) {
|
|
127
|
-
// Log.d("BundleDrop", "đ Forcing React context recreation from native...")
|
|
128
|
-
//
|
|
129
|
-
// reactApplicationContext
|
|
130
|
-
// .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
131
|
-
// .emit("bundleReloadStart", null)
|
|
132
|
-
//
|
|
133
|
-
// reactApplicationContext.runOnUiQueueThread {
|
|
134
|
-
// manager.recreateReactContextInBackground()
|
|
135
|
-
// }
|
|
136
|
-
// } else {
|
|
137
|
-
// Log.e("BundleDrop", "â ReactInstanceManager is null.")
|
|
138
|
-
// }
|
|
139
|
-
// }
|
|
140
|
-
|
|
141
128
|
override fun getConstants(): MutableMap<String, Any> {
|
|
142
129
|
val map = mutableMapOf<String, Any>()
|
|
143
130
|
downloadedBundlePath?.let {
|
|
@@ -145,4 +132,4 @@ class BundleDropModule(reactContext: ReactApplicationContext) :
|
|
|
145
132
|
}
|
|
146
133
|
return map
|
|
147
134
|
}
|
|
148
|
-
}
|
|
135
|
+
}
|
|
@@ -19,12 +19,6 @@ import Foundation
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
// legacy fallback: Documents/main.jsbundle
|
|
23
|
-
if let docs = fm.urls(for: .documentDirectory, in: .userDomainMask).first {
|
|
24
|
-
let legacy = docs.appendingPathComponent("main.jsbundle")
|
|
25
|
-
if fm.fileExists(atPath: legacy.path) { return legacy }
|
|
26
|
-
}
|
|
27
|
-
|
|
28
22
|
return nil
|
|
29
23
|
}
|
|
30
24
|
|
package/lib/CLI/cli.js
CHANGED
|
@@ -7,13 +7,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const commander_1 = require("commander");
|
|
9
9
|
const figures_1 = __importDefault(require("figures"));
|
|
10
|
-
const prompts_1 = __importDefault(require("prompts"));
|
|
11
10
|
const upload_cli_1 = __importDefault(require("./scripts/upload-cli"));
|
|
11
|
+
const post_init_1 = require("./scripts/post-init");
|
|
12
12
|
const package_json_1 = __importDefault(require("../../package.json"));
|
|
13
13
|
const program = new commander_1.Command();
|
|
14
14
|
program
|
|
15
15
|
.name('bundle-drop')
|
|
16
|
-
.version(package_json_1.default.version || '0.0.0', '-v, --version', 'Show CLI version');
|
|
16
|
+
.version(package_json_1.default.version || '0.0.0', '-v, --cli-version', 'Show CLI version');
|
|
17
17
|
const logo = chalk_1.default.cyanBright(`
|
|
18
18
|
______ ______
|
|
19
19
|
|_ _ \\ |_ _ \`.
|
|
@@ -27,7 +27,15 @@ program.addHelpText('before', `
|
|
|
27
27
|
${chalk_1.default.magentaBright('A blazing-fast OTA delivery system for React Native by GFean.\n')}
|
|
28
28
|
${chalk_1.default.bold.cyan('Available Commands:')}
|
|
29
29
|
`);
|
|
30
|
-
program.addHelpText('afterAll',
|
|
30
|
+
program.addHelpText('afterAll', `
|
|
31
|
+
${chalk_1.default.bold.cyan('Common Usage:')}
|
|
32
|
+
${chalk_1.default.gray('bundle-drop login')}
|
|
33
|
+
${chalk_1.default.gray('bundle-drop init')}
|
|
34
|
+
${chalk_1.default.gray('bundle-drop upload android --version 1.2.3 --channel General')}
|
|
35
|
+
${chalk_1.default.gray('bundle-drop upload ios --plist-file ios/Info.plist --channel General')}
|
|
36
|
+
${chalk_1.default.gray('bundle-drop upload android --buildgradle-path android/app/build.gradle --channel General --release-notes "Fixes"')}
|
|
37
|
+
|
|
38
|
+
${chalk_1.default.gray('Need help? â')} ${chalk_1.default.underline.gray('https://github.com/GFean/react-native-bundle-drop')}\n`);
|
|
31
39
|
// ------------------------
|
|
32
40
|
// Commands
|
|
33
41
|
// ------------------------
|
|
@@ -38,7 +46,19 @@ program
|
|
|
38
46
|
.option('--version <version>', 'App version. iOS will fallback to --plist-file; Android can fallback to build.gradle when provided.')
|
|
39
47
|
.option('--buildgradle-path <path>', 'Optional Android build.gradle path to read versionName')
|
|
40
48
|
.option('--channel <name>', 'Target channel name to associate the bundle') // â ADD THIS LINE
|
|
49
|
+
.option('--runtimeVersion <runtimeVersion>', 'Override runtimeVersion from metadata/config')
|
|
50
|
+
.option('--release-notes <text>', 'Release notes (max 2000 chars)')
|
|
51
|
+
.option('--token <token>', 'Personal Access Token (alternative to `bundle-drop login`)')
|
|
52
|
+
.option('--author <name>', 'Override the author name stored with the bundle')
|
|
41
53
|
.description(chalk_1.default.whiteBright('Bundle and upload an OTA zip to the server'))
|
|
54
|
+
.addHelpText('after', `
|
|
55
|
+
${chalk_1.default.bold('Examples:')}
|
|
56
|
+
${chalk_1.default.gray('bundle-drop upload android --version 1.2.3 --channel General')}
|
|
57
|
+
${chalk_1.default.gray('bundle-drop upload ios --plist-file ios/Info.plist --channel General')}
|
|
58
|
+
${chalk_1.default.gray('bundle-drop upload android --buildgradle-path android/app/build.gradle --channel QA --release-notes "Bug fixes"')}
|
|
59
|
+
${chalk_1.default.gray('bundle-drop upload android --version 1.2.3 --channel General --runtimeVersion 3.0.0')}
|
|
60
|
+
${chalk_1.default.gray('bundle-drop upload android --version 1.2.3 --channel General --token bdp_pat_xxx')}
|
|
61
|
+
`)
|
|
42
62
|
.action(upload_cli_1.default);
|
|
43
63
|
program
|
|
44
64
|
.command('logout')
|
|
@@ -68,63 +88,52 @@ program
|
|
|
68
88
|
});
|
|
69
89
|
program
|
|
70
90
|
.command('init')
|
|
91
|
+
.option('--token <token>', 'Personal Access Token (alternative to `bundle-drop login`)')
|
|
71
92
|
.description('Generate bundle.drop.config.js from your logged-in account context')
|
|
72
|
-
.action(async () => {
|
|
93
|
+
.action(async (options) => {
|
|
73
94
|
//eslint-disable-next-line
|
|
74
95
|
const fs = require('fs');
|
|
75
96
|
//eslint-disable-next-line
|
|
76
97
|
const path = require('path');
|
|
77
98
|
//eslint-disable-next-line
|
|
78
99
|
const os = require('os');
|
|
100
|
+
if (options.token) {
|
|
101
|
+
const serverUrl = process.env.BUNDLE_DROP_SERVER_URL?.replace(/\/$/, '') ||
|
|
102
|
+
'https://api.bundledrop.app';
|
|
103
|
+
//eslint-disable-next-line
|
|
104
|
+
await require('../CLI/scripts/init-config').initConfig({
|
|
105
|
+
serverUrl,
|
|
106
|
+
projects: [],
|
|
107
|
+
organizations: [],
|
|
108
|
+
downloadApiKey: '',
|
|
109
|
+
authToken: options.token,
|
|
110
|
+
});
|
|
111
|
+
await (0, post_init_1.runPostInitPrompts)();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
79
114
|
const tokenPath = path.join(os.homedir(), '.bundle-drop', 'auth.json');
|
|
80
115
|
if (!fs.existsSync(tokenPath)) {
|
|
81
|
-
console.log('âšī¸ Not logged in. Please run `bundle-drop login`
|
|
116
|
+
console.log('âšī¸ Not logged in. Please run `bundle-drop login` or use --token.');
|
|
82
117
|
return;
|
|
83
118
|
}
|
|
84
119
|
const data = JSON.parse(fs.readFileSync(tokenPath, 'utf-8'));
|
|
85
120
|
const projects = data.projects || [];
|
|
86
121
|
const organizations = data.organizations || [];
|
|
87
122
|
const downloadApiKey = data.downloadApiKey || '';
|
|
123
|
+
const token = data.token;
|
|
124
|
+
const serverUrl = data.serverUrl ||
|
|
125
|
+
data.baseUrl ||
|
|
126
|
+
process.env.BUNDLE_DROP_SERVER_URL?.replace(/\/$/, '') ||
|
|
127
|
+
'https://api.bundledrop.app';
|
|
88
128
|
//eslint-disable-next-line
|
|
89
129
|
await require('../CLI/scripts/init-config').initConfig({
|
|
90
|
-
serverUrl
|
|
130
|
+
serverUrl,
|
|
91
131
|
projects,
|
|
92
132
|
organizations,
|
|
93
133
|
downloadApiKey,
|
|
134
|
+
authToken: token,
|
|
94
135
|
});
|
|
95
|
-
|
|
96
|
-
const metroAnswer = await (0, prompts_1.default)({
|
|
97
|
-
type: 'confirm',
|
|
98
|
-
name: 'runMetro',
|
|
99
|
-
message: 'Also add the Metro alias for bundle.drop.config.js (recommended)?',
|
|
100
|
-
initial: true,
|
|
101
|
-
});
|
|
102
|
-
if (metroAnswer.runMetro) {
|
|
103
|
-
try {
|
|
104
|
-
//eslint-disable-next-line
|
|
105
|
-
await require('../CLI/scripts/init-metro-config').initMetroConfig();
|
|
106
|
-
}
|
|
107
|
-
catch (err) {
|
|
108
|
-
console.log(`â ī¸ Failed to initialize Metro config; please refer to manual setup instructions. (${err?.message || err})`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
// Offer to patch native entrypoints (after Metro prompt finishes)
|
|
112
|
-
const nativeAnswer = await (0, prompts_1.default)({
|
|
113
|
-
type: 'confirm',
|
|
114
|
-
name: 'runNative',
|
|
115
|
-
message: 'Patch native entrypoints (MainApplication/AppDelegate) to prefer OTA? (Standard RN setups only)',
|
|
116
|
-
initial: false,
|
|
117
|
-
});
|
|
118
|
-
if (nativeAnswer.runNative) {
|
|
119
|
-
try {
|
|
120
|
-
//eslint-disable-next-line
|
|
121
|
-
await require('../CLI/scripts/init-native-config').initNativeConfig();
|
|
122
|
-
console.log('â ī¸ Please double-check the native changes in MainApplication/AppDelegate.');
|
|
123
|
-
}
|
|
124
|
-
catch (err) {
|
|
125
|
-
console.log(`â ī¸ Failed to initialize native config; please refer to manual setup instructions. (${err?.message || err})`);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
136
|
+
await (0, post_init_1.runPostInitPrompts)();
|
|
128
137
|
});
|
|
129
138
|
program
|
|
130
139
|
.command('init-native')
|
|
@@ -4,10 +4,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.initConfig = initConfig;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
7
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
10
|
const path_1 = __importDefault(require("path"));
|
|
10
11
|
const prompts_1 = __importDefault(require("prompts"));
|
|
12
|
+
function normalizeServerUrl(url) {
|
|
13
|
+
return url.replace(/\/$/, '');
|
|
14
|
+
}
|
|
15
|
+
async function fetchProjectCredentials(params) {
|
|
16
|
+
const baseUrl = normalizeServerUrl(params.serverUrl);
|
|
17
|
+
const url = `${baseUrl}/projects/${encodeURIComponent(params.projectSlug)}/credentials`;
|
|
18
|
+
try {
|
|
19
|
+
const res = await axios_1.default.get(url, {
|
|
20
|
+
headers: {
|
|
21
|
+
Accept: 'application/json',
|
|
22
|
+
Authorization: `Bearer ${params.authToken}`,
|
|
23
|
+
},
|
|
24
|
+
timeout: 15000,
|
|
25
|
+
});
|
|
26
|
+
return res.data || null;
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
console.log(chalk_1.default.yellow(`â ī¸ Failed to fetch project credentials from ${url}. Please verify login and project access.`));
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
11
33
|
function findProjectRoot(startDir) {
|
|
12
34
|
let dir = path_1.default.resolve(startDir);
|
|
13
35
|
const MAX_UP = 12;
|
|
@@ -83,8 +105,26 @@ async function initConfig(params) {
|
|
|
83
105
|
if (org)
|
|
84
106
|
orgSlug = org.slug;
|
|
85
107
|
}
|
|
108
|
+
let resolvedServerUrl = normalizeServerUrl(params.serverUrl);
|
|
109
|
+
let apiKey = params.downloadApiKey || '';
|
|
110
|
+
if (projectSlug && params.authToken) {
|
|
111
|
+
const credentials = await fetchProjectCredentials({
|
|
112
|
+
serverUrl: resolvedServerUrl,
|
|
113
|
+
projectSlug,
|
|
114
|
+
authToken: params.authToken,
|
|
115
|
+
});
|
|
116
|
+
if (credentials?.downloadApiKey) {
|
|
117
|
+
apiKey = credentials.downloadApiKey;
|
|
118
|
+
}
|
|
119
|
+
else if (!apiKey) {
|
|
120
|
+
console.log(chalk_1.default.yellow('â ī¸ No project API key returned from /projects/:projectSlug/credentials; config will be created without apiKey.'));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else if (projectSlug && !params.authToken && !apiKey) {
|
|
124
|
+
console.log(chalk_1.default.yellow('â ī¸ Missing auth token; cannot fetch project API key.'));
|
|
125
|
+
}
|
|
86
126
|
const content = `module.exports = {
|
|
87
|
-
serverUrl: '${
|
|
127
|
+
serverUrl: '${resolvedServerUrl}',
|
|
88
128
|
runtimeVersion: {
|
|
89
129
|
ios: '1.0.0',
|
|
90
130
|
android: '1.0.0',
|
|
@@ -95,7 +135,7 @@ async function initConfig(params) {
|
|
|
95
135
|
project: {
|
|
96
136
|
name: '${projectName.replace(/'/g, "\\'")}',
|
|
97
137
|
slug: '${projectSlug}',
|
|
98
|
-
apiKey: '${
|
|
138
|
+
apiKey: '${apiKey.replace(/'/g, "\\'")}',
|
|
99
139
|
},
|
|
100
140
|
debugLocal: false,
|
|
101
141
|
};
|