@codemoreira/esad 2.0.1-1 ā 2.0.1-3
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 +1 -1
- package/src/cli/commands/init.js +15 -5
- package/src/cli/utils/process.js +20 -17
- package/src/cli/utils/transformer.js +9 -10
package/package.json
CHANGED
package/src/cli/commands/init.js
CHANGED
|
@@ -63,13 +63,23 @@ export default {
|
|
|
63
63
|
await renameProject(hostDir, hostName);
|
|
64
64
|
|
|
65
65
|
// Inject local context mock immediately to avoid crashes on fresh boot
|
|
66
|
-
|
|
66
|
+
const context = { projectName, devMode: {} };
|
|
67
|
+
fs.writeJsonSync(path.join(hostDir, '.esad.context.json'), context, { spaces: 2 });
|
|
67
68
|
|
|
68
|
-
|
|
69
|
+
// Stabilize filesystem before heavy operations
|
|
70
|
+
await new Promise(res => setTimeout(res, 500));
|
|
71
|
+
|
|
72
|
+
console.log(`\nš¦ Installing dependencies into host (this may take a minute)...`);
|
|
69
73
|
await runProcess('npm', ['install'], { cwd: hostDir });
|
|
70
|
-
|
|
71
|
-
console.log(
|
|
74
|
+
|
|
75
|
+
console.log(chalk.green(`\nš ESAD Workspace Initialized successfully!`));
|
|
76
|
+
console.log(chalk.cyan(`\nš Next steps:`));
|
|
77
|
+
console.log(` 1. cd ${projectName}/${hostName}`);
|
|
78
|
+
console.log(` 2. esad host dev (to start Host)`);
|
|
79
|
+
console.log(` 3. esad dev (in a module folder to federate)\n`);
|
|
72
80
|
} catch (err) {
|
|
73
|
-
console.error(
|
|
81
|
+
console.error(chalk.red(`\nā Failed to initialize workspace:`));
|
|
82
|
+
console.error(chalk.yellow(` ${err.message}`));
|
|
83
|
+
console.log(chalk.dim(`\n Check npm logs if it was an installation error.`));
|
|
74
84
|
}
|
|
75
85
|
};
|
package/src/cli/utils/process.js
CHANGED
|
@@ -3,7 +3,9 @@ const nativeSpawn = require('child_process').spawn;
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const fs = require('fs-extra');
|
|
5
5
|
|
|
6
|
-
const runProcess = (cmd, args,
|
|
6
|
+
const runProcess = (cmd, args, options = process.cwd()) => {
|
|
7
|
+
const cwd = typeof options === 'string' ? options : (options.cwd || process.cwd());
|
|
8
|
+
let childRef;
|
|
7
9
|
const promise = new Promise((resolve, reject) => {
|
|
8
10
|
let finished = false;
|
|
9
11
|
let started = false;
|
|
@@ -15,47 +17,45 @@ const runProcess = (cmd, args, cwd = process.cwd()) => {
|
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
const isWin = process.platform === 'win32';
|
|
18
|
-
const
|
|
20
|
+
const localBin = isWin ? `${cmd}.cmd` : cmd;
|
|
21
|
+
const localBinPath = path.join(cwd, 'node_modules', '.bin', localBin);
|
|
19
22
|
|
|
20
23
|
let command = cmd;
|
|
21
24
|
let finalArgs = args;
|
|
22
25
|
let useNativeSpawn = false;
|
|
23
26
|
|
|
24
27
|
if (fs.existsSync(localBinPath)) {
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
// 1. Priority: Local node_modules/.bin (fastest & consistent)
|
|
29
|
+
command = isWin ? `node_modules\\.bin\\${localBin}` : `./node_modules/.bin/${localBin}`;
|
|
30
|
+
useNativeSpawn = isWin;
|
|
27
31
|
} else {
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
// 2. Fallback: System Path (git, npm, npx, etc)
|
|
33
|
+
// cross-spawn handles .cmd/.exe resolution automatically
|
|
34
|
+
command = cmd;
|
|
35
|
+
finalArgs = args;
|
|
36
|
+
useNativeSpawn = false;
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
console.log(`[ESAD] Resolved Command: ${command} (CWD: ${cwd})`);
|
|
33
40
|
|
|
34
|
-
// Mark as started after a short delay
|
|
35
41
|
setTimeout(() => { started = true; }, 2000);
|
|
36
42
|
|
|
37
43
|
const spawnFn = useNativeSpawn ? nativeSpawn : spawn;
|
|
38
|
-
|
|
44
|
+
childRef = spawnFn(command, finalArgs, {
|
|
39
45
|
stdio: 'inherit',
|
|
40
46
|
cwd,
|
|
41
47
|
shell: true
|
|
42
48
|
});
|
|
43
49
|
|
|
44
|
-
|
|
45
|
-
promise.child = child;
|
|
46
|
-
promise.kill = (signal) => child.kill(signal);
|
|
47
|
-
|
|
48
|
-
child.on('error', err => {
|
|
50
|
+
childRef.on('error', err => {
|
|
49
51
|
if (started && err.code === 'ENOENT') {
|
|
50
52
|
console.warn(`[ESAD] Warning: Late ENOENT ignored for ${cmd}.`);
|
|
51
53
|
return;
|
|
52
54
|
}
|
|
53
|
-
|
|
54
|
-
console.error(`[ESAD] Process Error: ${err.code} - ${err.message}`);
|
|
55
|
-
finalize(reject, new Error(`Failed to start ${cmd}: ${err.message}`));
|
|
55
|
+
finalize(reject, err);
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
childRef.on('close', code => {
|
|
59
59
|
if (code !== 0) {
|
|
60
60
|
finalize(reject, new Error(`Process ${cmd} exited with code ${code}`));
|
|
61
61
|
} else {
|
|
@@ -64,6 +64,9 @@ const runProcess = (cmd, args, cwd = process.cwd()) => {
|
|
|
64
64
|
});
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
+
promise.child = childRef;
|
|
68
|
+
promise.kill = (signal) => childRef && childRef.kill(signal);
|
|
69
|
+
|
|
67
70
|
return promise;
|
|
68
71
|
};
|
|
69
72
|
|
|
@@ -10,20 +10,19 @@ const updateDevMode = (configPath, moduleId, url) => {
|
|
|
10
10
|
|
|
11
11
|
// 1. Ensure devMode object exists
|
|
12
12
|
if (!content.includes('devMode:')) {
|
|
13
|
-
// Inject devMode
|
|
14
|
-
content = content.replace(/
|
|
13
|
+
// Inject devMode after the opening brace of export default
|
|
14
|
+
content = content.replace(/(export default\s*\{)/, `$1\n devMode: {},\n`);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
// 2. Add or update the module entry
|
|
18
18
|
const entryRegex = new RegExp(`(['"]${moduleId}['"]|${moduleId}):\\s*['"]([^'"]*)['"]`, 'g');
|
|
19
19
|
|
|
20
20
|
if (entryRegex.test(content)) {
|
|
21
|
-
// Update existing
|
|
22
|
-
content = content.replace(entryRegex,
|
|
21
|
+
// Update existing entry
|
|
22
|
+
content = content.replace(entryRegex, `'${moduleId}': '${url}'`);
|
|
23
23
|
} else {
|
|
24
|
-
// Insert new entry
|
|
25
|
-
|
|
26
|
-
content = content.replace(devModeRegex, `$1\n '${moduleId}': '${url}',`);
|
|
24
|
+
// Insert new entry right after devMode: {
|
|
25
|
+
content = content.replace(/(devMode:\s*\{)/, `$1\n '${moduleId}': '${url}',`);
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
fs.writeFileSync(configPath, content);
|
|
@@ -44,9 +43,9 @@ const clearAllDevMode = (configPath) => {
|
|
|
44
43
|
if (!fs.existsSync(configPath)) return;
|
|
45
44
|
let content = fs.readFileSync(configPath, 'utf8');
|
|
46
45
|
|
|
47
|
-
//
|
|
48
|
-
const devModeBlockRegex =
|
|
49
|
-
content = content.replace(devModeBlockRegex, '');
|
|
46
|
+
// Simply reset devMode to empty object
|
|
47
|
+
const devModeBlockRegex = /devMode:\s*{[\s\S]*?}/;
|
|
48
|
+
content = content.replace(devModeBlockRegex, 'devMode: {}');
|
|
50
49
|
|
|
51
50
|
fs.writeFileSync(configPath, content);
|
|
52
51
|
};
|