@codemoreira/esad 1.3.1 → 1.3.2

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.3.1",
3
+ "version": "1.3.2",
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,39 +1,46 @@
1
1
  const fs = require('fs-extra');
2
2
  const path = require('path');
3
3
  const AdmZip = require('adm-zip');
4
+ const chalk = require('chalk');
4
5
  const { getWorkspaceConfig } = require('../utils/config');
6
+ const { resolveProjectDir, listAvailableModules } = require('../utils/resolution');
5
7
 
6
8
  module.exports = async (options) => {
7
9
  let cwd = process.cwd();
8
10
  let pkgPath = path.join(cwd, 'package.json');
9
11
 
10
- // Try to find workspace config for root-level execution
12
+ // Enforce Workspace Root
11
13
  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
- }
14
+ if (!configObj) {
15
+ console.error(chalk.red(`❌ Erro: Comando deve ser executado na raiz do projeto (esad.config.json não encontrado).`));
16
+ process.exit(1);
17
+ }
18
+
19
+ const workspaceRoot = path.dirname(configObj.path);
20
+ const { projectName } = configObj.data;
21
+
22
+ if (options.id) {
23
+ const targetDir = resolveProjectDir(options.id, configObj);
24
+ if (!targetDir) {
25
+ console.error(chalk.red(`\n❌ Erro: Não foi encontrado o módulo: ${options.id}`));
26
+ listAvailableModules(configObj);
27
+ process.exit(1);
28
+ }
29
+ cwd = targetDir;
30
+ pkgPath = path.join(cwd, 'package.json');
31
+ console.log(chalk.green(`📂 Módulo detectado para Deploy: ${path.relative(workspaceRoot, cwd)}`));
32
+ } else {
33
+ // Target host by default if in root
34
+ const hostDir = path.join(workspaceRoot, `${projectName}-host`);
35
+ if (fs.existsSync(hostDir)) {
36
+ cwd = hostDir;
37
+ pkgPath = path.join(cwd, 'package.json');
38
+ console.log(chalk.green(`📂 Host detectado para Deploy: ${path.relative(workspaceRoot, cwd)}`));
32
39
  }
33
40
  }
34
41
 
35
42
  if (!fs.existsSync(pkgPath)) {
36
- console.error(`❌ Error: Call this command from inside a Project directory or the Workspace Root.`);
43
+ console.error(chalk.red(`❌ Erro: Arquivo package.json não encontrado em ${cwd}.`));
37
44
  process.exit(1);
38
45
  }
39
46
 
@@ -2,34 +2,41 @@ const { spawn } = require('cross-spawn');
2
2
  const { getWorkspaceConfig } = require('../utils/config');
3
3
  const fs = require('fs-extra');
4
4
  const path = require('path');
5
+ const chalk = require('chalk');
5
6
  const { prepareNative } = require('../utils/scaffold');
7
+ const { resolveProjectDir, listAvailableModules } = require('../utils/resolution');
6
8
 
