@gfean/react-native-bundle-drop 0.3.2 → 0.3.5

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.
Files changed (51) hide show
  1. package/BundleDrop.podspec +4 -1
  2. package/LICENSE +15 -0
  3. package/README.md +120 -253
  4. package/android/build.gradle +91 -1
  5. package/android/gradle.properties +1 -0
  6. package/android/src/main/java/com/bundledrop/BundleDropFileOps.kt +131 -0
  7. package/android/src/main/java/com/bundledrop/BundleDropModule.kt +65 -89
  8. package/android/src/main/java/com/bundledrop/BundleDropOtaResolver.kt +93 -0
  9. package/ios/BundleDropBridge.m +14 -0
  10. package/ios/BundleDropFileOps.swift +220 -0
  11. package/ios/BundleDropLocator.swift +33 -44
  12. package/ios/BundleDropModule.swift +65 -15
  13. package/ios/BundleDropOtaResolver.swift +112 -0
  14. package/ios/BundleDropZipExtractor.h +13 -0
  15. package/ios/BundleDropZipExtractor.m +226 -0
  16. package/lib/CLI/cli.js +15 -3
  17. package/lib/CLI/scripts/init-config.js +12 -5
  18. package/lib/CLI/scripts/init-native-config.js +17 -9
  19. package/lib/CLI/scripts/post-init.js +9 -3
  20. package/lib/CLI/scripts/upload-cli.js +26 -9
  21. package/lib/api/types.d.ts +4 -3
  22. package/lib/bundleInfo.d.ts +12 -0
  23. package/lib/context.d.ts +17 -0
  24. package/lib/context.js +3 -0
  25. package/lib/errors.d.ts +25 -0
  26. package/lib/errors.js +26 -1
  27. package/lib/fs/fsUtils.d.ts +1 -2
  28. package/lib/fs/fsUtils.js +12 -27
  29. package/lib/fs/userProperties.d.ts +25 -4
  30. package/lib/fs/userProperties.js +51 -7
  31. package/lib/index.d.ts +1 -0
  32. package/lib/install/installFromZip.d.ts +1 -1
  33. package/lib/install/installFromZip.js +47 -42
  34. package/lib/loadConfig.d.ts +19 -0
  35. package/lib/loadConfig.js +11 -7
  36. package/lib/manager/downloadAndInstall.js +7 -25
  37. package/lib/manager/reporting.js +2 -2
  38. package/lib/manager/rollbackState.d.ts +3 -3
  39. package/lib/manager/rollbackState.js +6 -19
  40. package/lib/manager/updateCheck.js +2 -2
  41. package/lib/native/fs.d.ts +6 -0
  42. package/lib/native/fs.js +27 -0
  43. package/lib/runtime/initState.d.ts +2 -2
  44. package/lib/runtime/service.js +2 -0
  45. package/lib/scripts/bundle.js +2 -2
  46. package/lib/scripts/resolve-ios-version.d.ts +2 -0
  47. package/lib/scripts/resolve-ios-version.js +74 -0
  48. package/lib/scripts/upload-bundle.js +10 -4
  49. package/lib/types.d.ts +3 -0
  50. package/package.json +53 -16
  51. package/CLIENT_README.md +0 -411
@@ -90,11 +90,12 @@ final class BundleDropModule: NSObject {
90
90
  return
91
91
  }
