Package Exports
- @sapphire/cli
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@sapphire/cli) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Features
- Written in TypeScript
- Generate Sapphire projects easily
- Generate components (commands, listeners, etc.)
- Create your own templates for components
Usage
$ npm install -g @sapphire/cli
$ sapphire [command]
running command...
$ sapphire --version
0.0.1
$ sapphire help [command]
USAGE
$ sapphire COMMAND
...Commands
sapphire new|n [options] [name]
creates a new Sapphire project
Usage: $ sapphire new|n [options] [name]
creates a new Sapphire project
Arguments:
name project name
Options:
-v, --verbose
-h, --help display help for commandSee code: src/commands/new.ts
sapphire generate|g <component> <name>
generate a component (command, listener, etc.)
Usage: $ sapphire generate|g [options] <component> <name>
generates a component/piece
Arguments:
component component/piece name
name file name
Options:
-h, --help display help for commandSee code: src/commands/generate.ts
sapphire help [command]
display help for sapphire
Usage: $ sapphire help [command]
display help for command
Arguments:
command command nameComponent Templates
Default component templates are:
- command
- listener
- argument
- precondition
If you want to make your own templates, or want to override the default ones, read the next section.
Custom component templates
Enable custom component templates
In the .sapphirerc.json file:
- Set
customFileTemplates.enabledtotrue - Set
customFileTemplates.locationto the name of the directory you want to store your templates in.
Example:
{
"customFileTemplates": {
"enabled": true,
"location": "templates"
}
}Create custom component templates
- Create a file like this in your custom template directory
<templateName>.<language>.sapphire(e.gcommand.ts.sapphire). If you make its name same as one of the default template's, your template will override the default one. - Template's have 2 parts, config and the template, separated with
---. - We first need to type the config:
{
"category": "commands"
}category is the category of that template, CLI uses it to know where to create the component by finding that category's location from the locations field in .sapphirerc.json. You can create your own categories. Default categories are: commands, listeners, arguments, preconditions. This example uses the commands category.
- Now we add the separator.
{
"category": "commands"
}
---- And the last part, we add the template.
{
"category": "commands"
}
---
import { ApplyOptions } from '@sapphire/decorators';
import { MyExtendedCommand } from './somewhere';
import { Message } from 'discord.js';
@ApplyOptions<MyExtendedCommand.Options>({
description: 'A basic command'
})
export class {{name}}Command extends MyExtendedCommand {
public async run(message: Message) {
return message.channel.send('Hello world!');
}
}
If you look at the name of the class, you will see it includes {{name}}, this is the component's name and it is replaced with that name when creating the component. For example: if we created this component with the name HelloWorld, the name of the exported class would be HelloWorldCommand. It is not required but if you need it, this is how it's done.
- And now you can create component with your template
sapphire generate <templateName> <componentName>Buy us some doughnuts
Sapphire Community is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!
We accept donations through Open Collective, Ko-fi, Paypal, Patreon and GitHub Sponsorships. You can use the buttons below to donate through your method of choice.
| Donate With | Address |
|---|---|
| Open Collective | Click Here |
| Ko-fi | Click Here |
| Patreon | Click Here |
| PayPal | Click Here |
Contributors β¨
Thanks goes to these wonderful people (emoji key):
Jeroen Claassens π» π π π π |
Enes GenΓ§ π» π π π€ |
This project follows the all-contributors specification. Contributions of any kind welcome!
