npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bettergi/cli

v0.2.12

Published

构建 BetterGI 脚本的脚手架

Readme

本项目是一个为Better Genshin Impact 设计的 JavaScript 脚本开发脚手架,旨在帮助开发者快速创建脚本项目。

快速开始

使用 @bettergi/create-script 快速创建 JavaScript 脚本项目:

使用 npm

npm create @bettergi/script@latest

使用 pnpm

pnpm create @bettergi/script@latest

工具特点

  • 提供几乎零配置的开发体验,打包生成符合 BetterGI 规范的脚本文件。

  • 自动检测 BetterGI 的脚本目录,并输出构建结果,便于开发与调试。

    自动读取注册表项 HKCU\SOFTWARE\Classes\BetterGI\shell\open\command 获取 BetterGI 的安装位置,并调试输出到 User/JsScript 目录下。

  • 支持引入第三方外部模块,借助 npm 生态提升开发效率。

    import { merge } from "lodash-es";
    
    const obj1 = { a: 1, b: { c: 2 } };
    const obj2 = { b: { d: 3 }, e: 4 };
    const merged = merge({}, obj1, obj2);
  • 支持 ESM 代码分割,打包生成符合 BetterGI 规范的外部库(要求 bgi_version0.54.0)。

    • 默认代码分割:将 node_modules 外部库分别打包成单独的chunk。
    📁 MyScript
     ├─ 📄 main.js
     ├─ 📄 manifest.json
     ├─ 📄 settings.json
     ├─ 📁 libs
     │  ├─ 📄 @bettergi+utils.js
     │  └─ 📄 rolldown-runtime.js
    • 自定义代码分割:src 目录下的 js/ts 按照原目录结构打包。
    chunkGroups: [
      {
        test: /src[\\/](.*)\.(js|ts)$/,
        name: moduleId => moduleId.match(/src[\\/](.*)\.(js|ts)$/)?.[1]
      }
    ]
  • 支持使用 import 导入文本文件(.txt.json),大文本/预定义数据与脚本逻辑分离。

    import bar from "./bar.json";
    import foo from "./foo.txt";
    
    log.info(`${foo}`);
    log.info(`${JSON.stringify(bar)}`);
  • 支持使用 import 导入图片文件(.png.jpg.jpeg.bmp.tiff.webp),自动导入为 Mat 对象实例。

    • 导入为 Mat 对象。
    <!-- 示例代码 -->
    import mat from "./foo.png";
    
    const ir = captureGameRegion();
    const ro = RecognitionObject.templateMatch(mat);
    const result = ir.find(ro);
    <!-- 构建结果 -->
    var mat_foo = file.readImageMatSync("assets/foo-d3036d20a653.png");
    
    var ir = captureGameRegion();
    var ro = RecognitionObject.templateMatch(mat_foo);
    var result = ir.find(ro);
    • 导入为 Mat 对象(懒加载)。
    <!-- 示例代码 -->
    import matFn from "./foo.png?lazy";
    
    const ir = captureGameRegion();
    const ro = RecognitionObject.templateMatch(matFn());
    const result = ir.find(ro);
    <!-- 构建结果 -->
    function readImageMatSync_foo() {
      return file.readImageMatSync("assets/foo-d3036d20a653.png");
    }
    
    var ir = captureGameRegion();
    var ro = RecognitionObject.templateMatch(readImageMatSync_foo());
    var result = ir.find(ro);
    • 获取构建后的文件所在位置。
    <!-- 示例代码 -->
    import path from "./foo.png?path";
    
    log.info(path);
    <!-- 构建结果 -->
    var path_foo = "assets/foo-d3036d20a653.png";
    
    log.info(path_foo);

用法

手动安装

npm install --save-dev @bettergi/cli @bettergi/types

创建配置文件

在工作目录下创建一个 bettergi.config.ts (或 .js, .cjs, .mjs) 配置文件。

import { defineConfig } from "@bettergi/cli";

export default defineConfig({
  // 构建配置
  // main: "main.ts",
  // assetsDir: "assets",
  outDir: "dist",
  // additionalFiles: ["README.md", "LICENSE"], // 需要额外打包的文件
  // codeSplitting: true,
  // minify: false,
  // banner: true,

  // 清单信息
  manifest: {},

  // UI配置
  settings: [],

  // 调试配置
  bettergi: {}
});

创建 TypeScript 配置文件

在工作目录下创建一个 tsconfig.json 配置文件。其中,@bettergi/types 为 BetterGI 暴露的 js 接口类型声明; @bettergi/cli/loaders 为自定义 Loaders 的模块声明,如 import xxx from "./foo.png"。

{
  "include": ["main.ts", "./src/**/*.ts"],
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "moduleResolution": "bundler",
    "esModuleInterop": true,
    "declaration": false,
    "lib": ["ESNext"],
    "skipLibCheck": true,
    "strict": true,
    "alwaysStrict": false,
    "removeComments": false,
    "noEmitOnError": true,
    "types": ["@bettergi/types", "@bettergi/cli/loaders"]
  }
}

BetterGI 使用 ClearScript 的 V8 引擎来执行脚本,多数新特性支持较为良好。若环境出现特性兼容性问题,请自行修改 target 等配置。

开发模式

npx bettergi-cli --watch

构建脚本

npx bettergi-cli