@gfean/react-native-bundle-drop 0.3.5 → 0.3.7
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/build.gradle +2 -0
- package/android/src/main/java/com/bundledrop/BundleDropModule.kt +12 -48
- package/android/src/main/java/com/bundledrop/BundleDropNativePaths.kt +64 -0
- package/android/src/main/java/com/bundledrop/BundleDropOtaPrefs.kt +41 -0
- package/ios/BundleDropBridge.m +4 -0
- package/ios/BundleDropLocator.h +11 -0
- package/ios/BundleDropLocator.swift +11 -1
- package/ios/BundleDropModule.swift +10 -0
- package/lib/CLI/cli.js +56 -6
- package/lib/CLI/scripts/aipowered/apply-plan.d.ts +10 -0
- package/lib/CLI/scripts/aipowered/apply-plan.js +50 -0
- package/lib/CLI/scripts/aipowered/backend-client.d.ts +6 -0
- package/lib/CLI/scripts/aipowered/backend-client.js +34 -0
- package/lib/CLI/scripts/aipowered/diff-preview.d.ts +7 -0
- package/lib/CLI/scripts/aipowered/diff-preview.js +33 -0
- package/lib/CLI/scripts/aipowered/init-native-config.d.ts +2 -0
- package/lib/CLI/scripts/aipowered/init-native-config.js +131 -0
- package/lib/CLI/scripts/aipowered/scanner.d.ts +5 -0
- package/lib/CLI/scripts/aipowered/scanner.js +349 -0
- package/lib/CLI/scripts/aipowered/types.d.ts +53 -0
- package/lib/CLI/scripts/aipowered/types.js +2 -0
- package/lib/CLI/scripts/aipowered/validate-plan.d.ts +8 -0
- package/lib/CLI/scripts/aipowered/validate-plan.js +164 -0
- package/lib/CLI/scripts/init-config.js +10 -5
- package/lib/CLI/scripts/init-native-config.js +1 -1
- package/lib/CLI/scripts/post-init.js +7 -18
- package/lib/CLI/scripts/upload-cli.d.ts +2 -0
- package/lib/CLI/scripts/upload-cli.js +53 -25
- package/lib/CLI/utils/ui.d.ts +3 -0
- package/lib/CLI/utils/ui.js +26 -0
- package/lib/api/clientApi.d.ts +2 -1
- package/lib/api/clientApi.js +9 -0
- package/lib/api/types.d.ts +17 -0
- package/lib/context.d.ts +4 -4
- package/lib/context.js +2 -2
- package/lib/fs/bundlePointer.d.ts +2 -0
- package/lib/fs/bundlePointer.js +14 -4
- package/lib/index.d.ts +6 -3
- package/lib/index.js +5 -1
- package/lib/injectImageResolver.js +6 -15
- package/lib/loadConfig.d.ts +4 -4
- package/lib/manager/downloadAndInstall.d.ts +3 -0
- package/lib/manager/downloadAndInstall.js +23 -3
- package/lib/manager/reporting.d.ts +2 -0
- package/lib/manager/reporting.js +25 -0
- package/lib/manager/rollbackState.d.ts +25 -8
- package/lib/manager/rollbackState.js +87 -22
- package/lib/manager/updateCheck.js +15 -1
- package/lib/manager/updateState.d.ts +5 -1
- package/lib/manager/updateState.js +20 -11
- package/lib/native/bundleDropNative.d.ts +1 -0
- package/lib/native/bundleDropNative.js +14 -0
- package/lib/runtime/service.d.ts +28 -0
- package/lib/runtime/service.js +175 -16
- package/lib/scripts/bundle.d.ts +4 -1
- package/lib/scripts/bundle.js +41 -28
- package/lib/scripts/projectRoot.d.ts +1 -0
- package/lib/scripts/projectRoot.js +54 -0
- package/lib/scripts/upload-bundle.d.ts +2 -1
- package/lib/scripts/upload-bundle.js +46 -37
- package/lib/useBundleDrop.d.ts +2 -0
- package/lib/useBundleDrop.js +1 -0
- package/package.json +3 -2
package/android/build.gradle
CHANGED
|
@@ -99,6 +99,8 @@ dependencies {
|
|
|
99
99
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
100
100
|
testImplementation "junit:junit:4.13.2"
|
|
101
101
|
testImplementation "org.json:json:20231013"
|
|
102
|
+
testImplementation "androidx.test:core:1.6.1"
|
|
103
|
+
testImplementation "org.robolectric:robolectric:4.14.1"
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
// ---------------------------------------------------------------------------
|
|
@@ -15,54 +15,8 @@ class BundleDropModule(reactContext: ReactApplicationContext) :
|
|
|
15
15
|
var latestBundlePath: String? = null
|
|
16
16
|
private set
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
private fun getBinaryVersionKey(context: Context): String {
|
|
22
|
-
val pInfo = context.packageManager.getPackageInfo(context.packageName, 0)
|
|
23
|
-
val versionName = pInfo.versionName ?: "unknown"
|
|
24
|
-
@Suppress("DEPRECATION")
|
|
25
|
-
val versionCode = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
|
|
26
|
-
pInfo.longVersionCode
|
|
27
|
-
} else {
|
|
28
|
-
pInfo.versionCode.toLong()
|
|
29
|
-
}
|
|
30
|
-
return "$versionName-$versionCode"
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
private fun getStoredBinaryVersion(context: Context): String? {
|
|
34
|
-
return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
|
35
|
-
.getString(KEY_BINARY_VERSION, null)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private fun setStoredBinaryVersion(context: Context, version: String) {
|
|
39
|
-
context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
|
40
|
-
.edit().putString(KEY_BINARY_VERSION, version).apply()
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
fun getDownloadedBundlePath(context: Context): String? {
|
|
44
|
-
val bundleDropRoot = File(context.filesDir, "bundle-drop")
|
|
45
|
-
val result = BundleDropOtaResolver.resolve(
|
|
46
|
-
bundleDropRoot = bundleDropRoot,
|
|
47
|
-
filesDir = context.filesDir,
|
|
48
|
-
currentBinaryVersion = getBinaryVersionKey(context),
|
|
49
|
-
storedBinaryVersion = getStoredBinaryVersion(context),
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
result.storedVersion?.let { setStoredBinaryVersion(context, it) }
|
|
53
|
-
|
|
54
|
-
if (result.bundlePath == null) {
|
|
55
|
-
if (result.clearedOta) {
|
|
56
|
-
Log.d("BundleDrop", "Binary updated, clearing OTA bundle")
|
|
57
|
-
} else {
|
|
58
|
-
Log.d("BundleDrop", "📦 No OTA bundle found.")
|
|
59
|
-
}
|
|
60
|
-
} else {
|
|
61
|
-
Log.d("BundleDrop", "🔁 Using OTA bundle at: ${result.bundlePath}")
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return result.bundlePath
|
|
65
|
-
}
|
|
18
|
+
fun getDownloadedBundlePath(context: Context): String? =
|
|
19
|
+
BundleDropNativePaths.getDownloadedBundlePath(context)
|
|
66
20
|
|
|
67
21
|
@JvmStatic
|
|
68
22
|
fun resolveJSBundleFile(context: Context, fallback: String?): String? {
|
|
@@ -104,6 +58,16 @@ class BundleDropModule(reactContext: ReactApplicationContext) :
|
|
|
104
58
|
}
|
|
105
59
|
}
|
|
106
60
|
|
|
61
|
+
@ReactMethod
|
|
62
|
+
fun setOtaEnabled(enabled: Boolean, promise: Promise) {
|
|
63
|
+
try {
|
|
64
|
+
BundleDropOtaPrefs.writeOtaEnabled(reactApplicationContext, enabled)
|
|
65
|
+
promise.resolve(null)
|
|
66
|
+
} catch (e: Exception) {
|
|
67
|
+
promise.reject("ERR_SET_OTA_ENABLED", e.message, e)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
107
71
|
// Backward compat
|
|
108
72
|
@ReactMethod
|
|
109
73
|
fun forceReloadJS() {
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
package com.bundledrop
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.util.Log
|
|
5
|
+
import java.io.File
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Resolves the on-disk OTA JS bundle path (no React / bridge types).
|
|
9
|
+
*
|
|
10
|
+
* Shared by [BundleDropModule] so cold-start `resolveJSBundleFile`, the JS bridge
|
|
11
|
+
* `getDownloadedBundlePath`, and tests use the same logic — including the OTA-disabled gate.
|
|
12
|
+
*/
|
|
13
|
+
object BundleDropNativePaths {
|
|
14
|
+
private const val KEY_BINARY_VERSION = "binary_version"
|
|
15
|
+
|
|
16
|
+
private fun getBinaryVersionKey(context: Context): String {
|
|
17
|
+
val pInfo = context.packageManager.getPackageInfo(context.packageName, 0)
|
|
18
|
+
val versionName = pInfo.versionName ?: "unknown"
|
|
19
|
+
@Suppress("DEPRECATION")
|
|
20
|
+
val versionCode = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
|
|
21
|
+
pInfo.longVersionCode
|
|
22
|
+
} else {
|
|
23
|
+
pInfo.versionCode.toLong()
|
|
24
|
+
}
|
|
25
|
+
return "$versionName-$versionCode"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private fun getStoredBinaryVersion(context: Context): String? {
|
|
29
|
+
return context.getSharedPreferences(BundleDropOtaPrefs.PREFS_NAME, Context.MODE_PRIVATE)
|
|
30
|
+
.getString(KEY_BINARY_VERSION, null)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private fun setStoredBinaryVersion(context: Context, version: String) {
|
|
34
|
+
context.getSharedPreferences(BundleDropOtaPrefs.PREFS_NAME, Context.MODE_PRIVATE)
|
|
35
|
+
.edit().putString(KEY_BINARY_VERSION, version).apply()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@JvmStatic
|
|
39
|
+
fun getDownloadedBundlePath(context: Context): String? {
|
|
40
|
+
if (!BundleDropOtaPrefs.isOtaEnabled(context)) return null
|
|
41
|
+
|
|
42
|
+
val bundleDropRoot = File(context.filesDir, "bundle-drop")
|
|
43
|
+
val result = BundleDropOtaResolver.resolve(
|
|
44
|
+
bundleDropRoot = bundleDropRoot,
|
|
45
|
+
filesDir = context.filesDir,
|
|
46
|
+
currentBinaryVersion = getBinaryVersionKey(context),
|
|
47
|
+
storedBinaryVersion = getStoredBinaryVersion(context),
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
result.storedVersion?.let { setStoredBinaryVersion(context, it) }
|
|
51
|
+
|
|
52
|
+
if (result.bundlePath == null) {
|
|
53
|
+
if (result.clearedOta) {
|
|
54
|
+
Log.d("BundleDrop", "Binary updated, clearing OTA bundle")
|
|
55
|
+
} else {
|
|
56
|
+
Log.d("BundleDrop", "📦 No OTA bundle found.")
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
Log.d("BundleDrop", "🔁 Using OTA bundle at: ${result.bundlePath}")
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return result.bundlePath
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
package com.bundledrop
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.content.SharedPreferences
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Persist whether the native bundle resolver may load an OTA JS bundle on cold start.
|
|
8
|
+
*
|
|
9
|
+
* **Storage:** [PREFS_NAME] SharedPreferences file. [KEY_OTA_ENABLED] matches iOS
|
|
10
|
+
* `BundleDropLocator.otaEnabledKey` (`bundledrop_ota_enabled`) for cross-platform debugging.
|
|
11
|
+
* Older releases used [LEGACY_KEY_OTA_ENABLED]; it is still read when the new key is absent,
|
|
12
|
+
* and is removed when JS persists a value via [writeOtaEnabled].
|
|
13
|
+
*/
|
|
14
|
+
object BundleDropOtaPrefs {
|
|
15
|
+
const val PREFS_NAME = "BundleDropPrefs"
|
|
16
|
+
const val KEY_OTA_ENABLED = "bundledrop_ota_enabled"
|
|
17
|
+
private const val LEGACY_KEY_OTA_ENABLED = "ota_enabled"
|
|
18
|
+
|
|
19
|
+
fun preferences(context: Context): SharedPreferences =
|
|
20
|
+
context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
|
21
|
+
|
|
22
|
+
fun isOtaEnabled(context: Context): Boolean = readIsOtaEnabled(preferences(context))
|
|
23
|
+
|
|
24
|
+
fun readIsOtaEnabled(prefs: SharedPreferences): Boolean {
|
|
25
|
+
val hasNew = prefs.contains(KEY_OTA_ENABLED)
|
|
26
|
+
val hasLegacy = prefs.contains(LEGACY_KEY_OTA_ENABLED)
|
|
27
|
+
if (!hasNew && !hasLegacy) return true
|
|
28
|
+
return if (hasNew) {
|
|
29
|
+
prefs.getBoolean(KEY_OTA_ENABLED, true)
|
|
30
|
+
} else {
|
|
31
|
+
prefs.getBoolean(LEGACY_KEY_OTA_ENABLED, true)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
fun writeOtaEnabled(context: Context, enabled: Boolean) {
|
|
36
|
+
preferences(context).edit()
|
|
37
|
+
.putBoolean(KEY_OTA_ENABLED, enabled)
|
|
38
|
+
.remove(LEGACY_KEY_OTA_ENABLED)
|
|
39
|
+
.apply()
|
|
40
|
+
}
|
|
41
|
+
}
|
package/ios/BundleDropBridge.m
CHANGED
|
@@ -7,6 +7,10 @@ RCT_EXTERN_METHOD(getDownloadedBundlePath:(RCTPromiseResolveBlock)resolve
|
|
|
7
7
|
|
|
8
8
|
RCT_EXTERN_METHOD(restartReactNative)
|
|
9
9
|
|
|
10
|
+
RCT_EXTERN_METHOD(setOtaEnabled:(BOOL)enabled
|
|
11
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
12
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
13
|
+
|
|
10
14
|
// FS primitives
|
|
11
15
|
RCT_EXTERN_METHOD(fsExists:(NSString *)path
|
|
12
16
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
|
|
3
|
-
@objc public final class BundleDropLocator: NSObject {
|
|
3
|
+
@objc(BundleDropLocator) public final class BundleDropLocator: NSObject {
|
|
4
4
|
|
|
5
5
|
static let binaryVersionKey = "BundleDropBinaryVersion"
|
|
6
6
|
|
|
7
|
+
/// Matches Android `BundleDropOtaPrefs.KEY_OTA_ENABLED` for cross-platform debugging.
|
|
8
|
+
static let otaEnabledKey = "bundledrop_ota_enabled"
|
|
9
|
+
|
|
10
|
+
static func isOtaEnabled(userDefaults: UserDefaults = .standard) -> Bool {
|
|
11
|
+
if userDefaults.object(forKey: otaEnabledKey) == nil { return true }
|
|
12
|
+
return userDefaults.bool(forKey: otaEnabledKey)
|
|
13
|
+
}
|
|
14
|
+
|
|
7
15
|
static func getBinaryVersionKey(bundle: Bundle = .main) -> String {
|
|
8
16
|
let version = bundle.infoDictionary?["CFBundleShortVersionString"] as? String ?? "unknown"
|
|
9
17
|
let build = bundle.infoDictionary?["CFBundleVersion"] as? String ?? "0"
|
|
@@ -33,6 +41,8 @@ import Foundation
|
|
|
33
41
|
shouldLogBinaryUpdate: Bool = true,
|
|
34
42
|
log: (String) -> Void = { print($0) }
|
|
35
43
|
) -> URL? {
|
|
44
|
+
// Single gate for public and internal entrypoints (tests inject `userDefaults`).
|
|
45
|
+
if !isOtaEnabled(userDefaults: userDefaults) { return nil }
|
|
36
46
|
let lastVersion = userDefaults.string(forKey: binaryVersionKey)
|
|
37
47
|
let result = BundleDropOtaResolver.resolve(
|
|
38
48
|
bundleDropRoot: bundleDropRoot,
|
|
@@ -23,6 +23,16 @@ final class BundleDropModule: NSObject {
|
|
|
23
23
|
resolve(nil)
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
@objc
|
|
27
|
+
func setOtaEnabled(
|
|
28
|
+
_ enabled: Bool,
|
|
29
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
30
|
+
reject: @escaping RCTPromiseRejectBlock
|
|
31
|
+
) {
|
|
32
|
+
UserDefaults.standard.set(enabled, forKey: BundleDropLocator.otaEnabledKey)
|
|
33
|
+
resolve(nil)
|
|
34
|
+
}
|
|
35
|
+
|
|
26
36
|
@objc
|
|
27
37
|
func restartReactNative() {
|
|
28
38
|
DispatchQueue.main.async {
|
package/lib/CLI/cli.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.buildProgram = void 0;
|
|
8
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
9
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
10
|
const commander_1 = require("commander");
|
|
10
11
|
const figures_1 = __importDefault(require("figures"));
|
|
@@ -50,6 +51,38 @@ const logInvalidAuthFile = () => {
|
|
|
50
51
|
`CLI docs: ${DOCS_CLI_URL}\n` +
|
|
51
52
|
`CI/CD docs: ${DOCS_CI_CD_URL}`);
|
|
52
53
|
};
|
|
54
|
+
const fetchFreshAuthContext = async (params) => {
|
|
55
|
+
try {
|
|
56
|
+
const response = await axios_1.default.get(`${params.serverUrl}/auth/cli/context`, {
|
|
57
|
+
headers: {
|
|
58
|
+
Accept: 'application/json',
|
|
59
|
+
Authorization: `Bearer ${params.token}`,
|
|
60
|
+
},
|
|
61
|
+
timeout: 15000,
|
|
62
|
+
});
|
|
63
|
+
const context = response.data || {};
|
|
64
|
+
return {
|
|
65
|
+
user: context.email || context.firstName || context.lastName
|
|
66
|
+
? {
|
|
67
|
+
email: context.email,
|
|
68
|
+
firstName: context.firstName,
|
|
69
|
+
lastName: context.lastName,
|
|
70
|
+
}
|
|
71
|
+
: undefined,
|
|
72
|
+
projects: Array.isArray(context.projects) ? context.projects : [],
|
|
73
|
+
organizations: Array.isArray(context.organizations) ? context.organizations : [],
|
|
74
|
+
memberships: Array.isArray(context.memberships) ? context.memberships : [],
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
console.log(chalk_1.default.yellow('⚠️ Could not refresh BundleDrop project list; using cached login context.'));
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const writeStoredAuthData = (tokenPath, data) => {
|
|
83
|
+
fs_1.default.mkdirSync(path_1.default.dirname(tokenPath), { recursive: true });
|
|
84
|
+
fs_1.default.writeFileSync(tokenPath, JSON.stringify(data, null, 2), 'utf8');
|
|
85
|
+
};
|
|
53
86
|
const buildProgram = () => {
|
|
54
87
|
const program = new commander_1.Command();
|
|
55
88
|
program
|
|
@@ -82,6 +115,8 @@ ${chalk_1.default.gray('CI/CD →')} ${chalk_1.default.underline.gray(DOCS_CI_CD
|
|
|
82
115
|
.option('--release-notes <text>', 'Release notes (max 2000 chars)')
|
|
83
116
|
.option('--token <token>', 'Personal Access Token (alternative to `bundle-drop login`)')
|
|
84
117
|
.option('--author <name>', 'Override the author name stored with the bundle')
|
|
118
|
+
.option('--sourcemap', 'Generate source maps alongside the bundle for error tracking')
|
|
119
|
+
.option('--artifact-dir <path>', 'Copy bundle, source map, and result JSON to this directory before cleanup')
|
|
85
120
|
.description(chalk_1.default.whiteBright('Bundle and upload an OTA zip to the server'))
|
|
86
121
|
.addHelpText('after', `
|
|
87
122
|
${chalk_1.default.bold('Examples:')}
|
|
@@ -90,6 +125,7 @@ ${chalk_1.default.bold('Examples:')}
|
|
|
90
125
|
${chalk_1.default.gray('bundle-drop upload android --buildgradle-path android/app/build.gradle --channel QA --release-notes "Bug fixes"')}
|
|
91
126
|
${chalk_1.default.gray('bundle-drop upload android --version 1.2.3 --channel General --runtimeVersion 3.0.0')}
|
|
92
127
|
${chalk_1.default.gray('bundle-drop upload android --version 1.2.3 --channel General --token bdp_pat_xxx')}
|
|
128
|
+
${chalk_1.default.gray('bundle-drop upload android --version 1.2.3 --channel General --sourcemap --artifact-dir ./build/bundledrop')}
|
|
93
129
|
|
|
94
130
|
${chalk_1.default.gray('Uploading docs →')} ${chalk_1.default.underline.gray(DOCS_UPLOADING_URL)}
|
|
95
131
|
${chalk_1.default.gray('CI/CD docs →')} ${chalk_1.default.underline.gray(DOCS_CI_CD_URL)}
|
|
@@ -146,10 +182,19 @@ ${chalk_1.default.gray('CI/CD docs →')} ${chalk_1.default.underline.gray(DOCS_
|
|
|
146
182
|
logInvalidAuthFile();
|
|
147
183
|
return;
|
|
148
184
|
}
|
|
185
|
+
const serverUrl = normalizeServerUrl(data.serverUrl || data.baseUrl || process.env.BUNDLE_DROP_SERVER_URL);
|
|
186
|
+
const freshContext = await fetchFreshAuthContext({
|
|
187
|
+
serverUrl,
|
|
188
|
+
token: data.token,
|
|
189
|
+
});
|
|
190
|
+
const initData = freshContext ? { ...data, ...freshContext } : data;
|
|
191
|
+
if (freshContext) {
|
|
192
|
+
writeStoredAuthData(authState.tokenPath, initData);
|
|
193
|
+
}
|
|
149
194
|
await require('../CLI/scripts/init-config').initConfig({
|
|
150
|
-
serverUrl
|
|
151
|
-
projects:
|
|
152
|
-
organizations:
|
|
195
|
+
serverUrl,
|
|
196
|
+
projects: initData.projects || [],
|
|
197
|
+
organizations: initData.organizations || [],
|
|
153
198
|
downloadApiKey: data.downloadApiKey || '',
|
|
154
199
|
authToken: data.token,
|
|
155
200
|
});
|
|
@@ -157,9 +202,14 @@ ${chalk_1.default.gray('CI/CD docs →')} ${chalk_1.default.underline.gray(DOCS_
|
|
|
157
202
|
});
|
|
158
203
|
program
|
|
159
204
|
.command('init-native')
|
|
160
|
-
.
|
|
161
|
-
.
|
|
162
|
-
|
|
205
|
+
.option('--legacy', 'Use deterministic regex-based patching (no network)')
|
|
206
|
+
.description('Apply native changes (AppDelegate / MainApplication) automatically')
|
|
207
|
+
.action(async (options) => {
|
|
208
|
+
if (options.legacy) {
|
|
209
|
+
require('../CLI/scripts/init-native-config').initNativeConfig();
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
await require('../CLI/scripts/aipowered/init-native-config').initNativeConfigAi();
|
|
163
213
|
});
|
|
164
214
|
program
|
|
165
215
|
.command('init-metro')
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AiPatchPlan } from './types';
|
|
2
|
+
export type ApplyResult = {
|
|
3
|
+
backupDir: string;
|
|
4
|
+
changedFiles: string[];
|
|
5
|
+
};
|
|
6
|
+
export declare function restoreBackups(result: ApplyResult): void;
|
|
7
|
+
export declare function applyPatchPlans(params: {
|
|
8
|
+
projectRoot: string;
|
|
9
|
+
changes: AiPatchPlan[];
|
|
10
|
+
}): ApplyResult;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.restoreBackups = restoreBackups;
|
|
7
|
+
exports.applyPatchPlans = applyPatchPlans;
|
|
8
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const validate_plan_1 = require("./validate-plan");
|
|
12
|
+
const sha256 = (content) => crypto_1.default.createHash('sha256').update(content).digest('hex');
|
|
13
|
+
const timestamp = () => new Date().toISOString().replace(/[:.]/g, '-');
|
|
14
|
+
function restoreBackups(result) {
|
|
15
|
+
for (const relative of result.changedFiles) {
|
|
16
|
+
const backupPath = path_1.default.join(result.backupDir, relative);
|
|
17
|
+
if (fs_extra_1.default.existsSync(backupPath)) {
|
|
18
|
+
fs_extra_1.default.copyFileSync(backupPath, path_1.default.resolve(result.backupDir, '..', '..', relative));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function applyPatchPlans(params) {
|
|
23
|
+
const backupDir = path_1.default.join(params.projectRoot, '.bundledrop-backup', timestamp());
|
|
24
|
+
const changedFiles = [];
|
|
25
|
+
const result = { backupDir, changedFiles };
|
|
26
|
+
try {
|
|
27
|
+
for (const change of params.changes) {
|
|
28
|
+
if (!(0, validate_plan_1.isSafeRelativePath)(change.file) || !(0, validate_plan_1.isPatchableNativeEntrypoint)(change.file)) {
|
|
29
|
+
throw new Error(`Refusing to write AI plan outside native entrypoints: ${change.file}`);
|
|
30
|
+
}
|
|
31
|
+
const targetPath = path_1.default.join(params.projectRoot, change.file);
|
|
32
|
+
const original = fs_extra_1.default.readFileSync(targetPath, 'utf8');
|
|
33
|
+
if (sha256(original) !== change.originalSha256) {
|
|
34
|
+
throw new Error(`File changed since AI scan: ${change.file}`);
|
|
35
|
+
}
|
|
36
|
+
const backupPath = path_1.default.join(backupDir, change.file);
|
|
37
|
+
fs_extra_1.default.ensureDirSync(path_1.default.dirname(backupPath));
|
|
38
|
+
fs_extra_1.default.copyFileSync(targetPath, backupPath);
|
|
39
|
+
changedFiles.push(change.file);
|
|
40
|
+
const tmpPath = `${targetPath}.bundledrop-tmp`;
|
|
41
|
+
fs_extra_1.default.writeFileSync(tmpPath, change.updated, 'utf8');
|
|
42
|
+
fs_extra_1.default.renameSync(tmpPath, targetPath);
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
restoreBackups(result);
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.requestAiInitPlan = requestAiInitPlan;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const DEFAULT_AI_INIT_TIMEOUT_MS = 180000;
|
|
9
|
+
const resolveTimeoutMs = () => {
|
|
10
|
+
const value = Number(process.env.BUNDLE_DROP_AI_INIT_TIMEOUT_MS || process.env.AI_INIT_TIMEOUT_MS || '');
|
|
11
|
+
return Number.isFinite(value) && value > 0 ? value : DEFAULT_AI_INIT_TIMEOUT_MS;
|
|
12
|
+
};
|
|
13
|
+
async function requestAiInitPlan(params) {
|
|
14
|
+
try {
|
|
15
|
+
const response = await axios_1.default.post(`${params.serverUrl}/ai/init-plan`, params.request, {
|
|
16
|
+
headers: {
|
|
17
|
+
Accept: 'application/json',
|
|
18
|
+
Authorization: `Bearer ${params.authToken}`,
|
|
19
|
+
},
|
|
20
|
+
timeout: resolveTimeoutMs(),
|
|
21
|
+
});
|
|
22
|
+
return response.data;
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
const raw = error?.response?.data;
|
|
26
|
+
if (error?.code === 'ECONNABORTED' || /timeout/i.test(String(error?.message || ''))) {
|
|
27
|
+
throw new Error('AI planning request timed out. The backend may still be waiting on OpenAI; try again, or set BUNDLE_DROP_AI_INIT_TIMEOUT_MS to a larger value.');
|
|
28
|
+
}
|
|
29
|
+
const message = raw && typeof raw === 'object'
|
|
30
|
+
? raw.error || JSON.stringify(raw)
|
|
31
|
+
: raw || error?.message || 'AI planning request failed';
|
|
32
|
+
throw new Error(`AI planning request failed: ${message}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.buildUnifiedDiff = buildUnifiedDiff;
|
|
7
|
+
exports.colorizeUnifiedDiff = colorizeUnifiedDiff;
|
|
8
|
+
const diff_1 = require("diff");
|
|
9
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
+
function buildUnifiedDiff(params) {
|
|
11
|
+
return params.changes
|
|
12
|
+
.map(change => {
|
|
13
|
+
const original = params.originals.get(change.file) ?? '';
|
|
14
|
+
return (0, diff_1.createTwoFilesPatch)(`a/${change.file}`, `b/${change.file}`, original, change.updated, '', '', { context: 3 });
|
|
15
|
+
})
|
|
16
|
+
.join('\n');
|
|
17
|
+
}
|
|
18
|
+
function colorizeUnifiedDiff(diff) {
|
|
19
|
+
return diff
|
|
20
|
+
.split('\n')
|
|
21
|
+
.map(line => {
|
|
22
|
+
if (line.startsWith('+++') || line.startsWith('---'))
|
|
23
|
+
return chalk_1.default.bold(line);
|
|
24
|
+
if (line.startsWith('+'))
|
|
25
|
+
return chalk_1.default.green(line);
|
|
26
|
+
if (line.startsWith('-'))
|
|
27
|
+
return chalk_1.default.red(line);
|
|
28
|
+
if (line.startsWith('@@'))
|
|
29
|
+
return chalk_1.default.cyan(line);
|
|
30
|
+
return line;
|
|
31
|
+
})
|
|
32
|
+
.join('\n');
|
|
33
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.initNativeConfigAi = initNativeConfigAi;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
9
|
+
const apply_plan_1 = require("./apply-plan");
|
|
10
|
+
const backend_client_1 = require("./backend-client");
|
|
11
|
+
const diff_preview_1 = require("./diff-preview");
|
|
12
|
+
const scanner_1 = require("./scanner");
|
|
13
|
+
const validate_plan_1 = require("./validate-plan");
|
|
14
|
+
const ui_1 = require("../../utils/ui");
|
|
15
|
+
const DOCS_NATIVE_SETUP_URL = 'https://bundledrop.app/docs/installation#manual-native-setup';
|
|
16
|
+
const shouldApply = (change) => (change.confidence === 'high' && change.decisionType === 'safe_auto_patch') ||
|
|
17
|
+
((change.confidence === 'high' || change.confidence === 'medium') &&
|
|
18
|
+
change.decisionType === 'review_only_patch');
|
|
19
|
+
const addOrReplaceChange = (changes, change) => {
|
|
20
|
+
if (!change || !shouldApply(change))
|
|
21
|
+
return;
|
|
22
|
+
changes.set(change.file, change);
|
|
23
|
+
};
|
|
24
|
+
async function initNativeConfigAi() {
|
|
25
|
+
console.log(chalk_1.default.cyan('🧠 BundleDrop AI native initialization'));
|
|
26
|
+
const scan = (0, scanner_1.scanProjectForAiNativeInit)();
|
|
27
|
+
console.log(chalk_1.default.gray('Files that will be sent for AI planning:'));
|
|
28
|
+
scan.request.files.forEach(file => {
|
|
29
|
+
const mode = (0, scanner_1.isSummaryOnlyAiContextFile)(file.path) ? ' (summary only)' : '';
|
|
30
|
+
console.log(chalk_1.default.gray(` - ${file.path}${mode}`));
|
|
31
|
+
});
|
|
32
|
+
const host = scan.serverUrl.replace(/^https?:\/\//, '').replace(/\/.*$/, '');
|
|
33
|
+
console.log(chalk_1.default.gray(`Destination: ${host}`));
|
|
34
|
+
const sendAnswer = await (0, prompts_1.default)({
|
|
35
|
+
type: 'confirm',
|
|
36
|
+
name: 'send',
|
|
37
|
+
message: [
|
|
38
|
+
'BundleDrop will analyze a limited native setup context of your app to generate a safe patch plan.',
|
|
39
|
+
'',
|
|
40
|
+
'Included:',
|
|
41
|
+
' - native entrypoints are sent as-is',
|
|
42
|
+
' - project config/build files are summarized where possible',
|
|
43
|
+
' - prompts, patches, and project files are not stored by BundleDrop',
|
|
44
|
+
'',
|
|
45
|
+
'Send this setup context for AI planning? (y/n)',
|
|
46
|
+
].join('\n'),
|
|
47
|
+
initial: true,
|
|
48
|
+
});
|
|
49
|
+
if (!sendAnswer.send) {
|
|
50
|
+
console.log(chalk_1.default.gray('No files sent. No files changed.'));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const loading = (0, ui_1.startLoadingStatus)('Requesting AI native setup plan');
|
|
54
|
+
let plan;
|
|
55
|
+
try {
|
|
56
|
+
plan = await (0, backend_client_1.requestAiInitPlan)({
|
|
57
|
+
serverUrl: scan.serverUrl,
|
|
58
|
+
authToken: scan.authToken,
|
|
59
|
+
request: scan.request,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
loading.stop();
|
|
64
|
+
}
|
|
65
|
+
console.log(chalk_1.default.cyan('\nSummary:'));
|
|
66
|
+
console.log(plan.summary);
|
|
67
|
+
if (plan.confidence === 'low') {
|
|
68
|
+
console.log(chalk_1.default.yellow(`AI confidence is low, so no native files will be changed.\n` +
|
|
69
|
+
`Please use the manual setup guide: ${DOCS_NATIVE_SETUP_URL}`));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const selectedChanges = new Map();
|
|
73
|
+
plan.changes.forEach(change => addOrReplaceChange(selectedChanges, change));
|
|
74
|
+
for (const question of plan.questions) {
|
|
75
|
+
console.log(chalk_1.default.yellow(`\n${question.message}`));
|
|
76
|
+
const answer = await (0, prompts_1.default)({
|
|
77
|
+
type: 'confirm',
|
|
78
|
+
name: 'confirmed',
|
|
79
|
+
message: question.prompt,
|
|
80
|
+
initial: question.recommendedChoice === 'yes',
|
|
81
|
+
});
|
|
82
|
+
const confirmed = Boolean(answer.confirmed);
|
|
83
|
+
if (confirmed) {
|
|
84
|
+
addOrReplaceChange(selectedChanges, question.yesAction);
|
|
85
|
+
}
|
|
86
|
+
else if (question.noAction === 'manual_fallback') {
|
|
87
|
+
if (question.file)
|
|
88
|
+
selectedChanges.delete(question.file);
|
|
89
|
+
console.log(chalk_1.default.yellow(`Manual setup required. See ${DOCS_NATIVE_SETUP_URL}`));
|
|
90
|
+
}
|
|
91
|
+
else if (question.noAction === 'skip') {
|
|
92
|
+
if (question.file)
|
|
93
|
+
selectedChanges.delete(question.file);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
addOrReplaceChange(selectedChanges, question.noAction);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const changes = [...selectedChanges.values()];
|
|
100
|
+
if (!changes.length) {
|
|
101
|
+
console.log(chalk_1.default.gray('No native changes to apply.'));
|
|
102
|
+
console.log(chalk_1.default.gray(`If you expected changes, check that this React Native project has standard native entrypoints and no ambiguous custom bundle-loading setup. You can also continue with the manual setup guide: ${DOCS_NATIVE_SETUP_URL}`));
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const originals = new Map(scan.request.files.map(file => [file.path, file.content]));
|
|
106
|
+
(0, validate_plan_1.validateChangesBeforeApply)({ originals, changes });
|
|
107
|
+
console.log(chalk_1.default.cyan('\nProposed diff:'));
|
|
108
|
+
console.log((0, diff_preview_1.colorizeUnifiedDiff)((0, diff_preview_1.buildUnifiedDiff)({ projectRoot: scan.projectRoot, originals, changes })));
|
|
109
|
+
const finalAnswer = await (0, prompts_1.default)({
|
|
110
|
+
type: 'confirm',
|
|
111
|
+
name: 'apply',
|
|
112
|
+
message: 'Apply these AI-generated native changes?',
|
|
113
|
+
initial: true,
|
|
114
|
+
});
|
|
115
|
+
if (!finalAnswer.apply) {
|
|
116
|
+
console.log(chalk_1.default.gray('No files changed.'));
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const applyResult = (0, apply_plan_1.applyPatchPlans)({ projectRoot: scan.projectRoot, changes });
|
|
120
|
+
try {
|
|
121
|
+
(0, validate_plan_1.validateAppliedChanges)(scan.projectRoot, changes);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
(0, apply_plan_1.restoreBackups)(applyResult);
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
console.log(chalk_1.default.green('✅ AI native changes applied.'));
|
|
128
|
+
console.log(chalk_1.default.gray(`Backups saved at ${applyResult.backupDir}`));
|
|
129
|
+
console.log(chalk_1.default.gray('Recommended next check: review the native file changes and run your usual app build before shipping.'));
|
|
130
|
+
}
|
|
131
|
+
exports.default = initNativeConfigAi;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AiScannerResult } from './types';
|
|
2
|
+
export declare const isSummaryOnlyAiContextFile: (relativePath: string) => boolean;
|
|
3
|
+
export declare const isTrustedAiPlanningServer: (serverUrl: string) => boolean;
|
|
4
|
+
export declare function findProjectRoot(startDir?: string): string;
|
|
5
|
+
export declare function scanProjectForAiNativeInit(startDir?: string): AiScannerResult;
|