Skip to content

Commit

Permalink
chore: prepare release (#40)
Browse files Browse the repository at this point in the history
* chore: bump deps

* fix: optional chaining

* chore: stuff

* chore: update readme

* chore: bump package and workflows
  • Loading branch information
killbasa authored Dec 10, 2023
1 parent 60eb5b0 commit 5c60f7a
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 294 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ jobs:

steps:
- name: Check out Git repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Create archive
uses: thedoctor0/zip-release@0.7.1
uses: thedoctor0/zip-release@0.7.6
with:
type: "zip"
filename: "release.zip"

- name: Create release
uses: ncipollo/release-action@v1.12.0
uses: ncipollo/release-action@v1.13.0
with:
artifacts: "release.zip"
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -46,12 +46,12 @@ jobs:

steps:
- name: Check out Git repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up NodeJS
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
cache: yarn

- name: Install dependencies
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@kbotdev/eslint-config": "^1.1.1",
"@kbotdev/prettier-config": "^1.0.1",
"@kbotdev/ts-config": "^1.0.1",
"@types/node": "^20.10.3",
"@types/node": "^20.10.4",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"concurrently": "^8.2.2",
Expand All @@ -34,10 +34,10 @@
"gen-esm-wrapper": "^1.1.3",
"husky": "^8.0.3",
"lint-staged": "^15.2.0",
"prettier": "^3.1.0",
"prettier": "^3.1.1",
"tsx": "^4.6.2",
"turbo": "^1.11.0",
"typescript": "^5.3.2"
"turbo": "^1.11.1",
"typescript": "^5.3.3"
},
"lint-staged": {
"*.{mjs,cjs,js,ts}": [
Expand Down
16 changes: 10 additions & 6 deletions packages/modules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ This plugin allows developers to seperate commands and features into distinct mo
npm install @kbotdev/plugin-modules @sapphire/framework discord.js
```

## Subcommand plugin compatibility

If you are already using the [Subcommand plugin](https://github.com/sapphiredev/plugins/tree/main/packages/subcommands), make sure you do **NOT** manually register the subcommand plugin. This plugin already registers it due to the dependency.

## Examples

Work in progress
An example implementation can be found in KBot's repo: https://github.com/KBot-discord/KBot/tree/main/apps/bot/src/modules

## Usage

Expand All @@ -43,7 +47,7 @@ import { Module, type IsEnabledContext, type ModuleError } from '@kbotdev/plugin
import type { Piece, Result } from '@sapphire/framework';

export class ExampleModule extends Module {
public constructor(context: Module.Context, options: Piece.Options) {
public constructor(context: Module.LoaderContext, options: Piece.Options) {
super(context, {
...options,
// The name of the module that a user would see
Expand All @@ -59,8 +63,8 @@ export class ExampleModule extends Module {
// Or async
public async isEnabled(context: IsEnabledContext): Promise<boolean> {
try {
await SomethingThatMightError();
return true;
const data = await getGuildSettings(context.guild?.id);
return data.enabled;
} catch {
return false;
}
Expand Down Expand Up @@ -89,15 +93,15 @@ import type { Command } from '@sapphire/framework';
import type { ExampleModule } from '../modules/ExampleModule';

export class ExampleCommand extends ModuleCommand<ExampleModule> {
public constructor(context: ModuleCommand.Context, options: Command.Options) {
public constructor(context: ModuleCommand.LoaderContext, options: Command.Options) {
super(context, {
...options,

// Using the same name registered earlier
module: 'ExampleModule',
description: 'An awesome description.',

// A precondition that calls the 'isEnabled' function
// A precondition that calls the 'isEnabled' function on ExampleModule
preconditions: ['ModuleEnabled']
});
}
Expand Down
6 changes: 3 additions & 3 deletions packages/modules/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kbotdev/plugin-modules",
"version": "2.1.0",
"version": "3.0.0",
"description": "Module plugin for the Sapphire Framework",
"author": "@kbotdev",
"license": "MIT",
Expand Down Expand Up @@ -59,12 +59,12 @@
},
"devDependencies": {
"@favware/rollup-type-bundler": "^3.2.1",
"@sapphire/framework": "^5.0.2",
"@sapphire/framework": "^5.0.4",
"concurrently": "^8.2.2",
"discord.js": "^14.14.1",
"tsup": "^8.0.1",
"tsx": "^4.6.2",
"typescript": "^5.3.2"
"typescript": "^5.3.3"
},
"engines": {
"node": ">=18.x"
Expand Down
23 changes: 19 additions & 4 deletions packages/modules/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
import 'tslib';
import '@sapphire/plugin-subcommands/register';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
import type { Module } from './lib/structures/Module';
import type { ModuleStore } from './lib/structures/ModuleStore';
import type { ModulePluginOptions } from './lib/types/ModulePluginOptions';

export * from './lib/errors';
export * from './lib/structures';
export * from './lib/types';
// Errors
export * from './lib/errors/ModuleError';
export * from './lib/errors/ModuleIdentifiers';
export * from './lib/errors/ModuleNotFoundError';

// Structures
export * from './lib/structures/Module';
export * from './lib/structures/ModuleCommand';
export * from './lib/structures/ModuleStore';
export * from './lib/structures/ModuleSubcommand';

// Types
export * from './lib/types/ModuleCommandTypes';
export * from './lib/types/ModuleEvents';
export * from './lib/types/ModulePluginOptions';
export * from './lib/types/ModuleTypes';

export { loadListeners } from './listeners/_load';
export { loadPreconditions } from './preconditions/_load';

declare module '@sapphire/pieces' {
interface StoreRegistryEntries {
Expand Down
3 changes: 0 additions & 3 deletions packages/modules/src/lib/errors/index.ts

This file was deleted.

6 changes: 3 additions & 3 deletions packages/modules/src/lib/structures/Module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { IsEnabledContext, ModuleOptions } from '../types/ModuleTypes';
* @example
* ```ts
* export class ExampleModule extends Module {
* public constructor(context: Module.Context, options: Piece.Options) {
* public constructor(context: Module.LoaderContext, options: Piece.Options) {
* super(context, {
* ...options,
* fullName: 'Example Module',
Expand All @@ -39,7 +39,7 @@ export abstract class Module extends Piece {
*/
public readonly description: string | undefined;

public constructor(context: Module.Context, options: Module.Options) {
public constructor(context: Module.LoaderContext, options: Module.Options) {
super(context, options);

this.fullName = options.fullName;
Expand Down Expand Up @@ -81,5 +81,5 @@ export abstract class Module extends Piece {

export namespace Module {
export type Options = ModuleOptions;
export type Context = Piece.Context;
export type LoaderContext = Piece.LoaderContext;
}
4 changes: 0 additions & 4 deletions packages/modules/src/lib/structures/index.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/modules/src/lib/types/index.ts

This file was deleted.

17 changes: 17 additions & 0 deletions packages/modules/src/listeners/_load.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ModuleListener as PluginModuleMissingEnabledHandler } from './moduleMissingEnabledHandler';
import { ModuleListener as PluginModuleError } from './moduleError';
import { container } from '@sapphire/pieces';

export function loadListeners(): void {
void container.stores.loadPiece({
name: 'PluginModuleError',
piece: PluginModuleError,
store: 'listeners'
});

void container.stores.loadPiece({
name: 'PluginModuleMissingEnabledHandler',
piece: PluginModuleMissingEnabledHandler,
store: 'listeners'
});
}
10 changes: 10 additions & 0 deletions packages/modules/src/preconditions/_load.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ModuleEnabledPrecondition } from './ModuleEnabled';
import { container } from '@sapphire/pieces';

export function loadPreconditions(): void {
void container.stores.loadPiece({
name: 'ModuleEnabled',
piece: ModuleEnabledPrecondition,
store: 'preconditions'
});
}
12 changes: 5 additions & 7 deletions packages/modules/src/register.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import './index';

import { loadListeners, loadPreconditions } from './index';
import { ModuleStore } from './lib/structures/ModuleStore';
import { Plugin, SapphireClient, postInitialization, preInitialization } from '@sapphire/framework';
import { join } from 'path';

export class ModulesPlugin extends Plugin {
public static [preInitialization](this: SapphireClient): void {
Expand All @@ -14,13 +12,13 @@ export class ModulesPlugin extends Plugin {
}

public static [postInitialization](this: SapphireClient): void {
const { options, stores } = this;
const { options } = this;

if (options.modules?.enabled !== false) {
stores.get('preconditions').registerPath(join(__dirname, 'preconditions'));
loadPreconditions();

if (options.modules.loadModuleErrorListeners !== false) {
stores.get('listeners').registerPath(join(__dirname, 'listeners'));
if (options.modules?.loadModuleErrorListeners !== false) {
loadListeners();
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"target": "ES2022",
"importHelpers": true,
"noEmitHelpers": true,
"incremental": false
"incremental": false,
"noEmit": true
}
}
Loading

0 comments on commit 5c60f7a

Please sign in to comment.