Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(themes): output multiple themes #3020

Merged
merged 1 commit into from
Feb 27, 2025

Conversation

oasis-cloud
Copy link
Collaborator

@oasis-cloud oasis-cloud commented Feb 26, 2025

Summary by CodeRabbit

  • 新功能
    • 引入项目定制的动态样式生成,自动导入相应资源。
  • 重构
    • 优化样式构建流程,移除了旧的复制方法,采用更灵活的生成策略。
  • 样式
    • 为默认主题和暗黑主题新增字体引用,提升视觉一致性。
  • 文档
    • 更新了主题文件路径,调整为 CSS 格式以匹配新的构建方式。

Copy link

coderabbitai bot commented Feb 26, 2025

Walkthrough

本次变更主要针对构建 CSS 的脚本及相关文档。移除了原有的 copyStyles 函数,并引入了 generateAllStyles 函数,在 buildAllCSSbuildThemeCSS 中新增了基于 projectID 环境变量的动态处理逻辑。文档中主题文件的路径从 SCSS 文件更新为 CSS 文件,同时对主题文件新增了字体导入。对 replace-css-var.js 中的字符串处理做了调整以移除无用的字体导入语句。

Changes

文件 变化描述
scripts/build-taro.mjs, scripts/build.mjs 移除 copyStyles,新增 generateAllStyles;更新 buildAllCSSbuildThemeCSS 逻辑,实现根据 projectID 动态生成 SCSS 导入和动态输出文件名
scripts/replace-css-var.js 在读取主题内容后增加两处 .replace() 调用,移除 @import "./jd-font";@import './jd-font'; 字符串
src/packages/configprovider/doc.en-US.md, .../doc.md, .../doc.taro.md, .../doc.zh-TW.md 更新主题文件路径,由 .scss 修改为 .css
src/styles/theme-dark.scss, src/styles/theme-default.scss 在文件开头新增 @import './jd-font'; 导入语句

Sequence Diagram(s)

sequenceDiagram
    participant BuildScript
    participant SCSSHandler
    participant FileSystem

    BuildScript->>SCSSHandler: 调用 generateAllStyles()
    alt projectID 存在
        SCSSHandler->>FileSystem: 动态导入项目相关变量文件
    else projectID 不存在
        SCSSHandler->>FileSystem: 导入默认变量文件
    end
    SCSSHandler->>BuildScript: 返回生成的 SCSS 导入列表
Loading
sequenceDiagram
    participant BuildScript
    participant ThemeCollector
    participant FileSystem

    BuildScript->>ThemeCollector: 调用 buildThemeCSS()
    alt projectID 存在
        ThemeCollector->>FileSystem: 收集项目主题文件(默认及暗黑主题)
    else projectID 不存在
        ThemeCollector->>FileSystem: 收集默认主题文件
    end
    ThemeCollector->>BuildScript: 返回动态命名的主题文件
Loading

Possibly related PRs

Suggested reviewers

  • xiaoyatong
  • irisSong

Poem

小兔子轻跳过代码田,
新增函数如春风拂面。
旧式复制已成往事,
动态导入妙不可言。
主题变换星光点点,
代码世界欢歌笑语,
欢迎采纳这灵动改动! 🐇✨

Tip

CodeRabbit's docstrings feature is now available as part of our Pro Plan! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added action:review This PR needs more reviews (less than 2 approvals) 3.x Target branch 3.x labels Feb 26, 2025
Copy link

codecov bot commented Feb 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.82%. Comparing base (cb7c2c2) to head (87c6d4b).
Report is 7 commits behind head on feat_v3.x.

Additional details and impacted files
@@            Coverage Diff             @@
##           feat_v3.x    #3020   +/-   ##
==========================================
  Coverage      85.82%   85.82%           
==========================================
  Files            281      281           
  Lines          18494    18494           
  Branches        2803     2803           
==========================================
  Hits           15873    15873           
  Misses          2616     2616           
  Partials           5        5           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
scripts/build-taro.mjs (1)

271-289: 主题配置支持多项目,但需检查扩展性

这里通过 glob 搜索 theme-*.scss 并根据 projectID 映射到 defaultdark。若后续需要支持更多主题名称或维度(例如 light, blue, 等),建议预留扩展性,或增加错误提示(例如对应文件未找到时提示)。

scripts/build.mjs (3)

219-241: 确认多主题需求的场景,避免丢弃其他主题文件。
当前逻辑仅在不存在 projectID 时,全部主题文件都会被编译;当存在 projectID 时,则只编译默认主题和暗黑主题(如果文件名匹配 <projectID><projectID>-dark)。这可能会忽略其他并存的主题文件,建议确认这种单一场景下的处理逻辑能否满足全部业务需求,或考虑允许一次生成多个定制主题。


255-255: 注意输出文件重名冲突风险。
将所有打包出的文件都命名为 [name].css 可能在多项目场景下出现文件名冲突,建议在必要时添加哈希或额外前缀后缀以避免覆盖。

