libroadcast-cli 1.4.0 → 1.5.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/README.md CHANGED
@@ -16,26 +16,33 @@ libroadcast
16
16
  ```bash
17
17
  Usage: <command> [options]
18
18
 
19
+
19
20
  Commands:
20
21
  delay <broadcastId> <delayInSeconds> [--onlyDelay] [--noDelay]
21
22
  Sets the delay for all rounds in the specified broadcast.
22
- The delay is specified in seconds. (max 3600 seconds = 1 hour)
23
+ Note: The delay is specified in seconds. (max 3600 seconds = 1 hour)
23
24
  Options:
24
25
  --onlyDelay Set only the delay without changing the start time.
25
26
  --noDelay Remove the delay from the rounds.
27
+
26
28
  setPGN <broadcastId> <sourcePGNUrl> [--withFilter] [--slice <sliceFilter>]
27
29
  Sets the source PGN URL for all rounds in the specified broadcast.
28
- (optional) Use '{}' in the URL as a placeholder for the round number.
29
- Note: For livechesscloud URLs, please ensure it ends with "/{}".
30
+ (optional) Use "{}" in the URL as a placeholder for the round number.
31
+ Note: For livechesscloud URLs, please ensure it ends with "/{}".
30
32
  Options:
31
- --withFilter Apply round number filtering based on round number.
32
- --slice <sliceFilter> Apply slice filtering using the provided filter string.
33
+ --withFilter Apply round number filtering based on round number.
34
+ --slice <sliceFilter> Apply slice filtering using the provided filter string.
35
+
33
36
  setLichessGames <broadcastRoundId> <gameIds...>
34
37
  Sets the games for the specified broadcast round using Lichess game IDs.
35
38
  Note: Maximum of 64 game IDs can be provided.
36
39
 
40
+
37
41
  Examples:
38
- delay bcast123 300 --onlyDelay # Set a 5-minute delay without changing start time
39
- setPGN bcast123 https://example.com/pgns/round-{}/game.pgn --withFilter --slice "1-5,7,9-12"
40
- setLichessGames round456 gameId1 gameId2 gameId3 # Set specific games for the round
42
+ # Set a 5-minute delay without changing start time
43
+ $ delay bcast123 300 --onlyDelay
44
+ # Set source PGN URL with round and slice filters
45
+ $ setPGN bcast123 https://example.com/pgns/round-{}/game.pgn --withFilter --slice "1-5,7,9-12"
46
+ # Set Lichess games for a broadcast round
47
+ $ setLichessGames round456 gameId1 gameId2 gameId3
41
48
  ```
package/dist/cmd/delay.js CHANGED
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.delayCommand = void 0;
4
7
  const node_process_1 = require("node:process");
5
8
  const commandHandler_1 = require("../utils/commandHandler");
6
9
  const getInfoBroadcast_1 = require("../utils/getInfoBroadcast");
10
+ const colors_1 = __importDefault(require("../utils/colors"));
7
11
  const setDelayRounds = async (rounds, delay, onlyDelay, noDelay) => {
8
12
  for (const round of rounds) {
9
13
  await commandHandler_1.client
@@ -21,12 +25,12 @@ const setDelayRounds = async (rounds, delay, onlyDelay, noDelay) => {
21
25
  })
22
26
  .then((response) => {
23
27
  if (response.response.ok)
24
- console.log(`Successfully set delay for round ${round.id} to ${delay} seconds.`);
28
+ console.log(colors_1.default.green(`Successfully set delay for round ${colors_1.default.whiteBold(round.id)} to ${colors_1.default.whiteBold(delay.toString())} seconds.`));
25
29
  else
26
- console.error(`Failed to set delay for round ${round.id}: ${response.response.statusText}`);
30
+ console.error(colors_1.default.red(`Failed to set delay for round ${colors_1.default.whiteBold(round.id)}: ${colors_1.default.whiteBold(response.response.statusText)}`));
27
31
  })
28
32
  .catch((error) => {
29
- console.error(`Error setting delay for round ${round.id}:`, error);
33
+ console.error(colors_1.default.red(`Error setting delay for round ${colors_1.default.whiteBold(round.id)}:`), error);
30
34
  });
31
35
  await (0, commandHandler_1.sleep)(200);
32
36
  }