92
92
  do {
93
+ let fileURL = URL(fileURLWithPath: path)
93
94
  if encoding == "base64" {
94
- let data = try Data(contentsOf: URL(fileURLWithPath: path))
95
+ let data = try Data(contentsOf: fileURL)
95
96
  resolve(data.base64EncodedString())
96
97
  } else {
97
- let text = try String(contentsOfFile: path, encoding: .utf8)
98
+ let text = try String(contentsOf: fileURL, encoding: .utf8)
98
99
  resolve(text)
99
100
  }
100
101
  } catch {
@@ -115,14 +116,15 @@ final class BundleDropModule: NSObject {
115
116
  if !Self.fm.fileExists(atPath: dir) {
116
117
  try Self.fm.createDirectory(atPath: dir, withIntermediateDirectories: true)
117
118
  }
119
+ let fileURL = URL(fileURLWithPath: path)
118
120
  if encoding == "base64" {
119
121
  guard let data = Data(base64Encoded: content) else {
120
122
  reject("ERR_WRITE", "Invalid base64 data", nil)
121
123
  return
122
124
  }
123
- try data.write(to: URL(fileURLWithPath: path))
125
+ try data.write(to: fileURL)
124
126
  } else {
125
- try content.write(toFile: path, atomically: true, encoding: .utf8)
127
+ try content.write(to: fileURL, atomically: true, encoding: .utf8)
126
128
  }
127
129
  resolve(nil)
128
130
  } catch {
@@ -153,15 +155,27 @@ final class BundleDropModule: NSObject {
153
155
  reject: @escaping RCTPromiseRejectBlock
154
156
  ) {
155
157
  do {
156
- if Self.fm.fileExists(atPath: path) {
157
- try Self.fm.removeItem(atPath: path)
158
- }
158
+ try BundleDropFileOps.unlinkPath(path)
159
159
  resolve(nil)
160
160
  } catch {
161
161
  reject("ERR_UNLINK", error.localizedDescription, error)
162
162
  }
163
163
  }
164
164
 
165
+ @objc
166
+ func fsReadDir(
167
+ _ path: String,
168
+ resolve: @escaping RCTPromiseResolveBlock,
169
+ reject: @escaping RCTPromiseRejectBlock
170
+ ) {
171
+ do {
172
+ let items = try Self.fm.contentsOfDirectory(atPath: path)
173
+ resolve(items)
174
+ } catch {
175
+ reject("ERR_READDIR", error.localizedDescription, error)
176
+ }
177
+ }
178
+
165
179
  @objc
166
180
  func fsMoveFile(
167
181
  _ src: String,
@@ -170,17 +184,53 @@ final class BundleDropModule: NSObject {
170
184
  reject: @escaping RCTPromiseRejectBlock
171
185
  ) {
172
186
  do {
173
- let destDir = (dest as NSString).deletingLastPathComponent
174
- if !Self.fm.fileExists(atPath: destDir) {
175
- try Self.fm.createDirectory(atPath: destDir, withIntermediateDirectories: true)
176
- }
177
- if Self.fm.fileExists(atPath: dest) {
178
- try Self.fm.removeItem(atPath: dest)
179
- }
180
- try Self.fm.moveItem(atPath: src, toPath: dest)
187
+ try BundleDropFileOps.moveFile(srcPath: src, destPath: dest)
181
188
  resolve(nil)
182
189
  } catch {
183
190
  reject("ERR_MOVE", error.localizedDescription, error)
184
191
  }
185
192
  }
193
+
194
+ @objc
195
+ func fsUnzip(
196
+ _ zipPath: String,
197
+ destPath: String,
198
+ resolve: @escaping RCTPromiseResolveBlock,
199
+ reject: @escaping RCTPromiseRejectBlock
200
+ ) {
201
+ DispatchQueue.global(qos: .userInitiated).async {
202
+ do {
203
+ let filenames = try BundleDropZipExtractor.extractZip(atPath: zipPath,
204
+ toDirectory: destPath)
205
+ resolve(filenames ?? [])
206
+ } catch {
207
+ reject("ERR_UNZIP", error.localizedDescription, error)
208
+ }
209
+ }
210
+ }
211
+
212
+ @objc
213
+ func fsDownloadFile(
214
+ _ url: String,
215
+ destPath: String,
216
+ resolve: @escaping RCTPromiseResolveBlock,
217
+ reject: @escaping RCTPromiseRejectBlock
218
+ ) {
219
+ let config = URLSessionConfiguration.default
220
+ config.timeoutIntervalForRequest = 30
221
+ config.timeoutIntervalForResource = 300
222
+
223
+ BundleDropFileOps.downloadToFile(
224
+ urlString: url,
225
+ destPath: destPath,
226
+ configuration: config
227
+ ) { result in
228
+ switch result {
229
+ case .success:
230
+ resolve(nil)
231
+ case .failure(let error):
232
+ reject("ERR_DOWNLOAD", error.localizedDescription, error)
233
+ }
234
+ }
235
+ }
186
236
  }
@@ -0,0 +1,112 @@
1
+ import Foundation
2
+
3
+ struct BundleDropOtaResolveResult {
4
+ let bundleURL: URL?
5
+ let clearedOta: Bool
6
+ let storedVersion: String
7
+ }
8
+
9
+ enum BundleDropOtaResolver {
10
+ static func readCurrentPointer(
11
+ bundleDropRoot: URL,
12
+ fileManager: FileManager = .default
13
+ ) -> URL? {
14
+ let current = bundleDropRoot.appendingPathComponent("current.json")
15
+ guard fileManager.fileExists(atPath: current.path) else { return nil }
16
+
17
+ do {
18
+ let data = try Data(contentsOf: current)
19
+ let obj = try JSONSerialization.jsonObject(with: data) as? [String: Any]
20
+ guard let bundlePath = obj?["bundlePath"] as? String, !bundlePath.isEmpty else {
21
+ return nil
22
+ }
23
+
24
+ let url = URL(fileURLWithPath: bundlePath)
25
+ return fileManager.fileExists(atPath: url.path) ? url : nil
26
+ } catch {
27
+ return nil
28
+ }
29
+ }
30
+
31
+ static func clearOtaState(
32
+ bundleDropRoot: URL,
33
+ documentsDirectory: URL,
34
+ fileManager: FileManager = .default
35
+ ) {
36
+ let filesToClear = [
37
+ bundleDropRoot.appendingPathComponent("current.json"),
38
+ bundleDropRoot.appendingPathComponent("previous.json"),
39
+ bundleDropRoot.appendingPathComponent("state.json"),
40
+ documentsDirectory.appendingPathComponent("bundle-info.json"),
41
+ ]
42
+
43
+ filesToClear.forEach { url in
44
+ do {
45
+ if fileManager.fileExists(atPath: url.path) {
46
+ try fileManager.removeItem(at: url)
47
+ }
48
+ } catch {
49
+ // Best effort cleanup; a single bad file should not block native fallback.
50
+ }
51
+ }
52
+ }
53
+
54
+ static func hasOtaState(
55
+ bundleDropRoot: URL,
56
+ documentsDirectory: URL,
57
+ fileManager: FileManager = .default
58
+ ) -> Bool {
59
+ [
60
+ bundleDropRoot.appendingPathComponent("current.json"),
61
+ bundleDropRoot.appendingPathComponent("previous.json"),
62
+ bundleDropRoot.appendingPathComponent("state.json"),
63
+ documentsDirectory.appendingPathComponent("bundle-info.json"),
64
+ ].contains { url in
65
+ fileManager.fileExists(atPath: url.path)
66
+ }
67
+ }
68
+
69
+ static func resolve(
70
+ bundleDropRoot: URL,
71
+ documentsDirectory: URL,
72
+ currentBinaryVersion: String,
73
+ storedBinaryVersion: String?,
74
+ fileManager: FileManager = .default
75
+ ) -> BundleDropOtaResolveResult {
76
+ if let storedBinaryVersion = storedBinaryVersion,
77
+ storedBinaryVersion != currentBinaryVersion {
78
+ let hadOtaState = hasOtaState(
79
+ bundleDropRoot: bundleDropRoot,
80
+ documentsDirectory: documentsDirectory,
81
+ fileManager: fileManager
82
+ )
83
+ clearOtaState(
84
+ bundleDropRoot: bundleDropRoot,
85
+ documentsDirectory: documentsDirectory,
86
+ fileManager: fileManager
87
+ )
88
+ return BundleDropOtaResolveResult(
89
+ bundleURL: nil,
90
+ clearedOta: hadOtaState,
91
+ storedVersion: currentBinaryVersion
92
+ )
93
+ }
94
+
95
+ guard let bundleURL = readCurrentPointer(
96
+ bundleDropRoot: bundleDropRoot,
97
+ fileManager: fileManager
98
+ ) else {
99
+ return BundleDropOtaResolveResult(
100
+ bundleURL: nil,
101
+ clearedOta: false,
102
+ storedVersion: currentBinaryVersion
103
+ )
104
+ }
105
+
106
+ return BundleDropOtaResolveResult(
107
+ bundleURL: bundleURL,
108
+ clearedOta: false,
109
+ storedVersion: currentBinaryVersion
110
+ )
111
+ }
112
+ }
@@ -0,0 +1,13 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ @interface BundleDropZipExtractor : NSObject
4
+ + (nullable NSArray<NSString *> *)extractZipAtPath:(nonnull NSString *)zipPath
5
+ toDirectory:(nonnull NSString *)destPath
6
+ error:(NSError * _Nullable * _Nullable)error;
7
+ + (nullable NSArray<NSString *> *)extractZipAtPath:(nonnull NSString *)zipPath
8
+ toDirectory:(nonnull NSString *)destPath
9
+ maxZipFileSize:(NSUInteger)maxZipFileSize
10
+ maxEntrySize:(NSUInteger)maxEntrySize
11
+ maxTotalUncompressed:(NSUInteger)maxTotalUncompressed
12
+ error:(NSError * _Nullable * _Nullable)error;
13
+ @end
@@ -0,0 +1,226 @@
1
+ #import "BundleDropZipExtractor.h"
2
+ #include <zlib.h>
3
+
4
+ static uint16_t zipRead16(const uint8_t *buf) {
5
+ return (uint16_t)buf[0] | ((uint16_t)buf[1] << 8);
6
+ }
7
+
8
+ static uint32_t zipRead32(const uint8_t *buf) {
9
+ return (uint32_t)buf[0] | ((uint32_t)buf[1] << 8) |
10
+ ((uint32_t)buf[2] << 16) | ((uint32_t)buf[3] << 24);
11
+ }
12
+
13
+ @implementation BundleDropZipExtractor
14
+
15
+ static const NSUInteger kMaxZipFileSize = 256 * 1024 * 1024; // 256 MB
16
+ static const NSUInteger kMaxEntrySize = 128 * 1024 * 1024; // 128 MB per entry
17
+ static const NSUInteger kMaxTotalUncompressed = 512 * 1024 * 1024; // 512 MB total
18
+
19
+ + (BOOL)isPath:(NSString *)path safelyInsideDirectory:(NSString *)dir {
20
+ NSString *resolvedDir = [dir stringByResolvingSymlinksInPath];
21
+ NSString *resolvedPath = [path stringByResolvingSymlinksInPath];
22
+ NSString *prefix = [resolvedDir stringByAppendingString:@"/"];
23
+ return [resolvedPath hasPrefix:prefix];
24
+ }
25
+
26
+ + (NSArray<NSString *> *)extractZipAtPath:(NSString *)zipPath
27
+ toDirectory:(NSString *)destPath
28
+ error:(NSError **)error {
29
+ return [self extractZipAtPath:zipPath
30
+ toDirectory:destPath
31
+ maxZipFileSize:kMaxZipFileSize
32
+ maxEntrySize:kMaxEntrySize
33
+ maxTotalUncompressed:kMaxTotalUncompressed
34
+ error:error];
35
+ }
36
+
37
+ + (NSArray<NSString *> *)extractZipAtPath:(NSString *)zipPath
38
+ toDirectory:(NSString *)destPath
39
+ maxZipFileSize:(NSUInteger)maxZipFileSize
40
+ maxEntrySize:(NSUInteger)maxEntrySize
41
+ maxTotalUncompressed:(NSUInteger)maxTotalUncompressed
42
+ error:(NSError **)error {
43
+ NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:zipPath error:error];
44
+ if (!attrs) return nil;
45
+ NSUInteger fileSize = [attrs[NSFileSize] unsignedIntegerValue];
46
+ if (fileSize > maxZipFileSize) {
47
+ if (error)
48
+ *error = [NSError errorWithDomain:@"BundleDrop" code:5
49
+ userInfo:@{NSLocalizedDescriptionKey:
50
+ [NSString stringWithFormat:@"ZIP too large: %lu bytes (max %lu)",
51
+ (unsigned long)fileSize, (unsigned long)maxZipFileSize]}];
52
+ return nil;
53
+ }
54
+
55
+ NSData *data = [NSData dataWithContentsOfFile:zipPath options:0 error:error];
56
+ if (!data) return nil;
57
+
58
+ const uint8_t *bytes = data.bytes;
59
+ NSUInteger length = data.length;
60
+
61
+ NSInteger eocdOffset = -1;
62
+ for (NSInteger i = (NSInteger)length - 22;
63
+ i >= 0 && i >= (NSInteger)length - 65557; i--) {
64
+ if (zipRead32(bytes + i) == 0x06054b50) {
65
+ eocdOffset = i;
66
+ break;
67
+ }
68
+ }
69
+
70
+ if (eocdOffset < 0) {
71
+ if (error)
72
+ *error = [NSError errorWithDomain:@"BundleDrop" code:1
73
+ userInfo:@{NSLocalizedDescriptionKey: @"Invalid ZIP: end-of-central-directory not found"}];
74
+ return nil;
75
+ }
76
+
77
+ uint16_t entryCount = zipRead16(bytes + eocdOffset + 10);
78
+ uint32_t cdOffset = zipRead32(bytes + eocdOffset + 16);
79
+
80
+ NSFileManager *fm = [NSFileManager defaultManager];
81
+ if (![fm fileExistsAtPath:destPath]) {
82
+ [fm createDirectoryAtPath:destPath withIntermediateDirectories:YES attributes:nil error:nil];
83
+ }
84
+
85
+ NSMutableArray<NSString *> *filenames = [NSMutableArray new];
86
+ NSUInteger offset = cdOffset;
87
+ NSUInteger totalUncompressed = 0;
88
+
89
+ for (uint16_t idx = 0; idx < entryCount; idx++) {
90
+ if (offset + 46 > length) break;
91
+ if (zipRead32(bytes + offset) != 0x02014b50) break;
92
+
93
+ uint16_t method = zipRead16(bytes + offset + 10);
94
+ uint32_t compressedSize = zipRead32(bytes + offset + 20);
95
+ uint32_t uncompressedSize = zipRead32(bytes + offset + 24);
96
+ uint16_t nameLen = zipRead16(bytes + offset + 28);
97
+ uint16_t extraLen = zipRead16(bytes + offset + 30);
98
+ uint16_t commentLen = zipRead16(bytes + offset + 32);
99
+ uint32_t localHdrOffset = zipRead32(bytes + offset + 42);
100
+
101
+ if (offset + 46 + nameLen > length) break;
102
+
103
+ NSString *name = [[NSString alloc] initWithBytes:bytes + offset + 46
104
+ length:nameLen
105
+ encoding:NSUTF8StringEncoding];
106
+ offset += 46 + nameLen + extraLen + commentLen;
107
+
108
+ if (!name) continue;
109
+
110
+ if ([name hasSuffix:@"/"]) {
111
+ NSString *dirPath = [[destPath stringByAppendingPathComponent:name] stringByStandardizingPath];
112
+ if (![self isPath:dirPath safelyInsideDirectory:destPath]) {
113
+ if (error)
114
+ *error = [NSError errorWithDomain:@"BundleDrop" code:6
115
+ userInfo:@{NSLocalizedDescriptionKey:
116
+ [NSString stringWithFormat:@"Zip entry outside target dir: %@", name]}];
117
+ return nil;
118
+ }
119
+ [fm createDirectoryAtPath:dirPath withIntermediateDirectories:YES attributes:nil error:nil];
120
+ continue;
121
+ }
122
+
123
+ if (localHdrOffset + 30 > length) continue;
124
+ uint16_t localNameLen = zipRead16(bytes + localHdrOffset + 26);
125
+ uint16_t localExtraLen = zipRead16(bytes + localHdrOffset + 28);
126
+ NSUInteger dataStart = localHdrOffset + 30 + localNameLen + localExtraLen;
127
+ NSUInteger dataEnd = dataStart + compressedSize;
128
+ if (dataEnd > length) continue;
129
+
130
+ NSUInteger entryOutputSize = (method == 0) ? compressedSize : uncompressedSize;
131
+ if (entryOutputSize > maxEntrySize) {
132
+ if (error)
133
+ *error = [NSError errorWithDomain:@"BundleDrop" code:7
134
+ userInfo:@{NSLocalizedDescriptionKey:
135
+ [NSString stringWithFormat:@"ZIP entry too large: %lu bytes (max %lu)",
136
+ (unsigned long)entryOutputSize, (unsigned long)maxEntrySize]}];
137
+ return nil;
138
+ }
139
+ totalUncompressed += entryOutputSize;
140
+ if (totalUncompressed > maxTotalUncompressed) {
141
+ if (error)
142
+ *error = [NSError errorWithDomain:@"BundleDrop" code:8
143
+ userInfo:@{NSLocalizedDescriptionKey:
144
+ [NSString stringWithFormat:@"ZIP total uncompressed too large: %lu bytes (max %lu)",
145
+ (unsigned long)totalUncompressed, (unsigned long)maxTotalUncompressed]}];
146
+ return nil;
147
+ }
148
+
149
+ NSData *fileData;
150
+ if (method == 0) {
151
+ fileData = [data subdataWithRange:NSMakeRange(dataStart, compressedSize)];
152
+ } else if (method == 8) {
153
+ fileData = [self inflateRaw:bytes + dataStart
154
+ length:compressedSize
155
+ uncompressedSize:uncompressedSize
156
+ error:error];
157
+ if (!fileData) return nil;
158
+ } else {
159
+ if (error)
160
+ *error = [NSError errorWithDomain:@"BundleDrop" code:2
161
+ userInfo:@{NSLocalizedDescriptionKey:
162
+ [NSString stringWithFormat:@"Unsupported ZIP compression method: %d", method]}];
163
+ return nil;
164
+ }
165
+
166
+ NSString *filePath = [[destPath stringByAppendingPathComponent:name] stringByStandardizingPath];
167
+ if (![self isPath:filePath safelyInsideDirectory:destPath]) {
168
+ if (error)
169
+ *error = [NSError errorWithDomain:@"BundleDrop" code:6
170
+ userInfo:@{NSLocalizedDescriptionKey:
171
+ [NSString stringWithFormat:@"Zip entry outside target dir: %@", name]}];
172
+ return nil;
173
+ }
174
+ NSString *fileDir = [filePath stringByDeletingLastPathComponent];
175
+ if (![fm fileExistsAtPath:fileDir]) {
176
+ [fm createDirectoryAtPath:fileDir withIntermediateDirectories:YES attributes:nil error:nil];
177
+ }
178
+ [fileData writeToFile:filePath atomically:YES];
179
+ [filenames addObject:name];
180
+ }
181
+
182
+ return filenames;
183
+ }
184
+
185
+ #pragma mark - Raw DEFLATE decompression via zlib
186
+
187
+ + (NSData *)inflateRaw:(const uint8_t *)src
188
+ length:(NSUInteger)srcLen
189
+ uncompressedSize:(NSUInteger)dstLen
190
+ error:(NSError **)error {
191
+ if (dstLen == 0) return [NSData data];
192
+
193
+ NSMutableData *output = [NSMutableData dataWithLength:dstLen];
194
+
195
+ z_stream stream;
196
+ memset(&stream, 0, sizeof(stream));
197
+ stream.next_in = (Bytef *)src;
198
+ stream.avail_in = (uInt)srcLen;
199
+ stream.next_out = output.mutableBytes;
200
+ stream.avail_out = (uInt)dstLen;
201
+
202
+ int ret = inflateInit2(&stream, -MAX_WBITS);
203
+ if (ret != Z_OK) {
204
+ if (error)
205
+ *error = [NSError errorWithDomain:@"BundleDrop" code:3
206
+ userInfo:@{NSLocalizedDescriptionKey:
207
+ [NSString stringWithFormat:@"inflateInit2 failed: %d", ret]}];
208
+ return nil;
209
+ }
210
+
211
+ ret = inflate(&stream, Z_FINISH);
212
+ inflateEnd(&stream);
213
+
214
+ if (ret != Z_STREAM_END) {
215
+ if (error)
216
+ *error = [NSError errorWithDomain:@"BundleDrop" code:4
217
+ userInfo:@{NSLocalizedDescriptionKey:
218
+ [NSString stringWithFormat:@"inflate failed: %d", ret]}];
219
+ return nil;
220
+ }
221
+
222
+ output.length = stream.total_out;
223
+ return output;
224
+ }
225
+
226
+ @end
package/lib/CLI/cli.js CHANGED
@@ -23,6 +23,9 @@ const logo = chalk_1.default.cyanBright(`
23
23
  |_______/|______.'
24
24
  `) + chalk_1.default.bold.cyanBright(`\n${figures_1.default.star} React Native Bundle Drop CLI ${figures_1.default.star}`);
25
25
  const DEFAULT_SERVER_URL = 'https://api.bundledrop.app';
26
+ const DOCS_CLI_URL = 'https://bundledrop.app/docs/cli';
27
+ const DOCS_UPLOADING_URL = 'https://bundledrop.app/docs/uploading';
28
+ const DOCS_CI_CD_URL = 'https://bundledrop.app/docs/ci-cd';
26
29
  const getTokenPath = () => path_1.default.join(os_1.default.homedir(), '.bundle-drop', 'auth.json');
27
30
  const normalizeServerUrl = (url) => url?.replace(/\/$/, '') || DEFAULT_SERVER_URL;
28
31
  const readStoredAuthData = () => {
@@ -43,7 +46,9 @@ const readStoredAuthData = () => {
43
46
  }
44
47
  };
45
48
  const logInvalidAuthFile = () => {
46
- console.log('❌ Failed to read CLI auth session. Please run `bundle-drop login` again or use --token.');
49
+ console.log('❌ Failed to read CLI auth session. Please run `bundle-drop login` again or use --token.\n' +
50
+ `CLI docs: ${DOCS_CLI_URL}\n` +
51
+ `CI/CD docs: ${DOCS_CI_CD_URL}`);
47
52
  };
48
53
  const buildProgram = () => {
49
54
  const program = new commander_1.Command();
@@ -63,7 +68,9 @@ ${chalk_1.default.bold.cyan('Common Usage:')}
63
68
  ${chalk_1.default.gray('bundle-drop upload ios --plist-file ios/Info.plist --channel General')}
64
69
  ${chalk_1.default.gray('bundle-drop upload android --buildgradle-path android/app/build.gradle --channel General --release-notes "Fixes"')}
65
70
 
66
- ${chalk_1.default.gray('Need help? →')} ${chalk_1.default.underline.gray('https://github.com/GFean/react-native-bundle-drop')}\n`);
71
+ ${chalk_1.default.gray('Docs →')} ${chalk_1.default.underline.gray(DOCS_CLI_URL)}
72
+ ${chalk_1.default.gray('Uploading →')} ${chalk_1.default.underline.gray(DOCS_UPLOADING_URL)}
73
+ ${chalk_1.default.gray('CI/CD →')} ${chalk_1.default.underline.gray(DOCS_CI_CD_URL)}\n`);
67
74
  program
68
75
  .command('upload')
69
76
  .argument('<platform>', chalk_1.default.gray('ios or android'))
@@ -83,6 +90,9 @@ ${chalk_1.default.bold('Examples:')}
83
90
  ${chalk_1.default.gray('bundle-drop upload android --buildgradle-path android/app/build.gradle --channel QA --release-notes "Bug fixes"')}
84
91
  ${chalk_1.default.gray('bundle-drop upload android --version 1.2.3 --channel General --runtimeVersion 3.0.0')}
85
92
  ${chalk_1.default.gray('bundle-drop upload android --version 1.2.3 --channel General --token bdp_pat_xxx')}
93
+
94
+ ${chalk_1.default.gray('Uploading docs →')} ${chalk_1.default.underline.gray(DOCS_UPLOADING_URL)}
95
+ ${chalk_1.default.gray('CI/CD docs →')} ${chalk_1.default.underline.gray(DOCS_CI_CD_URL)}
86
96
  `)
87
97
  .action(upload_cli_1.default);
88
98
  program
@@ -122,7 +132,9 @@ ${chalk_1.default.bold('Examples:')}
122
132
  }
123
133
  const authState = readStoredAuthData();
124
134
  if (!authState.exists) {
125
- console.log('ℹ️ Not logged in. Please run `bundle-drop login` or use --token.');
135
+ console.log('ℹ️ Not logged in. Please run `bundle-drop login` or use --token.\n' +
136
+ `CLI docs: ${DOCS_CLI_URL}\n` +
137
+ `CI/CD docs: ${DOCS_CI_CD_URL}`);
126
138
  return;
127
139
  }
128
140
  if (authState.isInvalid || !authState.data) {
@@ -11,6 +11,8 @@ const chalk_1 = __importDefault(require("chalk"));
11
11
  const fs_extra_1 = __importDefault(require("fs-extra"));
12
12
  const path_1 = __importDefault(require("path"));
13
13
  const prompts_1 = __importDefault(require("prompts"));
14
+ const DOCS_PROJECT_CREATION_URL = 'https://bundledrop.app/docs/project-creation';
15
+ const DOCS_INSTALLATION_URL = 'https://bundledrop.app/docs/installation';
14
16
  function normalizeServerUrl(url) {
15
17
  return url.replace(/\/$/, '');
16
18
  }
@@ -28,7 +30,8 @@ async function fetchProjectCredentials(params) {
28
30
  return res.data || null;
29
31
  }
30
32
  catch (err) {
31
- console.log(chalk_1.default.yellow(`⚠️ Failed to fetch project credentials from ${url}. Please verify login and project access.`));
33
+ console.log(chalk_1.default.yellow(`⚠️ Failed to fetch project credentials from ${url}. Please verify login and project access.\n` +
34
+ `If the project is not set up yet, see ${DOCS_PROJECT_CREATION_URL}`));
32
35
  return null;
33
36
  }
34
37
  }
@@ -55,14 +58,16 @@ function hasExistingBundleDropConfig(startDir = process.cwd()) {
55
58
  async function initConfig(params) {
56
59
  const configPath = getBundleDropConfigPath();
57
60
  if (fs_extra_1.default.existsSync(configPath)) {
58
- console.log(chalk_1.default.yellow(`ℹ️ bundle.drop.config.js already exists at ${configPath}. If this is accidental, delete it and rerun the init/login.`));
61
+ console.log(chalk_1.default.yellow(`ℹ️ bundle.drop.config.js already exists at ${configPath}. If this is accidental, delete it and rerun the init/login.\n` +
62
+ `See ${DOCS_INSTALLATION_URL}`));
59
63
  return;
60
64
  }
61
65
  let orgSlug = '';
62
66
  let project = null;
63
67
  // Org selection
64
68
  if (!params.organizations || params.organizations.length === 0) {
65
- console.log(chalk_1.default.yellow('⚠️ No organizations returned; org slug will be left blank.'));
69
+ console.log(chalk_1.default.yellow(`⚠️ No organizations returned; org slug will be left blank.\n` +
70
+ `Create an organization first: ${DOCS_PROJECT_CREATION_URL}`));
66
71
  }
67
72
  else if (params.organizations.length === 1) {
68
73
  orgSlug = params.organizations[0].slug;
@@ -85,7 +90,8 @@ async function initConfig(params) {
85
90
  }
86
91
  // Project selection
87
92
  if (!params.projects?.length) {
88
- console.log(chalk_1.default.red('⚠️ No projects returned; project values will be left blank.'));
93
+ console.log(chalk_1.default.red(`⚠️ No projects returned; project values will be left blank.\n` +
94
+ `Create a project first: ${DOCS_PROJECT_CREATION_URL}`));
89
95
  }
90
96
  else if (params.projects.length === 1) {
91
97
  project = params.projects[0];
@@ -125,7 +131,8 @@ async function initConfig(params) {
125
131
  apiKey = credentials.downloadApiKey;
126
132
  }
127
133
  else if (!apiKey) {
128
- console.log(chalk_1.default.yellow('⚠️ No project API key returned from /projects/:projectSlug/credentials; config will be created without apiKey.'));
134
+ console.log(chalk_1.default.yellow('⚠️ No project API key returned from /projects/:projectSlug/credentials; config will be created without apiKey.\n' +
135
+ `See ${DOCS_INSTALLATION_URL}`));
129
136
  }
130
137
  }
131
138
  else if (projectSlug && !params.authToken && !apiKey) {
@@ -19,6 +19,9 @@ const chalk_1 = __importDefault(require("chalk"));
19
19
  const fs_extra_1 = __importDefault(require("fs-extra"));
20
20
  const path_1 = __importDefault(require("path"));
21
21
  const prompts_1 = __importDefault(require("prompts"));
22
+ const DOCS_INSTALLATION_URL = 'https://bundledrop.app/docs/installation';
23
+ const DOCS_ANDROID_NATIVE_SETUP_URL = `${DOCS_INSTALLATION_URL}#android-mainapplication`;
24
+ const DOCS_IOS_NATIVE_SETUP_URL = `${DOCS_INSTALLATION_URL}#ios-appdelegate`;
22
25
  function findProjectRoot(startDir) {
23
26
  let dir = path_1.default.resolve(startDir);
24
27
  const MAX_UP = 12;
@@ -226,7 +229,8 @@ function patchAndroidMainApplicationKotlin(filePath) {
226
229
  }
227
230
  else {
228
231
  console.log(chalk_1.default.yellow(` ⚠️ Could not find a suitable insertion point in ${filePath}.\n` +
229
- ` Please add the reactNativeHost + reactHost blocks manually (see CLIENT_README.md).`));
232
+ ` Please add the reactNativeHost + reactHost blocks manually.\n` +
233
+ ` See ${DOCS_ANDROID_NATIVE_SETUP_URL}`));
230
234
  return;
231
235
  }
