Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ permissions:
contents: read

env:
# 与便携包编译参数保持一致,复用测试和构建缓存。
# 与发布包编译参数保持一致,复用测试和构建缓存。
CGO_ENABLED: '0'
GOFLAGS: -trimpath

Expand Down Expand Up @@ -61,9 +61,9 @@ jobs:
node-version: 22
cache: npm
cache-dependency-path: web/package-lock.json
- name: 构建便携包
- name: 构建发布包
run: node build.mjs
- name: 上传便携包
- name: 上传发布包
uses: actions/upload-artifact@v4
with:
name: easybotce-${{ runner.os }}-${{ runner.arch }}
Expand All @@ -85,8 +85,8 @@ jobs:
env:
MYSQL_ROOT_PASSWORD: root-test-password
MYSQL_DATABASE: easybot_test
MYSQL_USER: easybot
MYSQL_PASSWORD: easybot-test-password
MYSQL_USER: EasybotCE
MYSQL_PASSWORD: EasybotCE-test-password
ports:
- 3306:3306
options: >-
Expand All @@ -102,7 +102,7 @@ jobs:
cache-dependency-path: go.sum
- name: Test against MySQL
env:
EASYBOT_TEST_DATABASE_DSN: mysql://easybot:easybot-test-password@127.0.0.1:3306/easybot_test
EASYBOT_TEST_DATABASE_DSN: mysql://EasybotCE:EasybotCE-test-password@127.0.0.1:3306/easybot_test
# 其他包由跨平台任务覆盖;外部数据库测试每次连接新测试库执行。
run: go test -count=1 -vet=off ./internal/store

Expand All @@ -113,12 +113,12 @@ jobs:
image: postgres:18.6
env:
POSTGRES_DB: easybot_test
POSTGRES_USER: easybot
POSTGRES_PASSWORD: easybot-test-password
POSTGRES_USER: EasybotCE
POSTGRES_PASSWORD: EasybotCE-test-password
ports:
- 5432:5432
options: >-
--health-cmd="pg_isready -h 127.0.0.1 -U easybot -d easybot_test"
--health-cmd="pg_isready -h 127.0.0.1 -U EasybotCE -d easybot_test"
--health-interval=3s
--health-timeout=5s
--health-retries=40
Expand All @@ -130,5 +130,5 @@ jobs:
cache-dependency-path: go.sum
- name: Test against PostgreSQL
env:
EASYBOT_TEST_DATABASE_DSN: postgres://easybot:easybot-test-password@127.0.0.1:5432/easybot_test?sslmode=disable
EASYBOT_TEST_DATABASE_DSN: postgres://EasybotCE:EasybotCE-test-password@127.0.0.1:5432/easybot_test?sslmode=disable
run: go test -count=1 -vet=off ./internal/store
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ token.txt
.env
.env.*
!.env.example
/Easybot

