✨ Transform your Sapphire commands from JS to TS with this simple CLI tool. Convert single files or entire directories with ease.
- Convert Sapphire JS commands to TS
- Transform single command files or directories
- Easily replace the original JS file in the same process
npm install -g saph-convert
Or directly use the CLI tool directly via npx
npx saph-convert <command> [options]
Convert single file:
npx saph-convert cf <file> [ouptutDirectory] [options]
Convert all files in a directory:
npx saph-convert cdir <directory> [ouptutDirectory] [options]
-o, --overwrite
: Overwrite existing TypeScript file(s) if they exist. Default: Enable.-r, --replace
: Replace original JavaScript file(s) with converted TypeScript file(s). Default: Enable.
cf <file> [ouptutDirectory] [options]
: Convert a single file.cdir <directory> [ouptutDirectory] [options]
: Convert all files in a directory.
## Convert a single file
npx saph-convert cf ./commands/ping.js
## Convert all files in a directory
npx saph-convert cdir ./commands
// src/commands/ping.js
const { ApplicationCommandRegistry, Command } = require('@sapphire/framework');
class UserCommand extends Command {
/*
* @param {Command.LoaderContext} registry
*/
constructor(context) {
super(context, {
name: 'ping',
description: 'Ping the bot to check if it is alive.'
});
}
/**
* @param {ApplicationCommandRegistry} registry
*/
registerApplicationCommands(registry) {
registry.registerChatInputCommand((builder) => builder.setName(this.name).setDescription(this.description));
}
/**
* @param {Command.ChatInputCommandInteraction} interaction
*/
async chatInputRun(interaction) {
return interaction.reply('Pong!');
}
}
// src/commands/ping.ts
import { Command } from '@sapphire/framework';
import { ApplyOptions } from '@sapphire/decorators';
@ApplyOptions<Command.Options>({ description: 'Ping the bot to check if it is alive.' })
export class UserCommand extends Command {
public override registerApplicationCommands(registry: ApplicationCommandRegistry) {
registry.registerChatInputCommand((builder) => builder.setName(this.name).setDescription(this.description));
}
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
return interaction.reply('Pong!');
}
}
Please make sure to read this Contributing Guide before making a pull request.
Thank you to all the people who already contributed to this project!