libroadcast-cli 1.3.3 → 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,21 +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.
23
+ Note: The delay is specified in seconds. (max 3600 seconds = 1 hour)
22
24
  Options:
23
25
  --onlyDelay Set only the delay without changing the start time.
24
26
  --noDelay Remove the delay from the rounds.
27
+
25
28
  setPGN <broadcastId> <sourcePGNUrl> [--withFilter] [--slice <sliceFilter>]
26
29
  Sets the source PGN URL for all rounds in the specified broadcast.
27
- (optional) Use '{}' in the URL as a placeholder for the round number.
28
- 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 "/{}".
29
32
  Options:
30
- --withFilter Apply round number filtering based on round number.
31
- --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
+
36
+ setLichessGames <broadcastRoundId> <gameIds...>
37
+ Sets the games for the specified broadcast round using Lichess game IDs.
38
+ Note: Maximum of 64 game IDs can be provided.
39
+
32
40
 
33
41
  Examples:
34
- delay bcast123 300 --onlyDelay # Set a 5-minute delay without changing start time
35
- setPGN bcast123 https://example.com/pgns/round-{}/game.pgn --withFilter --slice "1-5,7,9-12"
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
36
48
  ```
package/dist/cmd/delay.js CHANGED
@@ -1,10 +1,16 @@
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
- const utils_1 = require("../utils");
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"));
5
11
  const setDelayRounds = async (rounds, delay, onlyDelay, noDelay) => {
6
12
  for (const round of rounds) {
7
- await utils_1.client
13
+ await commandHandler_1.client
8
14
  .POST("/broadcast/round/{broadcastRoundId}/edit", {
9
15
  params: {
10
16
  path: { broadcastRoundId: round.id },
@@ -19,41 +25,37 @@ const setDelayRounds = async (rounds, delay, onlyDelay, noDelay) => {
19
25
  })
20
26
  .then((response) => {
21
27
  if (response.response.ok)
22
- 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.`));
23
29
  else
