Skip to content

feat: ignore字体集的生成文件,并在编译时自动生成#8264

Open
M1LKT wants to merge 2 commits into
AstrBotDevs:masterfrom
M1LKT:feat/ignoreFontsFile
Open

feat: ignore字体集的生成文件,并在编译时自动生成#8264
M1LKT wants to merge 2 commits into
AstrBotDevs:masterfrom
M1LKT:feat/ignoreFontsFile

Conversation

@M1LKT
Copy link
Copy Markdown
Contributor

@M1LKT M1LKT commented May 20, 2026

Modifications / 改动点

优化:MDI 图标字体按需裁剪并自动生成

subset-mdi-font.mjs 脚本从手动触发改为构建流程自动执行,同时排除生成文件避免污染仓库。

改动内容:

  1. package.json

    • dev / build / build-stage / build-prod / preview 五个脚本均加入 node scripts/subset-mdi-font.mjs 前置步骤
    • 每次启动开发服务器或构建时,自动扫描源码中使用的 mdi-* 图标,裁剪字体文件并输出到 src/assets/mdi-subset/
  2. .gitignore

    • 新增 src/assets/mdi-subset/ 规则,忽略脚本生成的 woff2 / woff / css 文件
  3. 仓库状态

    • 执行 git rm -r --cached src/assets/mdi-subset/ 将已追踪的字体文件移出暂存区,避免重复提交生成文件

效果:

  • 每次 pnpm dev / pnpm build 时自动生成最新的图标子集,无需手动运行 subset-icons

  • 生成文件不进入 git,仓库保持干净

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

验证步骤:

  1. 运行 pnpm dev,观察控制台输出是否包含字体裁剪日志:
image 2. 运行 `pnpm build`,确认构建流程包含字体生成步骤且最终产物中包含裁剪后的字体文件 3. 检查 git status,确认 `src/assets/mdi-subset/` 不出现在变更列表中

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了"验证步骤"和"运行截图"

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Automate generation of the MDI icon font subset during dashboard dev and build workflows and stop tracking the generated assets in version control.

New Features:

  • Run the MDI subset generation script automatically before dashboard dev, build, and preview commands.

Enhancements:

  • Exclude the generated MDI subset assets directory from git to keep the repository free of build artifacts.

Chores:

  • Remove previously committed MDI subset CSS assets from the repository.

@auto-assign auto-assign Bot requested review from Fridemn and Soulter May 20, 2026 13:38
@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. area:webui The bug / feature is about webui(dashboard) of astrbot. labels May 20, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • The subset-mdi-font.mjs invocation is duplicated across multiple scripts; consider extracting it into a separate npm script or using predev/prebuild lifecycle hooks to keep the scripts DRY and easier to maintain.
  • Running subset-mdi-font.mjs before vite preview may be redundant if preview is only serving the build output; you might want to restrict font generation to dev and build-related scripts to avoid unnecessary work in preview.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `subset-mdi-font.mjs` invocation is duplicated across multiple scripts; consider extracting it into a separate npm script or using `predev`/`prebuild` lifecycle hooks to keep the scripts DRY and easier to maintain.
- Running `subset-mdi-font.mjs` before `vite preview` may be redundant if preview is only serving the build output; you might want to restrict font generation to `dev` and build-related scripts to avoid unnecessary work in preview.

## Individual Comments

### Comment 1
<location path="dashboard/package.json" line_range="7-12" />
<code_context>
+    "dev": "node scripts/subset-mdi-font.mjs && vite --host",
</code_context>
<issue_to_address>
**suggestion:** Avoid duplicating the subset-mdi invocation across multiple scripts by leveraging npm pre-scripts or a shared script.

The `node scripts/subset-mdi-font.mjs` call is now duplicated in several scripts (`dev`, `build*`, `preview`). To keep this DRY and easier to maintain, consider using npm lifecycle hooks (e.g. `prebuild`, `prebuild-stage`, etc.) or a shared script like `"subset-icons"` that other scripts invoke (e.g. `npm run subset-icons && vite ...`). This avoids inconsistent updates if the subset command changes later.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread dashboard/package.json Outdated
Comment on lines +7 to +12
"dev": "node scripts/subset-mdi-font.mjs && vite --host",
"build:t2i-shiki-runtime": "node scripts/build-t2i-shiki-runtime.mjs",
"build": "vue-tsc --noEmit && vite build",
"build-stage": "vue-tsc --noEmit && vite build --base=/vue/free/stage/",
"build-prod": "vue-tsc --noEmit && vite build --base=/vue/free/",
"preview": "vite preview --port 5050",
"build": "node scripts/subset-mdi-font.mjs && vue-tsc --noEmit && vite build",
"build-stage": "node scripts/subset-mdi-font.mjs && vue-tsc --noEmit && vite build --base=/vue/free/stage/",
"build-prod": "node scripts/subset-mdi-font.mjs && vue-tsc --noEmit && vite build --base=/vue/free/",
"preview": "node scripts/subset-mdi-font.mjs && vite preview --port 5050",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Avoid duplicating the subset-mdi invocation across multiple scripts by leveraging npm pre-scripts or a shared script.

The node scripts/subset-mdi-font.mjs call is now duplicated in several scripts (dev, build*, preview). To keep this DRY and easier to maintain, consider using npm lifecycle hooks (e.g. prebuild, prebuild-stage, etc.) or a shared script like "subset-icons" that other scripts invoke (e.g. npm run subset-icons && vite ...). This avoids inconsistent updates if the subset command changes later.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request automates the Material Design Icons (MDI) subset generation by integrating the generation script into the project's build and development workflows within package.json. It also updates .gitignore to exclude the generated assets. Feedback suggests that the dev script lacks Hot Module Replacement (HMR) for new icons, which may lead to confusion unless a Vite plugin is used or the server is restarted. Additionally, running the subset script during the preview command is identified as redundant since that command serves already built assets from the dist directory.

Comment thread dashboard/package.json
"scripts": {
"dev": "vite --host",
"subset-icons": "node scripts/subset-mdi-font.mjs",
"dev": "node scripts/subset-mdi-font.mjs && vite --host",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

dev 脚本中自动运行字体子集生成脚本虽然实现了自动化,但由于它只在开发服务器启动时执行一次,因此不支持热更新(HMR)。如果开发者在开发过程中新增了图标,这些图标将不会被包含在生成的子集中,直到手动重启开发服务器。这可能会导致开发时的困惑(如图标不显示)。建议在文档中明确说明此限制,或者考虑将其实现为 Vite 插件以监听文件变化并自动重新生成。

Comment thread dashboard/package.json Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:webui The bug / feature is about webui(dashboard) of astrbot. size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant