@couch-kit/cli 0.2.4 → 0.2.5

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.
Files changed (2) hide show
  1. package/dist/index.js +44 -3
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1907,14 +1907,28 @@ var init_protocol = __esm(() => {
1907
1907
  });
1908
1908
 
1909
1909
  // ../core/src/constants.ts
1910
+ function generateId() {
1911
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
1912
+ return crypto.randomUUID();
1913
+ }
1914
+ if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
1915
+ const bytes = new Uint8Array(16);
1916
+ crypto.getRandomValues(bytes);
1917
+ return Array.from(bytes).map((b2) => b2.toString(16).padStart(2, "0")).join("");
1918
+ }
1919
+ const a = Math.random().toString(36).substring(2, 15);
1920
+ const b = Math.random().toString(36).substring(2, 10);
1921
+ return a + b;
1922
+ }
1910
1923
  function toErrorMessage(error) {
1911
1924
  if (error instanceof Error)
1912
1925
  return error.message;
1913
1926
  return String(error);
1914
1927
  }
1915
- var MAX_FRAME_SIZE;
1928
+ var MAX_FRAME_SIZE, DEFAULT_DISCONNECT_TIMEOUT;
1916
1929
  var init_constants = __esm(() => {
1917
1930
  MAX_FRAME_SIZE = 1024 * 1024;
1931
+ DEFAULT_DISCONNECT_TIMEOUT = 5 * 60 * 1000;
1918
1932
  });
1919
1933
 
1920
1934
  // ../core/src/index.ts
@@ -1945,6 +1959,20 @@ function collectFiles(dir, prefix = "") {
1945
1959
  }
1946
1960
  return files;
1947
1961
  }
1962
+ function detectPackageManager(dir) {
1963
+ for (let current = dir, parent = "";parent !== current; current = path.dirname(current)) {
1964
+ parent = current;
1965
+ if (fs.existsSync(path.join(current, "bun.lockb")) || fs.existsSync(path.join(current, "bun.lock")))
1966
+ return "bun";
1967
+ if (fs.existsSync(path.join(current, "pnpm-lock.yaml")))
1968
+ return "pnpm";
1969
+ if (fs.existsSync(path.join(current, "yarn.lock")))
1970
+ return "yarn";
1971
+ if (fs.existsSync(path.join(current, "package-lock.json")))
1972
+ return "npm";
1973
+ }
1974
+ return "npm";
1975
+ }
1948
1976
  var bundleCommand;
1949
1977
  var init_bundle = __esm(() => {
1950
1978
  init_esm();
@@ -1958,7 +1986,9 @@ var init_bundle = __esm(() => {
1958
1986
  if (options.build) {
1959
1987
  console.log(" Running build command...");
1960
1988
  if (fs.existsSync(path.join(sourceDir, "package.json"))) {
1961
- execSync("bun run build", { cwd: sourceDir, stdio: "ignore" });
1989
+ const pm = detectPackageManager(sourceDir);
1990
+ console.log(` Using ${pm} to build...`);
1991
+ execSync(`${pm} run build`, { cwd: sourceDir, stdio: "inherit" });
1962
1992
  } else {
1963
1993
  console.warn(" No package.json found, skipping build");
1964
1994
  }
@@ -2009,12 +2039,13 @@ var init_simulate = __esm(() => {
2009
2039
  const bots = [];
2010
2040
  const intervals = [];
2011
2041
  for (let i = 0;i < count; i++) {
2042
+ const secret = generateId();
2012
2043
  const ws = new WebSocket(url);
2013
2044
  ws.addEventListener("open", () => {
2014
2045
  console.log(`[Bot ${i}] Connected`);
2015
2046
  ws.send(JSON.stringify({
2016
2047
  type: MessageTypes.JOIN,
2017
- payload: { name: `Bot ${i}`, avatar: "bot" }
2048
+ payload: { name: `Bot ${i}`, avatar: "bot", secret }
2018
2049
  }));
2019
2050
  const id = setInterval(() => {
2020
2051
  if (ws.readyState === WebSocket.OPEN) {
@@ -2026,6 +2057,16 @@ var init_simulate = __esm(() => {
2026
2057
  }, interval + Math.random() * 500);
2027
2058
  intervals.push(id);
2028
2059
  });
2060
+ ws.addEventListener("message", (event) => {
2061
+ try {
2062
+ const msg = JSON.parse(typeof event.data === "string" ? event.data : event.data.toString());
2063
+ if (msg.type === MessageTypes.WELCOME) {
2064
+ console.log(`[Bot ${i}] Joined as ${msg.payload.playerId}`);
2065
+ } else if (msg.type === MessageTypes.ERROR) {
2066
+ console.error(`[Bot ${i}] Server error: ${msg.payload.message}`);
2067
+ }
2068
+ } catch {}
2069
+ });
2029
2070
  ws.addEventListener("close", () => {
2030
2071
  console.log(`[Bot ${i}] Disconnected`);
2031
2072
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@couch-kit/cli",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -36,7 +36,7 @@
36
36
  "clean": "rm -rf dist"
37
37
  },
38
38
  "dependencies": {
39
- "@couch-kit/core": "0.5.1",
39
+ "@couch-kit/core": "0.6.0",
40
40
  "commander": "^12.0.0"
41
41
  },
42
42
  "devDependencies": {