@@ -45,12 +49,12 @@ const delayCommand = async (args) => {
45
49
  const onlyDelay = args.includes("--onlyDelay");
46
50
  const noDelay = args.includes("--noDelay");
47
51
  if (onlyDelay && noDelay) {
48
- console.error("Cannot use --onlyDelay and --noDelay together.");
52
+ console.error(colors_1.default.red("Cannot use --onlyDelay and --noDelay together."));
49
53
  (0, node_process_1.exit)(1);
50
54
  }
51
55
  const broadcast = await (0, getInfoBroadcast_1.getBroadcast)(broadcastId);
52
56
  if (!broadcast?.rounds || broadcast.rounds.length === 0) {
53
- console.error("No rounds found for the specified broadcast.");
57
+ console.error(colors_1.default.red("No rounds found for the specified broadcast."));
54
58
  (0, node_process_1.exit)(1);
55
59
  }
56
60
  setDelayRounds(broadcast.rounds, parseInt(delay, 10), onlyDelay, noDelay);
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.setLichessGamesCommand = void 0;
4
7
  const node_process_1 = require("node:process");
5
8
  const commandHandler_1 = require("../utils/commandHandler");
6
9
  const getInfoBroadcast_1 = require("../utils/getInfoBroadcast");
10
+ const colors_1 = __importDefault(require("../utils/colors"));
7
11
  const setLichessGames = (round, games) => commandHandler_1.client
8
12
  .POST("/broadcast/round/{broadcastRoundId}/edit", {
9
13
  params: {
@@ -17,12 +21,12 @@ const setLichessGames = (round, games) => commandHandler_1.client
17
21
  })
18
22
  .then((response) => {
19
23
  if (response.response.ok)
20
- console.log(`Successfully set games for round ${round.id} to ${games}.`);
24
+ console.log(colors_1.default.green(`Successfully set games for round ${colors_1.default.whiteBold(round.id)} to ${colors_1.default.whiteBold(games)}.`));
21
25
  else
22
- console.error(`Failed to set games for round ${round.id}: ${response.response.statusText}`);
26
+ console.error(colors_1.default.red(`Failed to set games for round ${colors_1.default.whiteBold(round.id)}: ${colors_1.default.whiteBold(response.response.statusText)}`));
23
27
  })
24
28
  .catch((error) => {
25
- console.error(`Error setting games for round ${round.id}:`, error);
29
+ console.error(colors_1.default.red(`Error setting games for round ${colors_1.default.whiteBold(round.id)}:`), error);
26
30
  });
27
31
  const setLichessGamesCommand = async (args) => {
28
32
  const bId = args.shift();
@@ -33,7 +37,7 @@ const setLichessGamesCommand = async (args) => {
33
37
  }
34
38
  const round = await (0, getInfoBroadcast_1.getBroadcastRound)(bId);
35
39
  if (!round) {
36
- console.error(`Broadcast round with ID ${bId} not found or has no rounds.`);
40
+ console.error(colors_1.default.red(`Broadcast round with ID ${colors_1.default.whiteBold(bId)} not found or has no rounds.`));
37
41
  (0, node_process_1.exit)(1);
38
42
  }
39
43
  setLichessGames(round, games);
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.setPGNCommand = void 0;
4
7
  const node_process_1 = require("node:process");
5
8
  const commandHandler_1 = require("../utils/commandHandler");
6
9
  const getInfoBroadcast_1 = require("../utils/getInfoBroadcast");
10
+ const colors_1 = __importDefault(require("../utils/colors"));
7
11
  const setPGN = async (rounds, urlRound, setRoundFilter, setSliceFilter = null) => {
8
12
  for (let rN = 1; rN <= rounds.length; rN++) {
9
13
  const round = rounds[rN - 1];
@@ -23,12 +27,12 @@ const setPGN = async (rounds, urlRound, setRoundFilter, setSliceFilter = null) =
23
27
  })
24
28
  .then((response) => {
25
29
  if (response.response.ok)
26
- console.log(`Successfully set source for round ${round.id} to ${url}.`);
30
+ console.log(colors_1.default.green(`Successfully set source for round ${colors_1.default.whiteBold(round.id)} to ${colors_1.default.whiteBold(url)}.`));
27
31
  else
28
- console.error(`Failed to set source for round ${round.id}: ${response.response.statusText}`);
32
+ console.error(colors_1.default.red(`Failed to set source for round ${colors_1.default.whiteBold(round.id)}: ${colors_1.default.whiteBold(response.response.statusText)}`));
29
33
  })
30
34
  .catch((error) => {
31
- console.error(`Error setting source for round ${round.id}:`, error);
35
+ console.error(colors_1.default.red(`Error setting source for round ${colors_1.default.whiteBold(round.id)}:`), error);
32
36
  });
33
37
  await (0, commandHandler_1.sleep)(200);
34
38
  }
@@ -55,9 +59,9 @@ const setPGNCommand = async (args) => {
55
59
  throw new Error();
56
60
  }
57
61
  catch {
58
- console.error(isLCC
62
+ console.error(colors_1.default.red(isLCC
59
63
  ? 'Invalid URL. For livechesscloud URLs, please ensure it ends with "/{}".'
60
- : 'Invalid URL. Must be http/https with "{}" as round placeholder.');
64
+ : 'Invalid URL. Must be http/https with "{}" as round placeholder.'));
61
65
  (0, node_process_1.exit)(1);
62
66
  }
63
67
  const setRoundFilter = args.includes("--withFilter");
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const node_util_1 = require("node:util");
4
+ exports.default = {
5
+ red: (text) => (0, node_util_1.styleText)("red", text),
6
+ blue: (text) => (0, node_util_1.styleText)("blue", text),
7
+ boldYellow: (text) => (0, node_util_1.styleText)(["bold", "yellow"], text),
8
+ underItalic: (text) => (0, node_util_1.styleText)(["underline", "italic"], text),
9
+ bold: (text) => (0, node_util_1.styleText)("bold", text),
10
+ italic: (text) => (0, node_util_1.styleText)("italic", text),
11
+ gray: (text) => (0, node_util_1.styleText)("gray", text),
12
+ green: (text) => (0, node_util_1.styleText)("green", text),
13
+ whiteBold: (text) => (0, node_util_1.styleText)(["white", "bold"], text),
14
+ };
@@ -9,6 +9,7 @@ const openapi_fetch_1 = __importDefault(require("openapi-fetch"));
9
9
  const delay_1 = require("../cmd/delay");
10
10
  const setPGN_1 = require("../cmd/setPGN");
11
11
  const setLichessGames_1 = require("../cmd/setLichessGames");
12
+ const colors_1 = __importDefault(require("./colors"));
12
13
  exports.LICHESS_TOKEN = node_process_1.env.LICHESS_TOKEN;
13
14
  const LICHESS_DOMAIN = node_process_1.env.LICHESS_DOMAIN || "https://lichess.org/";
14
15
  exports.args = node_process_1.argv.slice(2);
@@ -35,7 +36,7 @@ exports.client = (0, openapi_fetch_1.default)({
35
36
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
36
37
  exports.sleep = sleep;
37
38
  const msgCommonErrorHelp = (msg) => {
38
- console.error(msg);
39
- console.info("Use --help to see usage.");
39
+ console.error(colors_1.default.red(msg));
40
+ console.info(colors_1.default.blue("Use --help to see usage."));
40
41
  };
41
42
  exports.msgCommonErrorHelp = msgCommonErrorHelp;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.getBroadcastRound = exports.getBroadcast = void 0;
4
7
  const commandHandler_1 = require("./commandHandler");
8
+ const colors_1 = __importDefault(require("./colors"));
5
9
  const getBroadcast = (broadcastId) => commandHandler_1.client
6
10
  .GET("/api/broadcast/{broadcastTournamentId}", {
7
11
  params: {
@@ -10,7 +14,7 @@ const getBroadcast = (broadcastId) => commandHandler_1.client
10
14
  })
11
15
  .then((response) => response.data)
12
16
  .catch((error) => {
13
- console.error("Error fetching broadcast:", error);
17
+ console.error(colors_1.default.red("Error fetching broadcast:"), error);
14
18
  return null;
15
19
  });
16
20
  exports.getBroadcast = getBroadcast;
@@ -26,7 +30,7 @@ const getBroadcastRound = (roundId) => commandHandler_1.client
26
30
  })
27
31
  .then((response) => response.data?.round)
28
32
  .catch((error) => {
29
- console.error("Error fetching broadcast round:", error);
33
+ console.error(colors_1.default.red("Error fetching broadcast round:"), error);
30
34
  return null;
31
35
  });
32
36
  exports.getBroadcastRound = getBroadcastRound;
@@ -1,39 +1,50 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.includeHelp = exports.showHelp = void 0;
4
7
  const commandHandler_1 = require("./commandHandler");
8
+ const colors_1 = __importDefault(require("./colors"));
5
9
  const msg = [
6
- "Usage: <command> [options]",
7
- "",
8
- "Commands:",
9
- " delay <broadcastId> <delayInSeconds> [--onlyDelay] [--noDelay]",
10
- " Sets the delay for all rounds in the specified broadcast.",
11
- " The delay is specified in seconds. (max 3600 seconds = 1 hour)",
12
- " Options:",
13
- " --onlyDelay Set only the delay without changing the start time.",
14
- " --noDelay Remove the delay from the rounds.",
15
- " setPGN <broadcastId> <sourcePGNUrl> [--withFilter] [--slice <sliceFilter>]",
16
- " Sets the source PGN URL for all rounds in the specified broadcast.",
17
- " (optional) Use '{}' in the URL as a placeholder for the round number.",
18
- ' Note: For livechesscloud URLs, please ensure it ends with "/{}".',
19
- " Options:",
20
- " --withFilter Apply round number filtering based on round number.",
21
- " --slice <sliceFilter> Apply slice filtering using the provided filter string.",
22
- " setLichessGames <broadcastRoundId> <gameIds...>",
23
- " Sets the games for the specified broadcast round using Lichess game IDs.",
24
- " Note: Maximum of 64 game IDs can be provided.",
25
- "",
26
- "Examples:",
27
- " delay bcast123 300 --onlyDelay # Set a 5-minute delay without changing start time",
28
- ' setPGN bcast123 https://example.com/pgns/round-{}/game.pgn --withFilter --slice "1-5,7,9-12"',
29
- " setLichessGames round456 gameId1 gameId2 gameId3 # Set specific games for the round",
10
+ `${colors_1.default.boldYellow("Usage:")} ${colors_1.default.underItalic("<command> [options]")}`,
11
+ ``,
12
+ ``,
13
+ `${colors_1.default.boldYellow("Commands:")}`,
14
+ ` ${colors_1.default.underItalic("delay <broadcastId> <delayInSeconds> [--onlyDelay] [--noDelay]")}`,
15
+ ` ${colors_1.default.gray("Sets the delay for all rounds in the specified broadcast.")}`,
16
+ ` ${colors_1.default.bold("Note:")} ${colors_1.default.gray("The delay is specified in seconds. (max 3600 seconds = 1 hour)")}`,
17
+ ` ${colors_1.default.bold("Options:")}`,
18
+ ` --onlyDelay ${colors_1.default.gray("Set only the delay without changing the start time.")}`,
19
+ ` --noDelay ${colors_1.default.gray("Remove the delay from the rounds.")}`,
20
+ ``,
21
+ ` ${colors_1.default.underItalic("setPGN <broadcastId> <sourcePGNUrl> [--withFilter] [--slice <sliceFilter>]")}`,
22
+ ` ${colors_1.default.gray("Sets the source PGN URL for all rounds in the specified broadcast.")}`,
23
+ ` ${colors_1.default.italic("(optional)")} ${colors_1.default.gray('Use "{}" in the URL as a placeholder for the round number.')}`,
24
+ ` ${colors_1.default.bold("Note:")} ${colors_1.default.gray('For livechesscloud URLs, please ensure it ends with "/{}".')}`,
25
+ ` ${colors_1.default.bold("Options:")}`,
26
+ ` --withFilter ${colors_1.default.gray("Apply round number filtering based on round number.")}`,
27
+ ` --slice <sliceFilter> ${colors_1.default.gray("Apply slice filtering using the provided filter string.")}`,
28
+ ``,
29
+ ` ${colors_1.default.underItalic("setLichessGames <broadcastRoundId> <gameIds...>")}`,
30
+ ` ${colors_1.default.gray("Sets the games for the specified broadcast round using Lichess game IDs.")}`,
31
+ ` ${colors_1.default.bold("Note:")} ${colors_1.default.gray("Maximum of 64 game IDs can be provided.")}`,
32
+ ``,
33
+ ``,
34
+ `${colors_1.default.boldYellow("Examples:")}`,
35
+ ` ${colors_1.default.gray("# Set a 5-minute delay without changing start time")}`,
36
+ ` $ ${colors_1.default.underItalic("delay")} ${colors_1.default.italic("bcast123 300 --onlyDelay")}`,
37
+ ` ${colors_1.default.gray("# Set source PGN URL with round and slice filters")}`,
38
+ ` $ ${colors_1.default.underItalic("setPGN")} ${colors_1.default.italic('bcast123 https://example.com/pgns/round-{}/game.pgn --withFilter --slice "1-5,7,9-12"')}`,
39
+ ` ${colors_1.default.gray("# Set Lichess games for a broadcast round")}`,
40
+ ` $ ${colors_1.default.underItalic("setLichessGames")} ${colors_1.default.italic("round456 gameId1 gameId2 gameId3")}`,
30
41
  ];
31
42
  const showHelp = (cmd) => {
32
43
  const ranges = {
33
- [commandHandler_1.Command.Delay]: [3, 9],
34
- [commandHandler_1.Command.SetPGN]: [9, 16],
35
- [commandHandler_1.Command.SetLCC]: [9, 16],
36
- [commandHandler_1.Command.SetLichessGames]: [16, 19],
44
+ [commandHandler_1.Command.Delay]: [4, 10],
45
+ [commandHandler_1.Command.SetPGN]: [11, 18],
46
+ [commandHandler_1.Command.SetLCC]: [11, 18],
47
+ [commandHandler_1.Command.SetLichessGames]: [19, 22],
37
48
  };
38
49
  const range = cmd ? ranges[cmd] : undefined;
39
50
  if (cmd === commandHandler_1.Command.SetLCC) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libroadcast-cli",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "CLI to help with broadcast maintenance on Lichess",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [
@@ -17,6 +17,7 @@
17
17
  "openapi-fetch": "^0.15.0"
18
18
  },
19
19
  "devDependencies": {
20
+ "prettier": "3.6.2",
20
21
  "typescript": "^5.9.3"
21
22
  },
22
23
  "bin": {
@@ -32,6 +33,8 @@
32
33
  "homepage": "https://github.com/SergioGlorias/broadcastCLI",
33
34
  "scripts": {
34
35
  "build": "tsc",
35
- "start": "pnpm build && node ./dist/index.js"
36
+ "start": "pnpm build && node ./dist/index.js",
37
+ "format": "prettier --write ./src/**/*.ts ./package.json",
38
+ "lint": "prettier --check ./src/**/*.ts ./package.json"
36
39
  }
37
40
  }