xp-command 1.6.1 → 1.7.0
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/LICENSE +1 -1
- package/README.md +2 -0
- package/bin/index.js +12 -1
- package/package.json +1 -1
- package/src/api.js +13 -10
- package/src/error.js +7 -0
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -241,6 +241,8 @@ Here is an example demonstrating the usage of the duration option: In the Dash 8
|
|
|
241
241
|
|
|
242
242
|
**Finding commands**: Use the [DataRefTool plugin](https://datareftool.com) to browse available commands.
|
|
243
243
|
|
|
244
|
+
**The special `sleep` command**: You can delay a command (and all subsequent commands) using the special `sleep` command with a dealy value in seconds (i.e. `- sleep[1]`).
|
|
245
|
+
|
|
244
246
|
## 🔄 Resetting aircraft profiles
|
|
245
247
|
|
|
246
248
|
If you've edited an aircraft configuration and xp-command crashes or stops working, you can reset to default settings by deleting the config files.
|
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/api.js
CHANGED
|
@@ -124,6 +124,13 @@ export const activateCommand = async (
|
|
|
124
124
|
value,
|
|
125
125
|
);
|
|
126
126
|
|
|
127
|
+
if (commandName === "sleep") {
|
|
128
|
+
if (duration) {
|
|
129
|
+
await new Promise((resolve) => setTimeout(resolve, duration * 1000));
|
|
130
|
+
}
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
127
134
|
const commandId = await getCommandId(commandName);
|
|
128
135
|
|
|
129
136
|
const url = new URL(
|
|
@@ -246,11 +253,9 @@ export const setDatarefValues = async (
|
|
|
246
253
|
value,
|
|
247
254
|
) => {
|
|
248
255
|
if (Array.isArray(datarefNamesWithOptionalIndex)) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
),
|
|
253
|
-
);
|
|
256
|
+
for (const dataref of datarefNamesWithOptionalIndex) {
|
|
257
|
+
await setDatarefValue(dataref, value);
|
|
258
|
+
}
|
|
254
259
|
} else {
|
|
255
260
|
await setDatarefValue(datarefNamesWithOptionalIndex, value);
|
|
256
261
|
}
|
|
@@ -266,11 +271,9 @@ export const activateCommands = async (
|
|
|
266
271
|
value,
|
|
267
272
|
) => {
|
|
268
273
|
if (Array.isArray(commandNamesWithOptionalDuration)) {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
),
|
|
273
|
-
);
|
|
274
|
+
for (const command of commandNamesWithOptionalDuration) {
|
|
275
|
+
await activateCommand(command, value);
|
|
276
|
+
}
|
|
274
277
|
} else {
|
|
275
278
|
await activateCommand(commandNamesWithOptionalDuration, value);
|
|
276
279
|
}
|
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
|
*/
|