24
- 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)}`));
25
31
  })
26
32
  .catch((error) => {
27
- 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);
28
34
  });
29
- await (0, utils_1.sleep)(200);
35
+ await (0, commandHandler_1.sleep)(200);
30
36
  }
31
37
  };
32
38
  const delayCommand = async (args) => {
33
39
  const [broadcastId, delay] = args.slice(0, 2);
34
- if (args.includes("--help") || args.includes("-h")) {
35
- (0, utils_1.showHelp)(utils_1.Command.Delay);
36
- process.exit(0);
37
- }
38
40
  if (!broadcastId || !delay) {
39
- (0, utils_1.showHelp)(utils_1.Command.Delay);
40
- process.exit(1);
41
+ (0, commandHandler_1.msgCommonErrorHelp)("Broadcast ID and delay are required.");
42
+ (0, node_process_1.exit)(1);
41
43
  }
42
44
  const delayNum = parseInt(delay, 10);
43
45
  if (isNaN(delayNum) && delayNum >= 0 && delayNum <= 3600) {
44
- console.error("Delay must be a number between 0 and 3600 seconds.");
45
- process.exit(1);
46
+ (0, commandHandler_1.msgCommonErrorHelp)("Delay must be a number between 0 and 3600 seconds.");
47
+ (0, node_process_1.exit)(1);
46
48
  }
47
49
  const onlyDelay = args.includes("--onlyDelay");
48
50
  const noDelay = args.includes("--noDelay");
49
51
  if (onlyDelay && noDelay) {
50
- console.error("Cannot use --onlyDelay and --noDelay together.");
51
- process.exit(1);
52
+ console.error(colors_1.default.red("Cannot use --onlyDelay and --noDelay together."));
53
+ (0, node_process_1.exit)(1);
52
54
  }
53
- const broadcast = await (0, utils_1.getBroadcast)(broadcastId);
55
+ const broadcast = await (0, getInfoBroadcast_1.getBroadcast)(broadcastId);
54
56
  if (!broadcast?.rounds || broadcast.rounds.length === 0) {
55
- console.error("No rounds found for the specified broadcast.");
56
- process.exit(1);
57
+ console.error(colors_1.default.red("No rounds found for the specified broadcast."));
58
+ (0, node_process_1.exit)(1);
57
59
  }
58
60
  setDelayRounds(broadcast.rounds, parseInt(delay, 10), onlyDelay, noDelay);
59
61
  };
@@ -0,0 +1,45 @@
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.setLichessGamesCommand = 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 setLichessGames = (round, games) => commandHandler_1.client
12
+ .POST("/broadcast/round/{broadcastRoundId}/edit", {
13
+ params: {
14
+ path: { broadcastRoundId: round.id },
15
+ query: { patch: 1 },
16
+ },
17
+ body: {
18
+ syncSource: "ids",
19
+ syncIds: games,
20
+ },
21
+ })
22
+ .then((response) => {
23
+ if (response.response.ok)
24
+ console.log(colors_1.default.green(`Successfully set games for round ${colors_1.default.whiteBold(round.id)} to ${colors_1.default.whiteBold(games)}.`));
25
+ else
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)}`));
27
+ })
28
+ .catch((error) => {
29
+ console.error(colors_1.default.red(`Error setting games for round ${colors_1.default.whiteBold(round.id)}:`), error);
30
+ });
31
+ const setLichessGamesCommand = async (args) => {
32
+ const bId = args.shift();
33
+ const games = args.slice(0, 64).join(" ");
34
+ if (!bId || !games) {
35
+ (0, commandHandler_1.msgCommonErrorHelp)("Broadcast ID and games IDs are required.");
36
+ (0, node_process_1.exit)(1);
37
+ }
38
+ const round = await (0, getInfoBroadcast_1.getBroadcastRound)(bId);
39
+ if (!round) {
40
+ console.error(colors_1.default.red(`Broadcast round with ID ${colors_1.default.whiteBold(bId)} not found or has no rounds.`));
41
+ (0, node_process_1.exit)(1);
42
+ }
43
+ setLichessGames(round, games);
44
+ };
45
+ exports.setLichessGamesCommand = setLichessGamesCommand;
@@ -1,12 +1,18 @@
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
- const utils_1 = require("../utils");
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"));
5
11
  const setPGN = async (rounds, urlRound, setRoundFilter, setSliceFilter = null) => {
6
12
  for (let rN = 1; rN <= rounds.length; rN++) {
7
13
  const round = rounds[rN - 1];
8
14
  const url = urlRound(rN);
9
- await utils_1.client
15
+ await commandHandler_1.client
10
16
  .POST("/broadcast/round/{broadcastRoundId}/edit", {
11
17
  params: {
12
18
  path: { broadcastRoundId: round.id },
@@ -21,30 +27,26 @@ const setPGN = async (rounds, urlRound, setRoundFilter, setSliceFilter = null) =
21
27
  })
22
28
  .then((response) => {
23
29
  if (response.response.ok)
24
- console.log(`Successfully set source LCC 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)}.`));
25
31
  else
26
- console.error(`Failed to set source LCC 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)}`));
27
33
  })
28
34
  .catch((error) => {
29
- console.error(`Error setting source LCC for round ${round.id}:`, error);
35
+ console.error(colors_1.default.red(`Error setting source for round ${colors_1.default.whiteBold(round.id)}:`), error);
30
36
  });
31
- await (0, utils_1.sleep)(200);
37
+ await (0, commandHandler_1.sleep)(200);
32
38
  }
33
39
  };
