@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.
Files changed (47) hide show
  1. package/BundleDrop.podspec +23 -0
  2. package/CLIENT_README.md +139 -0
  3. package/README.md +91 -0
  4. package/android/build.gradle +79 -0
  5. package/android/gradle.properties +5 -0
  6. package/android/src/main/AndroidManifest.xml +3 -0
  7. package/android/src/main/AndroidManifestNew.xml +2 -0
  8. package/android/src/main/java/com/bundledrop/BundleDropModule.kt +148 -0
  9. package/android/src/main/java/com/bundledrop/BundleDropPackage.kt +16 -0
  10. package/ios/BundleDropBridge.m +16 -0
  11. package/ios/BundleDropLocator.swift +34 -0
  12. package/ios/BundleDropModule.swift +58 -0
  13. package/lib/CLI/cli.d.ts +2 -0
  14. package/lib/CLI/cli.js +122 -0
  15. package/lib/CLI/scripts/init-config.d.ts +17 -0
  16. package/lib/CLI/scripts/init-config.js +106 -0
  17. package/lib/CLI/scripts/init-native-config.d.ts +2 -0
  18. package/lib/CLI/scripts/init-native-config.js +137 -0
  19. package/lib/CLI/scripts/login-cli.d.ts +2 -0
  20. package/lib/CLI/scripts/login-cli.js +56 -0
  21. package/lib/CLI/scripts/upload-cli.d.ts +8 -0
  22. package/lib/CLI/scripts/upload-cli.js +248 -0
  23. package/lib/CLI/utils/ui.d.ts +8 -0
  24. package/lib/CLI/utils/ui.js +16 -0
  25. package/lib/bundleInfo.d.ts +14 -0
  26. package/lib/bundleInfo.js +34 -0
  27. package/lib/image-manifest.d.ts +1 -0
  28. package/lib/image-manifest.js +4 -0
  29. package/lib/index.d.ts +51 -0
  30. package/lib/index.js +415 -0
  31. package/lib/injectImageResolver.d.ts +2 -0
  32. package/lib/injectImageResolver.js +121 -0
  33. package/lib/loadConfig.d.ts +17 -0
  34. package/lib/loadConfig.js +33 -0
  35. package/lib/patchImageAutoResolve.d.ts +1 -0
  36. package/lib/patchImageAutoResolve.js +25 -0
  37. package/lib/scripts/bundle.d.ts +2 -0
  38. package/lib/scripts/bundle.js +163 -0
  39. package/lib/scripts/download-bundle.d.ts +2 -0
  40. package/lib/scripts/download-bundle.js +79 -0
  41. package/lib/scripts/upload-bundle.d.ts +2 -0
  42. package/lib/scripts/upload-bundle.js +290 -0
  43. package/lib/types.d.ts +1 -0
  44. package/lib/types.js +2 -0
  45. package/lib/useBundleDrop.d.ts +40 -0
  46. package/lib/useBundleDrop.js +131 -0
  47. package/package.json +66 -0