7
9
  module.exports = async (options) => {
8
10
  let cwd = process.cwd();
9
11
  let pkgPath = path.join(cwd, 'package.json');
10
12
 
11
- // Try to find workspace config for root-level execution
13
+ // Enforce Workspace Root
12
14
  const configObj = getWorkspaceConfig();
13
- if (configObj) {
14
- const workspaceRoot = path.dirname(configObj.path);
15
- const { projectName } = configObj.data;
16
-
17
- if (options.id) {
18
- // Target a specific module
19
- const moduleDir = path.join(workspaceRoot, options.id);
20
- if (fs.existsSync(moduleDir)) {
21
- cwd = moduleDir;
22
- pkgPath = path.join(cwd, 'package.json');
23
- console.log(`📂 Auto-detected Module folder: ${path.relative(process.cwd(), moduleDir)}`);
24
- }
25
- } else {
26
- // Target host by default if in root
27
- const hostDir = path.join(workspaceRoot, `${projectName}-host`);
28
- if (fs.existsSync(hostDir)) {
29
- cwd = hostDir;
30
- pkgPath = path.join(cwd, 'package.json');
31
- console.log(`📂 Auto-detected Host App folder: ${path.relative(process.cwd(), hostDir)}`);
32
- }
15
+ if (!configObj) {
16
+ console.error(chalk.red(`❌ Erro: Comando deve ser executado na raiz do projeto (esad.config.json não encontrado).`));
17
+ process.exit(1);
18
+ }
19
+
20
+ const workspaceRoot = path.dirname(configObj.path);
21
+ const { projectName } = configObj.data;
22
+
23
+ if (options.id) {
24
+ const targetDir = resolveProjectDir(options.id, configObj);
25
+ if (!targetDir) {
26
+ console.error(chalk.red(`\n❌ Erro: Não foi encontrado o módulo: ${options.id}`));
27
+ listAvailableModules(configObj);
28
+ process.exit(1);
29
+ }
30
+ cwd = targetDir;
31
+ pkgPath = path.join(cwd, 'package.json');
32
+ console.log(chalk.green(`📂 Módulo detectado: ${path.relative(workspaceRoot, cwd)}`));
33
+ } else {
34
+ // Target host by default if in root
35
+ const hostDir = path.join(workspaceRoot, `${projectName}-host`);
36
+ if (fs.existsSync(hostDir)) {
37
+ cwd = hostDir;
38
+ pkgPath = path.join(cwd, 'package.json');
39
+ console.log(chalk.green(`📂 Host detectado: ${path.relative(workspaceRoot, cwd)}`));
33
40
  }
34
41
  }
35
42
 
@@ -0,0 +1,55 @@
1
+ const fs = require('fs-extra');
2
+ const path = require('path');
3
+ const chalk = require('chalk');
4
+
5
+ /**
6
+ * Resolves a project directory from a given ID, with support for prefixed names and auto-detection.
7
+ * @param {string} id The provided project ID
8
+ * @param {Object} configObj The workspace configuration object
9
+ * @returns {string|null} The absolute path to the project directory, or null if not found.
10
+ */
11
+ function resolveProjectDir(id, configObj) {
12
+ if (!configObj) return null;
13
+
14
+ const workspaceRoot = path.dirname(configObj.path);
15
+ const { projectName } = configObj.data;
16
+
17
+ // 1. Try exact match
18
+ let targetDir = path.join(workspaceRoot, id);
19
+ if (fs.existsSync(targetDir) && fs.statSync(targetDir).isDirectory()) {
20
+ return targetDir;
21
+ }
22
+
23
+ // 2. Try prefixed match (e.g., my-app-module-name)
24
+ targetDir = path.join(workspaceRoot, `${projectName}-${id}`);
25
+ if (fs.existsSync(targetDir) && fs.statSync(targetDir).isDirectory()) {
26
+ return targetDir;
27
+ }
28
+
29
+ return null;
30
+ }
31
+
32
+ /**
33
+ * Lists all available modules in the workspace, stripping the project prefix.
34
+ * @param {Object} configObj
35
+ */
36
+ function listAvailableModules(configObj) {
37
+ const workspaceRoot = path.dirname(configObj.path);
38
+ const { projectName } = configObj.data;
39
+
40
+ const entries = fs.readdirSync(workspaceRoot, { withFileTypes: true });
41
+ const modules = entries
42
+ .filter(e => e.isDirectory() && e.name.startsWith(projectName))
43
+ .map(e => {
44
+ const name = e.name.replace(`${projectName}-`, '');
45
+ return name;
46
+ });
47
+
48
+ console.log(chalk.yellow('\nMódulos disponíveis:'));
49
+ modules.forEach(m => console.log(chalk.blue(`- ${m}`)));
50
+ }
51
+
52
+ module.exports = {
53
+ resolveProjectDir,
54
+ listAvailableModules
55
+ };