34
40
  const setPGNCommand = async (args) => {
35
41
  const [bId, sourcePGN] = args.slice(0, 2);
36
- if (args.includes("--help") || args.includes("-h")) {
37
- (0, utils_1.showHelp)(utils_1.Command.SetPGN);
38
- process.exit(0);
39
- }
40
42
  if (!bId || !sourcePGN) {
41
- (0, utils_1.showHelp)(utils_1.Command.SetPGN);
42
- process.exit(1);
43
+ (0, commandHandler_1.msgCommonErrorHelp)("Broadcast ID and source PGN URL are required.");
44
+ (0, node_process_1.exit)(1);
43
45
  }
44
- const bcast = await (0, utils_1.getBroadcast)(bId);
46
+ const bcast = await (0, getInfoBroadcast_1.getBroadcast)(bId);
45
47
  if (!bcast?.rounds || bcast.rounds.length === 0) {
46
- console.error("No rounds found for the specified broadcast.");
47
- process.exit(1);
48
+ (0, commandHandler_1.msgCommonErrorHelp)("No rounds found for the specified broadcast.");
49
+ (0, node_process_1.exit)(1);
48
50
  }
49
51
  const urlRound = (roundNum) => roundNum ? sourcePGN.replaceAll("{}", roundNum.toString()) : sourcePGN;
50
52
  let isLCC = false;
@@ -57,11 +59,10 @@ const setPGNCommand = async (args) => {
57
59
  throw new Error();
58
60
  }
59
61
  catch {
60
- if (isLCC)
61
- console.error('Invalid URL. For livechesscloud URLs, please ensure it ends with "/{}".');
62
- else
63
- console.error('Invalid URL. Must be http/https with "{}" as round placeholder.');
64
- process.exit(1);
62
+ console.error(colors_1.default.red(isLCC
63
+ ? 'Invalid URL. For livechesscloud URLs, please ensure it ends with "/{}".'
64
+ : 'Invalid URL. Must be http/https with "{}" as round placeholder.'));
65
+ (0, node_process_1.exit)(1);
65
66
  }
66
67
  const setRoundFilter = args.includes("--withFilter");
67
68
  const sliceIndex = args.indexOf("--slice");
package/dist/index.js CHANGED
@@ -1,37 +1,34 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- const process_1 = require("process");
5
- const utils_1 = require("./utils");
6
- const delay_1 = require("./cmd/delay");
7
- const setPGN_1 = require("./cmd/setPGN");
8
- if (!utils_1.LICHESS_TOKEN) {
9
- console.error("Error: LICHESS_TOKEN environment variable is not set.");
10
- process.exit(1);
11
- }
12
- const args = process_1.argv.slice(2);
4
+ const node_process_1 = require("node:process");
5
+ const commandHandler_1 = require("./utils/commandHandler");
6
+ const help_1 = require("./utils/help");
13
7
  (async () => {
14
- if (args.includes("--version") || args.includes("-v")) {
8
+ if (commandHandler_1.args.includes("--version") || commandHandler_1.args.includes("-v")) {
15
9
  const { version } = require("../package.json");
16
10
  console.log(`libroadcast-cli v${version}`);
17
- process.exit(0);
11
+ (0, node_process_1.exit)(0);
18
12
  }
19
- if (args.length === 0 || args[0] === "--help" || args[0] === "-h") {
20
- (0, utils_1.showHelp)();
21
- process.exit(0);
13
+ if (commandHandler_1.args.length === 0 || (0, help_1.includeHelp)(commandHandler_1.args[0])) {
14
+ (0, help_1.showHelp)();
15
+ (0, node_process_1.exit)(0);
22
16
  }
23
- const command = args.shift();
24
- const commands = new Map([
25
- [utils_1.Command.Delay, delay_1.delayCommand],
26
- [utils_1.Command.SetLCC, setPGN_1.setPGNCommand],
27
- [utils_1.Command.SetPGN, setPGN_1.setPGNCommand],
28
- ]);
29
- const handler = commands.get(command);
30
- if (command === utils_1.Command.SetLCC)
17
+ const cmd = commandHandler_1.args.shift();
18
+ const handler = commandHandler_1.commands.get(cmd);
19
+ if (cmd === commandHandler_1.Command.SetLCC)
31
20
  console.warn("Warning: 'setLCC' command was removed. Will use 'setPGN' instead.");
21
+ if (commandHandler_1.args.find(help_1.includeHelp)) {
22
+ (0, help_1.showHelp)(cmd);
23
+ (0, node_process_1.exit)(0);
24
+ }
32
25
  if (!handler) {
33
- console.error("Unknown command. Supported commands: delay, setLCC, setPGN");
34
- process.exit(1);
26
+ console.error("Error: Command handler not found.");
27
+ (0, node_process_1.exit)(1);
28
+ }
29
+ if (!commandHandler_1.LICHESS_TOKEN) {
30
+ console.error("Error: LICHESS_TOKEN environment variable is not set.");
31
+ (0, node_process_1.exit)(1);
35
32
  }
36
- await handler(args);
33
+ await handler(commandHandler_1.args);
37
34
  })();
@@ -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
+ };
@@ -0,0 +1,42 @@
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.msgCommonErrorHelp = exports.sleep = exports.client = exports.commands = exports.Command = exports.args = exports.LICHESS_TOKEN = void 0;
7
+ const node_process_1 = require("node:process");
8
+ const openapi_fetch_1 = __importDefault(require("openapi-fetch"));
9
+ const delay_1 = require("../cmd/delay");
10
+ const setPGN_1 = require("../cmd/setPGN");
11
+ const setLichessGames_1 = require("../cmd/setLichessGames");
12
+ const colors_1 = __importDefault(require("./colors"));
13
+ exports.LICHESS_TOKEN = node_process_1.env.LICHESS_TOKEN;
14
+ const LICHESS_DOMAIN = node_process_1.env.LICHESS_DOMAIN || "https://lichess.org/";
15
+ exports.args = node_process_1.argv.slice(2);
16
+ var Command;
17
+ (function (Command) {
18
+ Command["Delay"] = "delay";
19
+ Command["SetLCC"] = "setLCC";
20
+ Command["SetPGN"] = "setPGN";
21
+ Command["SetLichessGames"] = "setLichessGames";
22
+ })(Command || (exports.Command = Command = {}));
23
+ exports.commands = new Map([
24
+ [Command.Delay, delay_1.delayCommand],
25
+ [Command.SetLCC, setPGN_1.setPGNCommand],
26
+ [Command.SetPGN, setPGN_1.setPGNCommand],
27
+ [Command.SetLichessGames, setLichessGames_1.setLichessGamesCommand],
28
+ ]);
29
+ exports.client = (0, openapi_fetch_1.default)({
30
+ baseUrl: LICHESS_DOMAIN,
31
+ headers: {
32
+ Authorization: `Bearer ${exports.LICHESS_TOKEN}`,
33
+ Accept: "application/json",
34
+ },
35
+ });
36
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
37
+ exports.sleep = sleep;
38
+ const msgCommonErrorHelp = (msg) => {
39
+ console.error(colors_1.default.red(msg));
40
+ console.info(colors_1.default.blue("Use --help to see usage."));
41
+ };
42
+ exports.msgCommonErrorHelp = msgCommonErrorHelp;
@@ -0,0 +1,36 @@
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.getBroadcastRound = exports.getBroadcast = void 0;
7
+ const commandHandler_1 = require("./commandHandler");
8
+ const colors_1 = __importDefault(require("./colors"));
9
+ const getBroadcast = (broadcastId) => commandHandler_1.client
10
+ .GET("/api/broadcast/{broadcastTournamentId}", {
11
+ params: {
12
+ path: { broadcastTournamentId: broadcastId },
13
+ },
14
+ })
15
+ .then((response) => response.data)
16
+ .catch((error) => {
17
+ console.error(colors_1.default.red("Error fetching broadcast:"), error);
18
+ return null;
19
+ });
20
+ exports.getBroadcast = getBroadcast;
21
+ const getBroadcastRound = (roundId) => commandHandler_1.client
22
+ .GET("/api/broadcast/{broadcastTournamentSlug}/{broadcastRoundSlug}/{broadcastRoundId}", {
23
+ params: {
24
+ path: {
25
+ broadcastTournamentSlug: "-",
26
+ broadcastRoundSlug: "-",
27
+ broadcastRoundId: roundId,
28
+ },
29
+ },
30
+ })
31
+ .then((response) => response.data?.round)
32
+ .catch((error) => {
33
+ console.error(colors_1.default.red("Error fetching broadcast round:"), error);
34
+ return null;
35
+ });
36
+ exports.getBroadcastRound = getBroadcastRound;
@@ -0,0 +1,57 @@
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.includeHelp = exports.showHelp = void 0;
7
+ const commandHandler_1 = require("./commandHandler");
8
+ const colors_1 = __importDefault(require("./colors"));
9
+ const msg = [
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")}`,
41
+ ];
42
+ const showHelp = (cmd) => {
43
+ const ranges = {
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],
48
+ };
49
+ const range = cmd ? ranges[cmd] : undefined;
50
+ if (cmd === commandHandler_1.Command.SetLCC) {
51
+ console.warn("Warning: 'setLCC' command was removed. Use 'setPGN' command instead.");
52
+ }
53
+ console.info(range ? msg.slice(...range).join("\n") : msg.join("\n"));
54
+ };
55
+ exports.showHelp = showHelp;
56
+ const includeHelp = (str) => ["--help", "-h"].includes(str);
57
+ exports.includeHelp = includeHelp;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libroadcast-cli",
3
- "version": "1.3.3",
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
  }
