Skip to content

Comments

feat:增加一个以组为单位的编译逻辑#3042

Merged
oasis-cloud merged 2 commits intojdf2e:feat_v3.xfrom
xiaoyatong:feat-tool
Mar 4, 2025
Merged

feat:增加一个以组为单位的编译逻辑#3042
oasis-cloud merged 2 commits intojdf2e:feat_v3.xfrom
xiaoyatong:feat-tool

Conversation

@xiaoyatong
Copy link
Collaborator

@xiaoyatong xiaoyatong commented Mar 4, 2025

🤔 这个变动的性质是?

  • 新特性提交
  • 日常 bug 修复
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

💡 需求背景和解决方案

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • fork仓库代码是否为最新避免文件冲突
  • Files changed 没有 package.json lock 等无关文件

Summary by CodeRabbit

  • 新功能

    • 引入新环境变量,增强了内容显示的定制性。
    • 新增辅助逻辑,更灵活地控制页面内容的展示。
  • 重构

    • 更新部分代码为更现代的写法,提升了逻辑清晰度和代码可维护性。

@coderabbitai
Copy link

coderabbitai bot commented Mar 4, 2025

Walkthrough

scripts/harmony/update-taro-entry.js 文件中,引入了环境变量 paramG,并将原有的 specialComponent 函数重构为箭头函数。新增了 isShow 辅助函数,用于封装判断某项是否显示的逻辑。同时,在 createConfig 函数中,逻辑被调整为:如果 paramG 存在且与 item.enName 匹配,则遍历 item.packages 并在通过 isShow 检查后将页面添加到 co.pages,否则沿用之前的判断逻辑并调用 specialComponent

Changes

文件路径 修改内容
scripts/harmony/update-taro-entry.js - 新增环境变量 paramG
- 将 specialComponent 改为箭头函数
- 新增辅助函数 isShow
- 优化 createConfig 内部逻辑,优先判断 paramG

Sequence Diagram(s)

sequenceDiagram
    participant C as createConfig
    participant E as paramG(环境变量)
    participant I as isShow
    participant S as specialComponent
    participant P as Packages遍历

    C->>E: 获取paramG
    alt paramG存在且匹配item.enName
       C->>P: 遍历item.packages
       P->>I: 调用isShow判断
       I-->>P: 返回判断结果
       P-->>C: 添加符合条件的页面至co.pages
    else
       C->>I: 调用isShow判断
       alt isShow返回true
          C->>S: 调用specialComponent处理
       end
    end
Loading

Possibly related PRs

Suggested reviewers

  • oasis-cloud

Poem

小兔跳跃在代码林,
新变量闪耀映晨曦。
isShow判定轻如风,
箭头函数舞动奇迹。
环境 paramG 领路前行,
代码花园因你更美丽。
🐇✨ Happy coding!

✨ 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 Mar 4, 2025
@codecov
Copy link

codecov bot commented Mar 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.05%. Comparing base (827ab5c) to head (bc4fb53).
Report is 6 commits behind head on feat_v3.x.

Additional details and impacted files
@@            Coverage Diff             @@
##           feat_v3.x    #3042   +/-   ##
==========================================
  Coverage      86.05%   86.05%           
==========================================
  Files            281      281           
  Lines          18255    18255           
  Branches        2749     2749           
==========================================
  Hits           15709    15709           
  Misses          2541     2541           
  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 (2)
scripts/harmony/update-taro-entry.js (2)

9-9: 代码风格建议

paramG变量声明后有多余的空格。建议保持一致的代码风格。

-const paramG = process.env.G
-   
+const paramG = process.env.G
+

7-48: 整体功能评估:按组编译的实现

这个PR成功实现了按组编译的功能,通过环境变量G可以指定要编译的组。实现方式清晰,并且保留了原有的按组件名称过滤的功能(当不使用G时)。

代码结构上,通过引入isShow辅助函数减少了代码重复,逻辑清晰。然而,嵌套的条件判断使代码略显复杂,未来可考虑进一步重构以减少嵌套并提高可读性。

建议:

  1. 考虑为无效的paramG值添加错误处理或默认行为
  2. 添加或更新文档,说明新功能的用途和使用方法
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1f7f105 and 0cb9a56.

