shoud-cli 1.0.4 → 1.0.6
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/tools/index.js +11 -11
package/package.json
CHANGED
package/src/tools/index.js
CHANGED
|
@@ -21,23 +21,22 @@ function sanitizePath(inputPath) {
|
|
|
21
21
|
return resolved;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Execute a shell command and return plain text output.
|
|
26
|
+
* On Windows, we use PowerShell with `Out-String` to get text.
|
|
27
|
+
*/
|
|
24
28
|
function executeShell(commandString) {
|
|
25
29
|
if (!commandString || commandString.trim().length === 0) {
|
|
26
30
|
throw new Error('Empty command.');
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
// ✅ On Windows, ensure PowerShell outputs text (not objects)
|
|
30
33
|
let finalCommand = commandString;
|
|
31
34
|
if (os.platform() === 'win32') {
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
} else if (commandString.trim() === 'ls') {
|
|
38
|
-
// ls is not a native PowerShell command – use Get-ChildItem
|
|
39
|
-
finalCommand = 'Get-ChildItem | Out-String -Width 4096';
|
|
40
|
-
}
|
|
35
|
+
// ✅ Force PowerShell to output plain text
|
|
36
|
+
// Escape double quotes in the command
|
|
37
|
+
const escaped = commandString.replace(/"/g, '`"');
|
|
38
|
+
// Wrap in a PowerShell script block and pipe to Out-String
|
|
39
|
+
finalCommand = `& { ${escaped} } | Out-String -Width 4096`;
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
try {
|
|
@@ -52,11 +51,12 @@ function executeShell(commandString) {
|
|
|
52
51
|
const trimmed = output.trim();
|
|
53
52
|
return trimmed || 'Command executed successfully with no output.';
|
|
54
53
|
} catch (err) {
|
|
54
|
+
// If the command fails, return the error message
|
|
55
55
|
if (err.stderr) {
|
|
56
56
|
return `Error: ${err.stderr.trim()}`;
|
|
57
57
|
}
|
|
58
|
-
// If the command fails but there's output, return it
|
|
59
58
|
if (err.stdout) {
|
|
59
|
+
// Some commands output to stdout even on failure (e.g., `dir`)
|
|
60
60
|
return err.stdout.trim();
|
|
61
61
|
}
|
|
62
62
|
throw new Error(`Command execution failed: ${err.message}`);
|