package/dist/utils.js DELETED
@@ -1,71 +0,0 @@
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.sleep = exports.getBroadcast = exports.showHelp = exports.Command = exports.client = exports.LICHESS_TOKEN = void 0;
7
- const process_1 = require("process");
8
- const openapi_fetch_1 = __importDefault(require("openapi-fetch"));
9
- exports.LICHESS_TOKEN = process_1.env.LICHESS_TOKEN;
10
- const LICHESS_DOMAIN = process_1.env.LICHESS_DOMAIN || "https://lichess.org/";
11
- exports.client = (0, openapi_fetch_1.default)({
12
- baseUrl: LICHESS_DOMAIN,
13
- headers: {
14
- Authorization: `Bearer ${exports.LICHESS_TOKEN}`,
15
- Accept: "application/json",
16
- },
17
- });
18
- var Command;
19
- (function (Command) {
20
- Command["Delay"] = "delay";
21
- Command["SetLCC"] = "setLCC";
22
- Command["SetPGN"] = "setPGN";
23
- })(Command || (exports.Command = Command = {}));
24
- const showHelp = (cmd) => {
25
- const msg = [
26
- "Usage: <command> [options]",
27
- "",
28
- "Commands:",
29
- " delay <broadcastId> <delayInSeconds> [--onlyDelay] [--noDelay]",
30
- " Sets the delay for all rounds in the specified broadcast.",
31
- " Options:",
32
- " --onlyDelay Set only the delay without changing the start time.",
33
- " --noDelay Remove the delay from the rounds.",
34
- " setPGN <broadcastId> <sourcePGNUrl> [--withFilter] [--slice <sliceFilter>]",
35
- " Sets the source PGN URL for all rounds in the specified broadcast.",
36
- " (optional) Use '{}' in the URL as a placeholder for the round number.",
37
- " Note: For livechesscloud URLs, please ensure it ends with \"/{}\".",
38
- " Options:",
39
- " --withFilter Apply round number filtering based on round number.",
40
- " --slice <sliceFilter> Apply slice filtering using the provided filter string.",
41
- "",
42
- "Examples:",
43
- " delay bcast123 300 --onlyDelay # Set a 5-minute delay without changing start time",
44
- " setPGN bcast123 https://example.com/pgns/round-{}/game.pgn --withFilter --slice \"1-5,7,9-12\"",
45
- ];
46
- const ranges = {
47
- [Command.Delay]: [3, 8],
48
- [Command.SetPGN]: [8, 15],
49
- [Command.SetLCC]: [8, 15],
50
- };
51
- const range = cmd ? ranges[cmd] : undefined;
52
- if (cmd === Command.SetLCC) {
53
- console.warn("Warning: 'setLCC' command was removed. Use 'setPGN' command instead.");
54
- }
55
- console.info(range ? msg.slice(...range).join("\n") : msg.join("\n"));
56
- };
57
- exports.showHelp = showHelp;
58
- const getBroadcast = (broadcastId) => exports.client
59
- .GET("/api/broadcast/{broadcastTournamentId}", {
60
- params: {
61
- path: { broadcastTournamentId: broadcastId },
62
- },
63
- })
64
- .then((response) => response.data)
65
- .catch((error) => {
66
- console.error("Error fetching broadcast:", error);
67
- return null;
68
- });
69
- exports.getBroadcast = getBroadcast;
70
- const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
71
- exports.sleep = sleep;