libroadcast-cli 1.1.1 → 1.2.1

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
@@ -15,6 +15,7 @@ libroadcast
15
15
 
16
16
  ```bash
17
17
  Usage: <command> [options]
18
+
18
19
  Commands:
19
20
  delay <broadcastId> <delayInSeconds> [--onlyDelay] [--noDelay]
20
21
  Sets the delay for all rounds in the specified broadcast.
@@ -23,4 +24,12 @@ Commands:
23
24
  --noDelay Remove the delay from the rounds.
24
25
  setLCC <broadcastId> <sourceLCCUrl>
25
26
  Sets the source LCC URL for all rounds in the specified broadcast.
27
+ setPGN <broadcastId> <sourcePGNUrl>
28
+ Sets the source PGN URL for all rounds in the specified broadcast.
29
+ (optional) Use '{}' in the URL as a placeholder for the round number.
30
+
31
+ Examples:
32
+ 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
26
35
  ```
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setPGNCommand = void 0;
4
+ const utils_1 = require("../utils");
5
+ const setPGN = (rounds, urlRound) => {
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: urlRound(rN),
20
+ },
21
+ })
22
+ .then((response) => {
23
+ if (response.response.ok)
24
+ console.log(`Successfully set source LCC for round ${round.id} to ${urlRound(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 setPGNCommand = async (args) => {
35
+ const [bId, sourcePGN] = 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.SetPGN);
39
+ process.exit(0);
40
+ }
41
+ // Validate required args
42
+ if (!bId || !sourcePGN) {
43
+ (0, utils_1.showHelp)(utils_1.Command.SetPGN);
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
+ const urlRound = (roundNum) => sourcePGN.replaceAll("{}", roundNum.toString());
52
+ try {
53
+ const url = new URL(urlRound(1));
54
+ if (!url.protocol.startsWith("http"))
55
+ throw new Error();
56
+ }
57
+ catch {
58
+ console.error('Invalid URL. Must be http/https with "{}" as round placeholder.');
59
+ process.exit(1);
60
+ }
61
+ setPGN(bcast.rounds, urlRound);
62
+ };
63
+ exports.setPGNCommand = setPGNCommand;
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ const process_1 = require("process");
5
5
  const utils_1 = require("./utils");
6
6
  const delay_1 = require("./cmd/delay");
7
7
  const setLCC_1 = require("./cmd/setLCC");
8
+ const setPGN_1 = require("./cmd/setPGN");
8
9
  // Ensure LICHESS_TOKEN is set
9
10
  if (!utils_1.LICHESS_TOKEN) {
10
11
  console.error("Error: LICHESS_TOKEN environment variable is not set.");
@@ -12,21 +13,27 @@ if (!utils_1.LICHESS_TOKEN) {
12
13
  }
13
14
  const args = process_1.argv.slice(2);
14
15
  (async () => {
16
+ // show version for --version or -v
17
+ if (args.includes("--version") || args.includes("-v")) {
18
+ const { version } = require("../package.json");
19
+ console.log(`libroadcast-cli v${version}`);
20
+ process.exit(0);
21
+ }
15
22
  // check args[0] is --help or -h
16
23
  if (args.length === 0 || args[0] === "--help" || args[0] === "-h") {
17
24
  (0, utils_1.showHelp)();
18
25
  process.exit(0);
19
26
  }
20
27
  const command = args.shift();
21
- switch (command) {
22
- case utils_1.Command.Delay:
23
- await (0, delay_1.delayCommand)(args);
24
- break;
25
- case utils_1.Command.SetLCC:
26
- await (0, setLCC_1.setLCCCommand)(args);
27
- break;
28
- default:
29
- console.error("Unknown command. Supported commands: delay, setLCC");
30
- process.exit(1);
28
+ const commands = new Map([
29
+ [utils_1.Command.Delay, delay_1.delayCommand],
30
+ [utils_1.Command.SetLCC, setLCC_1.setLCCCommand],
31
+ [utils_1.Command.SetPGN, setPGN_1.setPGNCommand],
32
+ ]);
33
+ const handler = commands.get(command);
34
+ if (!handler) {
35
+ console.error("Unknown command. Supported commands: delay, setLCC, setPGN");
36
+ process.exit(1);
31
37
  }
38
+ await handler(args);
32
39
  })();
package/dist/utils.js CHANGED
@@ -20,11 +20,13 @@ var Command;
20
20
  (function (Command) {
21
21
  Command["Delay"] = "delay";
22
22
  Command["SetLCC"] = "setLCC";
23
+ Command["SetPGN"] = "setPGN";
23
24
  })(Command || (exports.Command = Command = {}));
24
25
  // Function to show help messages
25
26
  const showHelp = (cmd) => {
26
27
  const msg = [
27
28
  "Usage: <command> [options]",
29
+ "",
28
30
  "Commands:",
29
31
  " delay <broadcastId> <delayInSeconds> [--onlyDelay] [--noDelay]",
30
32
  " Sets the delay for all rounds in the specified broadcast.",
@@ -33,17 +35,22 @@ const showHelp = (cmd) => {
33
35
  " --noDelay Remove the delay from the rounds.",
34
36
  " setLCC <broadcastId> <sourceLCCUrl>",
35
37
  " Sets the source LCC URL for all rounds in the specified broadcast.",
38
+ " setPGN <broadcastId> <sourcePGNUrl>",
39
+ " Sets the source PGN URL for all rounds in the specified broadcast.",
40
+ " (optional) Use '{}' in the URL as a placeholder for the round number.",
41
+ "",
42
+ "Examples:",
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",
36
46
  ];
37
- switch (cmd) {
38
- case Command.Delay:
39
- console.info(msg.slice(2, 7).join("\n"));
40
- break;
41
- case Command.SetLCC:
42
- console.info(msg.slice(7, 9).join("\n"));
43
- break;
44
- default:
45
- console.info(msg.join("\n"));
46
- }
47
+ const ranges = {
48
+ [Command.Delay]: [3, 8],
49
+ [Command.SetLCC]: [8, 10],
50
+ [Command.SetPGN]: [10, 13],
51
+ };
52
+ const range = cmd ? ranges[cmd] : undefined;
53
+ console.info(range ? msg.slice(...range).join("\n") : msg.join("\n"));
47
54
  };
48
55
  exports.showHelp = showHelp;
49
56
  const getBroadcast = (broadcastId) => exports.client
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libroadcast-cli",
3
- "version": "1.1.1",
3
+ "version": "1.2.1",
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 }}