@ayanaware/bento

中文文档
1.0.0-rc.29发布于 2022/06/05MITTypeScriptESM + CJS近 30 天下载 9145

Modular runtime framework designed to solve complex tasks

原始使用文档
文档目录9 节
  1. The Goal
  2. The Promises
  3. Stuff Bento does
  4. Stuff Bento does not do
  5. Install
  6. What is a Bento Component?
  7. How to use Bento
  8. Bento Application
  9. Testimonials

@ayanaware/bento npm (scoped) Discord install size

Documentation • Examples

Bento is an application framework designed to help with creating and maintaing modular projects.

The Goal

Assist developers with common patterns used in modular codebases. While staying out of their way, minimal headaches, minimal debt.

The Promises

  • Readability First: Bento's Code should be well documented and easy to read.
  • Limited Dependencies: Solve problems by writing code, Not adding dependencies.
  • Tests all the things: Catch some bugs before they get out.

Stuff Bento does

  • Plugable application framework.
  • Featuring: Components, Events, Plugins, Properties, Variables
  • Component and Plugin lifecycle management
  • Consistent Component API
  • Defines strict, opinionated, rules

Stuff Bento does not do

  • Bento should work in the browser, but it is not a website framework.

Install

yarn add @ayanaware/bento
npm i @ayanaware/bento

What is a Bento Component?

Bento indroduces a concept of components. Components are logical chunks of code that all work together to provide your application to the world.

All components recieve their own ComponentAPI instance. The Component API is consistent across all components and provides a way for components to speak to eachother. As well as many other "Quality of life" features. Such as: Dependency resolution and injection, Variable injection, component events, and more!

As a rule of thumb, components should not take on more then required. (IE: instead of having one component for connecting to Discord and processing messages. Have two, one for the connection and emitting the message events, and one that handles messages)

Here is a very basic example of a Bento component:

import { Component, ComponentAPI } from '@ayanaware/bento';

export class Basic implements Component {
    // required for all components, must be unique
    public name = 'Basic';
    // this property becomes available after onLoad see ComponentAPI for more info
    public api!: ComponentAPI;

    // Optionally define other components we depend upon
    // Some decorators auto append to this array such as @Subscribe
    public dependencies: Array<Component> = [];

    // Lifecycle event, called right before component fully loaded
    public async onLoad() {
        console.log('Hello world!');
    }

    // Lifecycle event, called right before component is unloaded
    public async onUnload() {
        console.log('Goodbye world!');
    }
}

A runnable version of this example is available on Gitlab

How to use Bento

Getting started with Bento is pretty simple. First import and initilize Bento and any plugins you wish to use. Then simply add the plugins to Bento. The below example assumes you have a directory called "components" in the same directory (relative) to it.

import { Bento, EntityType, FSEntityLoader } from '@ayanaware/bento';

// Create a Bento instance
const bento = new Bento();

// Anonymous async function so we can use await
(async () => {
    // Create FSEntityLoader
    // NOTE: Keep in mind all FSEntityLoader does is
    // find components in a path, instantiates them and
    // calls Bento.addComponent() behind the scenes
    const fsel = new FSEntityLoader();
    await fsel.addDirectory([__dirname, 'components'], EntityType.COMPONENT);

    // Apply plugin to Bento.
    await bento.addPlugin(fsloader);

    // Verify that Application looks good to continue
    await bento.verify();
})().catch(e => {
    console.error(`Error while starting Bento:\n${e}`);
    process.exit(1);
});

Bento Application

Application makes it even easier to bootstrap Bento Applications. Behind the scenes FSEntityLoader is used to find plugins and components in ./plugins and ./components respectively. Variables are also loaded using VariableFileLoader from ../env.example.json and ../env.json. Finally bento instance and afformentioned plugins are completely exposed in cases when you need them.

import { Application } from '@ayanaware/bento';

// Bento Application Helper
const app = new Application();

// Anonymous async function so we can use await
(async () => {
    // Default Variables are loaded from `../env.example.json`
    // Variables are loaded from `../env.json`
    // Plugins in `./plugins` are instantiated and added to Bento
    // Components in `./components` are instantiated and added to Bento
    // All this behavior can be modifed using cfg in Application constructor
    await app.start();

    // Must be called, calls `bento.verify();` and returns `ApplicationState`
    await app.verify();
})().catch(e => {
    console.error(`Error while starting Application:\n${e}`);
    process.exit(1);
});

More examples available here

Testimonials

Below are a few people raving about using Bento!

So far Bento has been nothing but good memories in production, it does its job very very well, we've scaled to 40k Guilds, 10 shards a cluster and Bento makes life with scaling less scary. -- Plexi Development (captchabot.xyz)

版本与发布记录

@ayanaware/bento 共发布 30 个版本,首次发布于 2019/11/16;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.0-rc.29latest2022/06/054 年前
1.0.0-rc.282022/06/054 年前
1.0.0-rc.272022/06/054 年前
1.0.0-rc.262021/10/065 年前
1.0.0-rc.252021/09/085 年前
1.0.0-rc.242021/09/045 年前

关于 @ayanaware/bento 的常见问题

@ayanaware/bento 是什么?

Modular runtime framework designed to solve complex tasks

如何安装 @ayanaware/bento?

在项目目录运行 npm install @ayanaware/bento,或使用 pnpm add / yarn add / bun add。

@ayanaware/bento 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ayanaware/bento 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@ayanaware/bento 可以商用吗?

@ayanaware/bento 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ayanaware/bento 的下载量有多少?

根据 npm 官方下载统计,@ayanaware/bento 在 2026/10/08 – 2026/11/06 这 30 天内被下载 9,145 次,日均约 305 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ayanaware/bento 还在维护吗?

最新版本 1.0.0-rc.29 发布于 2022/06/05(4 年前);至今共发布 30 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/11/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。