libroadcast-cli 2.5.0 → 2.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/.dockerignore +5 -0
- package/README.md +11 -7
- package/dist/cmd/push.js +2 -11
- package/dist/cmd/pushFilterID.js +3 -12
- package/dist/utils/commandHandler.js +2 -1
- package/dist/utils/pushTools.js +14 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,12 +6,6 @@ npm install -g libroadcast-cli
|
|
|
6
6
|
|
|
7
7
|
## Usage
|
|
8
8
|
|
|
9
|
-
```bash
|
|
10
|
-
libroadcast login
|
|
11
|
-
|
|
12
|
-
libroadcast <command> [options]
|
|
13
|
-
```
|
|
14
|
-
|
|
15
9
|
```bash
|
|
16
10
|
Usage: <command> [options]
|
|
17
11
|
|
|
@@ -82,11 +76,12 @@ Commands:
|
|
|
82
76
|
Options:
|
|
83
77
|
--loop <intervalInSeconds> Continuously push the PGN file at the specified interval in seconds.
|
|
84
78
|
|
|
85
|
-
pushFilterID <roundId> <PGNFromPathOrUrl> <FideIds...> [--loop <intervalInSeconds>]
|
|
79
|
+
pushFilterID <roundId> <PGNFromPathOrUrl> <FideIds...> [--loop <intervalInSeconds>] [--firstOngoing]
|
|
86
80
|
Upload a PGN file from a local path or URL to the specified broadcast round, filtering games by FIDE ID.
|
|
87
81
|
Note: The PGN file must be accessible from the provided path or URL.
|
|
88
82
|
Options:
|
|
89
83
|
--loop <intervalInSeconds> Continuously push the PGN file at the specified interval in seconds.
|
|
84
|
+
--firstOngoing Push the first ongoing games in each round.
|
|
90
85
|
|
|
91
86
|
|
|
92
87
|
Examples:
|
|
@@ -117,3 +112,12 @@ Examples:
|
|
|
117
112
|
# Push a PGN file from URL filtering by FIDE IDs in loop mode every 120 seconds
|
|
118
113
|
$ pushFilterID round456 https://example.com/games.pgn 12345 67890 --loop 120
|
|
119
114
|
```
|
|
115
|
+
|
|
116
|
+
### Test Docker Build Locally
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
docker build -t broadcast-cli .
|
|
120
|
+
|
|
121
|
+
docker run --rm -it broadcast-cli bash
|
|
122
|
+
> libroadcast
|
|
123
|
+
```
|
package/dist/cmd/push.js
CHANGED
|
@@ -2,7 +2,7 @@ import { exit } from "node:process";
|
|
|
2
2
|
import { msgCommonErrorHelp, sleep, checkTokenScopes, } from "../utils/commandHandler.js";
|
|
3
3
|
import { getBroadcastRound } from "../utils/getInfoBroadcast.js";
|
|
4
4
|
import cl from "../utils/colors.js";
|
|
5
|
-
import { pushPGN, readPGNFromURL } from "../utils/pushTools.js";
|
|
5
|
+
import { pushPGN, readPGNFromURL, loopChecker } from "../utils/pushTools.js";
|
|
6
6
|
let lastPGN = "";
|
|
7
7
|
const loop = async (roundInfo, pgnPath, loopTimer) => {
|
|
8
8
|
while (true) {
|
|
@@ -26,16 +26,7 @@ export const pushCommand = async (args) => {
|
|
|
26
26
|
console.error(cl.red("Round not found."));
|
|
27
27
|
exit(1);
|
|
28
28
|
}
|
|
29
|
-
const
|
|
30
|
-
let loopTimer = undefined;
|
|
31
|
-
if (loopArgIndex !== -1 && loopArgIndex + 1 < args.length) {
|
|
32
|
-
const loopTimerStr = args[loopArgIndex + 1];
|
|
33
|
-
loopTimer = parseInt(loopTimerStr, 10);
|
|
34
|
-
if (isNaN(loopTimer) || loopTimer <= 0) {
|
|
35
|
-
console.error(cl.red("Loop timer must be a positive integer."));
|
|
36
|
-
exit(1);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
29
|
+
const loopTimer = loopChecker(args);
|
|
39
30
|
if (loopTimer) {
|
|
40
31
|
console.log(cl.green(`Starting loop to push PGN every ${cl.whiteBold(loopTimer.toString())} seconds...`));
|
|
41
32
|
console.log(cl.blue("Press Ctrl+C to stop."));
|
package/dist/cmd/pushFilterID.js
CHANGED
|
@@ -3,10 +3,10 @@ import { msgCommonErrorHelp, sleep, checkTokenScopes, } from "../utils/commandHa
|
|
|
3
3
|
import { parsePgn, makePgn } from "chessops/pgn";
|
|
4
4
|
import { getBroadcastRound } from "../utils/getInfoBroadcast.js";
|
|
5
5
|
import cl from "../utils/colors.js";
|
|
6
|
-
import { pushPGN, readPGNFromURL } from "../utils/pushTools.js";
|
|
6
|
+
import { loopChecker, pushPGN, readPGNFromURL } from "../utils/pushTools.js";
|
|
7
7
|
const filterPgnByIds = (pgn, filterIds) => {
|
|
8
8
|
const parsed = parsePgn(pgn);
|
|
9
|
-
|
|
9
|
+
let filteredGames = parsed.filter((game) => {
|
|
10
10
|
const whiteFideId = game.headers.get("WhiteFideId");
|
|
11
11
|
const blackFideId = game.headers.get("BlackFideId");
|
|
12
12
|
if (filterIds.length > 1) {
|
|
@@ -61,16 +61,7 @@ export const pushFilterIDCommand = async (args) => {
|
|
|
61
61
|
console.error(cl.red("Round not found."));
|
|
62
62
|
exit(1);
|
|
63
63
|
}
|
|
64
|
-
const
|
|
65
|
-
let loopTimer = undefined;
|
|
66
|
-
if (loopArgIndex !== -1 && loopArgIndex + 1 < args.length) {
|
|
67
|
-
const loopTimerStr = args[loopArgIndex + 1];
|
|
68
|
-
loopTimer = parseInt(loopTimerStr, 10);
|
|
69
|
-
if (isNaN(loopTimer) || loopTimer <= 0) {
|
|
70
|
-
console.error(cl.red("Loop timer must be a positive integer."));
|
|
71
|
-
exit(1);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
64
|
+
const loopTimer = loopChecker(args);
|
|
74
65
|
if (loopTimer) {
|
|
75
66
|
console.log(cl.green(`Starting loop to push PGN every ${cl.whiteBold(loopTimer.toString())} seconds...`));
|
|
76
67
|
console.log(cl.blue("Press Ctrl+C to stop."));
|
|
@@ -18,7 +18,8 @@ import { loginCommand } from "../cmd/login.js";
|
|
|
18
18
|
import { getStoredCredentials } from "./credentials.js";
|
|
19
19
|
const getToken = () => {
|
|
20
20
|
const stored = getStoredCredentials();
|
|
21
|
-
|
|
21
|
+
const envToken = process.env.LICHESS_TOKEN;
|
|
22
|
+
return envToken || stored?.lichessToken;
|
|
22
23
|
};
|
|
23
24
|
const getDomain = () => {
|
|
24
25
|
const stored = getStoredCredentials();
|
package/dist/utils/pushTools.js
CHANGED
|
@@ -2,6 +2,7 @@ import { client, packageJson } from "./commandHandler.js";
|
|
|
2
2
|
import cl from "./colors.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { readFile } from "node:fs/promises";
|
|
5
|
+
import { exit } from "node:process";
|
|
5
6
|
export const pushPGN = async (round, pgn) => {
|
|
6
7
|
try {
|
|
7
8
|
const res = await client
|
|
@@ -60,3 +61,16 @@ export const readPGNFromURL = async (pgnURL) => {
|
|
|
60
61
|
return stats.toString();
|
|
61
62
|
}
|
|
62
63
|
};
|
|
64
|
+
export const loopChecker = (args) => {
|
|
65
|
+
const loopArgIndex = args.findIndex((arg) => arg === "--loop");
|
|
66
|
+
let loopTimer = undefined;
|
|
67
|
+
if (loopArgIndex !== -1 && loopArgIndex + 1 < args.length) {
|
|
68
|
+
const loopTimerStr = args[loopArgIndex + 1];
|
|
69
|
+
loopTimer = parseInt(loopTimerStr, 10);
|
|
70
|
+
if (isNaN(loopTimer) || loopTimer <= 0) {
|
|
71
|
+
console.error(cl.red("Loop timer must be a positive integer."));
|
|
72
|
+
exit(1);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return loopTimer;
|
|
76
|
+
};
|