@couch-kit/cli 0.2.4 → 0.2.6

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 +48 -3
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1887,6 +1887,9 @@ var init_esm = __esm(() => {
1887
1887
  } = import__.default);
1888
1888
  });
1889
1889
 
1890
+ // ../core/src/middleware.ts
1891
+ var init_middleware = () => {};
1892
+
1890
1893
  // ../core/src/types.ts
1891
1894
  var init_types = () => {};
1892
1895
 
@@ -1907,14 +1910,28 @@ var init_protocol = __esm(() => {
1907
1910
  });
1908
1911
 
1909
1912
  // ../core/src/constants.ts
1913
+ function generateId() {
1914
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
1915
+ return crypto.randomUUID();
1916
+ }
1917
+ if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
1918
+ const bytes = new Uint8Array(16);
1919
+ crypto.getRandomValues(bytes);
1920
+ return Array.from(bytes).map((b2) => b2.toString(16).padStart(2, "0")).join("");
1921
+ }
1922
+ const a = Math.random().toString(36).substring(2, 15);
1923
+ const b = Math.random().toString(36).substring(2, 10);
1924
+ return a + b;
1925
+ }
1910
1926
  function toErrorMessage(error) {
1911
1927
  if (error instanceof Error)
1912
1928
  return error.message;
1913
1929
  return String(error);
1914
1930
  }
1915
- var MAX_FRAME_SIZE;
1931
+ var MAX_FRAME_SIZE, DEFAULT_DISCONNECT_TIMEOUT;
1916
1932
  var init_constants = __esm(() => {
1917
1933
  MAX_FRAME_SIZE = 1024 * 1024;
1934
+ DEFAULT_DISCONNECT_TIMEOUT = 5 * 60 * 1000;
1918
1935
  });
1919
1936
 
1920
1937
  // ../core/src/index.ts
@@ -1922,6 +1939,7 @@ var init_src = __esm(() => {
1922
1939
  init_types();
1923
1940
  init_protocol();
1924
1941
  init_constants();
1942
+ init_middleware();
1925
1943
  });
1926
1944
 
1927
1945
  // src/commands/bundle.ts
@@ -1945,6 +1963,20 @@ function collectFiles(dir, prefix = "") {
1945
1963
  }
1946
1964
  return files;
1947
1965
  }
1966
+ function detectPackageManager(dir) {
1967
+ for (let current = dir, parent = "";parent !== current; current = path.dirname(current)) {
1968
+ parent = current;
1969
+ if (fs.existsSync(path.join(current, "bun.lockb")) || fs.existsSync(path.join(current, "bun.lock")))
1970
+ return "bun";
1971
+ if (fs.existsSync(path.join(current, "pnpm-lock.yaml")))
1972
+ return "pnpm";
1973
+ if (fs.existsSync(path.join(current, "yarn.lock")))
1974
+ return "yarn";
1975
+ if (fs.existsSync(path.join(current, "package-lock.json")))
1976
+ return "npm";
1977
+ }
1978
+ return "npm";
1979
+ }
1948
1980
  var bundleCommand;
1949
1981
  var init_bundle = __esm(() => {
1950
1982
  init_esm();
@@ -1958,7 +1990,9 @@ var init_bundle = __esm(() => {
1958
1990
  if (options.build) {
1959
1991
  console.log(" Running build command...");
1960
1992
  if (fs.existsSync(path.join(sourceDir, "package.json"))) {
1961
- execSync("bun run build", { cwd: sourceDir, stdio: "ignore" });
1993
+ const pm = detectPackageManager(sourceDir);
1994
+ console.log(` Using ${pm} to build...`);
1995
+ execSync(`${pm} run build`, { cwd: sourceDir, stdio: "inherit" });
1962
1996
  } else {
1963
1997
  console.warn(" No package.json found, skipping build");
1964
1998
  }
@@ -2009,12 +2043,13 @@ var init_simulate = __esm(() => {
2009
2043
  const bots = [];
2010
2044
  const intervals = [];
2011
2045
  for (let i = 0;i < count; i++) {
2046
+ const secret = generateId();
2012
2047
  const ws = new WebSocket(url);
2013
2048
  ws.addEventListener("open", () => {
2014
2049
  console.log(`[Bot ${i}] Connected`);
2015
2050
  ws.send(JSON.stringify({
2016
2051
  type: MessageTypes.JOIN,
2017
- payload: { name: `Bot ${i}`, avatar: "bot" }
2052
+ payload: { name: `Bot ${i}`, avatar: "bot", secret }
2018
2053
  }));
2019
2054
  const id = setInterval(() => {
2020
2055
  if (ws.readyState === WebSocket.OPEN) {
@@ -2026,6 +2061,16 @@ var init_simulate = __esm(() => {
2026
2061
  }, interval + Math.random() * 500);
2027
2062
  intervals.push(id);
2028
2063
  });
2064
+ ws.addEventListener("message", (event) => {
2065
+ try {
2066
+ const msg = JSON.parse(typeof event.data === "string" ? event.data : event.data.toString());
2067
+ if (msg.type === MessageTypes.WELCOME) {
2068
+ console.log(`[Bot ${i}] Joined as ${msg.payload.playerId}`);
2069
+ } else if (msg.type === MessageTypes.ERROR) {
2070
+ console.error(`[Bot ${i}] Server error: ${msg.payload.message}`);
2071
+ }
2072
+ } catch {}
2073
+ });
2029
2074
  ws.addEventListener("close", () => {
2030
2075
  console.log(`[Bot ${i}] Disconnected`);
2031
2076
  });
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.6",
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.7.0",
40
40
  "commander": "^12.0.0"
41
41
  },
42
42
  "devDependencies": {