libroadcast-cli 1.7.0 → 1.8.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.
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.startsPreviousCommand = void 0;
7
+ const node_process_1 = require("node:process");
8
+ const commandHandler_1 = require("../utils/commandHandler");
9
+ const getInfoBroadcast_1 = require("../utils/getInfoBroadcast");
10
+ const colors_1 = __importDefault(require("../utils/colors"));
11
+ const setStartsPrevious = async (rounds, startsPrevious) => {
12
+ for (const round of rounds) {
13
+ await (0, commandHandler_1.handleApiResponse)(commandHandler_1.client.POST("/broadcast/round/{broadcastRoundId}/edit", {
14
+ params: {
15
+ path: { broadcastRoundId: round.id },
16
+ query: { patch: 1 },
17
+ },
18
+ body: {
19
+ startsAfterPrevious: startsPrevious,
20
+ },
21
+ }), `Successfully set startsAfterPrevious for round ${colors_1.default.whiteBold(round.id)} to ${colors_1.default.whiteBold(startsPrevious.toString())}.`, `Error setting startsAfterPrevious for round ${colors_1.default.whiteBold(round.id)}`);
22
+ await (0, commandHandler_1.sleep)(200);
23
+ }
24
+ };
25
+ const startsPreviousCommand = async (args) => {
26
+ const [broadcastId, startsPrevious] = args.slice(0, 2);
27
+ if (!broadcastId || !startsPrevious) {
28
+ (0, commandHandler_1.msgCommonErrorHelp)("Broadcast ID and startsPrevious are required.");
29
+ (0, node_process_1.exit)(1);
30
+ }
31
+ const startsPreviousBool = startsPrevious.toLowerCase() === "true" ||
32
+ startsPrevious === "1" ||
33
+ startsPrevious.toLowerCase() === "yes";
34
+ const broadcast = await (0, getInfoBroadcast_1.getBroadcast)(broadcastId);
35
+ if (!broadcast?.rounds || broadcast.rounds.length === 0) {
36
+ console.error(colors_1.default.red("No rounds found for the specified broadcast."));
37
+ (0, node_process_1.exit)(1);
38
+ }
39
+ await setStartsPrevious(broadcast.rounds, startsPreviousBool);
40
+ };
41
+ exports.startsPreviousCommand = startsPreviousCommand;
@@ -6,11 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.handleApiResponse = exports.msgCommonErrorHelp = exports.sleep = exports.client = exports.commands = exports.Command = exports.args = exports.LICHESS_TOKEN = void 0;
7
7
  const node_process_1 = require("node:process");
8
8
  const openapi_fetch_1 = __importDefault(require("openapi-fetch"));
9
+ const colors_1 = __importDefault(require("./colors"));
9
10
  const delay_1 = require("../cmd/delay");
10
11
  const setPGN_1 = require("../cmd/setPGN");
11
12
  const setLichessGames_1 = require("../cmd/setLichessGames");
12
13
  const fixSchedule_1 = require("../cmd/fixSchedule");
13
- const colors_1 = __importDefault(require("./colors"));
14
+ const startsPrevious_1 = require("../cmd/startsPrevious");
14
15
  exports.LICHESS_TOKEN = node_process_1.env.LICHESS_TOKEN;
15
16
  const LICHESS_DOMAIN = (node_process_1.env.LICHESS_DOMAIN || "https://lichess.org").replace(/\/$/, "") + "/";
16
17
  exports.args = node_process_1.argv.slice(2);
@@ -20,12 +21,14 @@ var Command;
20
21
  Command["SetPGN"] = "setPGN";
21
22
  Command["SetLichessGames"] = "setLichessGames";
22
23
  Command["FixSchedule"] = "fixSchedule";
24
+ Command["StartsPrevious"] = "startsPrevious";
23
25
  })(Command || (exports.Command = Command = {}));
24
26
  exports.commands = new Map([
25
27
  [Command.Delay, delay_1.delayCommand],
26
28
  [Command.SetPGN, setPGN_1.setPGNCommand],
27
29
  [Command.SetLichessGames, setLichessGames_1.setLichessGamesCommand],
28
30
  [Command.FixSchedule, fixSchedule_1.fixScheduleCommand],
31
+ [Command.StartsPrevious, startsPrevious_1.startsPreviousCommand],
29
32
  ]);
30
33
  exports.client = (0, openapi_fetch_1.default)({
31
34
  baseUrl: LICHESS_DOMAIN,
@@ -35,6 +35,10 @@ const helpFixSchedule = [
35
35
  ` ${colors_1.default.bold("Options:")}`,
36
36
  ` --rounds <roundsToFix> ${colors_1.default.gray("Specify which rounds to fix using formats like '1-4', '8+', '3,5,7', etc.")}`,
37
37
  ].join("\n");
38
+ const helpStartsPrevious = [
39
+ ` ${colors_1.default.underItalic("startsPrevious <broadcastId> <startsPrevious>")}`,
40
+ ` ${colors_1.default.gray("Sets the startsAfterPrevious flag for all rounds in the specified broadcast.")}`,
41
+ ].join("\n");
38
42
  const msg = [
39
43
  `${colors_1.default.boldYellow("Usage:")} ${colors_1.default.underItalic("<command> [options]")}`,
40
44
  ``,
@@ -48,6 +52,8 @@ const msg = [
48
52
  ``,
49
53
  helpFixSchedule,
50
54
  ``,
55
+ helpStartsPrevious,
56
+ ``,
51
57
  ``,
52
58
  `${colors_1.default.boldYellow("Examples:")}`,
53
59
  ` ${colors_1.default.gray("# Set a 5-minute delay without changing start time")}`,
@@ -58,6 +64,8 @@ const msg = [
58
64
  ` $ ${colors_1.default.underItalic("setLichessGames")} ${colors_1.default.italic("round456 gameId1 gameId2 gameId3")}`,
59
65
  ` ${colors_1.default.gray("# Fix schedule of rounds 1 to 4 and all rounds after 8 by adding 15 minutes")}`,
60
66
  ` $ ${colors_1.default.underItalic("fixSchedule")} ${colors_1.default.italic("bcast123 15m --rounds 1-4,8+")}`,
67
+ ` ${colors_1.default.gray("# Set startsAfterPrevious to true for all rounds in a broadcast")}`,
68
+ ` $ ${colors_1.default.underItalic("startsPrevious")} ${colors_1.default.italic("bcast123 true")}`,
61
69
  ];
62
70
  const showHelp = (cmd) => {
63
71
  const ranges = {
@@ -65,6 +73,7 @@ const showHelp = (cmd) => {
65
73
  [commandHandler_1.Command.SetPGN]: helpSetPGN,
66
74
  [commandHandler_1.Command.SetLichessGames]: helpSetLichessGames,
67
75
  [commandHandler_1.Command.FixSchedule]: helpFixSchedule,
76
+ [commandHandler_1.Command.StartsPrevious]: helpStartsPrevious,
68
77
  };
69
78
  const range = cmd ? ranges[cmd] : undefined;
70
79
  console.info(range ? range : msg.join("\n"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libroadcast-cli",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "CLI to help with broadcast maintenance on Lichess",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [