@couch-kit/cli 0.0.6 → 0.0.7
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/dist/index.js +44 -32
- package/package.json +17 -2
package/dist/index.js
CHANGED
|
@@ -7670,11 +7670,11 @@ var require_websocket = __commonJS((exports, module) => {
|
|
|
7670
7670
|
});
|
|
7671
7671
|
}
|
|
7672
7672
|
if (protocols.length) {
|
|
7673
|
-
for (const
|
|
7674
|
-
if (typeof
|
|
7673
|
+
for (const protocol2 of protocols) {
|
|
7674
|
+
if (typeof protocol2 !== "string" || !subprotocolRegex.test(protocol2) || protocolSet.has(protocol2)) {
|
|
7675
7675
|
throw new SyntaxError("An invalid or duplicated subprotocol was specified");
|
|
7676
7676
|
}
|
|
7677
|
-
protocolSet.add(
|
|
7677
|
+
protocolSet.add(protocol2);
|
|
7678
7678
|
}
|
|
7679
7679
|
opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
|
|
7680
7680
|
}
|
|
@@ -8114,11 +8114,11 @@ var require_subprotocol = __commonJS((exports, module) => {
|
|
|
8114
8114
|
}
|
|
8115
8115
|
if (end === -1)
|
|
8116
8116
|
end = i;
|
|
8117
|
-
const
|
|
8118
|
-
if (protocols.has(
|
|
8119
|
-
throw new SyntaxError(`The "${
|
|
8117
|
+
const protocol3 = header.slice(start, end);
|
|
8118
|
+
if (protocols.has(protocol3)) {
|
|
8119
|
+
throw new SyntaxError(`The "${protocol3}" subprotocol is duplicated`);
|
|
8120
8120
|
}
|
|
8121
|
-
protocols.add(
|
|
8121
|
+
protocols.add(protocol3);
|
|
8122
8122
|
start = end = -1;
|
|
8123
8123
|
} else {
|
|
8124
8124
|
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
@@ -8127,11 +8127,11 @@ var require_subprotocol = __commonJS((exports, module) => {
|
|
|
8127
8127
|
if (start === -1 || end !== -1) {
|
|
8128
8128
|
throw new SyntaxError("Unexpected end of input");
|
|
8129
8129
|
}
|
|
8130
|
-
const
|
|
8131
|
-
if (protocols.has(
|
|
8132
|
-
throw new SyntaxError(`The "${
|
|
8130
|
+
const protocol2 = header.slice(start, i);
|
|
8131
|
+
if (protocols.has(protocol2)) {
|
|
8132
|
+
throw new SyntaxError(`The "${protocol2}" subprotocol is duplicated`);
|
|
8133
8133
|
}
|
|
8134
|
-
protocols.add(
|
|
8134
|
+
protocols.add(protocol2);
|
|
8135
8135
|
return protocols;
|
|
8136
8136
|
}
|
|
8137
8137
|
module.exports = { parse };
|
|
@@ -8360,10 +8360,10 @@ var require_websocket_server = __commonJS((exports, module) => {
|
|
|
8360
8360
|
];
|
|
8361
8361
|
const ws = new this.options.WebSocket(null, undefined, this.options);
|
|
8362
8362
|
if (protocols.size) {
|
|
8363
|
-
const
|
|
8364
|
-
if (
|
|
8365
|
-
headers.push(`Sec-WebSocket-Protocol: ${
|
|
8366
|
-
ws._protocol =
|
|
8363
|
+
const protocol2 = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
|
|
8364
|
+
if (protocol2) {
|
|
8365
|
+
headers.push(`Sec-WebSocket-Protocol: ${protocol2}`);
|
|
8366
|
+
ws._protocol = protocol2;
|
|
8367
8367
|
}
|
|
8368
8368
|
}
|
|
8369
8369
|
if (extensions[PerMessageDeflate.extensionName]) {
|
|
@@ -9760,6 +9760,26 @@ function ora(options) {
|
|
|
9760
9760
|
|
|
9761
9761
|
// src/commands/bundle.ts
|
|
9762
9762
|
import { execSync } from "child_process";
|
|
9763
|
+
// ../core/src/protocol.ts
|
|
9764
|
+
var MessageTypes = {
|
|
9765
|
+
JOIN: "JOIN",
|
|
9766
|
+
ACTION: "ACTION",
|
|
9767
|
+
PING: "PING",
|
|
9768
|
+
ASSETS_LOADED: "ASSETS_LOADED",
|
|
9769
|
+
WELCOME: "WELCOME",
|
|
9770
|
+
STATE_UPDATE: "STATE_UPDATE",
|
|
9771
|
+
PONG: "PONG",
|
|
9772
|
+
RECONNECTED: "RECONNECTED",
|
|
9773
|
+
ERROR: "ERROR"
|
|
9774
|
+
};
|
|
9775
|
+
// ../core/src/constants.ts
|
|
9776
|
+
var MAX_FRAME_SIZE = 1024 * 1024;
|
|
9777
|
+
function toErrorMessage(error) {
|
|
9778
|
+
if (error instanceof Error)
|
|
9779
|
+
return error.message;
|
|
9780
|
+
return String(error);
|
|
9781
|
+
}
|
|
9782
|
+
// src/commands/bundle.ts
|
|
9763
9783
|
var bundleCommand = new Command("bundle").description("Bundles the web controller into the Android assets directory").option("-s, --source <path>", "Source directory of web controller", "./web-controller").option("-o, --output <path>", "Android assets directory", "./android/app/src/main/assets/www").option("--no-build", "Skip build step (just copy)").action(async (options) => {
|
|
9764
9784
|
const spinner = ora("Bundling controller...").start();
|
|
9765
9785
|
try {
|
|
@@ -9783,7 +9803,7 @@ var bundleCommand = new Command("bundle").description("Bundles the web controlle
|
|
|
9783
9803
|
await import_fs_extra.default.copy(distDir, targetDir);
|
|
9784
9804
|
spinner.succeed(`Controller bundled to ${options.output}`);
|
|
9785
9805
|
} catch (e) {
|
|
9786
|
-
spinner.fail(`Bundle failed: ${e
|
|
9806
|
+
spinner.fail(`Bundle failed: ${toErrorMessage(e)}`);
|
|
9787
9807
|
process.exit(1);
|
|
9788
9808
|
}
|
|
9789
9809
|
});
|
|
@@ -9795,34 +9815,24 @@ var import_sender = __toESM(require_sender(), 1);
|
|
|
9795
9815
|
var import_websocket = __toESM(require_websocket(), 1);
|
|
9796
9816
|
var import_websocket_server = __toESM(require_websocket_server(), 1);
|
|
9797
9817
|
var wrapper_default = import_websocket.default;
|
|
9798
|
-
|
|
9799
|
-
var MessageTypes = {
|
|
9800
|
-
JOIN: "JOIN",
|
|
9801
|
-
ACTION: "ACTION",
|
|
9802
|
-
PING: "PING",
|
|
9803
|
-
ASSETS_LOADED: "ASSETS_LOADED",
|
|
9804
|
-
WELCOME: "WELCOME",
|
|
9805
|
-
STATE_UPDATE: "STATE_UPDATE",
|
|
9806
|
-
PONG: "PONG",
|
|
9807
|
-
RECONNECTED: "RECONNECTED",
|
|
9808
|
-
ERROR: "ERROR"
|
|
9809
|
-
};
|
|
9818
|
+
|
|
9810
9819
|
// src/commands/simulate.ts
|
|
9811
9820
|
var simulateCommand = new Command("simulate").description("Spawns headless bots to simulate players").option("-n, --count <number>", "Number of bots", "4").option("-u, --url <url>", "WebSocket URL of host", "ws://localhost:8082").option("-i, --interval <ms>", "Action interval in ms", "1000").action(async (options) => {
|
|
9812
9821
|
const count = parseInt(options.count);
|
|
9813
9822
|
const url = options.url;
|
|
9814
9823
|
const interval = parseInt(options.interval);
|
|
9815
|
-
console.log(
|
|
9824
|
+
console.log(`Spawning ${count} bots connecting to ${url}...`);
|
|
9816
9825
|
const bots = [];
|
|
9826
|
+
const intervals = [];
|
|
9817
9827
|
for (let i = 0;i < count; i++) {
|
|
9818
9828
|
const ws = new wrapper_default(url);
|
|
9819
9829
|
ws.on("open", () => {
|
|
9820
9830
|
console.log(`[Bot ${i}] Connected`);
|
|
9821
9831
|
ws.send(JSON.stringify({
|
|
9822
9832
|
type: MessageTypes.JOIN,
|
|
9823
|
-
payload: { name: `Bot ${i}`, avatar: "
|
|
9833
|
+
payload: { name: `Bot ${i}`, avatar: "bot" }
|
|
9824
9834
|
}));
|
|
9825
|
-
setInterval(() => {
|
|
9835
|
+
const id = setInterval(() => {
|
|
9826
9836
|
if (ws.readyState === wrapper_default.OPEN) {
|
|
9827
9837
|
ws.send(JSON.stringify({
|
|
9828
9838
|
type: MessageTypes.ACTION,
|
|
@@ -9830,6 +9840,7 @@ var simulateCommand = new Command("simulate").description("Spawns headless bots
|
|
|
9830
9840
|
}));
|
|
9831
9841
|
}
|
|
9832
9842
|
}, interval + Math.random() * 500);
|
|
9843
|
+
intervals.push(id);
|
|
9833
9844
|
});
|
|
9834
9845
|
ws.on("close", () => {
|
|
9835
9846
|
console.log(`[Bot ${i}] Disconnected`);
|
|
@@ -9844,6 +9855,7 @@ var simulateCommand = new Command("simulate").description("Spawns headless bots
|
|
|
9844
9855
|
process.on("SIGINT", () => {
|
|
9845
9856
|
console.log(`
|
|
9846
9857
|
Stopping bots...`);
|
|
9858
|
+
intervals.forEach((id) => clearInterval(id));
|
|
9847
9859
|
bots.forEach((b) => b.close());
|
|
9848
9860
|
process.exit();
|
|
9849
9861
|
});
|
|
@@ -9989,7 +10001,7 @@ Next steps:
|
|
|
9989
10001
|
bun run dev
|
|
9990
10002
|
`);
|
|
9991
10003
|
} catch (e) {
|
|
9992
|
-
spinner.fail(`Init failed: ${e
|
|
10004
|
+
spinner.fail(`Init failed: ${toErrorMessage(e)}`);
|
|
9993
10005
|
process.exit(1);
|
|
9994
10006
|
}
|
|
9995
10007
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@couch-kit/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
|
+
"description": "CLI tools for Couch Kit party games — bundle web controllers, simulate clients, and scaffold projects",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/faluciano/react-native-couch-kit.git",
|
|
9
|
+
"directory": "packages/cli"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/faluciano/react-native-couch-kit#readme",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"couch-kit",
|
|
14
|
+
"cli",
|
|
15
|
+
"party-game",
|
|
16
|
+
"bundler",
|
|
17
|
+
"react-native"
|
|
18
|
+
],
|
|
4
19
|
"files": [
|
|
5
20
|
"dist",
|
|
6
21
|
"README.md"
|
|
@@ -16,7 +31,7 @@
|
|
|
16
31
|
"clean": "rm -rf dist"
|
|
17
32
|
},
|
|
18
33
|
"dependencies": {
|
|
19
|
-
"@couch-kit/core": "0.
|
|
34
|
+
"@couch-kit/core": "0.3.0",
|
|
20
35
|
"commander": "^12.0.0",
|
|
21
36
|
"chalk": "^5.3.0",
|
|
22
37
|
"ora": "^8.0.1",
|