libroadcast-cli 1.2.0 → 1.3.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
@@ -22,14 +22,15 @@ Commands:
22
22
  Options:
23
23
  --onlyDelay Set only the delay without changing the start time.
24
24
  --noDelay Remove the delay from the rounds.
25
- setLCC <broadcastId> <sourceLCCUrl>
26
- Sets the source LCC URL for all rounds in the specified broadcast.
27
- setPGN <broadcastId> <sourcePGNUrl>
25
+ setPGN <broadcastId> <sourcePGNUrl> [--withFilter] [--slice <sliceFilter>]
28
26
  Sets the source PGN URL for all rounds in the specified broadcast.
29
27
  (optional) Use '{}' in the URL as a placeholder for the round number.
28
+ Note: For livechesscloud URLs, please ensure it ends with "/{}".
29
+ Options:
30
+ --withFilter Apply round number filtering based on round number.
31
+ --slice <sliceFilter> Apply slice filtering using the provided filter string.
30
32
 
31
33
  Examples:
32
34
  delay bcast123 300 --onlyDelay # Set a 5-minute delay without changing start time
33
- setLCC bcast123 https://view.livechesscloud.com/#47c48351-034a-4860-9b94-087490742803
34
- setPGN bcast123 https://example.com/pgns/round-{}/game.pgn
35
+ setPGN bcast123 https://example.com/pgns/round-{}/game.pgn --withFilter --slice "1-5,7,9-12"
35
36
  ```
package/dist/cmd/delay.js CHANGED
@@ -7,10 +7,8 @@ const setDelayRounds = (rounds, delay, onlyDelay, noDelay) => rounds.forEach((ro
7
7
  .POST("/broadcast/round/{broadcastRoundId}/edit", {
8
8
  params: {
9
9
  path: { broadcastRoundId: round.id },
10
- // @ts-ignore patch param is not yet documented
11
10
  query: { patch: 1 },
12
11
  },
13
- // @ts-ignore name of body properties due patch param is implicit
14
12
  body: {
15
13
  delay: noDelay ? undefined : delay,
16
14
  startsAt: round.startsAt && !onlyDelay
@@ -30,25 +28,20 @@ const setDelayRounds = (rounds, delay, onlyDelay, noDelay) => rounds.forEach((ro
30
28
  });
31
29
  const delayCommand = async (args) => {
32
30
  const [broadcastId, delay] = args.slice(0, 2);
33
- // check arg --help or -h
34
31
  if (args.includes("--help") || args.includes("-h")) {
35
32
  (0, utils_1.showHelp)(utils_1.Command.Delay);
36
33
  process.exit(0);
37
34
  }
38
- // Validate required args
39
35
  if (!broadcastId || !delay) {
40
36
  (0, utils_1.showHelp)(utils_1.Command.Delay);
41
37
  process.exit(1);
42
38
  }
43
39
  const delayNum = parseInt(delay, 10);
44
- // Validate delay is a number between 0s and 1h
45
40
  if (isNaN(delayNum) && delayNum >= 0 && delayNum <= 3600) {
46
41
  console.error("Delay must be a number between 0 and 3600 seconds.");
47
42
  process.exit(1);
48
43
  }
49
- // check arg --onlyDelay
50
44
  const onlyDelay = args.includes("--onlyDelay");
51
- // check arg --noDelay
52
45
  const noDelay = args.includes("--noDelay");
53
46
  if (onlyDelay && noDelay) {
54
47
  console.error("Cannot use --onlyDelay and --noDelay together.");
@@ -2,26 +2,26 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setPGNCommand = void 0;
4
4
  const utils_1 = require("../utils");
5
- const setPGN = (rounds, urlRound) => {
5
+ const setPGN = (rounds, urlRound, setRoundFilter, setSliceFilter = null) => {
6
6
  let rN = 1;
7
7
  rounds.forEach((round) => {
8
+ const url = urlRound(rN);
8
9
  utils_1.client
9
10
  .POST("/broadcast/round/{broadcastRoundId}/edit", {
10
11
  params: {
11
12
  path: { broadcastRoundId: round.id },
12
- // @ts-ignore patch param is not yet documented
13
13
  query: { patch: 1 },
14
14
  },
15
- // @ts-ignore name of body properties due patch param is implicit
16
15
  body: {
17
- // @ts-ignore property is not yet documented
18
16
  syncSource: "url",
19
- syncUrl: urlRound(rN),
17
+ syncUrl: url,
18
+ onlyRound: setRoundFilter ? rN : undefined,
19
+ slices: setSliceFilter ? setSliceFilter : undefined,
20
20
  },
21
21
  })
22
22
  .then((response) => {
23
23
  if (response.response.ok)
24
- console.log(`Successfully set source LCC for round ${round.id} to ${urlRound(rN)}.`);
24
+ console.log(`Successfully set source LCC for round ${round.id} to ${url}.`);
25
25
  else
26
26
  console.error(`Failed to set source LCC for round ${round.id}: ${response.response.statusText}`);
27
27
  })
@@ -33,12 +33,10 @@ const setPGN = (rounds, urlRound) => {
33
33
  };
34
34
  const setPGNCommand = async (args) => {
35
35
  const [bId, sourcePGN] = args.slice(0, 2);
36
- // check arg --help or -h
37
36
  if (args.includes("--help") || args.includes("-h")) {
38
37
  (0, utils_1.showHelp)(utils_1.Command.SetPGN);
39
38
  process.exit(0);
40
39
  }
41
- // Validate required args
42
40
  if (!bId || !sourcePGN) {
43
41
  (0, utils_1.showHelp)(utils_1.Command.SetPGN);
44
42
  process.exit(1);
@@ -48,16 +46,29 @@ const setPGNCommand = async (args) => {
48
46
  console.error("No rounds found for the specified broadcast.");
49
47
  process.exit(1);
50
48
  }
51
- const urlRound = (roundNum) => sourcePGN.replaceAll("{}", roundNum.toString());
49
+ const urlRound = (roundNum) => roundNum ? sourcePGN.replaceAll("{}", roundNum.toString()) : sourcePGN;
50
+ let isLCC = false;
52
51
  try {
53
- const url = new URL(urlRound(1));
52
+ const url = new URL(urlRound());
54
53
  if (!url.protocol.startsWith("http"))
55
54
  throw new Error();
55
+ isLCC = url.hostname === "view.livechesscloud.com";
56
+ if (isLCC && url.hash.length > 1 && !url.hash.endsWith("/{}"))
57
+ throw new Error();
56
58
  }
57
59
  catch {
58
- console.error('Invalid URL. Must be http/https with "{}" as round placeholder.');
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.');
59
64
  process.exit(1);
60
65
  }
61
- setPGN(bcast.rounds, urlRound);
66
+ const setRoundFilter = args.includes("--withFilter");
67
+ const sliceIndex = args.indexOf("--slice");
68
+ let setSliceFilter = null;
69
+ if (sliceIndex !== -1 && args.length > sliceIndex + 1) {
70
+ setSliceFilter = args[sliceIndex + 1];
71
+ }
72
+ setPGN(bcast.rounds, urlRound, setRoundFilter, setSliceFilter);
62
73
  };
63
74
  exports.setPGNCommand = setPGNCommand;
package/dist/index.js CHANGED
@@ -4,22 +4,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const process_1 = require("process");
5
5
  const utils_1 = require("./utils");
6
6
  const delay_1 = require("./cmd/delay");
7
- const setLCC_1 = require("./cmd/setLCC");
8
7
  const setPGN_1 = require("./cmd/setPGN");
9
- // Ensure LICHESS_TOKEN is set
10
8
  if (!utils_1.LICHESS_TOKEN) {
11
9
  console.error("Error: LICHESS_TOKEN environment variable is not set.");
12
10
  process.exit(1);
13
11
  }
14
12
  const args = process_1.argv.slice(2);
15
13
  (async () => {
16
- // show version for --version or -v
17
14
  if (args.includes("--version") || args.includes("-v")) {
18
15
  const { version } = require("../package.json");
19
16
  console.log(`libroadcast-cli v${version}`);
20
17
  process.exit(0);
21
18
  }
22
- // check args[0] is --help or -h
23
19
  if (args.length === 0 || args[0] === "--help" || args[0] === "-h") {
24
20
  (0, utils_1.showHelp)();
25
21
  process.exit(0);
@@ -27,10 +23,12 @@ const args = process_1.argv.slice(2);
27
23
  const command = args.shift();
28
24
  const commands = new Map([
29
25
  [utils_1.Command.Delay, delay_1.delayCommand],
30
- [utils_1.Command.SetLCC, setLCC_1.setLCCCommand],
26
+ [utils_1.Command.SetLCC, setPGN_1.setPGNCommand],
31
27
  [utils_1.Command.SetPGN, setPGN_1.setPGNCommand],
32
28
  ]);
33
29
  const handler = commands.get(command);
30
+ if (command === utils_1.Command.SetLCC)
31
+ console.warn("Warning: 'setLCC' command was removed. Will use 'setPGN' instead.");
34
32
  if (!handler) {
35
33
  console.error("Unknown command. Supported commands: delay, setLCC, setPGN");
36
34
  process.exit(1);
package/dist/utils.js CHANGED
@@ -15,14 +15,12 @@ exports.client = (0, openapi_fetch_1.default)({
15
15
  Accept: "application/json",
16
16
  },
17
17
  });
18
- // Commands names
19
18
  var Command;
20
19
  (function (Command) {
21
20
  Command["Delay"] = "delay";
22
21
  Command["SetLCC"] = "setLCC";
23
22
  Command["SetPGN"] = "setPGN";
24
23
  })(Command || (exports.Command = Command = {}));
25
- // Function to show help messages
26
24
  const showHelp = (cmd) => {
27
25
  const msg = [
28
26
  "Usage: <command> [options]",
@@ -33,23 +31,27 @@ const showHelp = (cmd) => {
33
31
  " Options:",
34
32
  " --onlyDelay Set only the delay without changing the start time.",
35
33
  " --noDelay Remove the delay from the rounds.",
36
- " setLCC <broadcastId> <sourceLCCUrl>",
37
- " Sets the source LCC URL for all rounds in the specified broadcast.",
38
- " setPGN <broadcastId> <sourcePGNUrl>",
34
+ " setPGN <broadcastId> <sourcePGNUrl> [--withFilter] [--slice <sliceFilter>]",
39
35
  " Sets the source PGN URL for all rounds in the specified broadcast.",
40
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
41
  "",
42
42
  "Examples:",
43
43
  " delay bcast123 300 --onlyDelay # Set a 5-minute delay without changing start time",
44
- " setLCC bcast123 https://view.livechesscloud.com/#47c48351-034a-4860-9b94-087490742803",
45
- " setPGN bcast123 https://example.com/pgns/round-{}/game.pgn",
44
+ " setPGN bcast123 https://example.com/pgns/round-{}/game.pgn --withFilter --slice \"1-5,7,9-12\"",
46
45
  ];
47
46
  const ranges = {
48
47
  [Command.Delay]: [3, 8],
49
- [Command.SetLCC]: [8, 10],
50
- [Command.SetPGN]: [10, 13],
48
+ [Command.SetPGN]: [8, 15],
49
+ [Command.SetLCC]: [8, 15],
51
50
  };
52
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
+ }
53
55
  console.info(range ? msg.slice(...range).join("\n") : msg.join("\n"));
54
56
  };
55
57
  exports.showHelp = showHelp;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libroadcast-cli",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "CLI to help with broadcast maintenance on Lichess",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [
@@ -1,58 +0,0 @@
1
- name: Release
2
-
3
- on:
4
- workflow_dispatch:
5
- inputs:
6
- version:
7
- description: 'Version tag (e.g. v1.2.3)'
8
- required: true
9
- description:
10
- description: 'Description'
11
- required: false
12
- default: ''
13
-
14
- permissions:
15
- id-token: write # Required for OIDC
16
- contents: read
17
-
18
- jobs:
19
- release:
20
- runs-on: ubuntu-latest
21
- permissions:
22
- contents: write
23
- id-token: write
24
- steps:
25
- - run: |
26
- [[ "${{ github.event.inputs.version }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-.*)?$ ]] || \
27
- (echo "Version must start with 'v' and match 'v<major>.<minor>.<patch>'" && exit 1)
28
- - uses: actions/checkout@v5
29
- with:
30
- fetch-depth: 0
31
- ref: ${{ github.ref }}
32
- - uses: pnpm/action-setup@v4
33
- - uses: actions/setup-node@v5
34
- with:
35
- node-version: '24'
36
- registry-url: https://registry.npmjs.org/
37
- cache: pnpm
38
- - run: pnpm install
39
- - run: |
40
- pnpm run build
41
- git config user.name "github-actions"
42
- git config user.email "github-actions@github.com"
43
- NPM_VERSION="${GITHUB_VERSION#v}"
44
- pnpm version "$NPM_VERSION" --allow-same-version
45
- env:
46
- GITHUB_VERSION: ${{ github.event.inputs.version }}
47
-
48
- - name: Publish to npm
49
- run: |
50
- pnpm publish --provenance --access public
51
- git push origin HEAD --follow-tags
52
-
53
- - name: Publish to github
54
- uses: softprops/action-gh-release@v2
55
- with:
56
- tag_name: ${{ github.event.inputs.version }}
57
- name: Release ${{ github.event.inputs.version }}
58
- body: ${{ github.event.inputs.description }}
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setLCCCommand = void 0;
4
- const utils_1 = require("../utils");
5
- const setSourceLCC = (rounds, sourceLCC) => {
6
- let rN = 1;
7
- rounds.forEach((round) => {
8
- utils_1.client
9
- .POST("/broadcast/round/{broadcastRoundId}/edit", {
10
- params: {
11
- path: { broadcastRoundId: round.id },
12
- // @ts-ignore patch param is not yet documented
13
- query: { patch: 1 },
14
- },
15
- // @ts-ignore name of body properties due patch param is implicit
16
- body: {
17
- // @ts-ignore property is not yet documented
18
- syncSource: "url",
19
- syncUrl: `${sourceLCC}/${rN}`,
20
- },
21
- })
22
- .then((response) => {
23
- if (response.response.ok)
24
- console.log(`Successfully set source LCC for round ${round.id} to ${sourceLCC}/${rN}.`);
25
- else
26
- console.error(`Failed to set source LCC for round ${round.id}: ${response.response.statusText}`);
27
- })
28
- .catch((error) => {
29
- console.error(`Error setting source LCC for round ${round.id}:`, error);
30
- });
31
- rN += 1;
32
- });
33
- };
34
- const setLCCCommand = async (args) => {
35
- const [bId, sourceLCC] = args.slice(0, 2);
36
- // check arg --help or -h
37
- if (args.includes("--help") || args.includes("-h")) {
38
- (0, utils_1.showHelp)(utils_1.Command.SetLCC);
39
- process.exit(0);
40
- }
41
- // Validate required args
42
- if (!bId || !sourceLCC) {
43
- (0, utils_1.showHelp)(utils_1.Command.SetLCC);
44
- process.exit(1);
45
- }
46
- const bcast = await (0, utils_1.getBroadcast)(bId);
47
- if (!bcast?.rounds || bcast.rounds.length === 0) {
48
- console.error("No rounds found for the specified broadcast.");
49
- process.exit(1);
50
- }
51
- // check sourceLCC is a valid URL
52
- let url;
53
- try {
54
- url = new URL(sourceLCC.startsWith("http")
55
- ? sourceLCC
56
- : `https://view.livechesscloud.com/${sourceLCC}`);
57
- }
58
- catch (e) {
59
- console.error("sourceLCC must be a valid URL or LCC ID.");
60
- process.exit(1);
61
- }
62
- setSourceLCC(bcast.rounds, url.toString());
63
- };
64
- exports.setLCCCommand = setLCCCommand;