mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
feat(cli): ✨ Add new CLI commands, move to project root
This commit is contained in:
parent
68f16f9101
commit
fc06b35c09
21 changed files with 332 additions and 67 deletions
94
cli/commands/emoji/add.ts
Normal file
94
cli/commands/emoji/add.ts
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
import { Args } from "@oclif/core";
|
||||
import chalk from "chalk";
|
||||
import { BaseCommand } from "~/cli/base";
|
||||
import { db } from "~drizzle/db";
|
||||
|
||||
export default class EmojiAdd extends BaseCommand<typeof EmojiAdd> {
|
||||
static override args = {
|
||||
shortcode: Args.string({
|
||||
description: "Shortcode of the emoji",
|
||||
required: true,
|
||||
}),
|
||||
file: Args.string({
|
||||
description: "Path to the image file (can be an URL)",
|
||||
required: true,
|
||||
}),
|
||||
};
|
||||
|
||||
static override description = "Adds a new emoji";
|
||||
|
||||
static override examples = ["<%= config.bin %> <%= command.id %>"];
|
||||
|
||||
static override flags = {};
|
||||
|
||||
public async run(): Promise<void> {
|
||||
const { flags, args } = await this.parse(EmojiAdd);
|
||||
|
||||
// Check if emoji already exists
|
||||
const existingEmoji = await db.query.Emojis.findFirst({
|
||||
where: (Emojis, { eq }) => eq(Emojis.shortcode, args.shortcode),
|
||||
});
|
||||
|
||||
if (existingEmoji) {
|
||||
this.log(
|
||||
`${chalk.red("✗")} Emoji with shortcode ${chalk.red(
|
||||
args.shortcode,
|
||||
)} already exists`,
|
||||
);
|
||||
this.exit(1);
|
||||
}
|
||||
|
||||
/* if (!user) {
|
||||
this.log(
|
||||
`${chalk.red("✗")} Failed to create user ${chalk.red(
|
||||
args.username,
|
||||
)}`,
|
||||
);
|
||||
this.exit(1);
|
||||
}
|
||||
|
||||
!flags.format &&
|
||||
this.log(
|
||||
`${chalk.green("✓")} Created user ${chalk.green(
|
||||
user.getUser().username,
|
||||
)} with id ${chalk.green(user.id)}`,
|
||||
);
|
||||
|
||||
this.log(
|
||||
formatArray(
|
||||
[user.getUser()],
|
||||
[
|
||||
"id",
|
||||
"username",
|
||||
"displayName",
|
||||
"createdAt",
|
||||
"updatedAt",
|
||||
"isAdmin",
|
||||
],
|
||||
flags.format as "json" | "csv" | undefined,
|
||||
),
|
||||
);
|
||||
|
||||
if (!flags.format && !flags["set-password"]) {
|
||||
const link = "";
|
||||
|
||||
this.log(
|
||||
flags.format
|
||||
? link
|
||||
: `\nPassword reset link for ${chalk.bold(
|
||||
`@${user.getUser().username}`,
|
||||
)}: ${chalk.underline(chalk.blue(link))}\n`,
|
||||
);
|
||||
|
||||
const qrcode = renderUnicodeCompact(link, {
|
||||
border: 2,
|
||||
});
|
||||
|
||||
// Pad all lines of QR code with spaces
|
||||
|
||||
this.log(` ${qrcode.replaceAll("\n", "\n ")}`);
|
||||
} */
|
||||
|
||||
this.exit(0);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue