xp-command 1.6.0 → 1.6.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/bin/index.js +12 -1
- package/package.json +1 -1
- package/src/clipboard.js +16 -9
- package/src/error.js +7 -0
package/bin/index.js
CHANGED
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
import { copyToClipboard } from "../src/clipboard.js";
|
|
25
25
|
import { editConfig, getConfig } from "../src/config.js";
|
|
26
26
|
import { clearLine, hideCursor, showCursor } from "../src/console.js";
|
|
27
|
-
import { isAPIError, isEconnRefused } from "../src/error.js";
|
|
27
|
+
import { isAPIError, isConfigError, isEconnRefused } from "../src/error.js";
|
|
28
28
|
import history from "../src/history.js";
|
|
29
29
|
import { Logger } from "../src/logger.js";
|
|
30
30
|
import { sleep } from "../src/sleep.js";
|
|
@@ -64,6 +64,17 @@ const processCommand = async (command) => {
|
|
|
64
64
|
showCursor();
|
|
65
65
|
return false;
|
|
66
66
|
}
|
|
67
|
+
if (isConfigError(error)) {
|
|
68
|
+
spinner.fail(
|
|
69
|
+
chalk.red(
|
|
70
|
+
`${PREFIX} Config error${typeof error.reason === "string" ? " - " + error.reason : ""}`,
|
|
71
|
+
),
|
|
72
|
+
);
|
|
73
|
+
hideCursor();
|
|
74
|
+
await sleep(1500);
|
|
75
|
+
showCursor();
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
67
78
|
}
|
|
68
79
|
|
|
69
80
|
if (command?.toLowerCase() === "config") {
|
package/package.json
CHANGED
package/src/clipboard.js
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { spawn } from "child_process";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @param {string|number} text
|
|
5
5
|
*/
|
|
6
6
|
export const copyToClipboard = async (text) => {
|
|
7
|
-
const
|
|
7
|
+
const cmd =
|
|
8
8
|
process.platform === "win32"
|
|
9
|
-
?
|
|
9
|
+
? { cmd: "clip", args: [] }
|
|
10
10
|
: process.platform === "darwin"
|
|
11
|
-
?
|
|
12
|
-
:
|
|
11
|
+
? { cmd: "pbcopy", args: [] }
|
|
12
|
+
: { cmd: "xclip", args: ["-selection", "clipboard"] };
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const proc = spawn(cmd.cmd, cmd.args);
|
|
16
|
+
proc.stdin.write(
|
|
17
|
+
String(text)
|
|
18
|
+
.split("\n")
|
|
19
|
+
.filter((line) => !!line.trim())
|
|
20
|
+
.join("\n"),
|
|
21
|
+
);
|
|
22
|
+
proc.stdin.end();
|
|
23
|
+
proc.on("close", resolve);
|
|
24
|
+
proc.on("error", reject);
|
|
18
25
|
});
|
|
19
26
|
};
|
package/src/error.js
CHANGED
|
@@ -11,6 +11,13 @@ export const isEconnRefused = (error) => {
|
|
|
11
11
|
);
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* @param {unknown} error
|
|
16
|
+
*/
|
|
17
|
+
export const isConfigError = (error) => {
|
|
18
|
+
return Boolean(error instanceof Error && error.name === "YAMLException");
|
|
19
|
+
};
|
|
20
|
+
|
|
14
21
|
/**
|
|
15
22
|
* @param {unknown} error
|
|
16
23
|
*/
|