📒 Files selected for processing (1)
  • scripts/harmony/update-taro-entry.js (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (4)
scripts/harmony/update-taro-entry.js (4)

7-9: 添加了有用的环境变量命令示例和新参数

这些注释清晰地说明了如何使用新的环境变量G进行分组编译,包括可能的值选项。新增的paramG变量正确地从环境变量中读取,为按组编译功能提供了支持。


12-12: 将函数声明改为箭头函数

specialComponent从普通函数声明改为箭头函数表达式。这是一个语法变化,功能保持不变,符合现代JavaScript编码风格。


18-20: 提取公共逻辑到辅助函数

很好的重构,将重复的条件检查提取到单独的isShow函数中,使代码更易维护和阅读。这遵循了DRY(不要重复自己)原则。


32-48:

Details

❓ Verification inconclusive

新增按组编译的逻辑实现

实现了基于paramG环境变量的新分组编译功能。如果paramG存在并且与当前导航组匹配,则添加该组下所有符合条件的组件页面。

一个值得注意的点:在使用paramG的新代码块中,没有检查specialComponent函数(即忽略了C环境变量的过滤)。如果这是有意为之,那么这个变化是合理的,因为它允许按组编译而不受组件名称过滤的影响。

是否有意在使用paramG时忽略C环境变量的过滤?请确认这是预期行为。


🏁 Script executed:

#!/bin/bash
# 检查是否有任何地方同时使用了G和C环境变量
grep -r "process.env.[GC]" --include="*.js" .

Length of output: 5880


确认按组编译逻辑是否预期跳过组件名称过滤

该部分代码实现了基于 paramG 环境变量的分组编译功能,其中:

  • paramG 存在且与当前导航组匹配时,直接对所有满足 isShow(it) 条件的组件页面进行添加;
  • paramG 不存在时,会先检查 process.env.C(通过 param 变量)并进一步调用 specialComponent 对组件名称进行过滤后再添加页面。

请确认这是否符合预期设计:在使用 paramG 进行分组编译时,是否有意跳过对组件名称的过滤逻辑(即忽略 specialComponent 检查)?

@xiaoyatong xiaoyatong requested a review from irisSong March 4, 2025 12:12
@oasis-cloud oasis-cloud merged commit 5d80f0a into jdf2e:feat_v3.x Mar 4, 2025
8 checks passed
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 (3)
scripts/harmony/update-taro-entry.js (3)

18-20: 良好的代码重构,抽取公共判断逻辑

将组件是否显示的判断条件抽取为 isShow 辅助函数,提高了代码可读性和维护性。

不过建议添加简单的函数文档注释,说明该函数的用途和判断条件。

+/**
+ * 判断组件是否应该显示
+ * @param {Object} item - 组件配置项
+ * @return {Boolean} - 是否应该显示
+ */
const isShow = (item) => {
  return !(item.exportEmpty == false) && item.show && item.taro
}

32-40: 实现了基于组筛选的核心逻辑

这段代码实现了按导航组(paramG)进行筛选的功能。当用户指定了特定导航组时,只会构建该组下的所有符合条件的组件。

不过,当 paramG 值不匹配任何 item.enName 时,可能导致没有组件被包含。建议添加错误处理或日志输出,提示用户输入了无效的导航组名称。

if(paramG) {
+  let matched = false;
   if(paramG === item.enName){
+    matched = true;
     item.packages.map((it) => {
       if (isShow(it)) {
         co.pages.push(`pages/${it.name.toLowerCase()}/index`)
       }
     })
   } 
+  if(paramG && !matched && item.enName === config.nav[0].enName) {
+    console.warn(`警告: 未找到名为 "${paramG}" 的导航组,请检查输入是否正确。可用的导航组: ${config.nav.map(n => n.enName).join(', ')}`)
+  }
}

41-48: 保留了原有的按组件名筛选逻辑

这段代码保留了原有的功能,如果没有指定 paramG,则回退到使用 param 环境变量按组件名称进行筛选的逻辑。

需要注意的是,当同时定义 paramGparam 时,param 的筛选条件会被忽略。如果这是预期行为,建议在注释中说明;如果需要两者都生效,可以考虑修改逻辑。

// G=nav pnpm dev:jdtaro:jdharmonycpp 
// base | layout | nav | dentry | dataentry | feedback | exhibition | business 
const paramG = process.env.G

// C=radio pnpm dev:jdtaro:jdharmonycpp or C=radio,button,cell pnpm dev:jdtaro:jdharmonycpp
+// 注意:当同时指定 G 和 C 参数时,只有 G 参数会生效
const specialComponent = (name) => {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0cb9a56 and bc4fb53.

📒 Files selected for processing (1)
  • scripts/harmony/update-taro-entry.js (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (2)
scripts/harmony/update-taro-entry.js (2)

7-9: 新增了按组构建的环境变量参数

这里添加了一个新的环境变量 paramG 来支持按导航组进行组件筛选,注释中清晰地说明了使用方法和可选值。


11-16: 函数风格优化,从命名函数改为箭头函数

specialComponent 从普通函数改为箭头函数,保持了功能不变的同时使代码风格更现代化。

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/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants