diff --git a/benchmarks/fetch.ts b/benchmarks/fetch.ts deleted file mode 100644 index 0e5798f5..00000000 --- a/benchmarks/fetch.ts +++ /dev/null @@ -1,18 +0,0 @@ -const timeBefore = performance.now(); - -const requests: Promise[] = []; - -// Repeat 1000 times -for (let i = 0; i < 1000; i++) { - requests.push( - fetch("https://mastodon.social", { - method: "GET", - }), - ); -} - -await Promise.all(requests); - -const timeAfter = performance.now(); - -console.log(`Time taken: ${timeAfter - timeBefore}ms`); diff --git a/benchmarks/posting.ts b/benchmarks/posting.ts deleted file mode 100644 index 8337712e..00000000 --- a/benchmarks/posting.ts +++ /dev/null @@ -1 +0,0 @@ -// diff --git a/benchmarks/timelines.ts b/benchmarks/timelines.ts deleted file mode 100644 index 9e00fc2c..00000000 --- a/benchmarks/timelines.ts +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Usage: TOKEN=your_token_here bun benchmark:timeline - */ - -import chalk from "chalk"; -import { config } from "config-manager"; - -const token = process.env.TOKEN; -const requestCount = Number(process.argv[2]) || 100; - -if (!token) { - console.log( - `${chalk.red( - "✗", - )} No token provided. Provide one via the TOKEN environment variable.`, - ); - process.exit(1); -} - -const fetchTimeline = () => - fetch(new URL("/api/v1/timelines/home", config.http.base_url), { - headers: { - Authorization: `Bearer ${token}`, - }, - }).then((res) => res.ok); - -const timeNow = performance.now(); - -const requests = Array.from({ length: requestCount }, () => fetchTimeline()); - -Promise.all(requests) - .then((results) => { - const timeTaken = performance.now() - timeNow; - if (results.every((t) => t)) { - console.log(`${chalk.green("✓")} All requests succeeded`); - } else { - console.log( - `${chalk.red("✗")} ${ - results.filter((t) => !t).length - } requests failed`, - ); - } - console.log( - `${chalk.green("✓")} ${ - requests.length - } requests fulfilled in ${chalk.bold( - (timeTaken / 1000).toFixed(5), - )}s`, - ); - }) - .catch((err) => { - console.log(`${chalk.red("✗")} ${err}`); - process.exit(1); - }); diff --git a/build.ts b/build.ts index 78f0c69b..aa1610f2 100644 --- a/build.ts +++ b/build.ts @@ -10,7 +10,6 @@ await $`rm -rf dist && mkdir dist`; await Bun.build({ entrypoints: [ "index.ts", - "cli.ts", "cli/index.ts", // Force Bun to include endpoints ...Object.values(routes), diff --git a/cli/base.ts b/cli/base.ts index b01bd5be..f4b143c9 100644 --- a/cli/base.ts +++ b/cli/base.ts @@ -1,14 +1,11 @@ import { Command } from "@oclif/core"; +import { setupDatabase } from "~drizzle/db"; +import { consoleLogger } from "@loggers"; export abstract class BaseCommand extends Command { protected async init(): Promise { await super.init(); - const { setupDatabase } = await import("~drizzle/db"); - const { consoleLogger } = await import("@loggers"); - - (async () => { - await setupDatabase(consoleLogger, false); - })(); + await setupDatabase(consoleLogger, false); } } diff --git a/cli/classes.ts b/cli/classes.ts index 0d55ddd8..13c36c70 100644 --- a/cli/classes.ts +++ b/cli/classes.ts @@ -2,7 +2,7 @@ import { Args, type Command, Flags, type Interfaces } from "@oclif/core"; import chalk from "chalk"; import { and, eq, like } from "drizzle-orm"; import { Users } from "~drizzle/schema"; -import type { User } from "~packages/database-interface/user"; +import { User } from "~packages/database-interface/user"; import { BaseCommand } from "./base"; export type FlagsType = Interfaces.InferredFlags< @@ -81,8 +81,6 @@ export abstract class UserFinderCommand< ? this.args.identifier.replace(/\*/g, "%") : this.args.identifier; - const { User } = await import("~packages/database-interface/user"); - return await User.manyFromSql( and( this.flags.type === "id" diff --git a/cli/index.ts b/cli/index.ts index ee0cfd48..ae5affd2 100644 --- a/cli/index.ts +++ b/cli/index.ts @@ -1,13 +1,15 @@ +import { execute } from "@oclif/core"; import EmojiAdd from "./commands/emoji/add"; import UserCreate from "./commands/user/create"; import UserDelete from "./commands/user/delete"; import UserList from "./commands/user/list"; import UserReset from "./commands/user/reset"; +// Use "explicit" oclif strategy to avoid issues with oclif's module resolver and bundling export const commands = { - "user list": UserList, - "user delete": UserDelete, - "user create": UserCreate, - "user reset": UserReset, - "emoji add": EmojiAdd, + "user:list": UserList, + "user:delete": UserDelete, + "user:create": UserCreate, + "user:reset": UserReset, + "emoji:add": EmojiAdd, }; diff --git a/cli/theme.json b/cli/theme.json index 4d77c5ec..02c01a6b 100644 --- a/cli/theme.json +++ b/cli/theme.json @@ -5,7 +5,7 @@ "dollarSign": "white", "flag": "white", "flagDefaultValue": "blue", - "flagOptions": "white", + "flagOptions": "green", "flagRequired": "red", "flagSeparator": "white", "sectionDescription": "white", diff --git a/entrypoint.sh b/entrypoint.sh index 31dcb813..43738e19 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -18,7 +18,7 @@ case "$1" in "cli") # Start the CLI shift 1 - bun run ./cli.js "$@" + bun run ./cli/index.js "$@" ;; *) # Run custom commands