- assetFileNames: '[name].css',
+ assetFileNames: '[name].[hash].css',

384-385: 将 Lottie 资源重复拷贝到 es 与 cjs 目录,可能增加发布包体积。
此操作会导致相同的动画资源在 es 与 cjs 两个目录均占空间,若资源体积较大,建议考虑共用同一路径或单独拆分到可共享的公共目录,再按需引用。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cb7c2c2 and 87c6d4b.

📒 Files selected for processing (9)
  • scripts/build-taro.mjs (5 hunks)
  • scripts/build.mjs (6 hunks)
  • scripts/replace-css-var.js (1 hunks)
  • src/packages/configprovider/doc.en-US.md (1 hunks)
  • src/packages/configprovider/doc.md (1 hunks)
  • src/packages/configprovider/doc.taro.md (1 hunks)
  • src/packages/configprovider/doc.zh-TW.md (1 hunks)
  • src/styles/theme-dark.scss (1 hunks)
  • src/styles/theme-default.scss (1 hunks)
✅ Files skipped from review due to trivial changes (5)
  • src/styles/theme-default.scss
  • src/packages/configprovider/doc.zh-TW.md
  • src/styles/theme-dark.scss
  • src/packages/configprovider/doc.md
  • src/packages/configprovider/doc.en-US.md
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: test
🔇 Additional comments (7)
scripts/replace-css-var.js (1)

25-25: 移除字体引入需谨慎验证

当前通过两次 replacejd-font 的导入语句去除,确保最终编译后的主题内容不包含 jd-font。请确认对应字体已在其他地方正确引入或已不再使用,避免造成可见的样式缺失或字体问题。

src/packages/configprovider/doc.taro.md (1)

32-32: 文档路径更新已匹配最新主题文件格式

文档从 .scss 文件改为 .css 文件的引用,对使用者而言更直观简洁,且与多主题输出方案保持一致,无需额外处理。

scripts/build-taro.mjs (2)

235-251: 逻辑可行,但需关注文件存在性

generateAllStyles 函数内通过 projectID 动态选择 variables-${projectID}.scss。在实际使用时,请验证该文件确实存在,并考虑在文件缺失时给予合理的异常处理或回退至默认变量文件。


298-298: 多主题并行输出配置正常但需留意命名冲突

使用 input: inputFiles[name].css 输出,会分别生成多个 CSS 文件。若后续同时存在多个关联主题并使用相似命名,可能产生命名冲突,须确保 inputFiles 不会彼此覆盖。

Also applies to: 302-302

scripts/build.mjs (3)

251-251: 动态传入 Rollup 打包入口合理。
将可用主题文件映射给 Rollup 的 input 对象能灵活地生成多份主题 CSS,符合新方案的多主题设计需求。


440-440: 日志标记清晰可读。
console.timeEnd('Copy package.json readme.md') 仅用于标记时间消耗,不存在明显问题。


183-199:

❓ Verification inconclusive

建议对动态引入的 SCSS 文件进行存在性检查,避免打包出错。
如果项目 ID 对应的 variables-${projectID}.scss 文件并不存在,Sass 编译阶段可能会报错,导致构建失败。建议在生成 import 语句之前先检查对应文件是否存在,并为不存在的情况提供降级处理或报错提示。

下面的脚本可自动检查相关文件是否存在,如未发现指定的项目 ID 变量文件,则提示确认:


🏁 Script executed:

#!/bin/bash
# Description: 检查 if styles/variables-${PROJECT_ID}.scss 是否存在
projectID="${VITE_APP_PROJECT_ID}"
if [ -n "$projectID" ]; then
  filePath="${projectID}"
  echo "Checking existence of styles/variables-${filePath}.scss..."
  if ! fd "variables-${filePath}.scss" ./src/styles; then
    echo "Warning: styles/variables-${filePath}.scss could not be found. Please confirm."
    exit 1
  fi
fi

Length of output: 28


建议对动态引入的 SCSS 文件进行存在性检查及环境变量的配置验证
当前构建逻辑会根据 VITE_APP_PROJECT_ID 动态生成对应的变量 SCSS 文件引用,但从验证脚本的输出看,该环境变量为空,导致检查逻辑根本未执行。如果项目预期中会配置 VITE_APP_PROJECT_ID,建议在生成 import 语句之前先确认对应文件(如 styles/variables-${VITE_APP_PROJECT_ID}.scss)是否存在,并在文件缺失时提供备选方案或明确的错误提示。请检查环境变量的设置是否符合预期,并考虑在脚本中增加对默认情况(例如未设置项目 ID 时使用 variables.scss)的处理。

@xiaoyatong xiaoyatong merged commit d4dfbc4 into jdf2e:feat_v3.x Feb 27, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Target branch 3.x action:review This PR needs more reviews (less than 2 approvals) size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants