Skip to content

CLI tool to effortlessly convert Sapphire.js JavaScript commands to TypeScript

License

Notifications You must be signed in to change notification settings

fearandesire/saph-convert

A CLI tool to convert Sapphire Framework command files from JavaScript to TypeScript.

GitHub npm

Table of Contents

Description

✨ Transform your Sapphire commands from JS to TS with this simple CLI tool. Convert single files or entire directories with ease.

Features

  • Convert Sapphire JS commands to TS
  • Transform single command files or directories
  • Easily replace the original JS file in the same process

Installation

npm install -g saph-convert

Or directly use the CLI tool directly via npx

npx saph-convert <command> [options]

Basic usage

Convert single file:

npx saph-convert cf <file> [ouptutDirectory] [options]

Convert all files in a directory:

npx saph-convert cdir <directory> [ouptutDirectory] [options]

Global 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.

Commands

  • cf <file> [ouptutDirectory] [options]: Convert a single file.
  • cdir <directory> [ouptutDirectory] [options]: Convert all files in a directory.

Conversion Examples

## Convert a single file
npx saph-convert cf ./commands/ping.js
## Convert all files in a directory
npx saph-convert cdir ./commands

Input

// 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!');
	}
}

Output

Back to top

// 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!');
	}
}

Contributors

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!

About

CLI tool to effortlessly convert Sapphire.js JavaScript commands to TypeScript

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •