An open API service indexing awesome lists of open source software.

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

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

[![GitHub](https://img.shields.io/github/license/fearandesire/saph-convert?style=flat-square)](https://github.com/fearandesire/cli/blob/main/LICENSE.md)
[![npm](https://img.shields.io/npm/v/saph-convert?color=crimson&logo=npm&style=flat-square)](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