232
236
  }
@@ -245,7 +249,8 @@ function patchAndroidMainApplicationKotlin(filePath) {
245
249
  }
246
250
  // 4. No recognizable template
247
251
  console.log(chalk_1.default.yellow(` ⚠️ Could not detect a supported MainApplication template in ${filePath}.\n` +
248
- ` Please add the BundleDrop override manually. See CLIENT_README.md section "Native setup (Android)".`));
252
+ ` Please add the BundleDrop override manually.\n` +
253
+ ` See ${DOCS_ANDROID_NATIVE_SETUP_URL}`));
249
254
  }
250
255
  // ---------------------------------------------------------------------------
251
256
  // Android MainApplication.java patcher (older RN versions)
@@ -296,7 +301,8 @@ function patchAndroidMainApplicationJava(filePath) {
296
301
  }
297
302
  }
298
303
  console.log(chalk_1.default.yellow(` ⚠️ Found getJSBundleFile() but could not safely parse its body.\n` +
299
- ` Please replace the method body manually. See CLIENT_README.md section "Native setup (Android)".`));
304
+ ` Please replace the method body manually.\n` +
305
+ ` See ${DOCS_ANDROID_NATIVE_SETUP_URL}`));
300
306
  return;
301
307
  }
302
308
  // 3. Has ReactNativeHost anonymous class — inject getJSBundleFile() inside it
