Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
latest
gramiojs/autoloadAutoload commands plugin for GramIO
This package works with Node.js, Deno, BunIt is unknown whether this package works with Cloudflare Workers



JSR Score
100%
Published
11 months ago (1.1.0)
@gramio/autoload
Autoload commands plugin for GramIO with Bun.build
support.
Usage
Important
Please read about Lazy-load plugins
Register the plugin
// index.ts import { Bot } from "gramio"; import { autoload } from "@gramio/autoload"; const bot = new Bot(process.env.TOKEN as string) .extend(await autoload()) .onStart(console.log); bot.start(); export type BotType = typeof bot;
Create command
// commands/command.ts import type { BotType } from ".."; export default (bot: BotType) => bot.command("start", (context) => context.send("hello!"));
Options
Key | Type | Default | Description |
---|---|---|---|
pattern? | string | string[] | "**/*.{ts,js,cjs,mjs}" | Glob patterns |
path? | string | "./commands" | Path to the folder |
import? | string | (file: any) => string | "default" | Import a specific export from a file |
failGlob? | boolean | true | Throws an error if no matches are found |
skipImportErrors? | boolean | false | Skip imports where needed export not defined |
onLoad? | (params: { absolute: string; relative: string }) => unknown | Hook that is called when loading a file | |
onFinish? | (paths: { absolute: string; relative: string }[]) => unknown; | Hook that is called after loading all files | |
fdir? | Options | Options to configure fdir | |
picomatch? | PicomatchOptions | Options to configure picomatch |
Bun build usage
You can use this plugin with Bun.build
, thanks to esbuild-plugin-autoload!
// @filename: build.ts import { autoload } from "esbuild-plugin-autoload"; // default import also supported await Bun.build({ entrypoints: ["src/index.ts"], target: "bun", outdir: "out", plugins: [autoload("./src/commands")], }).then(console.log);
Then, build it with bun build.ts
and run with bun out/index.ts
.
Bun compile usage
You can bundle and then compile it into a single executable binary file
import { autoload } from "esbuild-plugin-autoload"; // default import also supported await Bun.build({ entrypoints: ["src/index.ts"], target: "bun", outdir: "out", plugins: [autoload("./src/commands")], }).then(console.log); await Bun.$`bun build --compile out/index.js`;
Warning
You cannot use it in bun build --compile
mode without extra step (Feature issue)
Built and signed on
GitHub Actions
Add Package
deno add jsr:@gramio/autoload
Import symbol
import * as autoload from "@gramio/autoload";
Import directly with a jsr specifier
import * as autoload from "jsr:@gramio/autoload";
Add Package
pnpm i jsr:@gramio/autoload
pnpm dlx jsr add @gramio/autoload
Import symbol
import * as autoload from "@gramio/autoload";
Add Package
yarn add jsr:@gramio/autoload
yarn dlx jsr add @gramio/autoload
Import symbol
import * as autoload from "@gramio/autoload";
Add Package
vlt install jsr:@gramio/autoload
Import symbol
import * as autoload from "@gramio/autoload";
Add Package
npx jsr add @gramio/autoload
Import symbol
import * as autoload from "@gramio/autoload";
Add Package
bunx jsr add @gramio/autoload
Import symbol
import * as autoload from "@gramio/autoload";