This commit is contained in:
jacob
2024-04-28 13:48:50 -05:00
parent 91b3768e37
commit 30230d49c3
6 changed files with 35 additions and 28 deletions

View File

@@ -15,13 +15,10 @@ import { PayloadType, PluginType } from './structures';
import assert from 'assert';
import type { Payload } from '../types/utility';
//function wrappers for empty ok / err
export const ok = /* @__PURE__*/ () => Ok.EMPTY;
export const err = /* @__PURE__*/ () => Err.EMPTY;
export const ok = () => Ok.EMPTY;
export const err = () => Err.EMPTY;
export function partitionPlugins(
arr: (AnyEventPlugin | AnyCommandPlugin)[] = [],
): [Plugin[], Plugin[]] {
export function partitionPlugins(arr: (AnyEventPlugin | AnyCommandPlugin)[] = []): [Plugin[], Plugin[]] {
const controlPlugins = [];
const initPlugins = [];

View File

@@ -8,6 +8,10 @@ import type { Module } from '../types/core-modules';
import { existsSync } from 'fs';
import type { Logging } from './contracts/logging';
export const parseCallsite = (fpath: string) => {
return parse(fpath.replace(/file:\\?/, "")).name;
}
export const shouldHandle = (path: string, fpath: string) => {
const file_name = fpath+extname(path);
let newPath = join(dirname(path), file_name)

View File

@@ -1,8 +1,6 @@
import { ClientEvents } from 'discord.js';
import { EventType } from '../core/structures';
import type {
AnyEventPlugin,
} from '../types/core-plugin';
import type { AnyEventPlugin, } from '../types/core-plugin';
import type {
CommandModule,
EventModule,
@@ -11,18 +9,27 @@ import type {
} from '../types/core-modules';
import { partitionPlugins } from './_internal';
import type { Awaitable } from '../types/utility';
import callsites from 'callsites';
import * as Files from './module-loading'
import path, { basename } from 'path';
import * as Id from './id'
/**
* @since 1.0.0 The wrapper function to define command modules for sern
* @param mod
*/
export function commandModule(mod: InputCommand): CommandModule {
const [onEvent, plugins] = partitionPlugins(mod.plugins);
const initCallsite = callsites()[1].getFileName()?.replace(/file:\\?/, "");
if(!initCallsite) throw Error("initCallsite is null");
const filename = Files.parseCallsite(initCallsite);
mod.name ??= filename;
const id = Id.create(mod.name, mod.type)
return {
...mod,
__id: id,
onEvent,
plugins,
} as CommandModule;
} as unknown as CommandModule;
}
/**
* @since 1.0.0
@@ -31,6 +38,9 @@ export function commandModule(mod: InputCommand): CommandModule {
*/
export function eventModule(mod: InputEvent): EventModule {
const [onEvent, plugins] = partitionPlugins(mod.plugins);
const initCallsite = callsites()[1].getFileName();
console.log(initCallsite?.replace(/file:\\?/, ""))
return {
...mod,
plugins,

View File

@@ -25,8 +25,7 @@ export type Config <T extends (keyof Dependencies)[]> =
* Create a Presence module which **MUST** be put in a file called presence.(language-extension)
* adjacent to the file where **Sern.init** is CALLED.
*/
export function module<T extends (keyof Dependencies)[]>(conf: Config<T>)
{ return conf; }
export const module = <T extends (keyof Dependencies)[]>(conf: Config<T>) => conf;
/**