@@ -336,12 +342,14 @@ function patchAndroidMainApplicationJava(filePath) {
336
342
  }
337
343
  }
338
344
  console.log(chalk_1.default.yellow(` ⚠️ Found ReactNativeHost but could not safely parse its anonymous class.\n` +
339
- ` Please add getJSBundleFile() override manually. See CLIENT_README.md section "Native setup (Android)".`));
345
+ ` Please add getJSBundleFile() override manually.\n` +
346
+ ` See ${DOCS_ANDROID_NATIVE_SETUP_URL}`));
340
347
  return;
341
348
  }
342
349
  // 4. No recognizable template
343
350
  console.log(chalk_1.default.yellow(` ⚠️ Could not detect a supported MainApplication template in ${filePath}.\n` +
344
- ` Please add the BundleDrop override manually. See CLIENT_README.md section "Native setup (Android)".`));
351
+ ` Please add the BundleDrop override manually.\n` +
352
+ ` See ${DOCS_ANDROID_NATIVE_SETUP_URL}`));
345
353
  }
346
354
  function patchAndroidMainApplication(filePath) {
347
355
  const ext = path_1.default.extname(filePath);
@@ -354,7 +362,7 @@ function patchAndroidMainApplication(filePath) {
354
362
  }
355
363
  else {
356
364
  console.log(chalk_1.default.yellow(` ⚠️ Unsupported MainApplication file type (${ext}). Please patch manually.\n` +
357
- ` See CLIENT_README.md section "Native setup (Android)".`));
365
+ ` See ${DOCS_ANDROID_NATIVE_SETUP_URL}`));
358
366
  }
