@codemoreira/esad 1.2.3 → 1.2.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemoreira/esad",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
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
  "exports": {
@@ -4,9 +4,36 @@ const AdmZip = require('adm-zip');
4
4
  const { getWorkspaceConfig } = require('../utils/config');
5
5
 
6
6
  module.exports = async (options) => {
7
- const pkgPath = path.join(process.cwd(), 'package.json');
7
+ let cwd = process.cwd();
8
+ let pkgPath = path.join(cwd, 'package.json');
9
+
10
+ // Try to find workspace config for root-level execution
11
+ const configObj = getWorkspaceConfig();
12
+ if (configObj) {
13
+ const workspaceRoot = path.dirname(configObj.path);
14
+ const { projectName } = configObj.data;
15
+
16
+ // If ID is provided, try to find that module/host folder
17
+ if (options.id) {
18
+ const targetDir = path.join(workspaceRoot, options.id);
19
+ if (fs.existsSync(targetDir)) {
20
+ cwd = targetDir;
21
+ pkgPath = path.join(cwd, 'package.json');
22
+ console.log(`šŸ“‚ Auto-detected Project folder: ${path.relative(process.cwd(), targetDir)}`);
23
+ }
24
+ } else if (!fs.existsSync(pkgPath)) {
25
+ // If no ID and no package.json in current dir, assume we want to deploy the host from root
26
+ const hostDir = path.join(workspaceRoot, `${projectName}-host`);
27
+ if (fs.existsSync(hostDir)) {
28
+ cwd = hostDir;
29
+ pkgPath = path.join(cwd, 'package.json');
30
+ console.log(`šŸ“‚ Auto-detected Host App folder: ${path.relative(process.cwd(), hostDir)}`);
31
+ }
32
+ }
33
+ }
34
+
8
35
  if (!fs.existsSync(pkgPath)) {
9
- console.error(`āŒ Error: package.json not found.`);
36
+ console.error(`āŒ Error: Call this command from inside a Project directory or the Workspace Root.`);
10
37
  process.exit(1);
11
38
  }
12
39
 
@@ -17,14 +44,8 @@ module.exports = async (options) => {
17
44
 
18
45
  console.log(`\nā˜ļø Starting ESAD Deploy for ${moduleId} (v${version})\n`);
19
46
 
20
- const configObj = getWorkspaceConfig();
21
- if (!configObj) {
22
- console.error(`āŒ Error: esad.config.json not found in current directory or parent.`);
23
- process.exit(1);
24
- }
25
-
26
- const config = configObj.data;
27
- if (!config.deployEndpoint) {
47
+ const config = configObj ? configObj.data : null;
48
+ if (!config?.deployEndpoint) {
28
49
  console.error(`āŒ Error: 'deployEndpoint' not configured in esad.config.json.`);
29
50
  process.exit(1);
30
51
  }
@@ -32,16 +53,16 @@ module.exports = async (options) => {
32
53
  const deployUrl = config.deployEndpoint.replace('{{moduleId}}', moduleId);
33
54
  console.log(`šŸ“” Deployment Endpoint Resolved: ${deployUrl}`);
34
55
 
35
- const distPath = path.join(process.cwd(), 'dist');
56
+ const distPath = path.join(cwd, 'dist');
36
57
  if (!fs.existsSync(distPath)) {
37
- console.error(`āŒ Error: dist/ directory not found. Did you run the build command?`);
58
+ console.error(`āŒ Error: dist/ directory not found in ${cwd}. Did you run the build command?`);
38
59
  process.exit(1);
39
60
  }
40
61
 
41
62
  const zip = new AdmZip();
42
63
  zip.addLocalFolder(distPath);
43
64
 
44
- const zipPath = path.join(process.cwd(), `bundle-${moduleId}-${version}.zip`);
65
+ const zipPath = path.join(cwd, `bundle-${moduleId}-${version}.zip`);
45
66
  zip.writeZip(zipPath);
46
67
  console.log(`šŸ—œļø Zipped output to ${zipPath}`);
47
68
 
@@ -4,12 +4,34 @@ const fs = require('fs-extra');
4
4
  const path = require('path');
5
5
 
6
6
  module.exports = async (options) => {
7
- const pkgPath = path.join(process.cwd(), 'package.json');
8
- if (!fs.existsSync(pkgPath)) {
9
- console.error(`āŒ Error: Call this command from inside a Host or Module directory.`);
10
- return;
11
- }
7
+ let cwd = process.cwd();
8
+ let pkgPath = path.join(cwd, 'package.json');
12
9
 
10
+ // Try to find workspace config for root-level execution
11
+ const configObj = getWorkspaceConfig();
12
+ if (configObj) {
13
+ const workspaceRoot = path.dirname(configObj.path);
14
+ const { projectName } = configObj.data;
15
+
16
+ if (options.id) {
17
+ // Target a specific module
18
+ const moduleDir = path.join(workspaceRoot, options.id);
19
+ if (fs.existsSync(moduleDir)) {
20
+ cwd = moduleDir;
21
+ pkgPath = path.join(cwd, 'package.json');
22
+ console.log(`šŸ“‚ Auto-detected Module folder: ${path.relative(process.cwd(), moduleDir)}`);
23
+ }
24
+ } else {
25
+ // Target host by default if in root
26
+ const hostDir = path.join(workspaceRoot, `${projectName}-host`);
27
+ if (fs.existsSync(hostDir)) {
28
+ cwd = hostDir;
29
+ pkgPath = path.join(cwd, 'package.json');
30
+ console.log(`šŸ“‚ Auto-detected Host App folder: ${path.relative(process.cwd(), hostDir)}`);
31
+ }
32
+ }
33
+ }
34
+
13
35
  const pkg = fs.readJsonSync(pkgPath);
14
36
  const moduleId = options.id || pkg.name;
15
37
  const port = options.port || '8081';
@@ -19,13 +41,12 @@ module.exports = async (options) => {
19
41
 
20
42
  if (isHost && !options.id) {
21
43
  console.log(`\nšŸš€ Starting Host App Dev Server (Re.Pack/Rspack)...\n`);
22
- await spawn('npx', ['react-native', 'webpack-start'], { stdio: 'inherit', shell: true });
44
+ await spawn('npx', ['react-native', 'webpack-start'], { cwd, stdio: 'inherit', shell: true });
23
45
  return;
24
46
  }
25
47
 
26
48
  console.log(`\n⚔ Starting ESAD Dev Server for ${moduleId} on port ${port}...\n`);
27
49
 
28
- const configObj = getWorkspaceConfig();
29
50
  const config = configObj ? configObj.data : null;
30
51
  let devApiUrl = config?.devModeEndpoint ? config.devModeEndpoint.replace('{{moduleId}}', moduleId) : null;
31
52
 
@@ -43,7 +64,7 @@ module.exports = async (options) => {
43
64
 
44
65
  await setDevMode(true);
45
66
 
46
- const proc = spawn('npx', ['react-native', 'webpack-start', '--port', port], { stdio: 'inherit', shell: true });
67
+ const proc = spawn('npx', ['react-native', 'webpack-start', '--port', port], { cwd, stdio: 'inherit', shell: true });
47
68
 
48
69
  const shutdown = async () => {
49
70
  console.log(`\nšŸ›‘ Parando ESAD Dev Server e revertendo o registro na CDN...`);
@@ -4,6 +4,7 @@ const fs = require('fs-extra');
4
4
  const { spawn } = require('cross-spawn');
5
5
  const http = require('http');
6
6
  const readline = require('readline');
7
+ const { getWorkspaceConfig } = require('../utils/config');
7
8
 
8
9
  const rl = readline.createInterface({
9
10
  input: process.stdin,
@@ -13,11 +14,25 @@ const rl = readline.createInterface({
13
14
  const askQuestion = (query) => new Promise((resolve) => rl.question(query, resolve));
14
15
 
15
16
  module.exports = async (subcommand) => {
16
- const cwd = process.cwd();
17
- const pkgPath = path.join(cwd, 'package.json');
17
+ let cwd = process.cwd();
18
+ let pkgPath = path.join(cwd, 'package.json');
18
19
 
20
+ // Try to find workspace config to resolve host path from root
21
+ const configObj = getWorkspaceConfig();
22
+ if (configObj) {
23
+ const workspaceRoot = path.dirname(configObj.path);
24
+ const { projectName } = configObj.data;
25
+ const hostDir = path.join(workspaceRoot, `${projectName}-host`);
26
+
27
+ if (fs.existsSync(hostDir)) {
28
+ cwd = hostDir;
29
+ pkgPath = path.join(cwd, 'package.json');
30
+ console.log(`šŸ“‚ Auto-detected Host App folder: ${path.relative(process.cwd(), hostDir)}`);
31
+ }
32
+ }
33
+
19
34
  if (!fs.existsSync(pkgPath)) {
20
- console.error(`āŒ Error: Call this command from inside the Host App directory.`);
35
+ console.error(`āŒ Error: Call this command from inside the Host App or the Workspace Root.`);
21
36
  return;
22
37
  }
23
38
 
@@ -85,15 +100,20 @@ module.exports = async (subcommand) => {
85
100
  // 4. Start Bundler in a New Window
86
101
  console.log(`\nšŸ› ļø Starting Rspack Bundler in a new window...`);
87
102
  if (process.platform === 'win32') {
88
- // Use CMD /C START to open a new window
89
- spawn('cmd', ['/c', 'start', 'npx', 'react-native', 'webpack-start'], {
103
+ // Use CMD /C START /D <dir> to open a new window in the correct folder
104
+ spawn('cmd', ['/c', 'start', '/D', cwd, 'npx', 'react-native', 'webpack-start'], {
90
105
  detached: true,
91
106
  stdio: 'ignore',
92
107
  shell: true
93
108
  }).unref();
94
109
  } else {
95
110
  // For MacOS or Linux
96
- spawn('npx', ['react-native', 'webpack-start'], { detached: true, stdio: 'inherit', shell: true }).unref();
111
+ spawn('npx', ['react-native', 'webpack-start'], {
112
+ cwd,
113
+ detached: true,
114
+ stdio: 'inherit',
115
+ shell: true
116
+ }).unref();
97
117
  }
98
118
 
99
119
  // 5. Wait for Bundler (Port 8081)