package/lib/CLI/cli.js ADDED
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const commander_1 = require("commander");
9
+ const figures_1 = __importDefault(require("figures"));
10
+ const upload_cli_1 = __importDefault(require("./scripts/upload-cli"));
11
+ const package_json_1 = __importDefault(require("../../package.json"));
12
+ const program = new commander_1.Command();
13
+ program
14
+ .name('bundle-drop')
15
+ .version(package_json_1.default.version || '0.0.0', '-v, --version', 'Show CLI version');
16
+ const logo = chalk_1.default.cyanBright(`
17
+ ______ ______
18
+ |_ _ \\ |_ _ \`.
19
+ | |_) | | | \`. \\
20
+ | __'. | | | |
21
+ _| |__) |_| |_.' /
22
+ |_______/|______.'
23
+ `) + chalk_1.default.bold.cyanBright(`\n${figures_1.default.star} React Native Bundle Drop CLI ${figures_1.default.star}`);
24
+ program.addHelpText('beforeAll', logo);
25
+ program.addHelpText('before', `
26
+ ${chalk_1.default.magentaBright('A blazing-fast OTA delivery system for React Native by GFean.\n')}
27
+ ${chalk_1.default.bold.cyan('Available Commands:')}
28
+ `);
29
+ program.addHelpText('afterAll', `\n${chalk_1.default.gray('Need help? →')} ${chalk_1.default.underline.gray('https://github.com/GFean/react-native-bundle-drop')}\n`);
30
+ // ------------------------
31
+ // Commands
32
+ // ------------------------
33
+ program
34
+ .command('upload')
35
+ .argument('<platform>', chalk_1.default.gray('ios or android'))
36
+ .option('--plist-file <path>', 'Path to Info.plist for iOS')
37
+ .option('--version <version>', 'App version. iOS will fallback to --plist-file; Android can fallback to build.gradle when provided.')
38
+ .option('--buildgradle-path <path>', 'Optional Android build.gradle path to read versionName')
39
+ .option('--channel <name>', 'Target channel name to associate the bundle') // ← ADD THIS LINE
40
+ .description(chalk_1.default.whiteBright('Bundle and upload an OTA zip to the server'))
41
+ .action(upload_cli_1.default);
42
+ program
43
+ .command('logout')
44
+ .description('Log out of the CLI')
45
+ .action(() => {
46
+ //eslint-disable-next-line
47
+ const fs = require('fs');
48
+ //eslint-disable-next-line
49
+ const path = require('path');
50
+ //eslint-disable-next-line
51
+ const os = require('os');
52
+ const tokenPath = path.join(os.homedir(), '.bundle-drop', 'auth.json');
53
+ if (fs.existsSync(tokenPath)) {
54
+ fs.unlinkSync(tokenPath);
55
+ console.log('đŸšĒ Logged out.');
56
+ }
57
+ else {
58
+ console.log('â„šī¸ Not logged in.');
59
+ }
60
+ });
61
+ program
62
+ .command('login')
63
+ .description('Log in to the CLI')
64
+ .action(() => {
65
+ //eslint-disable-next-line
66
+ require('../CLI/scripts/login-cli').default();
67
+ });
68
+ program
69
+ .command('init')
70
+ .description('Generate bundle.drop.config.js from your logged-in account context')
71
+ .action(() => {
72
+ //eslint-disable-next-line
73
+ const fs = require('fs');
74
+ //eslint-disable-next-line
75
+ const path = require('path');
76
+ //eslint-disable-next-line
77
+ const os = require('os');
78
+ const tokenPath = path.join(os.homedir(), '.bundle-drop', 'auth.json');
79
+ if (!fs.existsSync(tokenPath)) {
80
+ console.log('â„šī¸ Not logged in. Please run `bundle-drop login` first.');
81
+ return;
82
+ }
83
+ const data = JSON.parse(fs.readFileSync(tokenPath, 'utf-8'));
84
+ const projects = data.projects || [];
85
+ const organizations = data.organizations || [];
86
+ const downloadApiKey = data.downloadApiKey || '';
87
+ //eslint-disable-next-line
88
+ require('../CLI/scripts/init-config').initConfig({
89
+ serverUrl: process.env.BUNDLE_DROP_SERVER_URL?.replace(/\/$/, '') || 'https://bundle-drop-backend.onrender.com',
90
+ projects,
91
+ organizations,
92
+ downloadApiKey,
93
+ });
94
+ });
95
+ program
96
+ .command('init-native')
97
+ .description('Attempt to apply native changes (AppDelegate / MainApplication) automatically')
98
+ .action(() => {
99
+ //eslint-disable-next-line
100
+ require('../CLI/scripts/init-native-config').initNativeConfig();
101
+ });
102
+ program
103
+ .command('whoami')
104
+ .description('Show currently logged in user')
105
+ .action(() => {
106
+ //eslint-disable-next-line
107
+ const fs = require('fs');
108
+ //eslint-disable-next-line
109
+ const path = require('path');
110
+ //eslint-disable-next-line
111
+ const os = require('os');
112
+ const tokenPath = path.join(os.homedir(), '.bundle-drop', 'auth.json');
113
+ if (fs.existsSync(tokenPath)) {
114
+ const data = fs.readFileSync(tokenPath, 'utf-8');
115
+ const { user } = JSON.parse(data);
116
+ console.log(`👤 Logged in as: ${chalk_1.default.cyan(user.firstName + ' ' + user.lastName)} <${user.email}>`);
117
+ }
118
+ else {
119
+ console.log('â„šī¸ Not logged in.');
120
+ }
121
+ });
122
+ program.parse();
@@ -0,0 +1,17 @@
1
+ type Project = {
2
+ name: string;
3
+ slug: string;
4
+ orgId: string;
5
+ };
6
+ type Org = {
7
+ slug: string;
8
+ orgId: string;
9
+ name: string;
10
+ };
11
+ export declare function initConfig(params: {
12
+ serverUrl: string;
13
+ projects: Project[];
14
+ organizations: Org[];
15
+ downloadApiKey?: string;
16
+ }): Promise<void>;
17
+ export default initConfig;
@@ -0,0 +1,106 @@
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.initConfig = initConfig;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const prompts_1 = __importDefault(require("prompts"));
11
+ function findProjectRoot(startDir) {
12
+ let dir = path_1.default.resolve(startDir);
13
+ const MAX_UP = 12;
14
+ for (let i = 0; i < MAX_UP; i++) {
15
+ if (fs_extra_1.default.existsSync(path_1.default.join(dir, 'package.json')))
16
+ return dir;
17
+ const parent = path_1.default.dirname(dir);
18
+ if (parent === dir)
19
+ break;
20
+ dir = parent;
21
+ }
22
+ return startDir;
23
+ }
24
+ async function initConfig(params) {
25
+ const projectRoot = findProjectRoot(process.cwd());
26
+ const configPath = path_1.default.join(projectRoot, 'bundle.drop.config.js');
27
+ if (fs_extra_1.default.existsSync(configPath)) {
28
+ 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.`));
29
+ return;
30
+ }
31
+ let orgSlug = '';
32
+ let project = null;
33
+ // Org selection
34
+ if (!params.organizations || params.organizations.length === 0) {
35
+ console.log(chalk_1.default.yellow('âš ī¸ No organizations returned; org slug will be left blank.'));
36
+ }
37
+ else if (params.organizations.length === 1) {
38
+ orgSlug = params.organizations[0].slug;
39
+ }
40
+ else {
41
+ const orgChoices = params.organizations.map(o => ({
42
+ title: `${o.name} (${o.slug})`,
43
+ value: o.slug,
44
+ }));
45
+ const { chosenOrg } = await (0, prompts_1.default)({
46
+ type: 'select',
47
+ name: 'chosenOrg',
48
+ message: 'Select an organization:',
49
+ choices: orgChoices,
50
+ });
51
+ orgSlug = chosenOrg || '';
52
+ if (!orgSlug) {
53
+ console.log(chalk_1.default.yellow('âš ī¸ No organization selected; org slug will be left blank.'));
54
+ }
55
+ }
56
+ // Project selection
57
+ if (!params.projects?.length) {
58
+ console.log(chalk_1.default.red('âš ī¸ No projects returned; project values will be left blank.'));
59
+ }
60
+ else if (params.projects.length === 1) {
61
+ project = params.projects[0];
62
+ }
63
+ else {
64
+ const choices = params.projects.map(p => ({
65
+ title: `${p.name} (${p.slug})`,
66
+ value: p.slug,
67
+ }));
68
+ const { projectSlug } = await (0, prompts_1.default)({
69
+ type: 'select',
70
+ name: 'projectSlug',
71
+ message: 'Select a project to target:',
72
+ choices,
73
+ });
74
+ project = params.projects.find(p => p.slug === projectSlug) || null;
75
+ if (!project) {
76
+ console.log(chalk_1.default.yellow('âš ī¸ No project selected; project values will be left blank.'));
77
+ }
78
+ }
79
+ const projectName = project?.name || '';
80
+ const projectSlug = project?.slug || '';
81
+ if (!orgSlug && project?.orgId) {
82
+ const org = params.organizations.find(o => o.orgId === project.orgId);
83
+ if (org)
84
+ orgSlug = org.slug;
85
+ }
86
+ const content = `module.exports = {
87
+ serverUrl: '${params.serverUrl}',
88
+ runtimeVersion: {
89
+ ios: '1.0.0',
90
+ android: '1.0.0',
91
+ },
92
+ org: {
93
+ slug: '${orgSlug}',
94
+ },
95
+ project: {
96
+ name: '${projectName.replace(/'/g, "\\'")}',
97
+ slug: '${projectSlug}',
98
+ apiKey: '${params.downloadApiKey || ''}',
99
+ },
100
+ debugLocal: false,
101
+ };
102
+ `;
103
+ await fs_extra_1.default.writeFile(configPath, content, 'utf8');
104
+ console.log(chalk_1.default.green(`✅ Created bundle.drop.config.js at ${configPath}`));
105
+ }
106
+ exports.default = initConfig;
@@ -0,0 +1,2 @@
1
+ export declare function initNativeConfig(): Promise<void>;
2
+ export default initNativeConfig;
@@ -0,0 +1,137 @@
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.initNativeConfig = initNativeConfig;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const prompts_1 = __importDefault(require("prompts"));
11
+ function findProjectRoot(startDir) {
12
+ let dir = path_1.default.resolve(startDir);
13
+ const MAX_UP = 12;
14
+ for (let i = 0; i < MAX_UP; i++) {
15
+ if (fs_extra_1.default.existsSync(path_1.default.join(dir, 'ios')) && fs_extra_1.default.existsSync(path_1.default.join(dir, 'android'))) {
16
+ return dir;
17
+ }
18
+ const parent = path_1.default.dirname(dir);
19
+ if (parent === dir)
20
+ break;
21
+ dir = parent;
22
+ }
23
+ return startDir;
24
+ }
25
+ function findFileByName(root, fileName) {
26
+ const stack = [root];
27
+ while (stack.length) {
28
+ const current = stack.pop();
29
+ const stat = fs_extra_1.default.statSync(current);
30
+ if (stat.isDirectory()) {
31
+ for (const entry of fs_extra_1.default.readdirSync(current)) {
32
+ stack.push(path_1.default.join(current, entry));
33
+ }
34
+ }
35
+ else if (stat.isFile() && current.endsWith(fileName)) {
36
+ return current;
37
+ }
38
+ }
39
+ return null;
40
+ }
41
+ function patchAndroidMainApplication(filePath) {
42
+ let content = fs_extra_1.default.readFileSync(filePath, 'utf8');
43
+ if (content.includes('BundleDropModule.getDownloadedBundlePath')) {
44
+ console.log(chalk_1.default.gray(`â„šī¸ Android already references BundleDrop in ${filePath}`));
45
+ return;
46
+ }
47
+ // Ensure import
48
+ if (!content.includes('import com.bundledrop.BundleDropModule')) {
49
+ content = content.replace(/(import\s+com\.facebook\.react\.ReactNativeHost[^\n]*\n)/, `$1import com.bundledrop.BundleDropModule\n`);
50
+ }
51
+ const methodRegex = /override fun getJSBundleFile\(\): String\?\s*\{\s*/;
52
+ if (!methodRegex.test(content)) {
53
+ console.log(chalk_1.default.yellow(`âš ī¸ Could not find getJSBundleFile() in ${filePath}. Please add manually:\n` +
54
+ `val bundlePath = BundleDropModule.getDownloadedBundlePath(this)\nif (bundlePath != null) return bundlePath`));
55
+ return;
56
+ }
57
+ content = content.replace(methodRegex, match => {
58
+ return (match +
59
+ ` val bundlePath = BundleDropModule.getDownloadedBundlePath(this)\n` +
60
+ ` if (bundlePath != null) {\n` +
61
+ ` return bundlePath\n` +
62
+ ` }\n`);
63
+ });
64
+ fs_extra_1.default.writeFileSync(filePath, content, 'utf8');
65
+ console.log(chalk_1.default.green(`✅ Patched Android MainApplication: ${filePath}`));
66
+ }
67
+ function patchIosAppDelegate(filePath) {
68
+ let content = fs_extra_1.default.readFileSync(filePath, 'utf8');
69
+ if (!content.includes('import BundleDrop')) {
70
+ content = content.replace(/^(import .*React.*\n)/m, `$1import BundleDrop\n`);
71
+ }
72
+ const bundleRegex = /override func bundleURL\(\) -> URL\?\s*\{[\s\S]*?#endif\s*\}/m;
73
+ if (bundleRegex.test(content)) {
74
+ content = content.replace(bundleRegex, () => {
75
+ return `override func bundleURL() -> URL? {
76
+ #if DEBUG
77
+ return RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
78
+ #else
79
+ // Release: OTA if present, else embedded bundle
80
+ if let url = BundleDropLocator.bundleURL() {
81
+ return url
82
+ }
83
+ return Bundle.main.url(forResource: "main", withExtension: "jsbundle")
84
+ #endif
85
+ }`;
86
+ });
87
+ }
88
+ else {
89
+ console.log(chalk_1.default.yellow(`âš ī¸ Could not find bundleURL() override in ${filePath}. Please add the OTA preference manually (Debug -> Metro, Release -> locator fallback).`));
90
+ }
91
+ fs_extra_1.default.writeFileSync(filePath, content, 'utf8');
92
+ console.log(chalk_1.default.green(`✅ Patched iOS AppDelegate: ${filePath}`));
93
+ }
94
+ async function initNativeConfig() {
95
+ const projectRoot = findProjectRoot(process.cwd());
96
+ const configPath = path_1.default.join(projectRoot, 'bundle.drop.config.js');
97
+ if (!fs_extra_1.default.existsSync(configPath)) {
98
+ console.log(chalk_1.default.yellow('â„šī¸ bundle.drop.config.js not found; run `bundle-drop init` first.'));
99
+ return;
100
+ }
101
+ const { confirm } = await (0, prompts_1.default)({
102
+ type: 'confirm',
103
+ name: 'confirm',
104
+ message: 'Apply BundleDrop native changes to iOS and Android?',
105
+ initial: true,
106
+ });
107
+ if (!confirm) {
108
+ console.log(chalk_1.default.gray('â„šī¸ Skipping native changes.'));
109
+ return;
110
+ }
111
+ // Android
112
+ const androidPath = path_1.default.join(projectRoot, 'android', 'app', 'src', 'main', 'java');
113
+ const mainAppKotlin = findFileByName(androidPath, 'MainApplication.kt');
114
+ const mainAppJava = findFileByName(androidPath, 'MainApplication.java');
115
+ if (mainAppKotlin) {
116
+ patchAndroidMainApplication(mainAppKotlin);
117
+ }
118
+ else if (mainAppJava) {
119
+ console.log(chalk_1.default.yellow(`âš ī¸ Found Java MainApplication at ${mainAppJava}. Automated patching for Java is not implemented; please apply the snippet manually.`));
120
+ }
121
+ else {
122
+ console.log(chalk_1.default.yellow('âš ī¸ Could not locate MainApplication in android/app/src/main/java.'));
123
+ }
124
+ // iOS
125
+ const appDelegateSwift = path_1.default.join(projectRoot, 'ios', 'AppDelegate.swift');
126
+ const appDelegateObjc = path_1.default.join(projectRoot, 'ios', 'AppDelegate.m');
127
+ if (fs_extra_1.default.existsSync(appDelegateSwift)) {
128
+ patchIosAppDelegate(appDelegateSwift);
129
+ }
130
+ else if (fs_extra_1.default.existsSync(appDelegateObjc)) {
131
+ console.log(chalk_1.default.yellow(`âš ī¸ Found Objective-C AppDelegate at ${appDelegateObjc}. Automated patching for ObjC is not implemented; please apply the snippet manually.`));
132
+ }
133
+ else {
134
+ console.log(chalk_1.default.yellow('âš ī¸ Could not locate AppDelegate in ios/.'));
135
+ }
136
+ }
137
+ exports.default = initNativeConfig;
@@ -0,0 +1,2 @@
1
+ declare const login: () => Promise<void>;
2
+ export default login;
@@ -0,0 +1,56 @@
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
+ // src/CLI/scripts/login-cli.ts
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const chalk_1 = __importDefault(require("chalk"));
9
+ const fs_extra_1 = __importDefault(require("fs-extra"));
10
+ const os_1 = __importDefault(require("os"));
11
+ const path_1 = __importDefault(require("path"));
12
+ const prompts_1 = __importDefault(require("prompts"));
13
+ const init_config_1 = require("./init-config");
14
+ const login = async () => {
15
+ const { email, password } = await (0, prompts_1.default)([
16
+ {
17
+ type: 'text',
18
+ name: 'email',
19
+ message: 'Enter your email:',
20
+ },
21
+ {
22
+ type: 'password',
23
+ name: 'password',
24
+ message: 'Enter your password:',
25
+ },
26
+ ]);
27
+ try {
28
+ const baseUrl = process.env.BUNDLE_DROP_SERVER_URL
29
+ ? process.env.BUNDLE_DROP_SERVER_URL.replace(/\/$/, '')
30
+ : 'https://bundle-drop-backend.onrender.com';
31
+ const loginUrl = `${baseUrl}/auth/login`;
32
+ const res = await axios_1.default.post(loginUrl, {
33
+ email,
34
+ password,
35
+ });
36
+ const { token, email: userEmail, firstName, lastName, projects = [], organizations = [], memberships = [], downloadApiKey, } = res.data;
37
+ const tokenPath = path_1.default.join(os_1.default.homedir(), '.bundle-drop', 'auth.json');
38
+ await fs_extra_1.default.ensureDir(path_1.default.dirname(tokenPath));
39
+ await fs_extra_1.default.writeJson(tokenPath, {
40
+ token,
41
+ user: { email: userEmail, firstName, lastName },
42
+ projects,
43
+ organizations,
44
+ memberships,
45
+ downloadApiKey,
46
+ });
47
+ console.log(chalk_1.default.green('✅ Logged in successfully as:'), chalk_1.default.cyan(`${firstName} ${lastName}`));
48
+ // Attempt to scaffold bundle.drop.config.js if missing
49
+ const serverUrl = new URL(loginUrl).origin;
50
+ await (0, init_config_1.initConfig)({ serverUrl, projects, organizations, downloadApiKey });
51
+ }
52
+ catch (err) {
53
+ console.error(chalk_1.default.red('❌ Login failed:'), err.response?.data?.error || err.message);
54
+ }
55
+ };
56
+ exports.default = login;
@@ -0,0 +1,8 @@
1
+ export default function upload(platform: string, options: {
2
+ plistFile?: string;
3
+ version?: string;
4
+ channel?: string;
5
+ buildGradlePath?: string;
6
+ runtimeVersion?: string;
7
+ releaseNotes?: string;
8
+ }): Promise<void>;