@gfean/react-native-bundle-drop 0.1.31
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/BundleDrop.podspec +23 -0
- package/CLIENT_README.md +139 -0
- package/README.md +91 -0
- package/android/build.gradle +79 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/bundledrop/BundleDropModule.kt +148 -0
- package/android/src/main/java/com/bundledrop/BundleDropPackage.kt +16 -0
- package/ios/BundleDropBridge.m +16 -0
- package/ios/BundleDropLocator.swift +34 -0
- package/ios/BundleDropModule.swift +58 -0
- package/lib/CLI/cli.d.ts +2 -0
- package/lib/CLI/cli.js +122 -0
- package/lib/CLI/scripts/init-config.d.ts +17 -0
- package/lib/CLI/scripts/init-config.js +106 -0
- package/lib/CLI/scripts/init-native-config.d.ts +2 -0
- package/lib/CLI/scripts/init-native-config.js +137 -0
- package/lib/CLI/scripts/login-cli.d.ts +2 -0
- package/lib/CLI/scripts/login-cli.js +56 -0
- package/lib/CLI/scripts/upload-cli.d.ts +8 -0
- package/lib/CLI/scripts/upload-cli.js +248 -0
- package/lib/CLI/utils/ui.d.ts +8 -0
- package/lib/CLI/utils/ui.js +16 -0
- package/lib/bundleInfo.d.ts +14 -0
- package/lib/bundleInfo.js +34 -0
- package/lib/image-manifest.d.ts +1 -0
- package/lib/image-manifest.js +4 -0
- package/lib/index.d.ts +51 -0
- package/lib/index.js +415 -0
- package/lib/injectImageResolver.d.ts +2 -0
- package/lib/injectImageResolver.js +121 -0
- package/lib/loadConfig.d.ts +17 -0
- package/lib/loadConfig.js +33 -0
- package/lib/patchImageAutoResolve.d.ts +1 -0
- package/lib/patchImageAutoResolve.js +25 -0
- package/lib/scripts/bundle.d.ts +2 -0
- package/lib/scripts/bundle.js +163 -0
- package/lib/scripts/download-bundle.d.ts +2 -0
- package/lib/scripts/download-bundle.js +79 -0
- package/lib/scripts/upload-bundle.d.ts +2 -0
- package/lib/scripts/upload-bundle.js +290 -0
- package/lib/types.d.ts +1 -0
- package/lib/types.js +2 -0
- package/lib/useBundleDrop.d.ts +40 -0
- package/lib/useBundleDrop.js +131 -0
- package/package.json +66 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
const adm_zip_1 = __importDefault(require("adm-zip"));
|
|
41
|
+
const child_process_1 = require("child_process");
|
|
42
|
+
const crypto_1 = require("crypto");
|
|
43
|
+
const fs = __importStar(require("fs"));
|
|
44
|
+
const path = __importStar(require("path"));
|
|
45
|
+
const packageRoot = path.resolve(__dirname, '..', '..');
|
|
46
|
+
function findProjectRoot(startDir) {
|
|
47
|
+
let dir = path.resolve(startDir);
|
|
48
|
+
const MAX_UP = 12;
|
|
49
|
+
for (let i = 0; i < MAX_UP; i++) {
|
|
50
|
+
const iosDir = path.join(dir, 'ios');
|
|
51
|
+
const androidDir = path.join(dir, 'android');
|
|
52
|
+
if (fs.existsSync(iosDir) && fs.existsSync(androidDir)) {
|
|
53
|
+
return dir;
|
|
54
|
+
}
|
|
55
|
+
const parent = path.dirname(dir);
|
|
56
|
+
if (parent === dir)
|
|
57
|
+
break;
|
|
58
|
+
dir = parent;
|
|
59
|
+
}
|
|
60
|
+
return startDir;
|
|
61
|
+
}
|
|
62
|
+
const platform = process.argv[2] || 'ios';
|
|
63
|
+
const isAndroid = platform === 'android';
|
|
64
|
+
const fileSuffix = isAndroid ? 'android' : 'ios';
|
|
65
|
+
const outputDir = path.resolve(packageRoot, 'dist');
|
|
66
|
+
const assetsDir = path.join(outputDir, 'assets');
|
|
67
|
+
const bundlePath = path.join(outputDir, 'main.jsbundle');
|
|
68
|
+
const metadataPath = path.join(outputDir, `metadata-${fileSuffix}.json`);
|
|
69
|
+
const zipPath = path.join(outputDir, `bundle-${platform}.zip`);
|
|
70
|
+
const imageManifest = {};
|
|
71
|
+
const projectRoot = findProjectRoot(process.cwd());
|
|
72
|
+
// load runtimeVersion from project-level bundle.drop.config.js if present
|
|
73
|
+
let runtimeVersion;
|
|
74
|
+
const configPath = path.resolve(projectRoot, 'bundle.drop.config.js');
|
|
75
|
+
if (fs.existsSync(configPath)) {
|
|
76
|
+
//eslint-disable-next-line
|
|
77
|
+
const cfg = require(configPath);
|
|
78
|
+
runtimeVersion = cfg?.runtimeVersion?.[platform];
|
|
79
|
+
if (!runtimeVersion) {
|
|
80
|
+
console.warn(`โ ๏ธ No runtimeVersion found for ${platform} in bundle.drop.config.js. Example: runtimeVersion: { ios: "1.0.0", android: "1.0.0" }`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
console.warn('โ ๏ธ bundle.drop.config.js not found in project root; runtimeVersion will be omitted.');
|
|
85
|
+
}
|
|
86
|
+
// ๐งน Clean up old files
|
|
87
|
+
[bundlePath, zipPath, metadataPath].forEach(file => {
|
|
88
|
+
if (fs.existsSync(file))
|
|
89
|
+
fs.unlinkSync(file);
|
|
90
|
+
});
|
|
91
|
+
if (fs.existsSync(assetsDir))
|
|
92
|
+
fs.rmSync(assetsDir, { recursive: true, force: true });
|
|
93
|
+
// ๐ Ensure output dirs
|
|
94
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
95
|
+
fs.mkdirSync(assetsDir, { recursive: true });
|
|
96
|
+
console.log(`๐ฆ Bundling React Native code for platform: ${platform}...`);
|
|
97
|
+
(0, child_process_1.execSync)(`npx react-native bundle \
|
|
98
|
+
--platform ${platform} \
|
|
99
|
+
--dev false \
|
|
100
|
+
--entry-file index.js \
|
|
101
|
+
--bundle-output ${bundlePath} \
|
|
102
|
+
--assets-dest ${assetsDir}`, { stdio: 'inherit' });
|
|
103
|
+
console.log('โ
Bundle created:', bundlePath);
|
|
104
|
+
// ๐ Create metadata
|
|
105
|
+
const bundleBuffer = fs.readFileSync(bundlePath);
|
|
106
|
+
const hash = (0, crypto_1.createHash)('sha256').update(bundleBuffer).digest('hex');
|
|
107
|
+
const metadata = {
|
|
108
|
+
platform,
|
|
109
|
+
hash,
|
|
110
|
+
timestamp: new Date().toISOString(),
|
|
111
|
+
bundlePath: 'main.jsbundle',
|
|
112
|
+
sizeInBytes: bundleBuffer.length,
|
|
113
|
+
};
|
|
114
|
+
if (runtimeVersion) {
|
|
115
|
+
metadata.runtimeVersion = runtimeVersion;
|
|
116
|
+
}
|
|
117
|
+
fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2));
|
|
118
|
+
console.log('๐ง Metadata saved:', metadataPath);
|
|
119
|
+
console.log('๐ Hash:', hash);
|
|
120
|
+
// ๐๏ธ Create zip
|
|
121
|
+
console.log('๐ฆ Zipping bundle...');
|
|
122
|
+
const zip = new adm_zip_1.default();
|
|
123
|
+
zip.addFile('main.jsbundle', bundleBuffer);
|
|
124
|
+
zip.addFile(`metadata-${fileSuffix}.json`, Buffer.from(JSON.stringify(metadata, null, 2)));
|
|
125
|
+
function addAssetsToZip(dir) {
|
|
126
|
+
const items = fs.readdirSync(dir);
|
|
127
|
+
for (const item of items) {
|
|
128
|
+
const fullPath = path.join(dir, item);
|
|
129
|
+
const relPath = path.relative(assetsDir, fullPath);
|
|
130
|
+
// Keep the relative path as-is (e.g., drawable-mdpi/img.png) without forcing an "assets/" prefix.
|
|
131
|
+
const normalizedPath = relPath;
|
|
132
|
+
if (fs.statSync(fullPath).isDirectory()) {
|
|
133
|
+
addAssetsToZip(fullPath);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
const buffer = fs.readFileSync(fullPath);
|
|
137
|
+
zip.addFile(normalizedPath, buffer);
|
|
138
|
+
if (isAndroid) {
|
|
139
|
+
// Build manifest keys that mirror how RN resolves asset URIs on Android.
|
|
140
|
+
// Example normalizedPath: drawable-mdpi/login_background.jpg
|
|
141
|
+
const withAssetsPrefix = `assets/${normalizedPath}`;
|
|
142
|
+
const manifestKey = normalizedPath.replace(/\.[^.]+$/, '');
|
|
143
|
+
const manifestKeyNoPrefix = manifestKey.replace(/^assets\//, '');
|
|
144
|
+
const baseNameKey = manifestKey.split('/').pop() || manifestKey;
|
|
145
|
+
const baseWithExt = normalizedPath.split('/').pop() || normalizedPath;
|
|
146
|
+
imageManifest[manifestKey] = normalizedPath;
|
|
147
|
+
imageManifest[manifestKeyNoPrefix] = normalizedPath;
|
|
148
|
+
imageManifest[withAssetsPrefix.replace(/\.[^.]+$/, '')] = normalizedPath;
|
|
149
|
+
// Add basename aliases to catch cases where the resolver only provides the filename.
|
|
150
|
+
imageManifest[baseNameKey] = normalizedPath;
|
|
151
|
+
imageManifest[baseWithExt] = normalizedPath;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
addAssetsToZip(assetsDir);
|
|
157
|
+
// ๐งฉ Inject manifest (Android only)
|
|
158
|
+
if (isAndroid && Object.keys(imageManifest).length > 0) {
|
|
159
|
+
zip.addFile('image-manifest.json', Buffer.from(JSON.stringify(imageManifest, null, 2)));
|
|
160
|
+
console.log(`๐งฉ Injected image-manifest.json with ${Object.keys(imageManifest).length} entries`);
|
|
161
|
+
}
|
|
162
|
+
zip.writeZip(zipPath);
|
|
163
|
+
console.log(`โ
OTA bundle zipped: ${zipPath}`);
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
const axios_1 = __importDefault(require("axios"));
|
|
41
|
+
const fs = __importStar(require("fs"));
|
|
42
|
+
const path = __importStar(require("path"));
|
|
43
|
+
const packageRoot = path.resolve(__dirname, '..', '..');
|
|
44
|
+
const outputDir = path.join(packageRoot, 'dist');
|
|
45
|
+
const platform = process.argv[2];
|
|
46
|
+
if (!platform || !['ios', 'android'].includes(platform)) {
|
|
47
|
+
console.error('โ Please provide platform: ios or android');
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
// Dynamically load config from project root
|
|
51
|
+
const projectRoot = process.cwd();
|
|
52
|
+
const configPath = path.resolve(projectRoot, 'bundle.drop.config.js');
|
|
53
|
+
if (!fs.existsSync(configPath)) {
|
|
54
|
+
console.error('โ bundle.drop.config.js not found in project root');
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
// eslint-disable-next-line
|
|
58
|
+
const config = require(configPath);
|
|
59
|
+
const { serverUrl, project, org } = config;
|
|
60
|
+
if (!org?.slug) {
|
|
61
|
+
console.error('โ Missing "org.slug" in bundle.drop.config.js');
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
const downloadUrl = `${serverUrl}/bundle/latest?platform=${platform}&orgSlug=${org.slug}&project=${project.slug}`;
|
|
65
|
+
const outputPath = path.join(outputDir, `main.${platform}.jsbundle`);
|
|
66
|
+
if (!fs.existsSync(outputDir)) {
|
|
67
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
68
|
+
}
|
|
69
|
+
console.log(`โฌ๏ธ Downloading latest ${platform} bundle from: ${downloadUrl}`);
|
|
70
|
+
axios_1.default
|
|
71
|
+
.get(downloadUrl, { responseType: 'arraybuffer' })
|
|
72
|
+
.then(async (response) => {
|
|
73
|
+
await fs.promises.writeFile(outputPath, Buffer.from(response.data));
|
|
74
|
+
console.log(`โ
Bundle downloaded and saved to: ${outputPath}`);
|
|
75
|
+
})
|
|
76
|
+
.catch(err => {
|
|
77
|
+
console.error('โ Download failed:', err.response?.data || err.message);
|
|
78
|
+
process.exit(1);
|
|
79
|
+
});
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
const axios_1 = __importDefault(require("axios"));
|
|
41
|
+
const child_process_1 = require("child_process");
|
|
42
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
43
|
+
const fs = __importStar(require("fs"));
|
|
44
|
+
const os_1 = __importDefault(require("os"));
|
|
45
|
+
const path = __importStar(require("path"));
|
|
46
|
+
const plist = __importStar(require("plist"));
|
|
47
|
+
const packageRoot = path.resolve(__dirname, '..', '..');
|
|
48
|
+
const outputDir = path.join(packageRoot, 'dist');
|
|
49
|
+
function findProjectRoot(startDir) {
|
|
50
|
+
let dir = path.resolve(startDir);
|
|
51
|
+
const MAX_UP = 12;
|
|
52
|
+
for (let i = 0; i < MAX_UP; i++) {
|
|
53
|
+
const iosDir = path.join(dir, 'ios');
|
|
54
|
+
const androidDir = path.join(dir, 'android');
|
|
55
|
+
if (fs.existsSync(iosDir) && fs.existsSync(androidDir)) {
|
|
56
|
+
return dir;
|
|
57
|
+
}
|
|
58
|
+
const parent = path.dirname(dir);
|
|
59
|
+
if (parent === dir)
|
|
60
|
+
break;
|
|
61
|
+
dir = parent;
|
|
62
|
+
}
|
|
63
|
+
return startDir;
|
|
64
|
+
}
|
|
65
|
+
// --- CONFIG LOADING ---
|
|
66
|
+
const projectRoot = findProjectRoot(process.cwd());
|
|
67
|
+
const configPath = path.resolve(projectRoot, 'bundle.drop.config.js');
|
|
68
|
+
if (!fs.existsSync(configPath)) {
|
|
69
|
+
console.error('โ bundle.drop.config.js not found in project root');
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
// eslint-disable-next-line
|
|
73
|
+
const config = require(configPath);
|
|
74
|
+
if (!config.project?.slug) {
|
|
75
|
+
console.error('โ Missing "project.slug" in bundle.drop.config.js');
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
if (!config.org?.slug) {
|
|
79
|
+
console.error('โ Missing "org.slug" in bundle.drop.config.js');
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
const serverUrl = config.serverUrl;
|
|
83
|
+
const orgSlug = config.org.slug;
|
|
84
|
+
const projectSlug = config.project.slug;
|
|
85
|
+
// --- AUTH ---
|
|
86
|
+
const authPath = path.join(os_1.default.homedir(), '.bundle-drop', 'auth.json');
|
|
87
|
+
if (!fs.existsSync(authPath)) {
|
|
88
|
+
console.error('โ Not authenticated. Please run `bundle-drop login` first.');
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
let token;
|
|
92
|
+
try {
|
|
93
|
+
const parsedAuth = JSON.parse(fs.readFileSync(authPath, 'utf-8'));
|
|
94
|
+
token = parsedAuth.token;
|
|
95
|
+
if (!token) {
|
|
96
|
+
throw new Error('Token missing in auth file');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
console.error(`โ Invalid auth file at ${authPath}:`, err.message);
|
|
101
|
+
console.error('โน๏ธ Please log in again with `bundle-drop login`.');
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
// --- PARSE ARGS ---
|
|
105
|
+
const platform = process.argv[2];
|
|
106
|
+
const args = process.argv.slice(3);
|
|
107
|
+
const plistArg = args.find(arg => arg.startsWith('--plist-file='));
|
|
108
|
+
const plistFile = plistArg?.split('=')[1];
|
|
109
|
+
const versionArg = args.find(arg => arg.startsWith('--version='));
|
|
110
|
+
const versionFromFlag = versionArg?.split('=')[1];
|
|
111
|
+
const buildGradleArg = args.find(arg => arg.startsWith('--buildgradle-path='));
|
|
112
|
+
const buildGradlePath = buildGradleArg?.split('=')[1];
|
|
113
|
+
const channelArg = args.find(arg => arg.startsWith('--channel='));
|
|
114
|
+
const channelName = channelArg?.split('=')[1];
|
|
115
|
+
const runtimeVersionArg = args.find(arg => arg.startsWith('--runtimeVersion='));
|
|
116
|
+
const runtimeVersionOverride = runtimeVersionArg?.split('=')[1];
|
|
117
|
+
const releaseNotesArg = args.find(arg => arg.startsWith('--release-notes='));
|
|
118
|
+
let releaseNotes = releaseNotesArg ? releaseNotesArg.split('=')[1] : undefined;
|
|
119
|
+
const MAX_NOTES = 2000;
|
|
120
|
+
if (releaseNotes && releaseNotes.length > MAX_NOTES) {
|
|
121
|
+
console.warn(`โ ๏ธ Release notes too long (${releaseNotes.length}); truncating to ${MAX_NOTES} chars.`);
|
|
122
|
+
releaseNotes = releaseNotes.slice(0, MAX_NOTES);
|
|
123
|
+
}
|
|
124
|
+
if (!platform || !['ios', 'android'].includes(platform)) {
|
|
125
|
+
console.error('โ Please pass a platform: ios or android');
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
if (!channelName) {
|
|
129
|
+
console.error('โ Missing required --channel=name');
|
|
130
|
+
process.exit(1);
|
|
131
|
+
}
|
|
132
|
+
// --- RESOLVE VERSION ---
|
|
133
|
+
let version;
|
|
134
|
+
function parseAndroidVersionFromGradle(filePath) {
|
|
135
|
+
if (!fs.existsSync(filePath)) {
|
|
136
|
+
console.error(`โ build.gradle not found at ${filePath}`);
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
140
|
+
const match = content.match(/versionName\s+['"]([^'"]+)['"]/);
|
|
141
|
+
if (!match) {
|
|
142
|
+
console.error('โ Could not parse versionName from build.gradle');
|
|
143
|
+
process.exit(1);
|
|
144
|
+
}
|
|
145
|
+
return match[1];
|
|
146
|
+
}
|
|
147
|
+
if (platform === 'ios') {
|
|
148
|
+
if (versionFromFlag) {
|
|
149
|
+
version = versionFromFlag;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
if (!plistFile) {
|
|
153
|
+
console.error('โ Please provide --plist-file=path/to/Info.plist or --version for iOS');
|
|
154
|
+
process.exit(1);
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
const plistContent = fs.readFileSync(plistFile, 'utf-8');
|
|
158
|
+
const parsed = plist.parse(plistContent);
|
|
159
|
+
version = parsed.CFBundleShortVersionString;
|
|
160
|
+
if (!version) {
|
|
161
|
+
console.error('โ Could not find CFBundleShortVersionString in plist');
|
|
162
|
+
process.exit(1);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
catch (err) {
|
|
166
|
+
console.error('โ Failed to read plist file:', err);
|
|
167
|
+
process.exit(1);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
if (versionFromFlag) {
|
|
173
|
+
version = versionFromFlag;
|
|
174
|
+
}
|
|
175
|
+
else if (buildGradlePath) {
|
|
176
|
+
version = parseAndroidVersionFromGradle(path.resolve(projectRoot, buildGradlePath));
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
// default to android/app/build.gradle when available
|
|
180
|
+
const defaultGradlePath = path.join(projectRoot, 'android', 'app', 'build.gradle');
|
|
181
|
+
if (fs.existsSync(defaultGradlePath)) {
|
|
182
|
+
version = parseAndroidVersionFromGradle(defaultGradlePath);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
console.error('โ Please provide --version=x.y.z for Android or --buildgradle-path=path/to/build.gradle');
|
|
186
|
+
process.exit(1);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
let runtimeVersion;
|
|
191
|
+
// --- BUNDLE STEP ---
|
|
192
|
+
const compiledBundleScript = path.join(packageRoot, 'lib', 'scripts', 'bundle.js');
|
|
193
|
+
const tsBundleScript = path.join(packageRoot, 'src', 'scripts', 'bundle.ts');
|
|
194
|
+
const bundleCommand = fs.existsSync(compiledBundleScript) ? `node ${compiledBundleScript}` : `ts-node ${tsBundleScript}`;
|
|
195
|
+
try {
|
|
196
|
+
console.log(`๐ฆ Running bundler for ${platform}...`);
|
|
197
|
+
(0, child_process_1.execSync)(`${bundleCommand} ${platform}`, {
|
|
198
|
+
stdio: 'inherit',
|
|
199
|
+
});
|
|
200
|
+
const suffix = platform === 'ios' ? 'ios' : 'android';
|
|
201
|
+
const metadataPath = path.join(outputDir, `metadata-${suffix}.json`);
|
|
202
|
+
try {
|
|
203
|
+
const parsed = JSON.parse(fs.readFileSync(metadataPath, 'utf-8'));
|
|
204
|
+
runtimeVersion = parsed.runtimeVersion;
|
|
205
|
+
if (runtimeVersion) {
|
|
206
|
+
console.log(`๐ Runtime Version: ${runtimeVersion}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
// ignore; backend can derive from metadata in zip
|
|
211
|
+
}
|
|
212
|
+
if (runtimeVersionOverride) {
|
|
213
|
+
runtimeVersion = runtimeVersionOverride;
|
|
214
|
+
console.log(`๐ Runtime Version (override flag): ${runtimeVersion}`);
|
|
215
|
+
}
|
|
216
|
+
else if (!runtimeVersion) {
|
|
217
|
+
runtimeVersion = config.runtimeVersion?.[platform];
|
|
218
|
+
if (runtimeVersion) {
|
|
219
|
+
console.log(`๐ Runtime Version (from config): ${runtimeVersion}`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (!runtimeVersion) {
|
|
223
|
+
console.error('โ runtimeVersion could not be determined; aborting upload.');
|
|
224
|
+
process.exit(1);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
catch (err) {
|
|
228
|
+
console.error('โ Failed to bundle:', err);
|
|
229
|
+
process.exit(1);
|
|
230
|
+
}
|
|
231
|
+
// --- UPLOAD STEP ---
|
|
232
|
+
const zipPath = path.join(outputDir, `bundle-${platform}.zip`);
|
|
233
|
+
if (!fs.existsSync(zipPath)) {
|
|
234
|
+
console.error(`โ Bundle ZIP not found at ${zipPath}`);
|
|
235
|
+
process.exit(1);
|
|
236
|
+
}
|
|
237
|
+
const form = new form_data_1.default();
|
|
238
|
+
// Prefer the new server key; keep legacy for compatibility.
|
|
239
|
+
form.append('orgSlug', orgSlug);
|
|
240
|
+
form.append('projectSlug', projectSlug);
|
|
241
|
+
form.append('project', projectSlug);
|
|
242
|
+
form.append('platform', platform);
|
|
243
|
+
form.append('version', version);
|
|
244
|
+
form.append('channelName', channelName);
|
|
245
|
+
form.append('runtimeVersion', runtimeVersion);
|
|
246
|
+
if (releaseNotes) {
|
|
247
|
+
form.append('releaseNotes', releaseNotes);
|
|
248
|
+
}
|
|
249
|
+
form.append('file', fs.createReadStream(zipPath));
|
|
250
|
+
console.log(`โฌ๏ธ Uploading ${platform} bundle (v${version}) to project "${projectSlug}" at ${serverUrl}...`);
|
|
251
|
+
axios_1.default
|
|
252
|
+
.post(`${serverUrl}/bundle/upload`, form, {
|
|
253
|
+
headers: {
|
|
254
|
+
...form.getHeaders(),
|
|
255
|
+
Authorization: `Bearer ${token}`,
|
|
256
|
+
},
|
|
257
|
+
maxContentLength: Infinity,
|
|
258
|
+
maxBodyLength: Infinity,
|
|
259
|
+
})
|
|
260
|
+
.then(res => {
|
|
261
|
+
console.log('โ
Upload complete:', res.data);
|
|
262
|
+
// --- CLEANUP ---
|
|
263
|
+
try {
|
|
264
|
+
fs.unlinkSync(zipPath);
|
|
265
|
+
console.log(`๐งน Deleted: ${zipPath}`);
|
|
266
|
+
const suffix = platform === 'ios' ? 'ios' : 'android';
|
|
267
|
+
const metadataPath = path.join(outputDir, `metadata-${suffix}.json`);
|
|
268
|
+
const assetsPath = path.join(outputDir, 'assets');
|
|
269
|
+
if (fs.existsSync(metadataPath)) {
|
|
270
|
+
fs.unlinkSync(metadataPath);
|
|
271
|
+
console.log(`๐งน Deleted: ${metadataPath}`);
|
|
272
|
+
}
|
|
273
|
+
if (fs.existsSync(assetsPath)) {
|
|
274
|
+
fs.rmSync(assetsPath, { recursive: true, force: true });
|
|
275
|
+
console.log(`๐งน Deleted: ${assetsPath}`);
|
|
276
|
+
}
|
|
277
|
+
const bundlePath = path.join(outputDir, 'main.jsbundle');
|
|
278
|
+
if (fs.existsSync(bundlePath)) {
|
|
279
|
+
fs.unlinkSync(bundlePath);
|
|
280
|
+
console.log(`๐งน Deleted: ${bundlePath}`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
catch (err) {
|
|
284
|
+
console.warn('โ ๏ธ Cleanup failed:', err);
|
|
285
|
+
}
|
|
286
|
+
})
|
|
287
|
+
.catch(err => {
|
|
288
|
+
console.error('โ Upload failed:', err?.response?.data || err.message);
|
|
289
|
+
process.exit(1);
|
|
290
|
+
});
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type UpdatePolicy = 'manual' | 'immediate' | 'on-next-launch';
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { BundleInfo } from './bundleInfo';
|
|
2
|
+
import type { UpdatePolicy } from './types';
|
|
3
|
+
type UseBundleDropOptions = {
|
|
4
|
+
/** Channel to target; defaults to "General". */
|
|
5
|
+
channelName?: string;
|
|
6
|
+
/** Update policy to honor on mount when autoInit is true. */
|
|
7
|
+
policy?: UpdatePolicy;
|
|
8
|
+
/** If true, initUpdateManager runs on mount with the provided policy. */
|
|
9
|
+
autoInit?: boolean;
|
|
10
|
+
/** Optional status callback for initUpdateManager. */
|
|
11
|
+
onStatusUpdate?: (status: string) => void;
|
|
12
|
+
/** For manual policy, set true to run a check without downloading. */
|
|
13
|
+
checkOnly?: boolean;
|
|
14
|
+
};
|
|
15
|
+
type UseBundleDropReturn = {
|
|
16
|
+
/** Last human-readable status message (downloads, checks, applies). */
|
|
17
|
+
status: string;
|
|
18
|
+
/** True while any bundle-drop action is running; use to disable UI. */
|
|
19
|
+
isBusy: boolean;
|
|
20
|
+
/** Locally stored bundle metadata (bundleVersion, hash, etc.), if any. */
|
|
21
|
+
installedInfo: BundleInfo | null;
|
|
22
|
+
/** True when a downloaded bundle is waiting to be applied. */
|
|
23
|
+
pendingApply: boolean;
|
|
24
|
+
/** True when a bundle file exists on disk (downloaded). */
|
|
25
|
+
hasBundle: boolean;
|
|
26
|
+
/** Check server for updates; updates status only. */
|
|
27
|
+
checkLatest: () => Promise<void>;
|
|
28
|
+
/** Download and apply immediately (reload). */
|
|
29
|
+
downloadImmediate: () => Promise<void>;
|
|
30
|
+
/** Download now, apply on next launch (sets pending). */
|
|
31
|
+
downloadForNextLaunch: () => Promise<void>;
|
|
32
|
+
/** Download without applying; keeps pending flag true. */
|
|
33
|
+
downloadManual: () => Promise<void>;
|
|
34
|
+
/** Apply a pending downloaded bundle (reload). */
|
|
35
|
+
applyPending: () => Promise<void>;
|
|
36
|
+
/** Re-read local bundle state (installedInfo/pending). */
|
|
37
|
+
refresh: () => Promise<void>;
|
|
38
|
+
};
|
|
39
|
+
export declare function useBundleDrop(options?: UseBundleDropOptions): UseBundleDropReturn;
|
|
40
|
+
export {};
|