# Go outputs
/bin/
Expand All @@ -15,6 +16,8 @@ token.txt
# Frontend outputs and local tooling state
/web/node_modules/
/web/dist/
/internal/webui/dist/*
!/internal/webui/dist/placeholder.txt
/web/.vscode/
/web/.idea/
/.idea/
Expand All @@ -33,3 +36,8 @@ token.txt

# CodeBuddy
.codebuddy/

# Python test/build artifacts (reference tooling only)
__pycache__/
*.py[cod]
!/internal/webui/dist/placeholder.txt
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ CI 在 PR 标题、正文说明或新增 commit 标题不含汉字时,通过

## 开发与验证

当前实现位于 仓库根目录包含 Go 后端(`cmd/easybot`、`internal`)和 Vue 管理台(`web`)。使用 Go 1.24+ 与 Node.js 20.19+,依赖以 `go.mod/go.sum` 和 `package-lock.json` 为准。详细运行方法见 [开发说明](docs/开发说明.md)。
当前实现位于 仓库根目录包含 Go 后端(`cmd/EasybotCE`、`internal`)和 Vue 管理台(`web`)。使用 Go 1.24+ 与 Node.js 20.19+,依赖以 `go.mod/go.sum` 和 `package-lock.json` 为准。详细运行方法见 [开发说明](docs/开发说明.md)。

后端在仓库根目录执行 `go test ./...` 和 `go vet ./...`;前端在 `web` 执行 `npm ci` 和 `npm run build`。涉及 MySQL/PostgreSQL 时使用空的专用测试库执行集成检查。Windows 启动改动需要验证从其他工作目录启动 exe,并在验证后停止服务。

Expand Down
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# EasybotCE Core

EasybotCE 的主程序,使用 Go 提供管理 API、Vue 3 提供网页管理台,默认使用 SQLite 保存数据。便携包包含程序和页面资源,解压后即可运行。
EasybotCE 的主程序,使用 Go 提供管理 API、Vue 3 提供网页管理台,默认使用 SQLite 保存数据。发布包包含程序和页面资源,解压后即可运行。

## 文档导航

Expand All @@ -23,24 +23,24 @@ EasybotCE 的主程序,使用 Go 提供管理 API、Vue 3 提供网页管理

## 快速开始

1. 从 [发布版本](https://github.com/EasybotCE/Core/releases) 下载适合当前系统的便携压缩包。
2. 解压到可写目录,保留包内的 `web` 目录。
1. 从 [发布版本](https://github.com/EasybotCE/Core/releases) 下载适合当前系统的发布包。
2. 解压到可写目录,页面资源已内置于程序中。
3. Windows 双击 `easybotce.exe`;Linux 在解压目录运行 `./easybotce`,缺少执行权限时先执行 `chmod +x easybotce`。
4. 浏览器打开 `http://127.0.0.1:5001`,运行期间保持程序窗口或终端打开。

默认仅监听本机回环地址,无需注册或登录。普通用户不需要安装 Go、Node.js、数据库服务器,也不需要额外启动前端服务。
默认管理服务与 Bridge 均绑定全部网卡。浏览器访问管理台时必须输入配置中的管理密码;普通用户不需要安装 Go、Node.js、数据库服务器,也不需要额外启动前端服务。外网使用前请配置防火墙,并建议为管理服务启用 HTTPS。

Windows 双击启动失败时会显示错误原因,按回车后关闭窗口;从已有终端或自动化任务启动时,程序直接返回错误码。

## 配置与登录

程序在首次启动时于程序目录创建 `config.json`,并生成 12 位数字管理密码写入配置;该密码仅在首次启动控制台显示一次。修改配置后需重启。配置结构为 `server`、`bridge`、`database`、`auth` 和 `logging`,完整示例见 [config.example.json](internal/config/config.example.json)。`EASYBOT_CONFIG` 可指定配置文件,环境变量可覆盖对应设置。
程序在首次启动时于程序目录创建 `config.json`,并生成 12 位数字管理密码写入配置;该密码仅在首次启动控制台显示一次。SQLite 数据库及其父目录(默认 `appdata/easybot.db`)也会在启动时自动创建。管理页面静态资源随发布程序构建并内置;直接源码运行时需先构建前端资源。修改配置后需重启。配置结构为 `server`、`bridge`、`database`、`auth` 和 `logging`,完整示例见 [config.example.json](internal/config/config.example.json)。`EASYBOT_CONFIG` 可指定配置文件,环境变量可覆盖对应设置。

默认仅监听本机,无需登录。改为非本机监听后使用配置中的 `auth.password` 登录;密码以明文保存在配置文件中,请限制文件访问权限。通过公网传输凭据时建议配置 HTTPS。旧版 .NET 格式配置不会被静默覆盖,需迁移到新结构。
默认监听 `0.0.0.0:5001`,本机及外网访问均需使用 `auth.password` 登录;Bridge 默认独立监听 `0.0.0.0:26991`。密码以明文保存在配置文件中,请限制文件访问权限。外网访问前配置防火墙,仅开放必要端口;通过公网传输凭据时建议配置 HTTPS。旧版 .NET 格式配置不会被静默覆盖,需迁移到新结构。

## 升级与原版迁移

升级前停止程序,备份并保留 `config.json` 和 `appdata`,再替换程序与 `web` 页面资源。已有 CE 数据库也可通过 `EASYBOT_SQLITE_PATH` 指定路径继续使用。
升级前停止程序,备份并保留 `config.json` 和 `appdata`,再替换程序。已有 CE 数据库也可通过 `EASYBOT_SQLITE_PATH` 指定路径继续使用。

原版 `.NET appsettings.json` 与 `token.txt` 不再作为 CE 启动配置;请按示例迁移监听地址、数据库、日志和 Bridge 设置。复制启动配置不会导入原版数据库、适配器或插件数据,原版数据库需要单独迁移。

Expand All @@ -52,17 +52,17 @@ Windows 双击启动失败时会显示错误原因,按回车后关闭窗口;
node build.mjs
```

脚本自动安装前端依赖、构建页面、编译程序并生成便携包:Windows 输出 `release/easybotce-windows-amd64.zip`,Linux 输出对应平台的 `.tar.gz`;本地编译程序同时保存在 `bin`。
脚本自动安装前端依赖、构建页面、编译程序并生成发布包:Windows 输出 `release/easybotce-windows-amd64.zip`,Linux 输出对应平台的 `.tar.gz`;本地编译程序同时保存在 `bin`。

手动运行、热更新和测试命令见 [开发说明](docs/开发说明.md),前端开发见 [管理台说明](web/README.md)。CI 包含跨平台测试、静态检查、便携包构建和数据库集成测试。
手动运行、热更新和测试命令见 [开发说明](docs/开发说明.md),前端开发见 [管理台说明](web/README.md)。CI 包含跨平台测试、静态检查、发布包构建和数据库集成测试。

贡献者和开发代理须遵守 [贡献规范](CONTRIBUTING.md)。建议使用中文说明 PR 和提交;中文 CI 仅提醒,不阻断合并。使用 AI 辅助贡献时须披露工具及用途,详细要求见贡献规范。

## 项目结构

| 路径 | 内容 |
| --- | --- |
| `cmd/easybot/` | 守护进程及管理 Web 服务入口 |
| `cmd/EasybotCE` | 守护进程及管理 Web 服务入口 |
| `internal/` | 配置、存储、适配器、运行日志和版本化管理 API |
| `web/` | Vue 3、TypeScript、Tailwind CSS v4 管理台 |
| `.github/workflows/` | CI 工作流 |
Expand All @@ -72,3 +72,7 @@ node build.mjs
## 许可证与署名

本仓库使用 [CC BY-NC 4.0(`CC-BY-NC-4.0`)](https://creativecommons.org/licenses/by-nc/4.0/) 许可证,该许可证不允许商业使用。分享或改编时,请注明 EasybotCE 及本仓库来源,附上许可证链接、标明改动,并保留已有作者、版权和许可声明。详见 [署名说明](AUTHORS.md)。

### Minecraft Bridge

Core 提供独立 Bridge WebSocket 服务端(默认端口 26991),不包含 Minecraft 插件本体。可使用授权范围内已有的 EasyBot 插件连接;协议兼容、安全开关、TLS 和真实验收边界见 [`docs/BRIDGE_MCDR.md`](docs/BRIDGE_MCDR.md)。
42 changes: 17 additions & 25 deletions build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,36 @@ import { fileURLToPath } from 'node:url'
const root = dirname(fileURLToPath(import.meta.url))
const env = { ...process.env, CGO_ENABLED: '0' }

function run(command, args, cwd) {
function run(label, command, args, cwd) {
if (process.platform === 'win32' && command === 'npm') {
// npm 的参数均为下方固定命令,不拼接用户输入。
args = ['/d', '/s', '/c', `npm ${args.join(' ')}`]
command = 'cmd.exe'
}
console.log(`▶ ${label}`)
const started = Date.now()
const result = spawnSync(command, args, {
cwd,
env,
stdio: 'inherit',
})
if (result.error || result.status !== 0) {
throw new Error(`${command} 执行失败(${result.status ?? result.error?.message})`)
throw new Error(`${label}失败(${result.status ?? result.error?.message})`)
}
console.log(`✓ ${label}(${((Date.now() - started) / 1000).toFixed(1)} 秒)`)
}

run('npm', ['ci', '--prefer-offline', '--no-audit', '--no-fund'], join(root, 'web'))
run('npm', ['run', 'build'], join(root, 'web'))
if (process.env.EASYBOT_SKIP_NPM_CI !== '1') {
run('安装前端依赖', 'npm', ['ci', '--prefer-offline', '--no-audit', '--no-fund'], join(root, 'web'))
} else {
console.log('跳过依赖安装(EASYBOT_SKIP_NPM_CI=1)')
}
run('构建前端', 'npm', ['run', 'build'], join(root, 'web'))
// 将页面资源嵌入 Go 程序,避免运行目录缺失 web/dist 导致管理台不可用。
cpSync(join(root, 'web', 'dist'), join(root, 'internal', 'webui', 'dist'), { recursive: true })
mkdirSync(join(root, 'bin'), { recursive: true })
const target = env.GOOS || (process.platform === 'win32' ? 'windows' : process.platform)
const output = join('bin', target === 'windows' ? 'easybotce.exe' : 'easybotce')
run('go', ['build', '-trimpath', '-o', output, './cmd/easybot'], root)
run('编译 Go 程序', 'go', ['build', '-trimpath', '-o', output, './cmd/EasybotCE'], root)

const arch = env.GOARCH || ({ x64: 'amd64', ia32: '386' }[process.arch] || process.arch)
const name = `easybotce-${target}-${arch}`
Expand All @@ -39,33 +47,17 @@ try {
copyFileSync(join(root, output), join(folder, target === 'windows' ? 'easybotce.exe' : 'easybotce'))
copyFileSync(join(root, 'internal', 'config', 'config.example.json'), join(folder, 'config.json'))
chmodSync(join(folder, 'config.json'), 0o600)
cpSync(join(root, 'web', 'dist'), join(folder, 'web', 'dist'), { recursive: true })
for (const file of ['LICENSE', 'AUTHORS.md']) copyFileSync(join(root, file), join(folder, file))
writeFileSync(join(folder, '使用说明.txt'), [
'EasybotCE 便携包',
target === 'windows' ? '解压到可写目录后,双击 easybotce.exe 启动,运行期间保持窗口打开。' : '解压后运行 ./easybotce;若缺少执行权限,先执行 chmod +x easybotce。',
'浏览器打开 http://127.0.0.1:5001,默认本机监听直接进入管理台,无需注册或登录。',
'修改同目录 config.json 中 server.address 可调整管理服务监听地址,保存后重启生效。',
'Bridge 配置位于 bridge.address;Web 管理界面和后台服务由同一守护进程运行。',
'旧版 .NET 配置需手动迁移;旧字段会被识别并拒绝加载。',
'非本地监听可直接使用 HTTP;网页只需输入 config.json 中的管理密码,不需要用户名或独立 API Key。',
'首次启动生成 12 位数字管理密码并写入 config.json,仅在控制台显示一次。',
'双击启动失败时,窗口显示错误原因并等待回车关闭。',
'请保留包内 web 目录。运行数据自动保存到 appdata 目录。',
'升级前停止程序、备份并保留 config.json 和 appdata,再替换程序和 web 目录。',
'默认使用 SQLite,无需安装开发环境或数据库服务器。',
].join('\n') + '\n', 'utf8')

if (target === 'windows' && process.platform === 'win32') {
env.EASYBOT_PACKAGE_DIR = folder
env.EASYBOT_ARCHIVE_PATH = join(release, `${name}.zip`)
run('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', 'Compress-Archive -Path (Join-Path $env:EASYBOT_PACKAGE_DIR "*") -DestinationPath $env:EASYBOT_ARCHIVE_PATH -Force'], root)
run('压缩 Windows 发布包', 'powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', 'Compress-Archive -Path (Join-Path $env:EASYBOT_PACKAGE_DIR "*") -DestinationPath $env:EASYBOT_ARCHIVE_PATH -Force'], root)
} else {
run('tar', ['-czf', join(release, `${name}.tar.gz`), '-C', folder, '.'], root)
run('压缩发布包', 'tar', ['-czf', join(release, `${name}.tar.gz`), '-C', folder, '.'], root)
}
} finally {
// 只删除本次新建的临时打包目录,已解压的程序及数据不受影响。
if (dirname(folder) !== release) throw new Error('无效的清理目录')
rmSync(folder, { recursive: true, force: true })
}
console.log(`便携包已生成:${release}`)
console.log(`发布包已生成:${release}`)
14 changes: 14 additions & 0 deletions cmd/EasybotCE/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"os"

"easybot/internal/bootstrap"
)

func main() {
if code := bootstrap.Run(); code != 0 {
bootstrap.WaitAfterFailure()
os.Exit(code)
}
}
121 changes: 0 additions & 121 deletions cmd/easybot/console.go

This file was deleted.

Loading
Loading