libroadcast-cli 1.0.0 → 1.0.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
@@ -1,17 +1,26 @@
1
1
  ## Installation
2
2
 
3
3
  ```bash
4
- pnpm install
4
+ npm install -g libroadcast-cli
5
5
  ```
6
6
 
7
7
  ## Usage
8
8
 
9
9
  ```bash
10
- pnpx tsx src/index.ts delay <broadcastId> <delayInSeconds> [--only-delay] [--no-delay]
10
+ export LICHESS_TOKEN=lip_yourtoken
11
+ export LICHESS_DOMAIN=http://localhost:8080/ # optional
12
+
13
+ libroadcast
11
14
  ```
12
15
 
13
16
  ```bash
14
- export LICHESS_TOKEN=lip_yourtoken
15
- export LICHESS_DOMAIN=http://localhost:8080/
16
- pnpx tsx src/index.ts delay <broadcastId> <delayInSeconds> [--only-delay] [--no-delay]
17
+ Usage: <command> [options]
18
+ Commands:
19
+ delay <broadcastId> <delayInSeconds> [--onlyDelay] [--noDelay]
20
+ Sets the delay for all rounds in the specified broadcast.
21
+ Options:
22
+ --onlyDelay Set only the delay without changing the start time.
23
+ --noDelay Remove the delay from the rounds.
24
+ setLCC <broadcastId> <sourceLCCUrl>
25
+ Sets the source LCC URL for all rounds in the specified broadcast.
17
26
  ```
