Skip to main content
Home

Built and signed on GitHub Actions

Autoload commands plugin for GramIO

This package works with Node.js, Deno, BunIt is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
JSR Score
100%
Published
11 months ago (1.1.0)

@gramio/autoload

npm JSR JSR Score

Autoload commands plugin for GramIO with Bun.build support.

Usage

full example

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)

Read more

Built and signed on
GitHub Actions

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@gramio/autoload

Import symbol

import * as autoload from "@gramio/autoload";
or

Import directly with a jsr specifier

import * as autoload from "jsr:@gramio/autoload";

Add Package

pnpm i jsr:@gramio/autoload
or (using pnpm 10.8 or older)
pnpm dlx jsr add @gramio/autoload

Import symbol

import * as autoload from "@gramio/autoload";

Add Package

yarn add jsr:@gramio/autoload
or (using Yarn 4.8 or older)
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";