@codemoreira/esad 2.0.1-3 → 2.0.1-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.
package/README.md CHANGED
@@ -1,82 +1,88 @@
1
- # ESAD (Easy Super App Development) šŸš€
2
-
3
- Zero-Config CLI and DevTools for React Native Module Federation + Expo.
4
-
5
- ESAD is a unified toolkit designed to abstract all the complexity from Super App development using **Re.Pack (Rspack)** and **Expo**.
6
-
7
- ---
8
-
9
- ## šŸ—ļø CLI Commands
10
-
11
- ### 1. Initialize a Workspace
12
- ```bash
13
- npx @codemoreira/esad init my-project
14
- ```
15
-
16
- ### 2. Create a Federated Module
17
- ```bash
18
- npx esad create-module module-name
19
- ```
20
-
21
- ### 3. Create a Local CDN / Registry
22
- ```bash
23
- npx esad create-cdn
24
- ```
25
-
26
- ### 4. Development & Native Automation
27
- Starts the Rspack server and **automatically patches** native files (Gradle, Entry Points) if necessary.
28
- ```bash
29
- npx esad host dev # Run the Host App
30
- npx esad dev --id module-name --port 9000 # Run a Module
31
- ```
32
-
33
- ### 5. Build for Production
34
- Prepares the bundle and chunks for deployment, generating a standardized `./build` directory.
35
- ```bash
36
- npx esad build --id module-name --platform android
37
- ```
38
-
39
- ### 6. Deployment
40
- Packages the `./build` folder and uploads it to your configured Registry/CDN via multipart POST.
41
- ```bash
42
- npx esad deploy --id module-name --version 1.0.0
43
- ```
44
-
45
- ---
46
-
47
- ## šŸ› ļø Library Usage
48
-
49
- ### šŸŽØ Bundler Plugin (`@codemoreira/esad/plugin`)
50
- Wrap your configuration to enable ESAD's smart resolution and redirection logic:
51
- ```javascript
52
- import { withESAD } from '@codemoreira/esad/plugin';
53
-
54
- export default withESAD({
55
- type: 'module', // or 'host'
56
- id: 'my-mini-app'
57
- });
58
- ```
59
-
60
- ### ⚔ Global State SDK (`@codemoreira/esad/client`)
61
- Share state across the Host and all Remote Modules reactively:
62
- ```javascript
63
- import { useESADState } from '@codemoreira/esad/client';
64
-
65
- const [user, setUser] = useESADState('user');
66
- ```
67
-
68
- ---
69
-
70
- ## šŸ  Template Features (Host & Module)
71
-
72
- ESAD provides high-quality, boilerplate-free templates:
73
- - **šŸš€ Rspack + Re.Pack**: Blazing fast builds powered by Rspack.
74
- - **šŸ“± Clean UI**: Modern, responsive designs built with **Vanilla StyleSheet** (No external CSS libraries required).
75
- - **šŸ›¤ļø Dynamic Navigation**: Pre-configured Dashboard and Module Viewer with **Suspense** support.
76
- - **šŸ” State-Driven Auth**: Built-in login and session management via the ESAD SDK.
77
- - **šŸ”§ Automated Patching**: CLI-driven injection of Re.Pack extensions into Android and iOS native projects.
78
-
79
- ---
80
-
81
- ## šŸŽØ Architecture & Workflow
82
- For technical diagrams and the modular deployment lifecycle, see [ESAD_ARCHITECTURE.md](./ESAD_ARCHITECTURE.md).
1
+ # ESAD (Easy Super App Development) šŸš€
2
+
3
+ Zero-Config CLI and DevTools for React Native Module Federation + Expo.
4
+
5
+ ESAD is a unified toolkit designed to abstract all the complexity from Super App development using **Re.Pack (Rspack)** and **Expo**. It provides a professional, linear workflow from scaffolding to deployment.
6
+
7
+ ---
8
+
9
+ ## šŸ—ļø CLI Workflow (V2)
10
+
11
+ ### 1. Initialize a Workspace
12
+ Creates the project root, a programmable `esad.config.js`, and the Host Application.
13
+ ```bash
14
+ npx @codemoreira/esad init my-project
15
+ ```
16
+
17
+ ### 2. Expand your Workspace
18
+ Create new Federated Modules or a Local Registry/CDN.
19
+ ```bash
20
+ esad create my-module # Creates a new module (Feature)
21
+ esad create --type cdn # Scaffolds a local registry for testing
22
+ ```
23
+
24
+ ### 3. Development Manager (Unified)
25
+ The `dev` command is the single entry point for development. It automatically detects if it should run the Host or a Module.
26
+
27
+ **Run the Host App (Interactive):**
28
+ ```bash
29
+ esad dev
30
+ ```
31
+ *Allows selecting Android, iOS, or Bundler Only. Automatically patches native files.*
32
+
33
+ **Run a specific Module:**
34
+ ```bash
35
+ esad dev my-module --port 9000
36
+ ```
37
+ *Starts the module server and updates the Host's local mapping automatically.*
38
+
39
+ ### 4. Build & Deploy
40
+ Prepare and push your features to the registry.
41
+
42
+ **Build for Production:**
43
+ ```bash
44
+ esad build my-module --platform android
45
+ ```
46
+
47
+ **Execute Programmable Deploy:**
48
+ ```bash
49
+ esad deploy my-module --version 1.0.0
50
+ ```
51
+
52
+ ---
53
+
54
+ ## šŸ› ļø Library Usage
55
+
56
+ ### šŸŽØ Bundler Plugin (`@codemoreira/esad/plugin`)
57
+ Wrap your configuration to enable ESAD's smart resolution and redirection logic:
58
+ ```javascript
59
+ import { withESAD } from '@codemoreira/esad/plugin';
60
+
61
+ export default withESAD({
62
+ type: 'module', // or 'host'
63
+ id: 'my-mini-app'
64
+ });
65
+ ```
66
+
67
+ ### ⚔ Global State SDK (`@codemoreira/esad/client`)
68
+ Share state across the Host and all Remote Modules reactively:
69
+ ```javascript
70
+ import { useESADState } from '@codemoreira/esad/client';
71
+
72
+ const [user, setUser] = useESADState('user');
73
+ ```
74
+
75
+ ---
76
+
77
+ ## šŸ  Template Features (Host & Module)
78
+ ESAD templates provide a high-end starting point:
79
+ - **šŸš€ Rspack + Re.Pack**: Blazing fast builds.
80
+ - **šŸ“± Professional Architecture**: Modular structure (`src/api`, `src/components`, `src/navigation`).
81
+ - **šŸ›¤ļø Dynamic Navigation**: Pre-configured Module Viewer with **Suspense** and **ErrorBoundary** support.
82
+ - **šŸ” State-Driven Auth**: Built-in login and session management via the ESAD SDK.
83
+ - **šŸ”§ Automated Native Patching**: Zero-config injection into Android/iOS projects.
84
+
85
+ ---
86
+
87
+ ## šŸŽØ Architecture & Workflow
88
+ For technical diagrams and the full lifecycle, see [ESAD_ARCHITECTURE.md](./ESAD_ARCHITECTURE.md).
package/bin/esad.js CHANGED
@@ -24,12 +24,13 @@ program
24
24
  await require('../src/cli/commands/create')(name, options);