package/dist/index.js CHANGED
@@ -103,7 +103,7 @@ const showHelp = (cmd) => {
103
103
  console.info(msg.slice(2, 7).join("\n"));
104
104
  break;
105
105
  case Command.SetLCC:
106
- console.info(msg.slice(7, 8).join("\n"));
106
+ console.info(msg.slice(7, 9).join("\n"));
107
107
  break;
108
108
  default:
109
109
  console.info(msg.join("\n"));
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "libroadcast-cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "",
5
5
  "main": "dist/index.ts",
6
6
  "keywords": [],
7
7
  "author": "",
8
- "license": "ISC",
8
+ "license": "MIT",
9
9
  "packageManager": "pnpm@10.20.0+sha512.cf9998222162dd85864d0a8102e7892e7ba4ceadebbf5a31f9c2fce48dfce317a9c53b9f6464d1ef9042cba2e02ae02a9f7c143a2b438cd93c91840f0192b9dd",
10
10
  "type": "module",
11
11
  "dependencies": {
package/src/index.ts DELETED
@@ -1,221 +0,0 @@
1
- #!/usr/bin/env node
2
- import { argv, env } from "process";
3
- import createClient from "openapi-fetch";
4
- import { components, paths } from "@lichess-org/types";
5
-
6
- const LICHESS_TOKEN = env.LICHESS_TOKEN;
7
- const LICHESS_DOMAIN = env.LICHESS_DOMAIN || "https://lichess.org/";
8
-
9
- if (!LICHESS_TOKEN) {
10
- console.error("Error: LICHESS_TOKEN environment variable is not set.");
11
- process.exit(1);
12
- }
13
-
14
- const args = argv.slice(2);
15
-
16
- const client = createClient<paths>({
17
- baseUrl: LICHESS_DOMAIN,
18
- headers: {
19
- Authorization: `Bearer ${LICHESS_TOKEN}`,
20
- Accept: "application/json",
21
- },
22
- });
23
-
24
- const getBroadcast = (broadcastId: string) =>
25
- client
26
- .GET("/api/broadcast/{broadcastTournamentId}", {
27
- params: {
28
- path: { broadcastTournamentId: broadcastId },
29
- },
30
- })
31
- .then((response) => response.data)
32
- .catch((error) => {
33
- console.error("Error fetching broadcast:", error);
34
- return null;
35
- });
36
-
37
- const setDelayRounds = (
38
- rounds: components["schemas"]["BroadcastRoundInfo"][],
39
- delay: number,
40
- onlyDelay: boolean,
41
- noDelay: boolean
42
- ) =>
43
- rounds.forEach((round) => {
44
- client
45
- .POST("/broadcast/round/{broadcastRoundId}/edit", {
46
- params: {
47
- path: { broadcastRoundId: round.id },
48
- // @ts-ignore patch param is not yet documented
49
- query: { patch: 1 },
50
- },
51
- // @ts-ignore name of body properties due patch param is implicit
52
- body: {
53
- delay: noDelay ? undefined : delay,
54
- startsAt:
55
- round.startsAt && !onlyDelay
56
- ? round.startsAt + delay * 1000
57
- : undefined,
58
- },
59
- })
60
- .then((response) => {
61
- if (response.response.ok)
62
- console.log(
63
- `Successfully set delay for round ${round.id} to ${delay} seconds.`
64
- );
65
- else
66
- console.error(
67
- `Failed to set delay for round ${round.id}: ${response.response.statusText}`
68
- );
69
- })
70
- .catch((error) => {
71
- console.error(`Error setting delay for round ${round.id}:`, error);
72
- });
73
- });
74
-
75
- const setSourceLCC = (
76
- rounds: components["schemas"]["BroadcastRoundInfo"][],
77
- sourceLCC: string
78
- ) => {
79
- let rN = 1;
80
- rounds.forEach((round) => {
81
- client
82
- .POST("/broadcast/round/{broadcastRoundId}/edit", {
83
- params: {
84
- path: { broadcastRoundId: round.id },
85
- // @ts-ignore patch param is not yet documented
86
- query: { patch: 1 },
87
- },
88
- // @ts-ignore name of body properties due patch param is implicit
89
- body: {
90
- // @ts-ignore property is not yet documented
91
- syncSource: "url",
92
- syncUrl: `${sourceLCC}/${rN}`,
93
- },
94
- })
95
- .then((response) => {
96
- if (response.response.ok)
97
- console.log(
98
- `Successfully set source LCC for round ${round.id} to ${sourceLCC}/${rN}.`
99
- );
100
- else
101
- console.error(
102
- `Failed to set source LCC for round ${round.id}: ${response.response.statusText}`
103
- );
104
- })
105
- .catch((error) => {
106
- console.error(`Error setting source LCC for round ${round.id}:`, error);
107
- });
108
- rN += 1;
109
- });
110
- };
111
-
112
- enum Command {
113
- Delay = "delay",
114
- SetLCC = "setLCC",
115
- }
116
-
117
- const showHelp = (cmd?: Command) => {
118
- const msg = [
119
- "Usage: <command> [options]",
120
- "Commands:",
121
- " delay <broadcastId> <delayInSeconds> [--onlyDelay] [--noDelay]",
122
- " Sets the delay for all rounds in the specified broadcast.",
123
- " Options:",
124
- " --onlyDelay Set only the delay without changing the start time.",
125
- " --noDelay Remove the delay from the rounds.",
126
- " setLCC <broadcastId> <sourceLCCUrl>",
127
- " Sets the source LCC URL for all rounds in the specified broadcast.",
128
- ];
129
- switch (cmd) {
130
- case Command.Delay:
131
- console.info(msg.slice(2, 7).join("\n"));
132
- break;
133
- case Command.SetLCC:
134
- console.info(msg.slice(7, 8).join("\n"));
135
- break;
136
- default:
137
- console.info(msg.join("\n"));
138
- }
139
- };
140
-
141
- (async () => {
142
- // check args[0] is --help or -h
143
- if (args.length === 0 || args[0] === "--help" || args[0] === "-h") {
144
- showHelp();
145
- process.exit(0);
146
- }
147
- switch (args[0]) {
148
- case Command.Delay:
149
- const [broadcastId, delay] = args.slice(1, 3);
150
- // check arg --help or -h
151
- if (args.includes("--help") || args.includes("-h")) {
152
- showHelp(Command.Delay);
153
- process.exit(0);
154
- }
155
- // Validate required args
156
- if (!broadcastId || !delay) {
157
- showHelp(Command.Delay);
158
- process.exit(1);
159
- }
160
- const delayNum = parseInt(delay, 10);
161
- // Validate delay is a number between 0s and 1h
162
- if (isNaN(delayNum) && delayNum >= 0 && delayNum <= 3600) {
163
- console.error("Delay must be a number between 0 and 3600 seconds.");
164
- process.exit(1);
165
- }
166
- // check arg --onlyDelay
167
- const onlyDelay = args.includes("--onlyDelay");
168
- // check arg --noDelay
169
- const noDelay = args.includes("--noDelay");
170
- if (onlyDelay && noDelay) {
171
- console.error("Cannot use --onlyDelay and --noDelay together.");
172
- process.exit(1);
173
- }
174
- const broadcast = await getBroadcast(broadcastId);
175
- if (!broadcast?.rounds || broadcast.rounds.length === 0) {
176
- console.error("No rounds found for the specified broadcast.");
177
- process.exit(1);
178
- }
179
- setDelayRounds(broadcast.rounds, parseInt(delay, 10), onlyDelay, noDelay);
180
- break;
181
-
182
- case Command.SetLCC:
183
- const [bId, sourceLCC] = args.slice(1, 3);
184
- // check arg --help or -h
185
- if (args.includes("--help") || args.includes("-h")) {
186
- showHelp(Command.SetLCC);
187
- process.exit(0);
188
- }
189
- // Validate required args
190
- if (!bId || !sourceLCC) {
191
- showHelp(Command.SetLCC);
192
- process.exit(1);
193
- }
194
-
195
- const bcast = await getBroadcast(bId);
196
- if (!bcast?.rounds || bcast.rounds.length === 0) {
197
- console.error("No rounds found for the specified broadcast.");
198
- process.exit(1);
199
- }
200
-
201
- // check sourceLCC is a valid URL
202
- let url: URL;
203
- try {
204
- url = new URL(
205
- sourceLCC.startsWith("http")
206
- ? sourceLCC
207
- : `https://view.livechesscloud.com/${sourceLCC}`
208
- );
209
- } catch (e) {
210
- console.error("sourceLCC must be a valid URL or LCC ID.");
211
- process.exit(1);
212
- }
213
-
214
- setSourceLCC(bcast.rounds, url.toString());
215
- break;
216
-
217
- default:
218
- console.error("Unknown command. Supported commands: delay, setLCC");
219
- process.exit(1);
220
- }
221
- })();
package/tsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "forceConsistentCasingInFileNames": true,
4
- "strict": true,
5
- "noImplicitAny": true,
6
- "strictNullChecks": true,
7
- "noUnusedLocals": true,
8
- "noUnusedParameters": true,
9
- "lib": ["DOM", "ES2024"],
10
- "target": "es2024",
11
- "moduleResolution": "node",
12
- "module": "ESNext",
13
- "outDir": "./dist",
14
- "rootDir": "./src",
15
- }
16
- }