https://github.com/fearandesire/saph-convert
CLI tool to effortlessly convert Sapphire.js JavaScript commands to TypeScript
https://github.com/fearandesire/saph-convert
cli discord discordjs javascript js-to-ts node nodejs sapphirejs typescript
Last synced: 4 months ago
JSON representation
CLI tool to effortlessly convert Sapphire.js JavaScript commands to TypeScript
- Host: GitHub
- URL: https://github.com/fearandesire/saph-convert
- Owner: fearandesire
- License: mit
- Created: 2024-06-21T01:21:46.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-02-08T01:11:58.000Z (4 months ago)
- Last Synced: 2025-02-08T01:38:00.660Z (4 months ago)
- Topics: cli, discord, discordjs, javascript, js-to-ts, node, nodejs, sapphirejs, typescript
- Language: TypeScript
- Homepage:
- Size: 48.9 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# [saph-convert](https://github.com/fearandesire/saph-convert)
**A CLI tool to convert Sapphire Framework command files from JavaScript to TypeScript.**
[](https://github.com/fearandesire/cli/blob/main/LICENSE.md)
[](https://www.npmjs.com/package/saph-convert)## Table of Contents
- [Table of Contents](#table-of-contents)
- [Description](#description)
- [Features](#features)
- [Usage](#usage)
- [Global Options](#global-options)
- [Commands](#commands)
- [Conversion Exemples](#conversion-exemples)
- [Input](#input)
- [Output](#output)
- [Contributors](#contributors)## Description
✨ Transform your [Sapphire](https://sapphirejs.dev/) 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
```bash
npm install -g saph-convert
```Or directly use the CLI tool directly via `npx`
```bash
npx saph-convert [options]
```### Basic usage
Convert single file:
```bash
npx saph-convert cf [ouptutDirectory] [options]
```Convert all files in a directory:
```bash
npx saph-convert cdir [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 [ouptutDirectory] [options]`: Convert a single file.
- `cdir [ouptutDirectory] [options]`: Convert all files in a directory.## Conversion Examples
```bash
## Convert a single file
npx saph-convert cf ./commands/ping.js
## Convert all files in a directory
npx saph-convert cdir ./commands
```### Input
```javascript
// 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](#table-of-contents)
```typescript
// src/commands/ping.ts
import { Command } from '@sapphire/framework';
import { ApplyOptions } from '@sapphire/decorators';@ApplyOptions({ 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][contributing] before making a pull request.
Thank you to all the people who already contributed to this project!
[contributing]: https://github.com/fearandesire/saph-convert/blob/main/.github/CONTRIBUTING.md
[toc]: #table-of-contents