359
367
  }
360
368
  // ---------------------------------------------------------------------------
@@ -431,7 +439,7 @@ function patchIosAppDelegateSwift(filePath) {
431
439
  fs_extra_1.default.writeFileSync(filePath, content, 'utf8');
432
440
  console.log(chalk_1.default.yellow(` ⚠️ Could not find bundleURL() override in ${filePath}.\n` +
433
441
  ` Please add manually: Debug → Metro, Release → BundleDropLocator.bundleURL() fallback to main.jsbundle.\n` +
434
- ` See CLIENT_README.md section "Native setup (iOS)".`));
442
+ ` See ${DOCS_IOS_NATIVE_SETUP_URL}`));
435
443
  }
436
444
  function patchIosAppDelegateObjc(filePath) {
437
445
  let content = fs_extra_1.default.readFileSync(filePath, 'utf8');
@@ -471,7 +479,7 @@ function patchIosAppDelegateObjc(filePath) {
471
479
  fs_extra_1.default.writeFileSync(filePath, content, 'utf8');
472
480
  console.log(chalk_1.default.yellow(` ⚠️ Could not find sourceURLForBridge: in ${filePath}.\n` +
473
481
  ` Please locate the method that returns the JS bundle URL and apply the Release OTA fallback.\n` +
474
- ` See CLIENT_README.md section "Native setup (iOS)".`));
482
+ ` See ${DOCS_IOS_NATIVE_SETUP_URL}`));
475
483
  }
476
484
  function patchIosAppDelegate(filePath) {
477
485
  const ext = path_1.default.extname(filePath);
@@ -484,7 +492,7 @@ function patchIosAppDelegate(filePath) {
484
492
  }
485
493
  else {
486
494
  console.log(chalk_1.default.yellow(` ⚠️ Unsupported AppDelegate file type (${ext}). Please patch manually.\n` +
487
- ` See CLIENT_README.md section "Native setup (iOS)".`));
495
+ ` See ${DOCS_IOS_NATIVE_SETUP_URL}`));
488
496
  }
489
497
  }
490
498
  async function initNativeConfig() {