25
25
  });
26
26
 
27
- // --- COMMAND: esad dev [moduleId] ---
27
+ // --- COMMAND: esad dev [id] ---
28
28
  program
29
- .command('dev [id]') // [id] as alias to -i for better UX
29
+ .command('dev [id]')
30
30
  .option('-i, --id <moduleId>', 'The Module ID to run in dev mode')
31
31
  .option('-p, --port <port>', 'The port to run the dev server on', '8081')
32
- .description('Starts the dev server and updates the local mapping')
32
+ .option('--platform <platform>', 'Platform for host: android, ios, bundler')
33
+ .description('Starts the development environment. Run without [id] for Host App or with [id] for a specific Module.')
33
34
  .action(async (id, options) => {
34
35
  const opts = { ...options, id: id || options.id };
35
36
  await require('../src/cli/commands/dev')(opts);
@@ -40,7 +41,7 @@ program
40
41
  .command('build [id]')
41
42
  .option('-i, --id <moduleId>', 'The Module ID to build')
42
43
  .option('-p, --platform <platform>', 'Platform: android, ios', 'android')
43
- .description('Builds a production bundle')
44
+ .description('Builds a production bundle for a module or the host application')
44
45
  .action(async (id, options) => {
45
46
  const opts = { ...options, id: id || options.id };
46
47
  await require('../src/cli/commands/build')(opts);
@@ -57,14 +58,6 @@ program
57
58
  await require('../src/cli/commands/deploy')(opts);
58
59
  });
59
60
 
60
- // --- COMMAND: esad host <sub> ---
61
- program
62
- .command('host <subcommand>')
63
- .description('Manage host application (android, ios, login)')
64
- .action(async (sub) => {
65
- await require('../src/cli/commands/host')(sub);
66
- });
67
-
68
61
  // --- COMMAND: esad doctor ---
69
62
  program
70
63
  .command('doctor')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemoreira/esad",
3
- "version": "2.0.1-3",
3
+ "version": "2.0.1-5",
4
4
  "description": "Easy Super App Development - Zero-Config CLI and DevTools for React Native Module Federation",
5
5
  "main": "src/plugin/index.js",
6
6
  "types": "./src/plugin/index.d.ts",
@@ -1,72 +1,175 @@
1
- const { runProcess } = require('../utils/process');
2
- const { getWorkspaceConfig } = require('../utils/config');
3
- const fs = require('fs-extra');
4
- const path = require('path');
5
- const chalk = require('chalk');
6
- const { prepareNative } = require('../utils/scaffold');
7
- const { resolveProjectDir } = require('../utils/resolution');
8
-
9
- module.exports = async (options) => {
10
- const configObj = getWorkspaceConfig();
11
- if (!configObj) {
12
- console.error(chalk.red(`āŒ Error: esad.config.js not found. Run this from your project root.`));
13
- process.exit(1);
14
- }
15
-
16
- const config = await configObj.load();
17
- const workspaceRoot = configObj.root;
18
- const projectName = config.default?.projectName || config.projectName;
19
-
20
- let cwd = process.cwd();
21
- let selectedModuleId = options.id;
22
-
23
- if (selectedModuleId) {
24
- const targetDir = resolveProjectDir(selectedModuleId, configObj);
25
- if (!targetDir) {
26
- console.error(chalk.red(`āŒ Error: Module not found: ${selectedModuleId}`));
27
- process.exit(1);
28
- }
29
- cwd = targetDir;
30
- }
31
-
32
- const pkgPath = path.join(cwd, 'package.json');
33
- const pkg = fs.readJsonSync(pkgPath);
34
- const moduleId = selectedModuleId || pkg.name;
35
- const port = options.port || '8081';
36
-
37
- // Determine if it's a Host or Module
38
- const isHost = pkg.name.endsWith('-host') || pkg.dependencies?.['@callstack/repack'];
39
-
40
- await prepareNative(cwd, 'all');
41
-
42
- if (isHost && !selectedModuleId) {
43
- console.log(`\nšŸš€ Starting ${chalk.green('Host App')} Dev Server (Re.Pack/Rspack)...\n`);
44
- await runProcess('npx', ['react-native', 'webpack-start'], { cwd });
45
- return;
46
- }
47
-
48
- const { updateDevMode, removeDevMode, syncContextDownwards } = require('../utils/transformer');
49
-
50
- console.log(`\n⚔ Starting ESAD Dev Server for ${chalk.cyan(moduleId)} on port ${port}...\n`);
51
-
52
- // Automate devMode update in esad.config.js
53
- const localBundleUrl = `http://localhost:${port}/index.bundle`;
54
- updateDevMode(configObj.path, moduleId, localBundleUrl);
55
- syncContextDownwards(configObj);
56
- console.log(chalk.gray(`šŸ“” Mode: Module Dev. Host configured to load ${moduleId} from ${localBundleUrl}`));
57
-
58
- const proc = runProcess('npx', ['react-native', 'webpack-start', '--port', port], { cwd });
59
-
60
- const shutdown = async () => {
61
- console.log(`\nšŸ›‘ Stopping ESAD Dev Server and reverting config...`);
62
- removeDevMode(configObj.path, moduleId);
63
- syncContextDownwards(configObj);
64
- if (proc.kill) proc.kill();
65
- process.exit(0);
66
- };
67
-
68
-
69
- process.on('SIGINT', shutdown);
70
- process.on('SIGTERM', shutdown);
71
- };
72
-
1
+ const { runProcess } = require('../utils/process');
2
+ const { getWorkspaceConfig } = require('../utils/config');
3
+ const fs = require('fs-extra');
4
+ const path = require('path');
5
+ const chalk = require('chalk');
6
+ const http = require('http');
7
+ const readline = require('readline');
8
+ const { spawn } = require('cross-spawn');
9
+ const { prepareNative } = require('../utils/scaffold');
10
+ const { resolveProjectDir } = require('../utils/resolution');
11
+
12
+ /**
13
+ * Check if a port is in use
14
+ */
15
+ const isPortInUse = (port) => new Promise((resolve) => {
16
+ const req = http.get(`http://localhost:${port}`, (res) => {
17
+ resolve(true);
18
+ });
19
+ req.on('error', () => {
20
+ resolve(false);
21
+ });
22
+ req.end();
23
+ });
24
+
25
+ const runHostDevFlow = async (cwd, options = {}) => {
26
+ let choice = options.platform ? options.platform.charAt(0).toLowerCase() : null;
27
+
28
+ if (!choice) {
29
+ const rl = readline.createInterface({
30
+ input: process.stdin,
31
+ output: process.stdout
32
+ });
33
+ const askQuestion = (query) => new Promise((resolve) => rl.question(query, resolve));
34
+
35
+ console.log(`\n${chalk.bold('ESAD Host Dev Manager')}`);
36
+ console.log(chalk.dim(`---------------------`));
37
+ console.log(`[a] Run on Android`);
38
+ console.log(`[i] Run on iOS`);
39
+ console.log(`[b] Bundler Only`);
40
+ console.log(`[c] Cancel`);
41
+
42
+ choice = (await askQuestion(`\nSelect platform: `)).toLowerCase();
43
+ rl.close();
44
+ }
45
+
46
+ if (choice === 'c') {
47
+ console.log(`\nāŒ Cancelled.`);
48
+ return;
49
+ }
50
+
51
+ const portBusy = await isPortInUse(8081);
52
+ let shouldStartBundler = true;
53
+
54
+ if (portBusy) {
55
+ console.log(`\nāš ļø Warning: Port 8081 is already in use.`);
56
+ console.log(`šŸ’” Skipping Bundler startup. Proceeding with Native Build.\n`);
57
+ shouldStartBundler = false;
58
+ }
59
+
60
+ if (shouldStartBundler && choice !== 'c') {
61
+ console.log(`\nšŸ› ļø Starting Rspack Bundler...`);
62
+ if (process.platform === 'win32') {
63
+ spawn('cmd', ['/c', 'start', '/D', cwd, 'npx.cmd', 'react-native', 'webpack-start'], {
64
+ detached: true,
65
+ stdio: 'ignore',
66
+ shell: true
67
+ }).unref();
68
+ } else {
69
+ spawn('npx', ['react-native', 'webpack-start'], {
70
+ cwd,
71
+ detached: true,
72
+ stdio: 'inherit',
73
+ shell: true
74
+ }).unref();
75
+ }
76
+
77
+ console.log(`ā³ Waiting for Rspack Bundler on port 8081...`);
78
+ const waitForBundler = async () => {
79
+ for (let i = 0; i < 30; i++) {
80
+ if (await isPortInUse(8081)) return true;
81
+ await new Promise(r => setTimeout(r, 2000));
82
+ }
83
+ return false;
84
+ };
85
+
86
+ if (!(await waitForBundler())) {
87
+ console.error(`\nāŒ Timeout: Bundler did not respond.`);
88
+ return;
89
+ }
90
+ console.log(`āœ… Bundler ready!`);
91
+ }
92
+
93
+ if (choice === 'a') {
94
+ console.log(`šŸ¤– Launching Android...`);
95
+ await runProcess('react-native', ['run-android', '--no-packager'], cwd);
96
+ } else if (choice === 'i') {
97
+ console.log(`šŸŽ Launching iOS...`);
98
+ await runProcess('react-native', ['run-ios', '--no-packager'], cwd);
99
+ } else if (choice === 'b') {
100
+ console.log(`✨ Bundler is active.`);
101
+ }
102
+ };
103
+
104
+ module.exports = async (options) => {
105
+ const configObj = getWorkspaceConfig();
106
+ if (!configObj) {
107
+ console.error(chalk.red(`āŒ Error: esad.config.js not found. Run this from your project root.`));
108
+ process.exit(1);
109
+ }
110
+
111
+ const config = configObj.data;
112
+ const workspaceRoot = configObj.root;
113
+ const projectName = config.projectName;
114
+
115
+ let cwd = process.cwd();
116
+ let selectedModuleId = options.id;
117
+
118
+ // 1. Module Dev Flow
119
+ if (selectedModuleId) {
120
+ const targetDir = resolveProjectDir(selectedModuleId, configObj);
121
+ if (!targetDir) {
122
+ console.error(chalk.red(`āŒ Error: Module not found: ${selectedModuleId}`));
123
+ process.exit(1);
124
+ }
125
+ cwd = targetDir;
126
+
127
+ const pkg = fs.readJsonSync(path.join(cwd, 'package.json'));
128
+ const moduleId = selectedModuleId || pkg.name;
129
+ const port = options.port || '8081';
130
+
131
+ await prepareNative(cwd, 'all');
132
+
133
+ const { updateDevMode, removeDevMode, syncContextDownwards } = require('../utils/transformer');
134
+
135
+ console.log(`\n⚔ Starting ESAD Dev Server for ${chalk.cyan(moduleId)} on port ${port}...\n`);
136
+ const localBundleUrl = `http://localhost:${port}/index.bundle`;
137
+ updateDevMode(configObj.path, moduleId, localBundleUrl);
138
+ syncContextDownwards(configObj);
139
+
140
+ const proc = runProcess('npx', ['react-native', 'webpack-start', '--port', port], { cwd });
141
+
142
+ const shutdown = async () => {
143
+ console.log(`\nšŸ›‘ Stopping ESAD Dev Server and reverting config...`);
144
+ removeDevMode(configObj.path, moduleId);
145
+ syncContextDownwards(configObj);
146
+ if (proc.kill) proc.kill();
147
+ process.exit(0);
148
+ };
149
+
150
+ process.on('SIGINT', shutdown);
151
+ process.on('SIGTERM', shutdown);
152
+ return;
153
+ }
154
+
155
+ // 2. Host Dev Flow (Auto-detection)
156
+ const pkgPath = path.join(cwd, 'package.json');
157
+ let isHost = fs.existsSync(pkgPath) && fs.readJsonSync(pkgPath).name.endsWith('-host');
158
+
159
+ if (!isHost) {
160
+ const hostDir = path.join(workspaceRoot, `${projectName}-host`);
161
+ if (fs.existsSync(hostDir)) {
162
+ cwd = hostDir;
163
+ isHost = true;
164
+ console.log(`šŸ“‚ Auto-detected Host App: ${chalk.dim(path.relative(process.cwd(), hostDir))}`);
165
+ }
166
+ }
167
+
168
+ if (isHost) {
169
+ await prepareNative(cwd, 'all');
170
+ await runHostDevFlow(cwd, options);
171
+ } else {
172
+ console.error(chalk.red(`āŒ Error: Could not detect Host or Module context.`));
173
+ console.log(`šŸ‘‰ Try: esad dev <module-id>`);
174
+ }
175
+ };
@@ -75,7 +75,7 @@ export default {
75
75
  console.log(chalk.green(`\nšŸŽ‰ ESAD Workspace Initialized successfully!`));
76
76
  console.log(chalk.cyan(`\nšŸ‘‰ Next steps:`));
77
77
  console.log(` 1. cd ${projectName}/${hostName}`);
78
- console.log(` 2. esad host dev (to start Host)`);
78
+ console.log(` 2. esad dev (to start Host)`);
79
79
  console.log(` 3. esad dev (in a module folder to federate)\n`);
80
80
  } catch (err) {
81
81
  console.error(chalk.red(`\nāŒ Failed to initialize workspace:`));
@@ -20,15 +20,14 @@ const getWorkspaceConfig = () => {
20
20
 
21
21
  try {
22
22
  const jiti = createJiti(__filename);
23
- const configModule = jiti(configPath);
24
- // jiti.import returns a promise for async imports if needed, but for esad.config.js
25
- // we expect a sync structure or we resolve it.
26
- // However, jiti v2 import is async.
27
-
23
+ let configData = jiti(configPath);
24
+ if (configData.default) configData = configData.default;
25
+
28
26
  return {
29
27
  path: configPath,
30
28
  root: path.dirname(configPath),
31
- load: () => configModule
29
+ data: configData,
30
+ load: () => configData
32
31
  };
33
32
  } catch (err) {
34
33
  console.error(`āŒ Failed to load esad.config.js: ${err.message}`);
@@ -59,7 +59,7 @@ function withESAD(env, options) {
59
59
  {
60
60
  test: /\.[cm]?[jt]sx?$/,
61
61
  include: [
62
- /node_modules[\\/](react-native|@react-native|expo|expo-modules-core|@expo|react-navigation|@react-navigation|@unimodules|unimodules|native-base)/,
62
+ /node_modules[\\/](react-native|@react-native|expo|expo-modules-core|@expo|react-navigation|@react-navigation|@unimodules|unimodules|native-base|react-native-screens|react-native-reanimated)/,
63
63
  ],
64
64
  type: 'javascript/auto',
65
65
  resolve: { fullySpecified: false },
@@ -67,10 +67,10 @@ function withESAD(env, options) {
67
67
  loader: 'babel-loader',
68
68
  options: {
69
69
  presets: [
70
- [
71
- 'babel-preset-expo',
72
- { native: { disableImportExportTransform: false } },
73
- ],
70
+ '@react-native/babel-preset',
71
+ ],
72
+ plugins: [
73
+ ['@babel/plugin-transform-react-jsx', { runtime: 'automatic' }],
74
74
  ],
75
75
  sourceType: 'unambiguous',
76
76
  caller: { name: 'repack' },
@@ -80,6 +80,7 @@ function withESAD(env, options) {
80
80
  {
81
81
  test: /\.[cm]?[jt]sx?$/,
82
82
  include: [dirname],
83
+ exclude: [/node_modules/],
83
84
  type: 'javascript/auto',
84
85
  use: {
85
86
  loader: 'babel-loader',
@@ -1,152 +0,0 @@
1
- const { runProcess } = require('../utils/process');
2
- const path = require('path');
3
- const fs = require('fs-extra');
4
- const { spawn } = require('cross-spawn');
5
- const http = require('http');
6
- const readline = require('readline');
7
- const { getWorkspaceConfig } = require('../utils/config');
8
- const { prepareNative } = require('../utils/scaffold');
9
-
10
- const rl = readline.createInterface({
11
- input: process.stdin,
12
- output: process.stdout
13
- });
14
-
15
- const askQuestion = (query) => new Promise((resolve) => rl.question(query, resolve));
16
-
17
- /**
18
- * Check if a port is in use
19
- */
20
- const isPortInUse = (port) => new Promise((resolve) => {
21
- const req = http.get(`http://localhost:${port}`, (res) => {
22
- resolve(true); // Responded, so it's in use
23
- });
24
- req.on('error', () => {
25
- resolve(false); // Refused, so it's free
26
- });
27
- req.end();
28
- });
29
-
30
- module.exports = async (subcommand) => {
31
- let cwd = process.cwd();
32
- let pkgPath = path.join(cwd, 'package.json');
33
-
34
- // Try to find workspace config to resolve host path from root
35
- const configObj = getWorkspaceConfig();
36
- if (configObj) {
37
- const workspaceRoot = path.dirname(configObj.path);
38
- const { projectName } = configObj.data;
39
- const hostDir = path.join(workspaceRoot, `${projectName}-host`);
40
-
41
- if (fs.existsSync(hostDir)) {
42
- cwd = hostDir;
43
- pkgPath = path.join(cwd, 'package.json');
44
- console.log(`šŸ“‚ Auto-detected Host App folder: ${path.relative(process.cwd(), hostDir)}`);
45
- }
46
- }
47
-
48
- if (!fs.existsSync(pkgPath)) {
49
- console.error(`āŒ Error: Call this command from inside the Host App or the Workspace Root.`);
50
- return;
51
- }
52
-
53
- const pkg = fs.readJsonSync(pkgPath);
54
-
55
- // 1. Initial Checks & Automated Native Preparation
56
- if (subcommand === 'dev' || subcommand === 'start') {
57
- await prepareNative(cwd, 'all');
58
-
59
- // 3. Platform Selection
60
- console.log(`\nESAD Host Dev Manager`);
61
- console.log(`---------------------`);
62
- console.log(`[a] Run on Android`);
63
- console.log(`[i] Run on iOS`);
64
- console.log(`[b] Bundler Only`);
65
- console.log(`[c] Cancel`);
66
-
67
- const choice = (await askQuestion(`\nSelect platform: `)).toLowerCase();
68
-
69
- if (choice === 'c') {
70
- console.log(`\nāŒ Cancelled.`);
71
- rl.close();
72
- return;
73
- }
74
-
75
- // 4. Check for Port 8081
76
- const portBusy = await isPortInUse(8081);
77
- let shouldStartBundler = true;
78
-
79
- if (portBusy) {
80
- console.log(`\nāš ļø Warning: Port 8081 is already in use by another process.`);
81
- console.log(`šŸ’” Skipping Bundler startup - assuming it's already running. Proceeding with Native Build only.\n`);
82
- shouldStartBundler = false;
83
- }
84
-
85
- // 4. Start Bundler in a New Window (if needed)
86
- if (shouldStartBundler && choice !== 'c') {
87
- console.log(`\nšŸ› ļø Starting Rspack Bundler in a new window...`);
88
- if (process.platform === 'win32') {
89
- const npxCmd = 'npx.cmd';
90
- spawn('cmd', ['/c', 'start', '/D', cwd, npxCmd, 'react-native', 'webpack-start'], {
91
- detached: true,
92
- stdio: 'ignore',
93
- shell: true
94
- }).unref();
95
- } else {
96
- spawn('npx', ['react-native', 'webpack-start'], {
97
- cwd,
98
- detached: true,
99
- stdio: 'inherit',
100
- shell: true
101
- }).unref();
102
- }
103
-
104
- // 5. Wait for Bundler (Port 8081)
105
- console.log(`ā³ Waiting for Rspack Bundler to initialize on port 8081...`);
106
- const waitForBundler = async () => {
107
- for (let i = 0; i < 30; i++) {
108
- if (await isPortInUse(8081)) return true;
109
- await new Promise(r => setTimeout(r, 2000));
110
- }
111
- return false;
112
- };
113
-
114
- const isReady = await waitForBundler();
115
- if (!isReady) {
116
- console.error(`\nāŒ Timeout: Bundler did not respond after 60 seconds.`);
117
- rl.close();
118
- return;
119
- }
120
- console.log(`āœ… Bundler stable and ready to use!`);
121
- }
122
-
123
- // 6. Launch Native App
124
- if (choice === 'a') {
125
- console.log(`šŸ¤– Compiling and launching on Android...`);
126
- await runProcess('react-native', ['run-android', '--no-packager'], cwd);
127
- } else if (choice === 'i') {
128
- console.log(`šŸŽ Compiling and launching on iOS...`);
129
- await runProcess('react-native', ['run-ios', '--no-packager'], cwd);
130
- } else if (choice === 'b') {
131
- if (portBusy) {
132
- console.log(`✨ Bundler is already active. You can launch manual native runs.`);
133
- } else {
134
- console.log(`✨ Bundler is running. You can open the app manually.`);
135
- }
136
- }
137
-
138
- rl.close();
139
- } else {
140
- // Other subcommands (android, ios directly)
141
- try {
142
- if (subcommand === 'android') {
143
- await runProcess('react-native', ['run-android', '--no-packager'], cwd);
144
- } else if (subcommand === 'ios') {
145
- await runProcess('react-native', ['run-ios', '--no-packager'], cwd);
146
- }
147
- } catch (err) {
148
- console.error(`āŒ Error running host command: ${err.message}`);
149
- }
150
- rl.close();
151
- }
152
- };